BxTimelineGridManageTools.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineGridManageTools extends BxBaseModGeneralGridAdministration
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. }
  17. public function performActionDelete($aParams = array())
  18. {
  19. $CNF = &$this->_oModule->_oConfig->CNF;
  20. $iAffected = 0;
  21. $aResult = [];
  22. $aIds = bx_get('ids');
  23. if(!$aIds || !is_array($aIds))
  24. return $this->_getActionResult($aResult);
  25. $aIdsAffected = [];
  26. foreach($aIds as $iId) {
  27. $aContentInfo = $this->_oModule->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  28. if($this->_oModule->isAllowedDelete($aContentInfo) === true && $this->_oModule->deleteEvent($aContentInfo)) {
  29. $aIdsAffected[] = $iId;
  30. $iAffected++;
  31. }
  32. }
  33. if($iAffected)
  34. $aResult = !$this->_bIsApi ? ['grid' => $this->getCode(false), 'blink' => $aIdsAffected] : [];
  35. else
  36. $aResult = ['msg' => _t($CNF['T']['grid_action_err_delete'])];
  37. return $this->_getActionResult($aResult);
  38. }
  39. protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  40. {
  41. if($sType == 'single' && $this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->isAllowedDelete($aRow) !== true)
  42. return '';
  43. return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  44. }
  45. protected function _getCellDescription($mixedValue, $sKey, $aField, $aRow)
  46. {
  47. $iProfile = $this->_oModule->_oConfig->isSystem($aRow['type'], $aRow['action']) ? $aRow['owner_id'] : $aRow['object_id'];
  48. $oProfile = $this->_getProfileObject($iProfile);
  49. $mixedValue = $this->_oTemplate->parseHtmlByName('grid_link.html', [
  50. 'href' => $this->_oModule->serviceGetLink($aRow['id']),
  51. 'target' => '_blank',
  52. 'title' => bx_replace_markers($aRow['description'], [
  53. 'profile_name' => $oProfile->getDisplayName()
  54. ])
  55. ]);
  56. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  57. }
  58. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  59. {
  60. if($this->_bIsApi)
  61. return ['type' => 'time', 'data' => $mixedValue];
  62. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  63. }
  64. protected function _switcherChecked2State($isChecked)
  65. {
  66. return $isChecked ? 'active' : 'hidden';
  67. }
  68. protected function _switcherState2Checked($mixedState)
  69. {
  70. return 'active' == $mixedState ? true : false;
  71. }
  72. protected function _enable ($mixedId, $isChecked)
  73. {
  74. $bResult = parent::_enable($mixedId, $isChecked);
  75. if(!$bResult)
  76. return $bResult;
  77. $aEvent = $this->_oModule->_oDb->getEvents(['browse' => 'id', 'value' => (int)$mixedId]);
  78. if(empty($aEvent) || !is_array($aEvent))
  79. return $bResult;
  80. $this->_oModule->{$isChecked ? 'onUnhide' : 'onHide'}($aEvent);
  81. return $bResult;
  82. }
  83. }
  84. /** @} */