BxTasksTemplate.php 28 KB

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