BxBaseModGeneralGridAdministration.php 4.5 KB

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