|
|
@@ -9,6 +9,12 @@
|
|
|
* @{
|
|
|
*/
|
|
|
|
|
|
+
|
|
|
+define('BX_CLASSES_AVAIL_ALWAYS', 1);
|
|
|
+define('BX_CLASSES_AVAIL_PREV_CLASS_COMPLETED', 2);
|
|
|
+define('BX_CLASSES_AVAIL_AFTER_START_DATE', 3);
|
|
|
+define('BX_CLASSES_AVAIL_AFTER_START_DATE_PREV_CLASS_COMPLETED', 4);
|
|
|
+
|
|
|
/**
|
|
|
* Classes module
|
|
|
*/
|
|
|
@@ -188,17 +194,28 @@ class BxClssModule extends BxBaseModTextModule
|
|
|
return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
|
|
|
}
|
|
|
|
|
|
- public function serviceClassesInContext ($iProfileId = 0)
|
|
|
+ public function serviceClassesInContext ($iContextProfileId = 0)
|
|
|
{
|
|
|
- if (!$iProfileId)
|
|
|
- $iProfileId = (int)bx_get('id') ? bx_get('id') : bx_get('profile_id');
|
|
|
+ if (!$iContextProfileId)
|
|
|
+ $iContextProfileId = (int)bx_get('id') ? bx_get('id') : bx_get('profile_id');
|
|
|
+
|
|
|
+ if (!($oContextProfile = BxDolProfile::getInstance($iContextProfileId)))
|
|
|
+ return MsgBox(_t('_sys_txt_error_occured'));
|
|
|
+
|
|
|
+ $mixedViewAllowed = $oContextProfile->checkAllowedProfileView();
|
|
|
+ if (CHECK_ACTION_RESULT_ALLOWED !== $mixedViewAllowed)
|
|
|
+ return MsgBox($mixedViewAllowed);
|
|
|
|
|
|
$aInputs = array();
|
|
|
- $aModules = $this->_oDb->getEntriesModulesByContext($iProfileId);
|
|
|
+ $aModules = $this->_oDb->getEntriesModulesByContext($iContextProfileId);
|
|
|
foreach ($aModules as $aModule) {
|
|
|
+ $iCounterCompleted = 0;
|
|
|
+ $iCounterAvail = 0;
|
|
|
+ $iCounterNa = 0;
|
|
|
+
|
|
|
$aInputs['module' . $aModule['id']] = array(
|
|
|
'type' => 'block_header',
|
|
|
- 'caption' => $aModule['module_title'],
|
|
|
+ 'caption' => ' ' . bx_process_output($aModule['module_title']),
|
|
|
'collapsed' => false,
|
|
|
'attrs' => array('id' => 'module_' . $aModule['id'], 'class' => ''),
|
|
|
);
|
|
|
@@ -206,14 +223,59 @@ class BxClssModule extends BxBaseModTextModule
|
|
|
$sContent = '';
|
|
|
if ($aClasses) {
|
|
|
foreach ($aClasses as $aClass) {
|
|
|
+ $sStatusClass = '';
|
|
|
+ // check class availability
|
|
|
+ $mixedAvailability = $this->checkAllowedViewForProfile($aClass, bx_get_logged_profile_id());
|
|
|
+ $sTip = '';
|
|
|
+ if ($mixedAvailability !== CHECK_ACTION_RESULT_ALLOWED) {
|
|
|
+ ++$iCounterNa;
|
|
|
+ $sStatusClass = 'bx-classes-class-status-na';
|
|
|
+ $sTip = strip_tags($mixedAvailability);
|
|
|
+ }
|
|
|
+ // check if class is completed
|
|
|
+ elseif ($this->serviceIsClassCompleted($aClass['id'])) {
|
|
|
+ ++$iCounterCompleted;
|
|
|
+ $sStatusClass = 'bx-classes-class-status-completed';
|
|
|
+ }
|
|
|
+ // class is available
|
|
|
+ else {
|
|
|
+ ++$iCounterAvail;
|
|
|
+ $sStatusClass = 'bx-classes-class-status-avail';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$sContent .= $this->_oTemplate->parseHtmlByName('classes_class_row.html', array(
|
|
|
- 'id' => $aClass['id'],
|
|
|
- 'title' => $aClass['title'] . '(' . ($this->serviceIsClassCompleted($aClass['id']) ? 'completed' : 'not completed') . ')',
|
|
|
- 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_VIEW_ENTRY'] . '&id=' . $aClass['id']),
|
|
|
+ 'id' => $aClass['id'],
|
|
|
+ 'status' => $sStatusClass,
|
|
|
+ 'bx_if:completed' => array(
|
|
|
+ 'condition' => 'bx-classes-class-status-completed' == $sStatusClass,
|
|
|
+ 'content' => array (
|
|
|
+ 'title' => bx_process_output($aClass['title']),
|
|
|
+ 'url' => $this->serviceGetLink($aClass['id']),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'bx_if:avail' => array(
|
|
|
+ 'condition' => 'bx-classes-class-status-avail' == $sStatusClass,
|
|
|
+ 'content' => array (
|
|
|
+ 'title' => bx_process_output($aClass['title']),
|
|
|
+ 'url' => $this->serviceGetLink($aClass['id']),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'bx_if:na' => array(
|
|
|
+ 'condition' => 'bx-classes-class-status-na' == $sStatusClass,
|
|
|
+ 'content' => array (
|
|
|
+ 'title' => bx_process_output($aClass['title']),
|
|
|
+ 'tip' => bx_html_attribute($sTip),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (0 == $iCounterAvail) {
|
|
|
+ $aInputs['module' . $aModule['id']]['collapsed'] = true;
|
|
|
+ }
|
|
|
+
|
|
|
$aInputs['class_module' . $aModule['id']] = array(
|
|
|
'type' => 'custom',
|
|
|
'name' => 'class_module' . $aModule['id'],
|
|
|
@@ -236,9 +298,14 @@ class BxClssModule extends BxBaseModTextModule
|
|
|
$this->_oTemplate->addJs('main.js');
|
|
|
|
|
|
return $this->_oTemplate->parseHtmlByName('classes_in_context.html', array(
|
|
|
- 'profile_id' => $iProfileId,
|
|
|
- 'new_class_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-class&profile_id=' . $iProfileId),
|
|
|
'form' => $oForm->getCode(),
|
|
|
+ 'bx_if:admin' => array(
|
|
|
+ 'condition' => isAdmin() || bx_srv($oContextProfile->getModule(), 'is_admin', array($oContextProfile->id(), bx_get_logged_profile_id())),
|
|
|
+ 'content' => array(
|
|
|
+ 'context_profile_id' => $iContextProfileId,
|
|
|
+ 'new_class_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-class&profile_id=' . $oContextProfile->id()),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@@ -249,6 +316,58 @@ class BxClssModule extends BxBaseModTextModule
|
|
|
|
|
|
return $this->_oDb->isClassCompleted($iClassId, $iProfileId);
|
|
|
}
|
|
|
+
|
|
|
+ public function serviceIsAdmin ($aDataEntry, $iProfileId = 0)
|
|
|
+ {
|
|
|
+ if (!$iProfileId)
|
|
|
+ $iProfileId = bx_get_logged_profile_id();
|
|
|
+
|
|
|
+ if (!($oProfileContext = BxDolProfile::getInstance(abs($aDataEntry['allow_view_to']))))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return bx_srv($oProfileContext->getModule(), 'is_admin', array($oProfileContext->id(), $iProfileId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function serviceIsPrevClassCompleted ($aDataEntry, $iProfileId = 0)
|
|
|
+ {
|
|
|
+ if (!$iProfileId)
|
|
|
+ $iProfileId = bx_get_logged_profile_id();
|
|
|
+
|
|
|
+ if (!($aPrevClass = $this->_oDb->getPrevEntry ($aDataEntry['id'])))
|
|
|
+ return true; // if there is no prev class it's considered as completed
|
|
|
+
|
|
|
+ return $this->serviceIsClassCompleted($aPrevClass['id'], $iProfileId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function serviceCheckAvailabilityForProfile ($aDataEntry, $iProfileId)
|
|
|
+ {
|
|
|
+ if (BX_CLASSES_AVAIL_ALWAYS == $aDataEntry['avail'] || isAdmin() || $this->serviceIsAdmin ($aDataEntry, $iProfileId))
|
|
|
+ return CHECK_ACTION_RESULT_ALLOWED;
|
|
|
+
|
|
|
+ // check start date
|
|
|
+ if ((BX_CLASSES_AVAIL_AFTER_START_DATE == $aDataEntry['avail'] || BX_CLASSES_AVAIL_AFTER_START_DATE_PREV_CLASS_COMPLETED == $aDataEntry['avail']) && $aDataEntry['start_date'] > time()) {
|
|
|
+ return _t('_bx_classes_txt_err_not_avail_before_start_date', bx_time_js($aDataEntry['start_date'], BX_FORMAT_DATE_TIME, true));
|
|
|
+ }
|
|
|
+
|
|
|
+ // check availability
|
|
|
+ if ((BX_CLASSES_AVAIL_PREV_CLASS_COMPLETED == $aDataEntry['avail'] || BX_CLASSES_AVAIL_AFTER_START_DATE_PREV_CLASS_COMPLETED == $aDataEntry['avail']) && !$this->serviceIsPrevClassCompleted($aDataEntry, $iProfileId)) {
|
|
|
+ if (!($aPrevClass = $this->_oDb->getPrevEntry ($aDataEntry['id'])))
|
|
|
+ return _t('_sys_txt_error_occured');
|
|
|
+ return _t('_bx_classes_txt_err_not_avail_before_prev_class_completed', $this->serviceGetLink($aPrevClass['id']), bx_process_output($aPrevClass['title']));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return CHECK_ACTION_RESULT_ALLOWED;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
|
|
|
+ {
|
|
|
+ $mixed = parent::_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
|
|
|
+ if (CHECK_ACTION_RESULT_ALLOWED === $mixed)
|
|
|
+ return $this->serviceCheckAvailabilityForProfile ($aDataEntry, $iProfileId);
|
|
|
+ else
|
|
|
+ return $mixed;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** @} */
|