BxRibbonsModule.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 Ribbons Ribbons
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxRibbonsModule extends BxBaseModGeneralModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. /**
  18. * ACTION METHODS
  19. */
  20. public function actionGetRibbons($iProfileId)
  21. {
  22. if($this->checkAllowed(true) != CHECK_ACTION_RESULT_ALLOWED)
  23. echo '';
  24. echo BxTemplFunctions::getInstance()->transBox('bx_ribbons', $this->_oTemplate->getRibbonsForSelector($iProfileId));
  25. }
  26. public function actionSetRibbons($iProfileId, $sRibbonsIds)
  27. {
  28. if($this->checkAllowed(true) != CHECK_ACTION_RESULT_ALLOWED)
  29. echo '';
  30. $this->_oDb->clearRibbonsForProfile($iProfileId);
  31. $aTmp = explode(',', $sRibbonsIds);
  32. foreach($aTmp as $iId){
  33. $this->_oDb->addRibbonToProfile($iProfileId, $iId);
  34. }
  35. }
  36. /**
  37. * SERVICE METHODS
  38. */
  39. /**
  40. * @page service Service Calls
  41. * @section bx_ribbons Ribbons
  42. * @subsection bx_ribbons-page_blocks Page Blocks
  43. * @subsubsection bx_ribbons-include_js include_js
  44. *
  45. * @code bx_srv('bx_ribbons', 'include_js', [...]); @endcode
  46. *
  47. * Get HTML for JS code including.
  48. *
  49. * @return HTML code
  50. *
  51. * @see BxRibbonsModule::serviceIncludeJs
  52. */
  53. /**
  54. * @ref bx_ribbons-include_js "include_js"
  55. */
  56. public function serviceIncludeJs ()
  57. {
  58. $this->_oTemplate->addJs(array('main.js'));
  59. return $this->_oTemplate->getJsCode('ribbons');
  60. }
  61. /**
  62. * @page service Service Calls
  63. * @section bx_ribbons Ribbons
  64. * @subsection bx_ribbons-page_blocks Page Blocks
  65. * @subsubsection bx_ribbons-get_ribbons_manage get_ribbons_manage
  66. *
  67. * @code bx_srv('bx_ribbons', 'get_ribbons_manage', [...]); @endcode
  68. *
  69. * Get HTML form for manage.
  70. *
  71. * @return HTML form code
  72. *
  73. * @see BxRibbonsModule::serviceGetRibbonsManage
  74. */
  75. /**
  76. * @ref bx_ribbons-get_ribbons_manage "get_ribbons_manage"
  77. */
  78. public function serviceGetRibbonsManage()
  79. {
  80. $this->_oTemplate->addJs('jquery.form.min.js');
  81. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
  82. if(!$oGrid)
  83. return '';
  84. return $oGrid->getCode();
  85. }
  86. /**
  87. * @page service Service Calls
  88. * @section bx_ribbons Ribbons
  89. * @subsection bx_ribbons-page_blocks Page Blocks
  90. * @subsubsection bx_ribbons-get_ribbons get_ribbons
  91. *
  92. * @code bx_srv('bx_ribbons', 'get_ribbons', [...]); @endcode
  93. *
  94. * Get HTML code for block.
  95. *
  96. * @param $iProfileId integer value with profile ID.
  97. * @return form code
  98. *
  99. * @see BxRibbonsModule::serviceGetRibbons
  100. */
  101. /**
  102. * @ref bx_ribbons-get_ribbons "get_ribbons"
  103. */
  104. public function serviceGetRibbons($iProfileId)
  105. {
  106. return $this->_oTemplate->getRibbonsForBlock($iProfileId);
  107. }
  108. /**
  109. * @page service Service Calls
  110. * @section bx_ribbons Ribbons
  111. * @subsection bx_ribbons-page_blocks Page Blocks
  112. * @subsubsection bx_ribbons-include_js get_modules
  113. *
  114. * @code bx_srv('bx_ribbons', 'get_modules', [...]); @endcode
  115. *
  116. * Get array of profiles modules for options
  117. *
  118. * @return array
  119. *
  120. * @see BxRibbonsModule::serviceGetModules
  121. */
  122. /**
  123. * @ref bx_ribbons-get_modules "get_modules"
  124. */
  125. public function serviceGetModules()
  126. {
  127. $aResult = array();
  128. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  129. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  130. foreach($aModules as $aModule){
  131. if(BxDolRequest::serviceExists($aModule['name'], 'act_as_profile')){
  132. $aResult[$aModule['name']] = $aModule['title'];
  133. }
  134. }
  135. return $aResult;
  136. }
  137. // ====== PERMISSION METHODS
  138. /**
  139. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  140. */
  141. public function checkAllowedAdd ($isPerformAction = false)
  142. {
  143. return $this->checkAllowed($isPerformAction);
  144. }
  145. /**
  146. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  147. */
  148. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  149. {
  150. return $this->checkAllowed($isPerformAction);
  151. }
  152. /**
  153. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  154. */
  155. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  156. {
  157. return $this->checkAllowed($isPerformAction);
  158. }
  159. /**
  160. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  161. */
  162. public function checkAllowedSetThumb ($iContentId = 0)
  163. {
  164. return CHECK_ACTION_RESULT_ALLOWED;
  165. }
  166. private function checkAllowed($isPerformAction = false)
  167. {
  168. $aCheck = checkActionModule($this->_iProfileId, 'use ribbons', $this->getName(), $isPerformAction);
  169. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  170. return _t('_sys_txt_access_denied');
  171. return CHECK_ACTION_RESULT_ALLOWED;
  172. }
  173. }
  174. /** @} */