BxTasksMenuTimer.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. $sJsObject = $this->_oModule->_oConfig->getJsObject('timer');
  36. $aTimer = $this->_oModule->_oDb->getTimers([
  37. 'sample' => 'content_profile_ids',
  38. 'content_id' => $this->_iContentId,
  39. 'profile_id' => $this->_iProfileId
  40. ]);
  41. $aItems = [];
  42. if($aTimer && is_array($aTimer)) {
  43. if((int)$aTimer['started'] > 0)
  44. $aItems = [
  45. ['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')],
  46. ['name' => 'log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  47. ['name' => 'edit-and-log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  48. ];
  49. else
  50. $aItems = [
  51. ['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')],
  52. ['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')],
  53. ['name' => 'log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  54. ['name' => 'edit-and-log', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  55. ];
  56. }
  57. else {
  58. $aItems = [
  59. ['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')],
  60. ['name' => 'time', 'class' => '', 'link' => '', 'onclick' => '', 'target' => '', 'title' => ''],
  61. ];
  62. }
  63. return $aItems;
  64. }
  65. protected function _getMenuItemStart($aItem)
  66. {
  67. if($this->_bIsApi) {
  68. return array_merge($aItem, [
  69. 'display_type' => 'callback',
  70. 'data' => [
  71. 'request_url' => $this->_sModule . '/process_timer/&params[]=start&params[]=' . $this->_iContentId . '&params[]=' . $this->_iProfileId,
  72. 'on_callback' => 'hide'
  73. ]
  74. ]);
  75. }
  76. return true;
  77. }
  78. protected function _getMenuItemPause($aItem)
  79. {
  80. if($this->_bIsApi) {
  81. return array_merge($aItem, [
  82. 'display_type' => 'callback',
  83. 'data' => [
  84. 'request_url' => $this->_sModule . '/process_timer/&params[]=pause&params[]=' . $this->_iContentId . '&params[]=' . $this->_iProfileId,
  85. 'on_callback' => 'hide'
  86. ]
  87. ]);
  88. }
  89. return true;
  90. }
  91. protected function _getMenuItemResume($aItem)
  92. {
  93. if($this->_bIsApi) {
  94. return array_merge($aItem, [
  95. 'display_type' => 'callback',
  96. 'data' => [
  97. 'request_url' => $this->_sModule . '/process_timer/&params[]=resume&params[]=' . $this->_iContentId . '&params[]=' . $this->_iProfileId,
  98. 'on_callback' => 'hide'
  99. ]
  100. ]);
  101. }
  102. return true;
  103. }
  104. protected function _getMenuItemClear($aItem)
  105. {
  106. if($this->_bIsApi) {
  107. return array_merge($aItem, [
  108. 'display_type' => 'callback',
  109. 'data' => [
  110. 'request_url' => $this->_sModule . '/process_timer/&params[]=clear&params[]=' . $this->_iContentId . '&params[]=' . $this->_iProfileId,
  111. 'on_callback' => 'hide'
  112. ]
  113. ]);
  114. }
  115. return true;
  116. }
  117. protected function _getMenuItemTime($aItem, $aParams = [])
  118. {
  119. $CNF = &$this->_oModule->_oConfig->CNF;
  120. $iId = $this->_iContentId;
  121. $sObject = $CNF['OBJECT_REPORTS_TIME'];
  122. $oObject = !empty($sObject) ? BxDolReport::getObjectInstance($sObject, $iId) : false;
  123. if(!$oObject || !$oObject->isEnabled())
  124. return '';
  125. $aObjectOptions = [
  126. 'dynamic_mode' => $this->_bDynamicMode,
  127. 'show_do_report_as_button' => $this->_bShowAsButton,
  128. 'show_do_report_label' => $this->_bShowTitle,
  129. 'show_do_report_icon' => false,
  130. 'show_counter' => false
  131. ];
  132. if($aParams && is_array($aParams))
  133. $aObjectOptions = array_merge($aObjectOptions, $aParams);
  134. if($this->_bIsApi)
  135. return [
  136. 'id' => $aItem['id'],
  137. 'name' => $aItem['name'],
  138. 'display_type' => 'element',
  139. 'data' => $oObject->getElementApi($aObjectOptions)
  140. ];
  141. return $oObject->getElementBlock($aObjectOptions);
  142. }
  143. protected function _getMenuItemLog($aItem)
  144. {
  145. return $this->_getMenuItemTime($aItem, [
  146. 'uniq_id' => genRndPwd(3, false),
  147. 'show_do_report_form' => false,
  148. 'do_report_label' => '_bx_tasks_txt_timer_log'
  149. ]);
  150. }
  151. protected function _getMenuItemEditAndLog($aItem)
  152. {
  153. return $this->_getMenuItemTime($aItem, [
  154. 'do_report_label' => '_bx_tasks_txt_timer_edit_and_log'
  155. ]);
  156. }
  157. protected function _getMenuItemDefault($aItem)
  158. {
  159. if($this->_bIsApi)
  160. return $aItem;
  161. $aItem['class_wrp'] = 'bx-tasks-timer-action' . (!empty($aItem['class_wrp']) ? ' ' . $aItem['class_wrp'] : '');
  162. if($this->_bShowAsButton)
  163. $aItem['class_link'] = 'bx-btn' . (isset($aItem['primary']) && (int)$aItem['primary'] == 1 ? ' bx-btn-primary' : '') . (!empty($aItem['class_link']) ? ' ' . $aItem['class_link'] : '');
  164. if(!$this->_bShowTitle)
  165. $aItem['bx_if:title']['condition'] = false;
  166. return parent::_getMenuItemDefault ($aItem);
  167. }
  168. }
  169. /** @} */