BxBaseModGeneralGridAdministration.php 5.6 KB

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