BxBaseModGeneralGridAdministration.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. * @{
  9. */
  10. define('BX_DOL_MANAGE_TOOLS_ADMINISTRATION', 'administration');
  11. define('BX_DOL_MANAGE_TOOLS_COMMON', 'common');
  12. class BxBaseModGeneralGridAdministration extends BxTemplGrid
  13. {
  14. protected $MODULE;
  15. protected $_oModule;
  16. protected $_sManageType;
  17. protected $_sParamsDivider;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  21. if(!$oTemplate)
  22. $oTemplate = $this->_oModule->_oTemplate;
  23. parent::__construct ($aOptions, $oTemplate);
  24. $this->_sManageType = BX_DOL_MANAGE_TOOLS_ADMINISTRATION;
  25. $this->_sParamsDivider = '#-#';
  26. $this->_sDefaultSortingOrder = 'DESC';
  27. }
  28. public function performActionDelete($aParams = array())
  29. {
  30. $CNF = &$this->_oModule->_oConfig->CNF;
  31. $iAffected = 0;
  32. $aIds = bx_get('ids');
  33. if(!$aIds || !is_array($aIds)) {
  34. echoJson(array());
  35. exit;
  36. }
  37. $aIdsAffected = array ();
  38. foreach($aIds as $iId) {
  39. $aContentInfo = $this->_getContentInfo($iId);
  40. if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  41. continue;
  42. if(!$this->_doDelete($iId, $aParams))
  43. continue;
  44. if(!$this->_onDelete($iId, $aParams))
  45. continue;
  46. $this->_oModule->checkAllowedDelete($aContentInfo, true);
  47. $aIdsAffected[] = $iId;
  48. $iAffected++;
  49. }
  50. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
  51. }
  52. protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  53. {
  54. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  55. return '';
  56. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  57. }
  58. protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  59. {
  60. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  61. $sMenuName = $this->_oModule->_oConfig->CNF['OBJECT_MENU_MANAGE_TOOLS'];
  62. $oMenu = BxDolMenu::getObjectInstance($sMenuName);
  63. $oMenu->setContentId($aRow['id']);
  64. $sMenu = $oMenu->getCode();
  65. if(empty($sMenu))
  66. return '';
  67. $a['attr'] = array_merge($a['attr'], array(
  68. "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
  69. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
  70. ));
  71. return $this->_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  72. }
  73. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  74. {
  75. if(empty($sFilterName) || empty($aFilterValues))
  76. return '';
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  79. foreach($aFilterValues as $sKey => $sValue)
  80. $aFilterValues[$sKey] = _t($sValue);
  81. $aInputModules = array(
  82. 'type' => 'select',
  83. 'name' => $sFilterName,
  84. 'attrs' => array(
  85. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  86. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  87. ),
  88. 'value' => $sFilterValue,
  89. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  90. );
  91. $oForm = new BxTemplFormView(array());
  92. return $oForm->genRow($aInputModules);
  93. }
  94. protected function _getSearchInput()
  95. {
  96. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  97. $aInputSearch = array(
  98. 'type' => 'text',
  99. 'name' => 'search',
  100. 'attrs' => array(
  101. 'id' => 'bx-grid-search-' . $this->_sObject,
  102. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $sJsObject . '.onChangeFilter(this)'
  103. )
  104. );
  105. $oForm = new BxTemplFormView(array());
  106. return $oForm->genRow($aInputSearch);
  107. }
  108. protected function _getContentInfo($iId)
  109. {
  110. return $this->_oModule->_oDb->getContentInfoById($iId);
  111. }
  112. protected function _getManageAccountUrl($sFilter = '')
  113. {
  114. $sModuleAccounts = 'bx_accounts';
  115. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  116. return '';
  117. $sTypeUpc = strtoupper($this->_sManageType);
  118. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  119. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
  120. return '';
  121. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
  122. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sLink);
  123. if(!empty($sFilter))
  124. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  125. return $sLink;
  126. }
  127. protected function _doDelete($iId, $aParams = array())
  128. {
  129. return $this->_oModule->serviceDeleteEntity($iId) == '';
  130. }
  131. protected function _onDelete($iId, $aParams = array())
  132. {
  133. return true;
  134. }
  135. }
  136. /** @} */