BxBaseModGeneralGridAdministration.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. 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 = 'administration';
  25. $this->_sParamsDivider = '#-#';
  26. }
  27. public function performActionDelete($aParams = array())
  28. {
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. $iAffected = 0;
  31. $aIds = bx_get('ids');
  32. if(!$aIds || !is_array($aIds)) {
  33. $this->_echoResultJson(array());
  34. exit;
  35. }
  36. $aIdsAffected = array ();
  37. foreach($aIds as $iId) {
  38. $aContentInfo = $this->_getContentInfo($iId);
  39. if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  40. continue;
  41. if(!$this->_doDelete($iId, $aParams))
  42. continue;
  43. if(!$this->_onDelete($iId, $aParams))
  44. continue;
  45. $this->_oModule->checkAllowedDelete($aContentInfo, true);
  46. $aIdsAffected[] = $iId;
  47. $iAffected++;
  48. }
  49. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
  50. }
  51. protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  52. {
  53. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  54. $sMenuName = $this->_oModule->_oConfig->CNF['OBJECT_MENU_MANAGE_TOOLS'];
  55. bx_import('BxDolMenu');
  56. $sMenu = BxDolMenu::getObjectInstance($sMenuName)->getCode();
  57. if(empty($sMenu))
  58. return '';
  59. $a['attr'] = array_merge($a['attr'], array(
  60. "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
  61. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
  62. ));
  63. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  64. }
  65. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  66. {
  67. if(empty($sFilterName) || empty($aFilterValues))
  68. return '';
  69. $CNF = &$this->_oModule->_oConfig->CNF;
  70. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  71. foreach($aFilterValues as $sKey => $sValue)
  72. $aFilterValues[$sKey] = _t($sValue);
  73. $aInputModules = array(
  74. 'type' => 'select',
  75. 'name' => $sFilterName,
  76. 'attrs' => array(
  77. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  78. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  79. ),
  80. 'value' => $sFilterValue,
  81. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  82. );
  83. bx_import('BxTemplFormView');
  84. $oForm = new BxTemplFormView(array());
  85. return $oForm->genRow($aInputModules);
  86. }
  87. protected function _getSearchInput()
  88. {
  89. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  90. $aInputSearch = array(
  91. 'type' => 'text',
  92. 'name' => 'search',
  93. 'attrs' => array(
  94. 'id' => 'bx-grid-search-' . $this->_sObject,
  95. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $sJsObject . '.onChangeFilter(this)'
  96. )
  97. );
  98. bx_import('BxTemplFormView');
  99. $oForm = new BxTemplFormView(array());
  100. return $oForm->genRow($aInputSearch);
  101. }
  102. protected function _getContentInfo($iId)
  103. {
  104. return $this->_oModule->_oDb->getContentInfoById($iId);
  105. }
  106. protected function _doDelete($iId, $aParams = array())
  107. {
  108. return $this->_oModule->serviceDeleteEntity($iId) == '';
  109. }
  110. protected function _onDelete($iId, $aParams = array())
  111. {
  112. return true;
  113. }
  114. }
  115. /** @} */