BxReputationGridHandlers.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Reputation Reputation
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxReputationGridHandlers extends BxBaseModGeneralGrid
  12. {
  13. protected $_sFilter;
  14. protected $_sFilter1Name;
  15. protected $_sFilter1Value;
  16. protected $_aFilter1Values;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. $this->_sModule = 'bx_reputation';
  20. parent::__construct ($aOptions, $oTemplate);
  21. $this->_aQueryReset = array($this->_aOptions['filter_get'], $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  22. $this->_sFilter = '';
  23. if(($sFilter = $this->_getFilterValue()))
  24. $this->_sFilter = $sFilter;
  25. $this->_sFilter1Name = 'filter1';
  26. $this->_aFilter1Values = [];
  27. $aUnits = $this->_oModule->_oDb->getHandlers(['type' => 'alert_units_list']);
  28. if(!empty($aUnits) && is_array($aUnits))
  29. foreach($aUnits as $sUnit)
  30. $this->_aFilter1Values[$sUnit] = $this->_oModule->getUnitTitle($sUnit);
  31. if(($sFilter1 = bx_get($this->_sFilter1Name)) !== false) {
  32. $this->_sFilter1Value = bx_process_input($sFilter1);
  33. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  34. }
  35. }
  36. public function getCode($isDisplayHeader = true)
  37. {
  38. $mixedResult = parent::getCode($isDisplayHeader);
  39. if(!$mixedResult)
  40. return $mixedResult;
  41. return $this->_oModule->_oTemplate->getJsCode('handlers', ['sObjNameGrid' => $this->_sObject]) . $mixedResult;
  42. }
  43. public function performActionEdit()
  44. {
  45. $CNF = &$this->_oModule->_oConfig->CNF;
  46. $sAction = 'edit';
  47. $aIds = $this->_getIds();
  48. if($aIds === false)
  49. return $this->_getActionResult([]);
  50. $iHandler = array_shift($aIds);
  51. $aHandler = $this->_oModule->_oDb->getHandlers(['type' => 'by_id', 'value' => $iHandler]);
  52. if(!is_array($aHandler) || empty($aHandler))
  53. return $this->_getActionResult([]);
  54. $sForm = $CNF['OBJECT_FORM_HANDLER_DISPLAY_EDIT'];
  55. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_HANDLER'], $CNF['OBJECT_FORM_HANDLER_DISPLAY_EDIT']);
  56. $oForm->setId($sForm);
  57. $oForm->setName($sForm);
  58. $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', [
  59. 'o' => $this->_sObject,
  60. 'a' => $sAction,
  61. $this->_aOptions['filter_get'] => $this->_sFilter,
  62. 'id' => $iHandler
  63. ]));
  64. $oForm->initChecker($aHandler);
  65. if($oForm->isSubmittedAndValid()) {
  66. if(!$oForm->update($iHandler))
  67. return $this->_getActionResult(['msg' => _t($CNF['T']['err_cannot_perform'])]);
  68. return $this->_bIsApi ? [] : echoJson(['grid' => $this->getCode(false), 'blink' => $iHandler]);
  69. }
  70. if($this->_bIsApi)
  71. return $this->getFormBlockAPI($oForm, $sAction, $iHandler);
  72. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('handler_popup'), _t($CNF['T']['popup_title_handler_edit']), $this->_oModule->_oTemplate->parseHtmlByName('popup_handler.html', [
  73. 'form_id' => $oForm->getId(),
  74. 'form' => $oForm->getCode(true),
  75. 'object' => $this->_sObject,
  76. 'action' => $sAction
  77. ]));
  78. return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  79. }
  80. public function performActionActivate()
  81. {
  82. $this->_performActionEnable(true);
  83. }
  84. public function performActionDeactivate()
  85. {
  86. $this->_performActionEnable(false);
  87. }
  88. protected function _isCheckboxDisabled($aRow)
  89. {
  90. return false;
  91. }
  92. protected function _getCellAlertUnit($mixedValue, $sKey, $aField, $aRow)
  93. {
  94. return self::_getCellDefault($this->_oModule->getUnitTitle($mixedValue), $sKey, $aField, $aRow);
  95. }
  96. protected function _getCellAlertAction($mixedValue, $sKey, $aField, $aRow)
  97. {
  98. return self::_getCellDefault($this->_oModule->getActionTitle($mixedValue), $sKey, $aField, $aRow);
  99. }
  100. protected function _getFilterControls()
  101. {
  102. parent::_getFilterControls();
  103. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  104. $sContent .= $this->_getSearchInput();
  105. return $sContent;
  106. }
  107. protected function _getFilterOnChange()
  108. {
  109. return $this->_oModule->_oConfig->getJsObject('handlers') . '.onChangeFilter(this)';
  110. }
  111. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  112. {
  113. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  114. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  115. if(!empty($this->_sFilter1Value))
  116. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `alert_unit`=?", $this->_sFilter1Value);
  117. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  118. }
  119. protected function _performActionEnable($isChecked)
  120. {
  121. $CNF = &$this->_oModule->_oConfig->CNF;
  122. $aIds = bx_get('ids');
  123. if(!$aIds || !is_array($aIds))
  124. return $this->_getActionResult([]);
  125. $iAffected = 0;
  126. $aIdsAffected = array();
  127. foreach($aIds as $iId)
  128. if($this->_enable($iId, $isChecked)) {
  129. $aIdsAffected[] = $iId;
  130. $iAffected++;
  131. }
  132. if(!$iAffected)
  133. return $this->_getActionResult(['msg' => _t($CNF['T']['grid_action_err_perform'])]);
  134. return $this->_bIsApi ? [] : echoJson(['grid' => $this->getCode(false), 'blink' => $aIdsAffected]);
  135. }
  136. protected function _getIds()
  137. {
  138. $aIds = bx_get('ids');
  139. if(!$aIds || !is_array($aIds)) {
  140. $iId = (int)bx_get('id');
  141. if(!$iId)
  142. return false;
  143. $aIds = [$iId];
  144. }
  145. return $aIds;
  146. }
  147. }
  148. /** @} */