BxTasksMenuTimer.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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' => 'pause', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.pause(this, ' . $this->_iContentId . ', ' . $this->_iProfileId . ')', 'target' => '_self', 'title' => _t('_bx_tasks_txt_timer_pause')],
  47. ['name' => 'log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  48. ['name' => 'edit-and-log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  49. ];
  50. else
  51. $aItems = [
  52. ['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')],
  53. ['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')],
  54. ['name' => 'log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  55. ['name' => 'edit-and-log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  56. ];
  57. }
  58. else {
  59. $aItems = [
  60. ['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')],
  61. ['name' => 'time', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  62. ];
  63. }
  64. return $aItems;
  65. }
  66. protected function _getMenuItemTime($aItem, $aParams = [])
  67. {
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. $iId = $this->_iContentId;
  70. $sObject = $CNF['OBJECT_REPORTS_TIME'];
  71. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  72. if(!$oObject || !$oObject->isEnabled())
  73. return '';
  74. $aObjectOptions = [
  75. 'dynamic_mode' => $this->_bDynamicMode,
  76. 'show_do_report_as_button' => $this->_bShowAsButton,
  77. 'show_do_report_label' => $this->_bShowTitle,
  78. 'show_do_report_icon' => false,
  79. 'show_counter' => false
  80. ];
  81. if($aParams && is_array($aParams))
  82. $aObjectOptions = array_merge($aObjectOptions, $aParams);
  83. if($this->_bIsApi)
  84. return [
  85. 'id' => $aItem['id'],
  86. 'name' => $aItem['name'],
  87. 'display_type' => 'element',
  88. 'data' => $oObject->getElementApi($aObjectOptions)
  89. ];
  90. return $oObject->getElementBlock($aObjectOptions);
  91. }
  92. protected function _getMenuItemLog($aItem)
  93. {
  94. return $this->_getMenuItemTime($aItem, [
  95. 'uniq_id' => genRndPwd(3, false),
  96. 'show_do_report_form' => false,
  97. 'do_report_label' => '_bx_tasks_txt_timer_log'
  98. ]);
  99. }
  100. protected function _getMenuItemEditAndLog($aItem)
  101. {
  102. return $this->_getMenuItemTime($aItem, [
  103. 'do_report_label' => '_bx_tasks_txt_timer_edit_and_log'
  104. ]);
  105. }
  106. protected function _getMenuItemDefault($aItem)
  107. {
  108. if($this->_bIsApi)
  109. return $aItem;
  110. $aItem['class_wrp'] = 'bx-tasks-timer-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  111. if($this->_bShowAsButton)
  112. $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  113. if(!$this->_bShowTitle)
  114. $aItem['bx_if:title']['condition'] = false;
  115. return parent::_getMenuItemDefault ($aItem);
  116. }
  117. }
  118. /** @} */