BxBaseModGeneralGridAdministration.php 4.7 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 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. $sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
  28. $sPrefixClass = $this->_oModule->_oConfig->getClassPrefix();
  29. //TODO: remove this check when 'delete with content' feature will be realized in onDelete method.
  30. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  31. $this->_echoResultJson(array('msg' => 'TODO: delete with content'));
  32. return;
  33. }
  34. $iAffected = 0;
  35. $aIds = bx_get('ids');
  36. if(!$aIds || !is_array($aIds)) {
  37. $this->_echoResultJson(array());
  38. exit;
  39. }
  40. bx_import('FormsEntryHelper', $this->_oModule->_aModule);
  41. $sClass = $sPrefixClass . 'FormsEntryHelper';
  42. $oFormsHelper = new $sClass($this->_oModule);
  43. $aIdsAffected = array ();
  44. foreach($aIds as $iId) {
  45. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  46. if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  47. continue;
  48. if($oFormsHelper->deleteData($iId) != '')
  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($sPrefixLang . '_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. $sMenu = BxDolMenu::getObjectInstance($sMenuName)->getCode();
  64. if(empty($sMenu))
  65. return '';
  66. $a['attr'] = array_merge($a['attr'], array(
  67. "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
  68. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
  69. ));
  70. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  71. }
  72. protected function _getFilterSelectOne($sFilterName, $aFilterValues)
  73. {
  74. if(empty($sFilterName) || empty($aFilterValues))
  75. return '';
  76. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  77. $sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
  78. $sFilterField = '_s' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sFilterName)));
  79. foreach($aFilterValues as $sKey => $sValue)
  80. $aFilterValues[$sKey] = _t($sValue);
  81. $aInputModules = array(
  82. 'type' => 'select',
  83. 'name' => $sFilterName,
  84. 'attrs' => array(
  85. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  86. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  87. ),
  88. 'value' => $this->$sFilterField,
  89. 'values' => array_merge(array('' => _t($sPrefixLang . '_grid_filter_item_title_adm_select_one')), $aFilterValues)
  90. );
  91. bx_import('BxTemplFormView');
  92. $oForm = new BxTemplFormView(array());
  93. return $oForm->genRow($aInputModules);
  94. }
  95. protected function _getSearchInput()
  96. {
  97. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  98. $aInputSearch = array(
  99. 'type' => 'text',
  100. 'name' => 'search',
  101. 'attrs' => array(
  102. 'id' => 'bx-grid-search-' . $this->_sObject,
  103. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $sJsObject . '.onChangeFilter(this)'
  104. )
  105. );
  106. bx_import('BxTemplFormView');
  107. $oForm = new BxTemplFormView(array());
  108. return $oForm->genRow($aInputSearch);
  109. }
  110. protected function _onDelete($iId, $aParams = array())
  111. {
  112. return true;
  113. }
  114. }
  115. /** @} */