1
0

BxTasksTemplate.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. require_once('BxTasksMenuTimer.php');
  11. require_once('BxTasksMenuTimers.php');
  12. class BxTasksTemplate extends BxBaseModTextTemplate
  13. {
  14. public function __construct(&$oConfig, &$oDb)
  15. {
  16. $this->MODULE = 'bx_tasks';
  17. parent::__construct($oConfig, $oDb);
  18. }
  19. public function getJsCodeView($sType, $aParams = [], $mixedWrap = true)
  20. {
  21. $aParams = array_merge([
  22. 'aHtmlIds' => $this->_oConfig->getHtmlIds()
  23. ], $aParams);
  24. return parent::getJsCode($sType, $aParams, $mixedWrap === true ? [
  25. 'wrap' => true,
  26. 'mask' => '{var} {object} = new {class}({params}); {object}.init();'
  27. ] : $mixedWrap);
  28. }
  29. public function getJsCodeTimer($sType, $aParams = [], $mixedWrap = true)
  30. {
  31. $aParams = array_merge([
  32. 'aHtmlIds' => $this->_oConfig->getHtmlIds()
  33. ], $aParams);
  34. if(is_array($mixedWrap))
  35. return parent::getJsCode($sType, $aParams, [
  36. 'wrap' => true,
  37. 'mask' => "{var} {object} = new {class}({params}); {object}.init({content_id}, {profile_id}, {started});",
  38. 'mask_markers' => $mixedWrap
  39. ]);
  40. else
  41. parent::getJsCode($sType, $aParams, $mixedWrap);
  42. }
  43. public function getBlockMenuBrowse()
  44. {
  45. $CNF = &$this->_oConfig->CNF;
  46. $iProfileId = bx_get_logged_profile_id();
  47. $sMenuUse = $this->_bIsApi ? [] : '';
  48. if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_USE_TOOLS_SUBMENU'])) !== false)
  49. $sMenuUse = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  50. $sMenuManage = $this->_bIsApi ? [] : '';
  51. if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU'])) !== false)
  52. $sMenuManage = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  53. $sMenuBrowse = $this->_bIsApi ? [] : '';
  54. if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_BROWSE'])) !== false) {
  55. $oMenu->setProfileId($iProfileId);
  56. $sMenuBrowse = $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  57. }
  58. if($this->_bIsApi)
  59. return [
  60. 'menu_use' => $sMenuUse,
  61. 'menu_browse' => $sMenuBrowse,
  62. 'menu_manage' => $sMenuManage
  63. ];
  64. return $this->parseHtmlByName('menu_browse.html', [
  65. 'menu_use' => $sMenuUse,
  66. 'bx_if:show_menu_browse' => [
  67. 'condition' => $sMenuBrowse != '',
  68. 'content' => [
  69. 'menu_browse' => $sMenuBrowse
  70. ]
  71. ],
  72. 'bx_if:show_menu_manage' => [
  73. 'condition' => $sMenuManage != '',
  74. 'content' => [
  75. 'menu_manage' => $sMenuManage
  76. ]
  77. ]
  78. ]);
  79. }
  80. public function getBlockBudget($aBudget)
  81. {
  82. $iTotal = (int)$aBudget['value_total'];
  83. $iSpent = (int)$aBudget['value_spent'];
  84. $iRemains = $iRemainsPercent = 0;
  85. if($iTotal) {
  86. $iRemains = $iTotal - $iSpent;
  87. $iRemainsPercent = round(100 * $iRemains / $iTotal, 2);
  88. }
  89. if($this->_bIsApi)
  90. return [
  91. 'total' => $iTotal,
  92. 'spent' => $iSpent,
  93. 'remains' => $iRemains,
  94. 'remains_percent' => $iRemainsPercent
  95. ];
  96. return $this->parseHtmlByName('block_budget.html', [
  97. 'total' => $this->_oConfig->timeI2S($iTotal),
  98. 'spent' => $this->_oConfig->timeI2S($iSpent),
  99. 'bx_if:show_remains' => [
  100. 'condition' => $iRemains > 0,
  101. 'content' => [
  102. 'remains' => _t('_bx_tasks_txt_budget_remains_value', $this->_oConfig->timeI2S($iRemains), $iRemainsPercent)
  103. ]
  104. ]
  105. ]);
  106. }
  107. /**
  108. * Use Gallery image for both because currently there is no Unit types with small thumbnails.
  109. */
  110. protected function getUnitThumbAndGallery ($aData)
  111. {
  112. list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
  113. return array($sPhotoGallery, $sPhotoGallery);
  114. }
  115. public function entryAssignments ($aProfiles, $aParams = [])
  116. {
  117. $aUnitParamsDefault = ['template' => ['name' => $aParams['unit_name'] ?? 'unit', 'size' => $aParams['unit_size'] ?? 'thumb']];
  118. $aTmplVarsProfiles = [];
  119. foreach($aProfiles as $mixedProfile) {
  120. $bProfile = is_array($mixedProfile);
  121. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  122. if(!$oProfile)
  123. continue;
  124. $aUnitParams = $aUnitParamsDefault;
  125. if($bProfile && is_array($mixedProfile['info']))
  126. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  127. $aTmplVarsProfiles[] = $this->_bIsApi ? BxDolProfile::getData($oProfile) : [
  128. 'unit' => $oProfile->getUnit(0, $aUnitParams)
  129. ];
  130. }
  131. if($this->_bIsApi)
  132. return $aTmplVarsProfiles;
  133. return $aTmplVarsProfiles ? $this->parseHtmlByName('entry-assignments.html', [
  134. 'bx_repeat:profiles' => $aTmplVarsProfiles
  135. ]) : MsgBox(_t('_sys_txt_empty'));
  136. }
  137. public function entryTimer ($iContentId, $iProfileId)
  138. {
  139. $mixedResult = $this->getTimer($iContentId, $iProfileId);
  140. if($this->_bIsApi)
  141. return $mixedResult;
  142. $this->addCss(['timer.css']);
  143. $this->addJs(['timer.js']);
  144. return $mixedResult . $this->getJsCodeTimer('timer', [], [
  145. 'content_id' => $iContentId,
  146. 'profile_id' => $iProfileId,
  147. 'started' => $this->_oDb->isTimerStarted($iContentId, $iProfileId),
  148. ]);
  149. }
  150. public function getBlockTimers ($iProfileId)
  151. {
  152. $CNF = &$this->_oConfig->CNF;
  153. $oModule = $this->getModule();
  154. $sJsObject = $this->_oConfig->getJsObject('timer');
  155. $aTimers = $this->_oDb->getTimers(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
  156. if(!$aTimers || !is_array($aTimers))
  157. return $this->_bIsApi ? [] : MsgBox(_t('_Empty'));
  158. $oPermalinks = BxDolPermalinks::getInstance();
  159. $sTimerName = 'hor-sm';
  160. $sTimersKey = $this->_bIsApi ? 'timers' : 'bx_repeat:timers';
  161. $aTmplVarsSections = [];
  162. foreach($aTimers as $aTimer) {
  163. $aContentInfo = $this->_oDb->getContentInfoById($aTimer['content_id']);
  164. if(!$aContentInfo || !is_array($aContentInfo))
  165. continue;
  166. $sContextType = '';
  167. $aTmplVarsContext = [];
  168. if(($iAllowViewTo = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($oContext = BxDolProfile::getInstance(abs($iAllowViewTo))) !== false) {
  169. $sContextType = $oContext->getModule();
  170. $aTmplVarsContext = $this->_bIsApi ? BxDolProfile::getData($oContext) : [
  171. 'title' => $oContext->getDisplayName(),
  172. 'url' => $oContext->getUrl()
  173. ];
  174. }
  175. $sUrl = bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  176. if(!isset($aTmplVarsSections[$sContextType]))
  177. $aTmplVarsSections[$sContextType] = [
  178. 'section_title' => $oModule->getModuleTitle($sContextType),
  179. $sTimersKey => []
  180. ];
  181. $aTmplVarsSections[$sContextType][$sTimersKey][] = array_merge([
  182. 'content_title' => $aContentInfo[$CNF['FIELD_TITLE']],
  183. 'content_url' => $this->_bIsApi ? bx_api_get_relative_url($sUrl) : $sUrl,
  184. 'timer' => $this->getTimer($aTimer['content_id'], $iProfileId, $sTimerName),
  185. ], $this->_bIsApi ? [
  186. 'context' => $aTmplVarsContext,
  187. ] : [
  188. 'bx_if:show_context' => [
  189. 'condition' => !empty($aTmplVarsContext),
  190. 'content' => $aTmplVarsContext
  191. ],
  192. 'js_code_timer' => $sJsObject . '.init(' . $aTimer['content_id'] . ', ' . $iProfileId . ', ' . ($aTimer['started'] != 0 ? 1 : 0) . ');'
  193. ]);
  194. }
  195. $aTmplVarsSections = array_values($aTmplVarsSections);
  196. $oActions = new BxTasksMenuTimers([
  197. 'object' => str_replace('_', '-', $this->_oConfig->getName()) . '_timers',
  198. 'template' => 'menu_custom_hor.html',
  199. 'menu_id' => $this->_oConfig->getHtmlIds('timers_actions'),
  200. 'persistent' => 0
  201. ]);
  202. $oActions->setParams($iProfileId);
  203. if($this->_bIsApi)
  204. return [
  205. 'sections' => $aTmplVarsSections,
  206. 'actions' => $oActions->getCodeAPI()
  207. ];
  208. $this->addCss(['forms.css', 'timer.css']);
  209. $this->addJs(['timer.js']);
  210. return $this->parseHtmlByName('browse_timers.html', [
  211. 'js_code' => $this->getJsCode('timer', [
  212. 'sName' => $sTimerName,
  213. 'bMulti' => true
  214. ]),
  215. 'bx_repeat:sections' => $aTmplVarsSections,
  216. 'actions' => $oActions->getCode()
  217. ]);
  218. }
  219. public function getTimer ($iContentId, $iProfileId, $sName = '')
  220. {
  221. $CNF = &$this->_oConfig->CNF;
  222. $sPrefix = str_replace('_', '-', $this->_oConfig->getName());
  223. $sJsObject = $this->_oConfig->getJsObject('timer');
  224. $aTimer = $this->_oDb->getTimers(['sample' => 'content_profile_ids', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
  225. $bTimer = $aTimer && is_array($aTimer);
  226. $bStarted = $bTimer && (int)$aTimer['started'] > 0;
  227. $iHours = $iMinutes = $iSeconds = 0;
  228. if($bTimer) {
  229. $iDuration = (int)$aTimer['duration'];
  230. if($bStarted)
  231. $iDuration += time() - (int)$aTimer['started'];
  232. list($iHours, $iMinutes, $iSeconds) = $this->_oConfig->timeI2A($iDuration, true);
  233. }
  234. $oActions = new BxTasksMenuTimer([
  235. 'object' => $sPrefix . '_timer',
  236. 'template' => 'menu_custom_hor.html',
  237. 'menu_id' => $this->_oConfig->getHtmlIds('timer_actions'),
  238. 'title_public' => '',
  239. 'config_api' => [],
  240. 'persistent' => 0
  241. ]);
  242. $oActions->setParams($iContentId, $iProfileId);
  243. if($this->_bIsApi) {
  244. $sState = '';
  245. if($bStarted)
  246. $sState = 'started';
  247. else if($bTimer)
  248. $sState = 'paused';
  249. return [
  250. 'id' => $bTimer ? $aTimer['id'] : 0,
  251. 'time' => [
  252. 'hours' => $iHours,
  253. 'minutes' => $iMinutes,
  254. 'seconds' => $iSeconds,
  255. ],
  256. 'state' => $sState,
  257. 'request_url' => $this->MODULE . '/process_timer/&params[]=reload&params[]=' . $iContentId . '&params[]=' . $iProfileId,
  258. 'actions' => $oActions->getCodeAPI()
  259. ];
  260. }
  261. return $this->parseHtmlByName('entry-timer' . ($sName ? '-' . $sName : '') . '.html', [
  262. 'html_id' => $this->_oConfig->getHtmlIds('timer') . $iContentId . '-' . $iProfileId,
  263. 'hours' => sprintf("%02d", $iHours),
  264. 'minutes' => sprintf("%02d", $iMinutes),
  265. 'seconds' => sprintf("%02d", $iSeconds),
  266. 'actions' => $oActions->getCode()
  267. ]);
  268. }
  269. public function getEntriesList($iContextId = 0, $aParams = [])
  270. {
  271. $CNF = &$this->_oConfig->CNF;
  272. $sJsObject = $this->_oConfig->getJsObject('tasks');
  273. $iLoggedId = bx_get_logged_profile_id();
  274. $oModule = $this->getModule();
  275. $bContext = !empty($iContextId);
  276. $bAllowAdd = $bContext && $oModule->isAllowAdd($iContextId);
  277. $aFilters = [];
  278. if(($sFilters = $_COOKIE[$CNF['COOKIE_SETTING_KEY']] ?? false))
  279. $aFilters = json_decode($sFilters, true);
  280. $iFilterSelected = $aParams['filter'] ?? ($aFilters[$iContextId] ?? 0);
  281. $mixedFilters = $this->_getEntriesFilters($iContextId, array_merge($aParams, ['filter_selected' => $iFilterSelected]));
  282. $aEntries = $this->getEntries($iContextId, array_merge($aParams, [
  283. 'filter' => $iFilterSelected,
  284. ]));
  285. if($this->_bIsApi) {
  286. $aActions = [];
  287. if($bAllowAdd)
  288. $aActions = array_merge($aActions, [[
  289. 'name' => 'add_list',
  290. 'title' => _t('_bx_tasks_txt_new_task_list'),
  291. 'type' => 'modal',
  292. 'callback' => $this->MODULE . '/process_task_list_form&params[]=' . $iContextId . '&params[]=0',
  293. ], [
  294. 'name' => 'add_task',
  295. 'title' => _t('_bx_tasks_txt_new_task'),
  296. 'type' => 'modal',
  297. 'callback' => $this->MODULE . '/process_task_form&params[]=' . $iContextId . '&params[]=0',
  298. ]]);
  299. return [
  300. 'context_id' => $iContextId,
  301. 'filters' => $mixedFilters,
  302. 'lists' => $aEntries,
  303. 'actions' => $aActions,
  304. 'request_url' => $this->MODULE . '/' . ($bContext ? 'browse_context' : 'browse_tasks_by_profile') . '&params[]=' . ($bContext ? $iContextId : $iLoggedId),
  305. ];
  306. }
  307. $this->addCssJs();
  308. $this->addJs([
  309. 'jquery-ui/jquery-ui.min.js',
  310. 'tasks.js',
  311. 'modules/base/general/js/|forms.js'
  312. ]);
  313. return $this->parseHtmlByName('browse_tasks.html', [
  314. 'object' => $sJsObject,
  315. 'context_id' => $iContextId,
  316. 'bx_if:show_filters' => [
  317. 'condition' => !empty($mixedFilters),
  318. 'content' => [
  319. 'object' => $sJsObject,
  320. 'context_id' => $iContextId,
  321. 'filters' => $mixedFilters
  322. ]
  323. ],
  324. 'bx_if:allow_add_list' => [
  325. 'condition' => $bAllowAdd,
  326. 'content' => [
  327. 'context_id' => $iContextId,
  328. 'object' => $sJsObject,
  329. ]
  330. ],
  331. 'bx_if:allow_add_task' => [
  332. 'condition' => $bAllowAdd,
  333. 'content' => [
  334. 'context_id' => $iContextId,
  335. 'object' => $sJsObject,
  336. ]
  337. ],
  338. 'task_lists' => $aEntries,
  339. 'js_code' => $this->getJsCodeView('tasks', ['t_confirm_block_deletion' => _t('_bx_tasks_txt_msg_confirm_tasklist_deletion')])
  340. ]);
  341. }
  342. public function getEntries($iContextId = 0, $aParams = [])
  343. {
  344. $CNF = &$this->_oConfig->CNF;
  345. $sJsObject = $this->_oConfig->getJsObject('tasks');
  346. $oModule = $this->getModule();
  347. $oPermalinks = BxDolPermalinks::getInstance();
  348. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  349. $aTypes = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_TYPES']);
  350. $aPriorities = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_PRIORITIES']);
  351. $aStates = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_STATES']);
  352. $bContext = !empty($iContextId);
  353. $bAllowAdd = $bContext && $oModule->isAllowAdd($iContextId);
  354. $bAllowManage = $bContext && $oModule->isAllowManageByContext($iContextId);
  355. $bShowManage = false; //--- Hidden for now.
  356. $iProfileId = bx_get_logged_profile_id();
  357. $aLists = [];
  358. if(!$bContext) {
  359. $iProfile = $aParams['for_profile'] ?? $iProfileId;
  360. $aContexts = $this->_oModule->getContexts();
  361. foreach($aContexts as $sName => $sTitle) {
  362. $aIds = $this->_oModule->_oDb->getContextsIdsByType($sName, $iProfile);
  363. foreach($aIds as $iId) {
  364. $oContext = BxDolProfile::getInstance($iId);
  365. if(!$oContext)
  366. continue;
  367. $aLists[] = [
  368. 'id' => $iId,
  369. 'title' => _t('_bx_tasks_txt_list_title', $oContext->getDisplayName(), $sTitle)
  370. ];
  371. }
  372. }
  373. }
  374. else {
  375. $aListInbox = ['id' => 0, 'title' => _t('_bx_tasks_txt_list_inbox')];
  376. if(($iListId = $aParams['list'] ?? false) === false) {
  377. $aLists[] = $aListInbox;
  378. if(($aListsAdd = $this->_oDb->getLists($iContextId)) && is_array($aListsAdd))
  379. $aLists = array_merge($aLists, $aListsAdd);
  380. }
  381. else
  382. $aLists[] = $iListId != 0 ? $this->_oDb->getList($iListId) : $aListInbox;
  383. }
  384. $aParams = array_merge($aParams, [
  385. 'with_stats' => true
  386. ]);
  387. $aTmplVarsLists = [];
  388. foreach($aLists as $aList) {
  389. $iTasksContextId = $bContext ? $iContextId : ($aList['id'] ?? false);
  390. if(!$iTasksContextId)
  391. continue;
  392. $bTasksAllowManage = $bContext ? $bAllowManage : $oModule->isAllowManageByContext($iTasksContextId);
  393. $aTasks = $this->_oDb->getTasks($iTasksContextId, $bContext ? $aList['id'] : false, $aParams);
  394. if((!$aTasks || !is_array($aTasks)) && (($bContext && !$aList['id']) || !$bTasksAllowManage))
  395. continue;
  396. $aTmplVarsTasks = [];
  397. foreach($aTasks as $aTask) {
  398. $iTaskId = (int)$aTask[$CNF['FIELD_ID']];
  399. $sTime = '';
  400. if(!empty($aTask['time_total']))
  401. $sTime = _t('_bx_tasks_txt_total', $this->_oConfig->timeI2S($aTask['time_total']) . (!empty($aTask['time']) ? ' (' . $this->_oConfig->timeI2S($aTask['time']) . ')' : ''));
  402. if(!empty($aTask['estimate']))
  403. $sTime .= ' ' . _t('_bx_tasks_txt_estimate', $this->_oConfig->timeI2S(60 * (int)$aTask['estimate']));
  404. $aMembers = $oConnection->getConnectedInitiators($iTaskId);
  405. $aTmplVarsMembers = [];
  406. foreach($aMembers as $iMember)
  407. if(($oProfile = BxDolProfile::getInstance($iMember)) !== false && !($oProfile instanceof BxDolProfileUndefined))
  408. $aTmplVarsMembers[] = $this->_bIsApi ? BxDolProfile::getData($oProfile) : ['info' => $oProfile->getUnit(0, ['template' => 'unit_wo_info'])];
  409. $bCompleted = $aTask[$CNF['FIELD_COMPLETED']] == 1;
  410. $sUrl = bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iTaskId));
  411. $aActions = [];
  412. if($this->_bIsApi && $bShowManage && $bTasksAllowManage)
  413. $aActions[] = [
  414. 'name' => 'set_completed',
  415. 'title' => _t('_bx_tasks_menu_item_title_set_' . ($bCompleted ? 'uncompleted' : 'completed')),
  416. 'type' => 'callback',
  417. 'callback' => $this->MODULE . '/set_completed&params[]=' . $iTaskId . '&params[]=' . ($bCompleted ? 0 : 1),
  418. 'on_callback' => 'refresh'
  419. ];
  420. $aTmplVarsTasks[] = array_merge([
  421. 'id' => $iTaskId,
  422. 'title' => bx_process_output($aTask[$CNF['FIELD_TITLE']]),
  423. 'created' => $aTask[$CNF['FIELD_ADDED']],
  424. 'class' => $bCompleted ? 'completed' : 'uncompleted',
  425. 'due' => $aTask[$CNF['FIELD_DUE_DATE']] ?: '',
  426. 'type' => $aTypes[$aTask[$CNF['FIELD_TYPE']]] ?? '',
  427. 'priority' => $aPriorities[$aTask[$CNF['FIELD_PRIORITY']]] ?? '',
  428. 'state' => $aStates[$aTask[$CNF['FIELD_STATE']]] ?? '',
  429. 'time' => $sTime,
  430. 'badges' => $oModule->serviceGetBadges($iTaskId, true),
  431. 'url' => $sUrl
  432. ], $this->_bIsApi ? [
  433. 'url' => bx_api_get_relative_url($sUrl),
  434. 'completed' => $bCompleted ? 1 : 0,
  435. 'members' => $aTmplVarsMembers,
  436. 'actions' => $aActions
  437. ] : [
  438. 'created' => bx_time_js($aTask[$CNF['FIELD_ADDED']]),
  439. 'due' => $aTask[$CNF['FIELD_DUE_DATE']] > 0 ? bx_time_js($aTask[$CNF['FIELD_DUE_DATE']]) : '',
  440. 'object' => $sJsObject,
  441. 'bx_repeat:members' => $aTmplVarsMembers,
  442. 'bx_if:show_manage' => [
  443. 'condition' => $bShowManage,
  444. 'content' => [
  445. 'bx_if:allow_manage' => [
  446. 'condition' => $bTasksAllowManage,
  447. 'content' => [
  448. 'id' => $iTaskId,
  449. 'object' => $sJsObject,
  450. 'checked' => $bCompleted ? 'checked' : '',
  451. ]
  452. ],
  453. 'bx_if:deny_manage' => [
  454. 'condition' => !$bTasksAllowManage,
  455. 'content' => [
  456. 'id' => $iTaskId,
  457. 'checked' => $bCompleted ? 'checked' : '',
  458. ]
  459. ]
  460. ]
  461. ]
  462. ]);
  463. }
  464. $iListId = (int)$aList[$CNF['FIELD_LIST_ID']];
  465. if($this->_bIsApi) {
  466. $aActions = [];
  467. if($bAllowAdd)
  468. $aActions = array_merge($aActions, [[
  469. 'name' => 'edit_list',
  470. 'title' => _t('_bx_tasks_txt_edit_task_list'),
  471. 'type' => 'modal',
  472. 'callback' => $this->MODULE . '/process_task_list_form&params[]=' . $iTasksContextId . '&params[]=' . $iListId,
  473. ], [
  474. 'name' => 'add_task',
  475. 'title' => _t('_bx_tasks_txt_new_task'),
  476. 'type' => 'modal',
  477. 'callback' => $this->MODULE . '/process_task_form&params[]=' . $iTasksContextId . '&params[]=' . $iListId,
  478. ]]);
  479. if($bAllowManage)
  480. $aActions[] = [
  481. 'name' => 'delete_list',
  482. 'title' => _t('_bx_tasks_txt_delete_task_list'),
  483. 'type' => 'callback',
  484. 'callback' => $this->MODULE . '/delete_task_list&params[]=' . $iTasksContextId . '&params[]=' . $iListId,
  485. 'on_callback' => 'hide_row'
  486. ];
  487. $aTmplVarsLists[] = [
  488. 'context_id' => $iTasksContextId,
  489. 'list_id' => $iListId,
  490. 'list_title' => $aList[$CNF['FIELD_LIST_TITLE']],
  491. 'tasks' => $aTmplVarsTasks,
  492. 'actions' => $aActions
  493. ];
  494. continue;
  495. }
  496. $sClass = $sCompleted = $sAll = "";
  497. if (isset($aFilterValues[$iListId])){
  498. $sClass = $aFilterValues[$iListId];
  499. if ($sClass == 'completed')
  500. $sCompleted= 'selected';
  501. if ($sClass == 'all')
  502. $sAll = 'selected';
  503. }
  504. $aTmplVarsAllowEditList = $aTmplVarsAllowAdd = [];
  505. if($bAllowAdd) {
  506. $aTmplVarsAllowEditList = [
  507. 'title' => $aList[$CNF['FIELD_LIST_TITLE']],
  508. 'context_id' => $iTasksContextId,
  509. 'list_id' => $iListId,
  510. 'object' => $sJsObject,
  511. ];
  512. $aTmplVarsAllowAdd = [
  513. 'context_id' => $iTasksContextId,
  514. 'list_id' => $iListId,
  515. 'object' => $sJsObject,
  516. ];
  517. }
  518. $aTmplVarsAllowDeleteList = [];
  519. if($bAllowManage) {
  520. $aTmplVarsAllowDeleteList = [
  521. 'context_id' => $iTasksContextId,
  522. 'list_id' => $iListId,
  523. 'object' => $sJsObject,
  524. ];
  525. }
  526. $aTmplVarsLists[] = [
  527. 'bx_if:allow_edit_list' => [
  528. 'condition' => $bAllowAdd,
  529. 'content' => $aTmplVarsAllowEditList
  530. ],
  531. 'bx_if:allow_add' => [
  532. 'condition' => $bAllowAdd,
  533. 'content' => $aTmplVarsAllowAdd
  534. ],
  535. 'bx_if:allow_delete_list' => [
  536. 'condition' => $bAllowManage,
  537. 'content' => $aTmplVarsAllowDeleteList
  538. ],
  539. 'bx_if:deny_edit_list' => [
  540. 'condition' => !$bAllowAdd,
  541. 'content' => [
  542. 'title' => $aList[$CNF['FIELD_LIST_TITLE']],
  543. ]
  544. ],
  545. 'bx_repeat:tasks' => $aTmplVarsTasks,
  546. 'list_id' => $iListId,
  547. 'list_by_viewer' => ($bContext ? 'l' : 'c') . $iListId . '-' . $iProfileId,
  548. 'object' => $sJsObject
  549. ];
  550. }
  551. if($this->_bIsApi)
  552. return $aTmplVarsLists;
  553. return $this->parseHtmlByName('tasks.html', [
  554. 'html_id' => $this->_oConfig->getHtmlIds('tasks'),
  555. 'bx_repeat:task_lists' => $aTmplVarsLists,
  556. ]);
  557. }
  558. public function getStickers($aStickers)
  559. {
  560. $aTmplVarsStickers = [];
  561. foreach($aStickers as $aSticker)
  562. $aTmplVarsStickers[] = [
  563. 'title' => $aSticker['title'],
  564. 'bx_if:show_color' => [
  565. 'condition' => $aSticker['color'] != '',
  566. 'content' => [
  567. 'color' => $aSticker['color']
  568. ]
  569. ]
  570. ];
  571. return $this->parseHtmlByName('stickers.html', [
  572. 'bx_repeat:stickers' => $aTmplVarsStickers
  573. ]);
  574. }
  575. protected function _getEntriesFilters($iContextId = 0, $aParams = [])
  576. {
  577. $sJsObject = $this->_oConfig->getJsObject('tasks');
  578. $iLoggedId = bx_get_logged_profile_id();
  579. $bShowTemporary = $aParams['show_temporary'] ?? false;
  580. $this->_oDb->cleanFilters($iContextId, $iLoggedId);
  581. $aInput = [
  582. 'type' => 'select',
  583. 'name' => 'filters',
  584. 'area_label' => '_bx_tasks_filter_title_select',
  585. 'value' => $aParams['filter_selected'] ?? 0,
  586. 'values' => [
  587. ['key' => 0, 'value' => _t('_bx_tasks_filter_title_select')]
  588. ],
  589. 'attrs' => [
  590. 'onchange' => $sJsObject . '.applyFilter(this, ' . $iContextId . ')'
  591. ]
  592. ];
  593. $aTypes = [
  594. '_bx_tasks_txt_flt_system' => ['sample' => 'active', 'context_id' => 0, 'author' => 0],
  595. '_bx_tasks_txt_flt_contextual' => ['sample' => 'active', 'context_id' => $iContextId, 'author' => 0],
  596. '_bx_tasks_txt_flt_my_permanent' => ['sample' => 'active', 'context_id' => $iContextId, 'author' => $iLoggedId, 'permanent' => 1],
  597. ];
  598. if($bShowTemporary)
  599. $aTypes['_bx_tasks_txt_flt_my_temporary'] = ['sample' => 'active', 'context_id' => $iContextId, 'author' => $iLoggedId, 'permanent' => 0];
  600. foreach($aTypes as $sTitle => $aType) {
  601. $aFilterItems = $this->_oDb->getFilters($aType);
  602. if($aFilterItems && is_array($aFilterItems)) {
  603. $aInput['values'][] = ['type' => 'group_header', 'value' => _t($sTitle)];
  604. foreach($aFilterItems as $aFilterItem)
  605. $aInput['values'][] = [
  606. 'key' => $aFilterItem['id'],
  607. 'value' => _t($aFilterItem['title'])
  608. ];
  609. $aInput['values'][] = ['type' => 'group_end'];
  610. }
  611. }
  612. if($this->_bIsApi)
  613. return [
  614. 'values' => $aInput['values'],
  615. 'value' => $aInput['value'],
  616. 'request_url_add' => $this->MODULE . '/create_filter&params[]=' . $iContextId,
  617. 'request_url_apply' => $this->MODULE . '/apply_filter&params[]=' . $iContextId . '&params[]=',
  618. 'request_url_save' => $this->MODULE . '/save_filter&params[]=' . $iContextId . '&params[]='
  619. ];
  620. $oForm = new BxTemplFormView([]);
  621. return $oForm->genInputSelect($aInput);
  622. }
  623. }
  624. /** @} */