BxTasksMenuTimer.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. * @defgroup Tasks Tasks
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. class BxTasksMenuTimer extends BxTemplMenuCustom
  11. {
  12. protected $_sModule;
  13. protected $_oModule;
  14. protected $_iContentId;
  15. protected $_iProfileId;
  16. protected $_bShowAsButton;
  17. protected $_bShowTitle;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. parent::__construct($aObject, $oTemplate);
  21. $this->_sModule = 'bx_tasks';
  22. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  23. $this->_iContentId = 0;
  24. $this->_iProfileId = 0;
  25. $this->_bShowAsButton = true;
  26. $this->_bShowTitle = true;
  27. }
  28. public function setParams($iContentId, $iProfileId)
  29. {
  30. $this->_iContentId = $iContentId;
  31. $this->_iProfileId = $iProfileId;
  32. }
  33. protected function getMenuItemsRaw ()
  34. {
  35. $sPrefix = str_replace('_', '-', $this->_oModule->_oConfig->getName());
  36. $sJsObject = $this->_oModule->_oConfig->getJsObject('timer');
  37. $aTimer = $this->_oModule->_oDb->getTimers([
  38. 'sample' => 'content_profile_ids',
  39. 'content_id' => $this->_iContentId,
  40. 'profile_id' => $this->_iProfileId
  41. ]);
  42. $aItems = [];
  43. if($aTimer && is_array($aTimer)) {
  44. if((int)$aTimer['started'] > 0)
  45. $aItems = [
  46. ['name' => 'stop', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.stop(this, ' . $this->_iContentId . ', ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timer_stop')],
  47. ];
  48. else
  49. $aItems = [
  50. ['name' => 'resume', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.resume(this, ' . $this->_iContentId . ', ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timer_resume')],
  51. ['name' => 'clear', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.clear(this, ' . $this->_iContentId . ', ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timer_clear')],
  52. ['name' => 'log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  53. ];
  54. }
  55. else {
  56. $aItems = [
  57. ['name' => 'start', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.start(this, ' . $this->_iContentId . ', ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timer_start')],
  58. ['name' => 'time', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  59. ];
  60. }
  61. return $aItems;
  62. }
  63. protected function _getMenuItemTime($aItem, $aParams = [])
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. $iId = $this->_iContentId;
  67. $sObject = $CNF['OBJECT_REPORTS_TIME'];
  68. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  69. if(!$oObject || !$oObject->isEnabled())
  70. return '';
  71. $aObjectOptions = [
  72. 'dynamic_mode' => $this->_bDynamicMode,
  73. 'show_do_report_as_button' => $this->_bShowAsButton,
  74. 'show_do_report_label' => $this->_bShowTitle,
  75. 'show_do_report_icon' => false,
  76. 'show_counter' => false
  77. ];
  78. if($aParams && is_array($aParams))
  79. $aObjectOptions = array_merge($aObjectOptions, $aParams);
  80. if($this->_bIsApi)
  81. return [
  82. 'id' => $aItem['id'],
  83. 'name' => $aItem['name'],
  84. 'display_type' => 'element',
  85. 'data' => $oObject->getElementApi($aObjectOptions)
  86. ];
  87. return $oObject->getElementBlock($aObjectOptions);
  88. }
  89. protected function _getMenuItemLog($aItem)
  90. {
  91. return $this->_getMenuItemTime($aItem, [
  92. 'do_report_label' => '_bx_tasks_txt_timer_log'
  93. ]);
  94. }
  95. protected function _getMenuItemDefault($aItem)
  96. {
  97. if($this->_bIsApi)
  98. return $aItem;
  99. $aItem['class_wrp'] = 'bx-tasks-timer-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  100. if($this->_bShowAsButton)
  101. $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  102. if(!$this->_bShowTitle)
  103. $aItem['bx_if:title']['condition'] = false;
  104. return parent::_getMenuItemDefault ($aItem);
  105. }
  106. }
  107. /** @} */