BxBaseModGeneralGridAdministration.php 5.6 KB

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