BxBaseModGeneralGridAdministration.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 DolphinModules
  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, $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. $sFilterField = '_s' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sFilterName)));
  78. foreach($aFilterValues as $sKey => $sValue)
  79. $aFilterValues[$sKey] = _t($sValue);
  80. $aInputModules = array(
  81. 'type' => 'select',
  82. 'name' => $sFilterName,
  83. 'attrs' => array(
  84. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  85. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  86. ),
  87. 'value' => $this->$sFilterField,
  88. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  89. );
  90. bx_import('BxTemplFormView');
  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. bx_import('BxTemplFormView');
  106. $oForm = new BxTemplFormView(array());
  107. return $oForm->genRow($aInputSearch);
  108. }
  109. protected function _onDelete($iId, $aParams = array())
  110. {
  111. return true;
  112. }
  113. }
  114. /** @} */