BxClssModule.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Classes Classes
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Classes module
  13. */
  14. class BxClssModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. $CNF = &$this->_oConfig->CNF;
  20. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  21. $CNF['FIELD_PUBLISHED'],
  22. $CNF['FIELD_CMTS_SETTINGS'],
  23. $CNF['FIELD_AVAIL_SETTINGS'],
  24. $CNF['FIELD_START_DATE'],
  25. $CNF['FIELD_END_DATE'],
  26. ));
  27. }
  28. public function actionReorderClasses($iProfileId = 0)
  29. {
  30. $oProfileContext = $iProfileId ? BxDolProfile::getInstance($iProfileId) : null;
  31. if (!$oProfileContext) {
  32. echo _t('_sys_txt_error_occured');
  33. exit;
  34. }
  35. // TODO: check permission for reordering
  36. foreach ($_REQUEST as $k => $v) {
  37. if (0 !== strncmp($k, 'classes_order_', 14))
  38. continue;
  39. $iModuleId = (int)str_replace('classes_order_', '', $k);
  40. if (!$iModuleId)
  41. continue;
  42. $aClassesOrder = explode(',', $v);
  43. if (!$aClassesOrder || !is_array($aClassesOrder))
  44. continue;
  45. $this->_oDb->updateClassesOrder($iProfileId, $iModuleId, $aClassesOrder);
  46. }
  47. }
  48. public function actionReorderModules($iProfileId = 0)
  49. {
  50. $oProfileContext = $iProfileId ? BxDolProfile::getInstance($iProfileId) : null;
  51. if (!$oProfileContext) {
  52. echo _t('_sys_txt_error_occured');
  53. exit;
  54. }
  55. // TODO: check permission for reordering
  56. $aModulesOrder = bx_get('modules_order');
  57. if (!$aModulesOrder || !is_array($aModulesOrder)) {
  58. echo _t('_sys_txt_error_occured');
  59. exit;
  60. }
  61. $this->_oDb->updateModulesOrder($iProfileId, $aModulesOrder);
  62. }
  63. public function actionAddModule($iProfileId = 0)
  64. {
  65. $oProfileContext = $iProfileId ? BxDolProfile::getInstance($iProfileId) : null;
  66. if (!$oProfileContext) {
  67. echoJson(array('action' => 'ShowMsg', 'msg' => _t('_sys_txt_error_occured')));
  68. exit;
  69. }
  70. // TODO: check permission for adding to context
  71. $aForm = array(
  72. 'form_attrs' => array(
  73. 'id' => 'bx-classes-module-add',
  74. 'action' => BX_DOL_URL_ROOT . 'modules/index.php?r=classes/add_module/' . $iProfileId,
  75. 'method' => 'post',
  76. ),
  77. 'params' => array (
  78. 'db' => array(
  79. 'submit_name' => 'do_submit',
  80. 'table' => $this->_oConfig->CNF['TABLE_MODULES'],
  81. 'key' => 'id',
  82. ),
  83. ),
  84. 'inputs' => array(
  85. 'module_title' => array(
  86. 'type' => 'text',
  87. 'name' => 'module_title',
  88. 'caption' => 'Module title', // TODO: translate
  89. 'checker' => array(
  90. 'func' => 'Avail',
  91. 'error' => 'Something must be entered', // TODO: translate
  92. ),
  93. 'db' => array('pass' => 'Xss'),
  94. ),
  95. 'submit' => array(
  96. 'type' => 'input_set',
  97. 0 => array (
  98. 'type' => 'submit',
  99. 'name' => 'do_submit',
  100. 'value' => _t('_Submit'),
  101. ),
  102. 1 => array (
  103. 'type' => 'reset',
  104. 'name' => 'close',
  105. 'value' => _t('_Cancel'),
  106. 'attrs' => array(
  107. 'class' => 'bx-def-margin-sec-left',
  108. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide();",
  109. ),
  110. ),
  111. ),
  112. ),
  113. );
  114. $oForm = new BxTemplFormView($aForm);
  115. $oForm->initChecker();
  116. if ($oForm->isSubmittedAndValid()) {
  117. $iModuleId = $oForm->insert(array(
  118. 'profile_id' => $iProfileId,
  119. 'author' => bx_get_logged_profile_id(),
  120. 'added' => time(),
  121. 'changed' => time(),
  122. 'order' => 123, // TODO: calc max order
  123. ));
  124. if ($iModuleId) {
  125. echoJson(array('action' => 'ReloadLessonsAndClosePopup'));
  126. }
  127. else {
  128. echoJson(array('action' => 'ShowMsg', 'msg' => _t('_sys_txt_error_occured')));
  129. }
  130. }
  131. else {
  132. echo $this->_oTemplate->parseHtmlByName('classes_add_module_form.html', array(
  133. 'form' => $oForm->getCode(),
  134. 'profile_id' => $iProfileId,
  135. ));
  136. }
  137. }
  138. /**
  139. * Entry post for Timeline module
  140. */
  141. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  142. {
  143. $CNF = &$this->_oConfig->CNF;
  144. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  145. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  146. return $aResult;
  147. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  148. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  149. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  150. return $aResult;
  151. }
  152. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  153. {
  154. $CNF = &$this->_oConfig->CNF;
  155. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  156. if (1 == $aContentInfo[$CNF['FIELD_CMTS_SETTINGS']])
  157. return false;
  158. return parent::serviceCheckAllowedCommentsPost($iContentId, $sObjectComments);
  159. }
  160. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  161. {
  162. $CNF = &$this->_oConfig->CNF;
  163. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  164. if (1 == $aContentInfo[$CNF['FIELD_CMTS_SETTINGS']])
  165. return false;
  166. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  167. }
  168. public function serviceClassesInContext ($iProfileId = 0)
  169. {
  170. if (!$iProfileId)
  171. $iProfileId = (int)bx_get('id') ? bx_get('id') : bx_get('profile_id');
  172. $aInputs = array();
  173. $aModules = $this->_oDb->getEntriesModulesByContext($iProfileId);
  174. foreach ($aModules as $aModule) {
  175. $aInputs['module' . $aModule['id']] = array(
  176. 'type' => 'block_header',
  177. 'caption' => $aModule['module_title'],
  178. 'collapsed' => false,
  179. 'attrs' => array('id' => 'module_' . $aModule['id'], 'class' => ''),
  180. );
  181. $aClasses = $this->_oDb->getEntriesByModule($aModule['id']);
  182. $sContent = '';
  183. if ($aClasses) {
  184. foreach ($aClasses as $aClass) {
  185. $sContent .= $this->_oTemplate->parseHtmlByName('classes_class_row.html', array(
  186. 'id' => $aClass['id'],
  187. 'title' => $aClass['title'],
  188. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_VIEW_ENTRY'] . '&id=' . $aClass['id']),
  189. ));
  190. }
  191. }
  192. $aInputs['class_module' . $aModule['id']] = array(
  193. 'type' => 'custom',
  194. 'name' => 'class_module' . $aModule['id'],
  195. 'caption' => '',
  196. 'content' => $sContent,
  197. );
  198. }
  199. $aForm = array(
  200. 'form_attrs' => array(
  201. 'id' => 'bx-classes-list-view',
  202. ),
  203. 'inputs' => $aInputs,
  204. );
  205. $oForm = new BxTemplFormView($aForm);
  206. $oForm->setShowEmptySections(true);
  207. $this->_oTemplate->addCss('main.css');
  208. $this->_oTemplate->addJs('main.js');
  209. return $this->_oTemplate->parseHtmlByName('classes_in_context.html', array(
  210. 'profile_id' => $iProfileId,
  211. 'new_class_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-class&profile_id=' . $iProfileId),
  212. 'form' => $oForm->getCode(),
  213. ));
  214. }
  215. }
  216. /** @} */