Skip to content

Commit

Permalink
Ticket #4817 - Courses improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Nov 5, 2024
1 parent 3ccb69b commit 7ed0d5f
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 14 deletions.
18 changes: 18 additions & 0 deletions modules/boonex/courses/classes/BxCoursesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

class BxCoursesConfig extends BxBaseModGroupsConfig
{
protected $_aPerPageDefault;

function __construct($aModule)
{
parent::__construct($aModule);

$this->_aMenuItems2MethodsActions = array_merge($this->_aMenuItems2MethodsActions, array(
'view-course-profile' => 'checkAllowedView',
'edit-course-profile' => 'checkAllowedEdit',
'hide-course-profile' => 'checkAllowedHide',
'unhide-course-profile' => 'checkAllowedUnhide',
'edit-course-cover' => 'checkAllowedChangeCover',
'invite-to-course' => 'checkAllowedInvite',
'delete-course-profile' => 'checkAllowedDelete',
Expand Down Expand Up @@ -205,6 +209,7 @@ function __construct($aModule)
'status' => array (
'name' => 'bx-courses-status-not-active',
'map' => array (
'hidden' => '_bx_courses_txt_status_hidden',
BX_PROFILE_STATUS_PENDING => '_bx_courses_txt_account_pending',
BX_PROFILE_STATUS_SUSPENDED => '_bx_courses_txt_account_suspended',
),
Expand Down Expand Up @@ -307,6 +312,19 @@ function __construct($aModule)
'popup_content_node' => $sHtmlPrefix . '-popup-content-node',
'popup_content_data' => $sHtmlPrefix . '-popup-content-data',
];

$this->_aPerPageDefault = [
'default' => 12,
'structure_l1' => !$this->_bIsApi ? 2 : 9999
];
}

public function getPerPageDefault($sType)
{
if(!isset($this->_aPerPageDefault[$sType]))
$sType = 'default';

return (int)$this->_aPerPageDefault[$sType];
}

public function isContent()
Expand Down
5 changes: 4 additions & 1 deletion modules/boonex/courses/classes/BxCoursesDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public function getContentStructure($aParams)

if(isset($aParams['start'], $aParams['per_page']) && (int)$aParams['per_page'] != 0)
$sLimitClause = $aParams['start'] . ', ' . $aParams['per_page'];

$sOrderClause = "`tcs`.`order` ASC";
break;

case 'entry_id_counters':
Expand Down Expand Up @@ -343,13 +345,14 @@ public function getContentData($aParams)
];

$sWhereClause = "AND `tcd`.`entry_id`=:entry_id AND `tcd`.`node_id`=:node_id";
$sOrderClause = "`tcd`.`order` ASC";

if(isset($aParams['usage'])) {
$aMethod['params'][1]['usage'] = $aParams['usage'];

$sWhereClause .= " AND `tcd`.`usage`=:usage";
}

$sOrderClause = "`tcd`.`order` ASC";
break;

case 'siblings':
Expand Down
12 changes: 11 additions & 1 deletion modules/boonex/courses/classes/BxCoursesFormEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ public function __construct($aInfo, $oTemplate = false)
parent::__construct($aInfo, $oTemplate);

if(isset($this->aInputs['initial_members']))
$this->aInputs['initial_members']['value'] = array();
$this->aInputs['initial_members']['value'] = [];
}

public function insert ($aValsToAdd = [], $isIgnore = false)
{
$CNF = &$this->_oModule->_oConfig->CNF;

if($this->_oModule->_oConfig->isContent())
$aValsToAdd[$CNF['FIELD_STATUS']] = 'hidden';

return parent::insert ($aValsToAdd, $isIgnore);
}
}

Expand Down
21 changes: 21 additions & 0 deletions modules/boonex/courses/classes/BxCoursesGridCntDataManage.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ protected function _getActionAddAt($sType, $sKey, $a, $isSmall = false, $isDisab
return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
}

protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
{
$oModule = BxDolModule::getInstance($aRow['content_type']);
if(!$oModule)
return '';

$CNF_MODULE = &$oModule->_oConfig->CNF;
if(!isset($CNF_MODULE['URI_EDIT_ENTRY']))
return '';

$sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF_MODULE['URI_EDIT_ENTRY'] . '&id=' . $aRow['content_id']));

if($this->_bIsApi)
return array_merge($a, ['name' => $sKey, 'type' => 'link', 'url' => bx_api_get_relative_url($sUrl)]);

$a['attr'] = array_merge($a['attr'], [
"onclick" => "window.open('" . $sUrl . "', '_self');"
]);
return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
}

protected function _delete($mixedId)
{
$aData = $this->_oModule->_oDb->getContentData(['sample' => 'id', 'id' => (int)$mixedId]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function getCode ($isDisplayHeader = true)
return parent::getCode($isDisplayHeader);
}

//TODO: Need to check level and return correct title.
public function getFormBlockTitleAPI($sAction, $iId = 0)
{
$CNF = &$this->_oModule->_oConfig->CNF;
Expand Down
5 changes: 5 additions & 0 deletions modules/boonex/courses/classes/BxCoursesMenuViewActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class BxCoursesMenuViewActions extends BxBaseModGroupsMenuViewActions
public function __construct($aObject, $oTemplate = false)
{
$this->MODULE = 'bx_courses';

parent::__construct($aObject, $oTemplate);

$this->addMarkers(array(
'js_object' => $this->_oModule->_oConfig->getJsObject('entry')
));
}
}

Expand Down
110 changes: 107 additions & 3 deletions modules/boonex/courses/classes/BxCoursesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ function __construct(&$aModule)
$this->_aSearchableNamesExcept[] = $this->_oConfig->CNF['FIELD_JOIN_CONFIRMATION'];
}

public function actionPerform()
{
$CNF = &$this->_oConfig->CNF;

$mixedContent = $this->_getContent();
if($mixedContent === false)
return echoJson(['code' => 1]);

list($iContentId, $aContentInfo) = $mixedContent;

$sAction = bx_process_input(bx_get('action'));
if(empty($CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']][$sAction]))
return echoJson(['code' => 2]);

$sMethodCheck = $CNF['MENU_ITEM_TO_METHOD'][$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']][$sAction];
$sMethodPerform = '_perform' . bx_gen_method_name($sAction, ['-', '_']);
if(!method_exists($this, $sMethodCheck) || $this->$sMethodCheck($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED || !method_exists($this, $sMethodPerform))
return echoJson(['code' => 3, 'msg' => _t('_sys_txt_access_denied')]);

return echoJson($this->$sMethodPerform($aContentInfo) ? ['reload' => 1] : []);
}

public function actionPassNode()
{
$iNodeId = bx_get('node_id');
Expand All @@ -58,11 +80,33 @@ public function actionPassData()
public function serviceGetSafeServices()
{
return array_merge(parent::serviceGetSafeServices(), [
'Hide' => '',
'Publish' => '',
'PassNode' => '',
'PassData' => '',
]);
}

public function serviceHide($iContentId)
{
$aContentInfo = $this->_oDb->getContentInfoById($iContentId);

if($this->checkAllowedHide($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
return false;

return $this->_performHideCourseProfile($aContentInfo);
}

public function servicePublish($iContentId)
{
$aContentInfo = $this->_oDb->getContentInfoById($iContentId);

if($this->checkAllowedUnhide($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
return false;

return $this->_performUnhideCourseProfile($aContentInfo);
}

public function servicePassNode($iNodeId)
{
$CNF = &$this->_oConfig->CNF;
Expand Down Expand Up @@ -243,6 +287,16 @@ public function serviceOnContentAdded($sContentType, $iContentId, $iContextId, $
}

public function serviceOnContentAddedRedirect($sContentType, $iContentId)
{
return $this->serviceOnContentActionRedirect('add', $sContentType, $iContentId);
}

public function serviceOnContentEditedRedirect($sContentType, $iContentId)
{
return $this->serviceOnContentActionRedirect('edit', $sContentType, $iContentId);
}

public function serviceOnContentActionRedirect($sAction, $sContentType, $iContentId)
{
$CNF = &$this->_oConfig->CNF;

Expand Down Expand Up @@ -356,7 +410,7 @@ public function serviceEntityStructureL1Block($iContentId = 0)
'level' => 1,
'selected' => ($iNodeId = bx_get('parent_id')) !== false ? (int)$iNodeId : 0,
'start' => ($iStart = bx_get('start')) !== false ? (int)$iStart : 0,
'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : 2,
'per_page' => ($iPerPage = bx_get('per_page')) !== false ? (int)$iPerPage : $this->_oConfig->getPerPageDefault('structure_l1'),
]);

return $this->_bIsApi ? [bx_api_get_block('course_structure', $mixedResult)] : $mixedResult;
Expand Down Expand Up @@ -396,6 +450,34 @@ public function serviceEntityNodeBlock($iContentId = 0, $iNodeId = 0, $iUsage =
return $this->_bIsApi ? [bx_api_get_block('lesson_structure', $mixedResult)] : $mixedResult;
}

public function checkAllowedHide($aDataEntry, $isPerformAction = false)
{
$CNF = &$this->_oConfig->CNF;

if($aDataEntry[$CNF['FIELD_STATUS']] != 'active')
return CHECK_ACTION_RESULT_NOT_ALLOWED;

// moderator and owner always have access
if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
return CHECK_ACTION_RESULT_ALLOWED;

return CHECK_ACTION_RESULT_NOT_ALLOWED;
}

public function checkAllowedUnhide($aDataEntry, $isPerformAction = false)
{
$CNF = &$this->_oConfig->CNF;

if($aDataEntry[$CNF['FIELD_STATUS']] == 'active')
return CHECK_ACTION_RESULT_NOT_ALLOWED;

// moderator and owner always have access
if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
return CHECK_ACTION_RESULT_ALLOWED;

return CHECK_ACTION_RESULT_NOT_ALLOWED;
}

public function getNodeLevelByParent($aParentInfo)
{
return (is_array($aParentInfo) && !empty($aParentInfo['level']) ? (int)$aParentInfo['level'] : 0) + 1;
Expand Down Expand Up @@ -610,7 +692,9 @@ public function decodeDataAPI($aData, $aParams = [])
$CNF = $this->_oConfig->CNF;

$aResult = parent::decodeDataAPI($aData, $aParams);
$aResultAdd = [];
$aResultAdd = [
$CNF['FIELD_STATUS'] => $aData[CNF['FIELD_STATUS']]
];

$iEntryId = (int)$aData[$CNF['FIELD_ID']];
$aLevelToNode = $this->_oConfig->getContentLevel2Node(false);
Expand All @@ -633,7 +717,7 @@ public function decodeDataAPI($aData, $aParams = [])
$aResultAdd = [
'percent' => $iPassPercent,
'counters' => $aCounters,
'status' => $sPassStatus,
'pass_status' => $sPassStatus,
'show_pass' => $iPassPercent > 0 && $iPassPercent < 100,
];

Expand Down Expand Up @@ -675,6 +759,26 @@ protected function _getOptionsContentModules()

return $aResult;
}

protected function _performHideCourseProfile($aDataEntry) {
$CNF = &$this->_oConfig->CNF;

if(!$this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS'] => 'hidden'], [$CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']]]))
return false;

$this->checkAllowedHide($aDataEntry, true);
return true;
}

protected function _performUnhideCourseProfile($aDataEntry) {
$CNF = &$this->_oConfig->CNF;

if(!$this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS'] => 'active'], [$CNF['FIELD_ID'] => $aDataEntry[$CNF['FIELD_ID']]]))
return false;

$this->checkAllowedHide($aDataEntry, true);
return true;
}
}

/** @} */
13 changes: 13 additions & 0 deletions modules/boonex/courses/classes/BxCoursesPageEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ class BxCoursesPageEntry extends BxBaseModGroupsPageEntry
public function __construct($aObject, $oTemplate = false)
{
$this->MODULE = 'bx_courses';

parent::__construct($aObject, $oTemplate);

$CNF = &$this->_oModule->_oConfig->CNF;

$bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id();
$bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
if(($oInformer = BxDolInformer::getInstance($this->_oTemplate)) && ($bLoggedOwner || $bLoggedModerator)) {
$aInformers = [];

if($aInformers)
foreach($aInformers as $aInformer)
$oInformer->add($aInformer['name'], $this->_replaceMarkers($aInformer['msg']), $aInformer['type']);
}
}

public function getCode ()
Expand Down
Loading

0 comments on commit 7ed0d5f

Please sign in to comment.