BxTasksModule.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  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. /**
  11. * Task states
  12. */
  13. define('BX_TASKS_STATE_BACBLOG', 1);
  14. define('BX_TASKS_STATE_TODO', 2);
  15. define('BX_TASKS_STATE_IN_PROGRESS', 3);
  16. define('BX_TASKS_STATE_IN_REVIEW', 4);
  17. define('BX_TASKS_STATE_CANCELLED', 5);
  18. define('BX_TASKS_STATE_DUPLICATE', 6);
  19. define('BX_TASKS_STATE_DONE', 7);
  20. class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
  21. {
  22. function __construct(&$aModule)
  23. {
  24. parent::__construct($aModule);
  25. $this->_oConfig->init($this->_oDb);
  26. $CNF = &$this->_oConfig->CNF;
  27. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  28. $CNF['FIELD_PUBLISHED'],
  29. $CNF['FIELD_ALLOW_COMMENTS']
  30. ));
  31. }
  32. /**
  33. * Action methods
  34. */
  35. /**
  36. * Get possible recipients for start conversation form
  37. */
  38. public function actionAjaxGetInitialMembers($iContextPid)
  39. {
  40. $sTerm = bx_get('term');
  41. $sModule = $this->_oConfig->getName();
  42. $a = bx_srv('system', 'profiles_search', [$sTerm, [
  43. 'module' => $sModule,
  44. 'search_params' => ['name' => $sModule . '_initial_members', 'context_pid' => $iContextPid]
  45. ]], 'TemplServiceProfiles');
  46. header('Content-Type:text/javascript; charset=utf-8');
  47. echo(json_encode($a));
  48. }
  49. public function actionSetCompleted($iContentId, $iCompleted)
  50. {
  51. return echoJson($this->serviceSetCompleted($iContentId, $iCompleted));
  52. }
  53. public function actionApplyFilter($iContextId, $iFilterId)
  54. {
  55. return echoJson([
  56. 'content' => $this->serviceApplyFilter($iContextId, $iFilterId),
  57. 'eval' => $this->_oConfig->getJsObject('tasks') . '.onApplyFilter(oData)'
  58. ]);
  59. }
  60. public function actionCreateFilter($iContextId)
  61. {
  62. $mixedResult = $this->serviceCreateFilter($iContextId);
  63. if(is_array($mixedResult))
  64. return echoJson($aRes);
  65. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oConfig->getHtmlIds('filter_popup'), _t('_bx_tasks_popup_f_title_add'), $this->_oTemplate->parseHtmlByName('popup_form.html', [
  66. 'form_id' => $mixedResult->getId(),
  67. 'form' => $mixedResult->getCode(true)
  68. ]));
  69. return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  70. }
  71. public function actionProcessTaskListForm($iContextId, $iId)
  72. {
  73. $mixedResult = $this->serviceProcessTaskListForm($iContextId, $iId);
  74. if(($bReload = is_bool($mixedResult) || is_numeric($mixedResult)) || is_array($mixedResult)) {
  75. if($bReload)
  76. $mixedResult = [
  77. 'eval' => $this->_oConfig->getJsObject('tasks') . '.reloadData(oData, ' . $iContextId . ')',
  78. ];
  79. return echoJson($mixedResult);
  80. }
  81. echo $mixedResult;
  82. }
  83. public function actionDeleteTaskList($iContextId, $iId)
  84. {
  85. return echoJson($this->serviceDeleteTaskList($iContextId, $iId) ? [
  86. 'context_id' => $iContextId,
  87. ] : []);
  88. }
  89. public function actionProcessTaskForm($iContextId, $iListId)
  90. {
  91. $mixedResult = $this->serviceProcessTaskForm($iContextId, $iListId);
  92. if(($bReload = is_bool($mixedResult) || is_numeric($mixedResult)) || is_array($mixedResult)) {
  93. if($bReload)
  94. $mixedResult = [
  95. 'eval' => $this->_oConfig->getJsObject('tasks') . '.reloadData(oData, ' . $iContextId . ')',
  96. ];
  97. return echoJson($mixedResult);
  98. }
  99. echo $mixedResult;
  100. }
  101. public function actionProcessTaskFormEditProperty($iContentId, $sProperty)
  102. {
  103. $mixedResult = $this->serviceProcessTaskFormEditProperty($iContentId, $sProperty);
  104. if(($bReload = is_bool($mixedResult)) || is_array($mixedResult)) {
  105. if($bReload)
  106. $mixedResult = [
  107. 'eval' => $this->_oConfig->getJsObject('tasks') . '.reload(oData)',
  108. ];
  109. return echoJson($mixedResult);
  110. }
  111. echo $mixedResult;
  112. }
  113. public function actionCalendarData()
  114. {
  115. // check permissions
  116. $aSQLPart = array();
  117. $iContextId = (int)bx_get('context_id');
  118. if(!$this->isAllowView($iContextId))
  119. return;
  120. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  121. if($iContextId) {
  122. $aSQLPart = $oPrivacy ? $oPrivacy->getContentByGroupAsSQLPart(- $iContextId) : array();
  123. }
  124. // get entries
  125. $aEntries = $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), bx_get('event'), $aSQLPart);
  126. header('Content-Type: application/json; charset=utf-8');
  127. echo json_encode($aEntries);
  128. }
  129. public function actionProcessTimer($sAction, $iContentId, $iProfileId)
  130. {
  131. if(!$this->_iProfileId || $this->_iProfileId != $iProfileId)
  132. return echoJson(['msg' => _t('_sys_txt_access_denied')]);
  133. $aResult = $this->serviceProcessTimer($sAction, $iContentId, $iProfileId);
  134. if($aResult['code'] == 0)
  135. $aResult = array_merge($aResult, [
  136. 'content_id' => $iContentId,
  137. 'profile_id' => $iProfileId,
  138. 'content' => $this->_oTemplate->getTimer($iContentId, $iProfileId),
  139. 'eval' => $this->_oConfig->getJsObject('timer') . '.onPerformAction' . bx_gen_method_name($sAction) . '(oData)'
  140. ]);
  141. return echoJson($aResult);
  142. }
  143. public function serviceGetSafeServices()
  144. {
  145. return array_merge(parent::serviceGetSafeServices(), [
  146. 'ProcessTaskListForm' => '',
  147. 'DeleteTaskList' => '',
  148. 'ProcessTaskForm' => '',
  149. 'ProcessTaskFormEditProperty' => '',
  150. 'SetCompleted' => '',
  151. 'CreateFilter' => '',
  152. 'ApplyFilter' => '',
  153. 'ProcessTimer' => '',
  154. ]);
  155. }
  156. public function serviceProcessTaskListForm($iContextId, $iId)
  157. {
  158. if(!$this->isAllowAdd(abs($iContextId)))
  159. return [];
  160. $CNF = &$this->_oConfig->CNF;
  161. $bAdd = $iId == 0;
  162. $aContentInfo = [];
  163. $sFormDisplay = $sPopupTitle = '';
  164. if($bAdd) {
  165. $sFormDisplay = $CNF['OBJECT_FORM_LIST_ENTRY_DISPLAY_ADD'];
  166. $sPopupTitle = _t('_bx_tasks_form_list_entry_display_add');
  167. }
  168. else {
  169. $aContentInfo = $this->_oDb->getList($iId);
  170. $sFormDisplay = $CNF['OBJECT_FORM_LIST_ENTRY_DISPLAY_EDIT'];
  171. $sPopupTitle = _t('_bx_tasks_form_list_entry_display_edit');
  172. }
  173. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_LIST_ENTRY'], $sFormDisplay);
  174. if(!$oForm)
  175. return [];
  176. $oForm->setAction(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'process_task_list_form/' . $iContextId . '/' . $iId . '/');
  177. $oForm->initChecker($aContentInfo, []);
  178. if($oForm->isSubmittedAndValid()) {
  179. return $bAdd ? $oForm->insert(['context_id' => $iContextId]) : (bool)$oForm->update($iId);
  180. }
  181. else {
  182. if($this->_bIsApi)
  183. return $oForm->getCodeAPI();
  184. $sContent = $this->_oTemplate->parseHtmlByName('popup_form.html', [
  185. 'form_id' => $oForm->getId(),
  186. 'form' => $oForm->getCode(true)
  187. ]);
  188. if($oForm->isSubmitted())
  189. return [
  190. 'form' => $sContent,
  191. 'form_id' => $oForm->getId()
  192. ];
  193. return $sContent;
  194. }
  195. }
  196. public function serviceDeleteTaskList($iContextId, $iId)
  197. {
  198. if(!$this->isAllowManageByContext($iContextId))
  199. return false;
  200. $CNF = &$this->_oConfig->CNF;
  201. $aTasks = $this->_oDb->getTasks($iContextId, $iId);
  202. if(!empty($aTasks) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false)
  203. foreach($aTasks as &$aTask)
  204. $oConnection->onDeleteContent($aTask[$CNF['FIELD_ID']]);
  205. return $this->_oDb->deleteList($iId);
  206. }
  207. public function serviceProcessTaskForm($iContextId, $iListId)
  208. {
  209. if(!$this->isAllowAdd($iContextId))
  210. return [];
  211. $CNF = &$this->_oConfig->CNF;
  212. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  213. if(!$oForm)
  214. return [];
  215. $oForm->setAction(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'process_task_form/' . $iContextId . '/' . $iListId . '/');
  216. $oForm->setContextId($iContextId);
  217. $oForm->initChecker();
  218. if($oForm->isSubmittedAndValid()) {
  219. $iContentId = $oForm->insert([$CNF['FIELD_ALLOW_VIEW_TO'] => -$iContextId, $CNF['FIELD_TASKLIST'] => $iListId]);
  220. if($iContentId)
  221. $this->onPublished($iContentId);
  222. return $iContentId;
  223. }
  224. else {
  225. if($this->_bIsApi)
  226. return $oForm->getCodeAPI();
  227. $sContent = $this->_oTemplate->parseHtmlByName('popup_form.html', [
  228. 'form_id' => $oForm->getId(),
  229. 'form' => $oForm->getCode(true)
  230. ]);
  231. if($oForm->isSubmitted())
  232. return [
  233. 'form' => $sContent,
  234. 'form_id' => $oForm->getId()
  235. ];
  236. return $sContent;
  237. }
  238. }
  239. public function serviceProcessTaskFormEditProperty($iContentId, $sProperty)
  240. {
  241. $CNF = &$this->_oConfig->CNF;
  242. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  243. if(!$this->isAllowAdd(abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']])))
  244. return [];
  245. $sForm = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_' . strtoupper($sProperty)] ?? false;
  246. if(!$sForm)
  247. return [];
  248. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sForm);
  249. $oForm->setId($sForm);
  250. $oForm->setName($sForm);
  251. $oForm->setAction(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'process_task_form_edit_property/' . $iContentId . '/' . $sProperty . '/');
  252. if(!$oForm)
  253. return [];
  254. $oForm->initChecker($aContentInfo);
  255. if($oForm->isSubmittedAndValid()) {
  256. if(!$oForm->update($iContentId))
  257. return ['msg' => _t('_bx_tasks_txt_err_cannot_perform_action')];
  258. if(($sMethod = '_onEdit' . bx_gen_method_name($sProperty)) && method_exists($this, $sMethod))
  259. $this->$sMethod($aContentInfo, $oForm);
  260. else
  261. $this->_onEditProperty($aContentInfo, $sProperty, $oForm);
  262. return true;
  263. }
  264. else {
  265. if($this->_bIsApi)
  266. return $oForm->getCodeAPI();
  267. $sContent = $this->_oTemplate->parseHtmlByName('popup_form.html', [
  268. 'form_id' => $oForm->getId(),
  269. 'form' => $oForm->getCode(true)
  270. ]);
  271. if($oForm->isSubmitted())
  272. return [
  273. 'form' => $sContent,
  274. 'form_id' => $oForm->getId()
  275. ];
  276. return $sContent;
  277. }
  278. }
  279. public function serviceSetCompleted($iContentId, $iCompleted)
  280. {
  281. if(!$this->isAllowManage($iContentId) || !$this->complete($iContentId, $iCompleted))
  282. return ['code' => 1];
  283. return [
  284. 'code' => 0,
  285. 'reload' => 1
  286. ];
  287. }
  288. public function serviceCreateFilter($iContextId)
  289. {
  290. $iAuthorId = bx_get_logged_profile_id();
  291. $oForm = $this->_getFilterForm($iContextId);
  292. if(!$oForm)
  293. return [];
  294. $oForm->initChecker();
  295. if($oForm->isSubmittedAndValid()) {
  296. $aValsToAdd = [
  297. 'context_id' => $iContextId,
  298. 'author' => $iAuthorId,
  299. 'added' => time()
  300. ];
  301. $sTitle = '';
  302. $aValues = [];
  303. foreach($oForm->aInputs as $sName => $aInput) {
  304. if(in_array($sName, ['save_me', 'save_all', 'title', 'controls']))
  305. continue;
  306. if(($mixedValue = $oForm->getCleanValue($sName))) {
  307. $sFltTitle = '';
  308. if(($aFltValues = $aInput['values'] ?? false) && is_array($aFltValues))
  309. $sFltTitle = ' (' . (is_array($mixedValue) ? implode(', ', array_intersect_key($aFltValues, array_flip($mixedValue))) : $aFltValues[$mixedValue]) . ')';
  310. $sTitle .= $aInput['caption'] . $sFltTitle . ' + ';
  311. $aValues[] = [
  312. 'f' => $sName,
  313. 'v' => $mixedValue
  314. ];
  315. }
  316. }
  317. if($aValues && is_array($aValues) && ($aCnds = $this->_getFilterConditions($iContextId, $aValues)))
  318. $aValsToAdd['conditions'] = json_encode($aCnds);
  319. if(($bForAll = $oForm->getCleanValue('save_all') == 'on') || ($oForm->getCleanValue('save_me') == 'on')) {
  320. $aValsToAdd = array_merge($aValsToAdd, [
  321. 'author' => $bForAll ? 0 : $iAuthorId,
  322. 'title' => $oForm->getCleanValue('title') ?: $sFltTitle,
  323. 'permanent' => 1
  324. ]);
  325. }
  326. else
  327. $aValsToAdd['title'] = trim($sTitle, " +");
  328. $aRes = [];
  329. if(($iId = (int)$oForm->insert($aValsToAdd)) != 0) {
  330. $this->applyFilter($iContextId, $iId);
  331. $aRes = ['reload' => 1];
  332. }
  333. else
  334. $aRes = ['msg' => _t('_bx_tasks_txt_err_cannot_perform_action')];
  335. return $aRes;
  336. }
  337. return $this->_bIsApi ? $oForm->getCodeAPI() : $oForm;
  338. }
  339. public function serviceApplyFilter($iContextId, $iFilterId)
  340. {
  341. $this->applyFilter($iContextId, $iFilterId);
  342. return $this->_oTemplate->getEntries($iContextId, ['filter' => $iFilterId]);
  343. }
  344. public function serviceProcessTimer($sAction, $iContentId, $iProfileId)
  345. {
  346. $CNF = &$this->_oConfig->CNF;
  347. $aResult = ['code' => 1, 'msg' => _t('_sys_txt_error_occured')];
  348. $iNow = time();
  349. switch($sAction) {
  350. case 'start':
  351. $this->stopTimerByAuthor($iProfileId);
  352. $iTimer = false;
  353. $aTimer = $this->getTimer($iContentId, $iProfileId);
  354. if($aTimer && is_array($aTimer)) {
  355. if($this->updateTimerById($aTimer['id'], ['started' => $iNow]))
  356. $iTimer = $aTimer['id'];
  357. }
  358. else
  359. $iTimer = $this->_oDb->insertTimer(['content_id' => $iContentId, 'profile_id' => $iProfileId, 'started' => $iNow]);
  360. if($iTimer !== false)
  361. $aResult = ['code' => 0, 'id' => $iTimer];
  362. break;
  363. case 'stop':
  364. if($this->stopTimerByAuthor($iProfileId))
  365. $aResult = ['code' => 0];
  366. break;
  367. case 'resume':
  368. $this->stopTimerByAuthor($iProfileId);
  369. $aTimer = $this->getTimer($iContentId, $iProfileId);
  370. if($aTimer && is_array($aTimer) && $this->updateTimerById($aTimer['id'], ['started' => $iNow]))
  371. $aResult = ['code' => 0];
  372. break;
  373. case 'reload':
  374. $aTimer = $this->getTimer($iContentId, $iProfileId);
  375. $aResult = [
  376. 'code' => 0,
  377. 'started' => $aTimer && ($aTimer['started'] ?? 0) != 0
  378. ];
  379. break;
  380. case 'log':
  381. $aTimer = $this->getTimer($iContentId, $iProfileId);
  382. if(!$aTimer || !is_array($aTimer) || !$aTimer['duration'])
  383. break;
  384. list($iH, $iM) = $this->_oConfig->timeI2A($aTimer['duration'], true);
  385. $iNow = time();
  386. $iTrackId = $this->_oDb->insertTimeTrack([
  387. 'object_id' => $iContentId,
  388. 'author_id' => $iProfileId,
  389. 'author_nip' => $iProfileId == $this->_iProfileId ? bx_get_ip_hash(getVisitorIP()) : 0,
  390. 'value' => $this->_oConfig->timeA2I([(int)$iH, (int)$iM + 1]),
  391. 'value_date' => $iNow,
  392. 'date' => $iNow
  393. ]);
  394. if(!$iTrackId)
  395. break;
  396. $oTime = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS_TIME'], $iContentId);
  397. if(!$oTime || !$oTime->isEnabled())
  398. break;
  399. if(!$oTime->putReport($iContentId, $iProfileId, $iTrackId))
  400. break;
  401. $this->_oDb->deleteTimer([
  402. 'content_id' => $iContentId,
  403. 'profile_id' => $iProfileId
  404. ]);
  405. $aResult = ['code' => 0];
  406. break;
  407. case 'clear':
  408. if($this->_oDb->deleteTimer(['content_id' => $iContentId, 'profile_id' => $iProfileId]) !== false)
  409. $aResult = ['code' => 0];
  410. break;
  411. }
  412. return $aResult;
  413. }
  414. public function serviceManageTools($sType = 'common')
  415. {
  416. $CNF = &$this->_oConfig->CNF;
  417. $mixedResults = '';
  418. if(!($mixedResults = parent::serviceManageTools($sType)))
  419. return $mixedResults;
  420. return array_merge(parent::serviceManageTools($sType), [
  421. 'menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU'])
  422. ]);
  423. }
  424. public function serviceGetBlockMenuBrowse()
  425. {
  426. $mixedResult = $this->_oTemplate->getBlockMenuBrowse();
  427. return $this->_bIsApi ? [
  428. bx_api_get_block('tasks_browse', $mixedResult)
  429. ] : $mixedResult;
  430. }
  431. public function serviceGetBlockMenuContext($iProfileId)
  432. {
  433. $CNF = &$this->_oConfig->CNF;
  434. if(!$this->isAllowView($iProfileId))
  435. return $this->_bIsApi ? [] : '';
  436. $oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU_VIEW_CONTEXT']);
  437. if(!$oMenu)
  438. return $this->_bIsApi ? [] : '';
  439. $oMenu->addMarkers(['profile_id' => $iProfileId]);
  440. return $this->_bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  441. }
  442. public function serviceGetBlockContextPreValues($iContextPid = 0)
  443. {
  444. $CNF = &$this->_oConfig->CNF;
  445. if(!$this->isAllowManageByContext($iContextPid))
  446. return $this->_bIsApi ? [] : '';
  447. $bContextPid = !empty($iContextPid);
  448. $sGrid = $CNF['OBJECT_GRID_PRE_VALUES'];
  449. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  450. if(!$oGrid)
  451. return $this->_bIsApi ? [] : '';
  452. if($bContextPid)
  453. $oGrid->setContextPid($iContextPid);
  454. if($this->_bIsApi)
  455. return [
  456. bx_api_get_block('grid', $oGrid->getCodeAPI())
  457. ];
  458. $this->_oTemplate->addCss(['manage_tools.css']);
  459. $this->_oTemplate->addJs(['modules/base/text/js/|manage_tools.js', 'pre_values.js']);
  460. $this->_oTemplate->addJsTranslation(['_sys_grid_search']);
  461. $aResult = [
  462. 'content' => $this->_oTemplate->getJsCode('pre_values', [
  463. 'sObjNameGrid' => $sGrid,
  464. 'sPageUrl' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CONTEXT_VALUES'], ['profile_id' => $iContextPid])
  465. ]) . $oGrid->getCode()
  466. ];
  467. return $aResult;
  468. }
  469. public function serviceGetBlockContextAuthorize($iContextPid = 0)
  470. {
  471. $sModule = 'bx_github';
  472. $sMethod = 'get_block_authorize';
  473. if(!bx_is_srv($sModule, $sMethod))
  474. return '';
  475. $aContext = $this->_oDb->getContexts(['sample' => 'id', 'id' => $iContextPid]);
  476. if(empty($aContext) || !is_array($aContext) || empty($aContext['gh_app_id']) || empty($aContext['gh_username']) || empty($aContext['gh_repository']))
  477. return '';
  478. return bx_srv($sModule, $sMethod, [$aContext['gh_app_id']]);
  479. }
  480. public function serviceGetBlockContextSettings($iContextPid = 0)
  481. {
  482. $CNF = &$this->_oConfig->CNF;
  483. $iContextAuthorPid = 0;
  484. if(!$this->isAllowManageByContext($iContextPid) || !($iContextAuthorPid = $this->getContextAuthorId($iContextPid)))
  485. return $this->_bIsApi ? [] : '';
  486. $aContext = $this->_oDb->getContexts(['sample' => 'id', 'id' => $iContextPid]);
  487. $bContext = !empty($aContext) && is_array($aContext);
  488. $sMessageText = '';
  489. $iMessageTimer = 0;
  490. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_CONTEXT'], $CNF['OBJECT_FORM_CONTEXT_DISPLAY_EDIT']);
  491. $oForm->setProfileId($iContextAuthorPid);
  492. $oForm->initChecker($aContext);
  493. if($oForm->isSubmittedAndValid()) {
  494. if(!$bContext)
  495. $bResult = $oForm->insert(['id' => $iContextPid]);
  496. else
  497. $bResult = $oForm->update($iContextPid) !== false;
  498. $sMessageText = '_bx_tasks_txt' . (!$bResult ? '_err_cannot' : '_msg') . '_perform_action';
  499. $iMessageTimer = $bResult ? 3 : 0;
  500. }
  501. return $this->_bIsApi ? bx_api_get_block('form', $oForm->getCodeAPI(), [
  502. 'ext' => [
  503. 'name' => $oForm->getName(),
  504. 'request' => ['url' => '/api.php?r=' . $this->MODULE . '/get_block_context_settings&profile_id=' . $iContextPid, 'immutable' => true]
  505. ]
  506. ]) : (!empty($sMessageText) ? MsgBox(_t($sMessageText), $iMessageTimer) : '') . $oForm->getCode();
  507. }
  508. public function serviceGetBlockManageTime($sType = 'common', $iContextPid = 0)
  509. {
  510. $CNF = &$this->_oConfig->CNF;
  511. $bContextPid = !empty($iContextPid);
  512. $sGrid = $CNF['OBJECT_GRID_TIME_' . ($bContextPid ? 'CONTEXT_' : '') . strtoupper($sType)];
  513. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  514. if(!$oGrid)
  515. return $this->_bIsApi ? [] : '';
  516. if($bContextPid)
  517. $oGrid->setContextPid($iContextPid);
  518. if($this->_bIsApi)
  519. return [
  520. bx_api_get_block('grid', $oGrid->getCodeAPI())
  521. ];
  522. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  523. $this->_oTemplate->addCss(array_merge($aCssCalendar, ['manage_tools.css', 'time.css']));
  524. $this->_oTemplate->addJs(array_merge($aJsCalendar, ['modules/base/text/js/|manage_tools.js', 'time.js']));
  525. $this->_oTemplate->addJsTranslation(['_sys_grid_search']);
  526. $aResult = [
  527. 'content' => $this->_oTemplate->getJsCode('time', [
  528. 'sObjNameGrid' => $sGrid
  529. ]) . $oGrid->getCode()
  530. ];
  531. if(!$bContextPid)
  532. $aResult['menu'] = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU']);
  533. return $aResult;
  534. }
  535. public function serviceGetBlockTimers()
  536. {
  537. $mixedResult = $this->_oTemplate->getBlockTimers($this->_iProfileId);
  538. return $this->_bIsApi ? [
  539. bx_api_get_block('tasks_timers', $mixedResult)
  540. ] : $mixedResult;
  541. }
  542. /**
  543. * Data for Timeline module
  544. */
  545. public function serviceGetTimelineData()
  546. {
  547. $sModule = $this->_aModule['name'];
  548. return array(
  549. 'handlers' => array(
  550. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  551. array('group' => $sModule . '_completed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'completed', 'module_name' => $sModule, 'module_method' => 'get_timeline_completed', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  552. array('group' => $sModule . '_reopened', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'reopened', 'module_name' => $sModule, 'module_method' => 'get_timeline_reopened', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  553. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  554. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  555. ),
  556. 'alerts' => array(
  557. array('unit' => $sModule, 'action' => 'added'),
  558. array('unit' => $sModule, 'action' => 'completed'),
  559. array('unit' => $sModule, 'action' => 'reopened'),
  560. array('unit' => $sModule, 'action' => 'edited'),
  561. array('unit' => $sModule, 'action' => 'deleted'),
  562. )
  563. );
  564. }
  565. /**
  566. * Entry task for Timeline module
  567. */
  568. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  569. {
  570. $CNF = &$this->_oConfig->CNF;
  571. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  572. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  573. return $aResult;
  574. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  575. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  576. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  577. return $aResult;
  578. }
  579. public function serviceGetTimelineCompleted($aEvent, $aBrowseParams = array())
  580. {
  581. $CNF = &$this->_oConfig->CNF;
  582. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  583. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  584. return $aResult;
  585. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  586. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  587. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  588. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_completed');
  589. return $aResult;
  590. }
  591. public function serviceGetTimelineReopened($aEvent, $aBrowseParams = array())
  592. {
  593. $CNF = &$this->_oConfig->CNF;
  594. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  595. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  596. return $aResult;
  597. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  598. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  599. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  600. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_reopened');
  601. return $aResult;
  602. }
  603. public function serviceGetNotificationsData()
  604. {
  605. $sModule = $this->_aModule['name'];
  606. $sEventPrivacy = $sModule . '_allow_view_event_to';
  607. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  608. $sEventPrivacy = '';
  609. $aResult = parent::serviceGetNotificationsData();
  610. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  611. array('group' => $sModule . '_completed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'completed', 'module_name' => $sModule, 'module_method' => 'get_notifications_completed', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  612. array('group' => $sModule . '_reopened', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'reopened', 'module_name' => $sModule, 'module_method' => 'get_notifications_reopened', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  613. array('group' => $sModule . '_expired', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'expired', 'module_name' => $sModule, 'module_method' => 'get_notifications_expired', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  614. array('group' => $sModule . '_assign', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'assigned', 'module_name' => $sModule, 'module_method' => 'get_notifications_assigned', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  615. array('group' => $sModule . '_assign', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'unassigned'),
  616. ));
  617. $aResult['settings'] = array_merge($aResult['settings'], array(
  618. array('group' => 'content', 'unit' => $sModule, 'action' => 'completed', 'types' => array('personal', 'follow_member', 'follow_context')),
  619. array('group' => 'content', 'unit' => $sModule, 'action' => 'reopened', 'types' => array('personal', 'follow_member', 'follow_context')),
  620. array('group' => 'content', 'unit' => $sModule, 'action' => 'expired', 'types' => array('personal')),
  621. array('group' => 'content', 'unit' => $sModule, 'action' => 'assigned', 'types' => array('personal')),
  622. ));
  623. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  624. array('unit' => $sModule, 'action' => 'completed'),
  625. array('unit' => $sModule, 'action' => 'reopened'),
  626. array('unit' => $sModule, 'action' => 'expired'),
  627. array('unit' => $sModule, 'action' => 'assigned'),
  628. array('unit' => $sModule, 'action' => 'unassigned'),
  629. ));
  630. return $aResult;
  631. }
  632. public function serviceGetNotificationsCompleted($aEvent)
  633. {
  634. return $this->_serviceGetNotificationsByAction($aEvent, 'completed');
  635. }
  636. public function serviceGetNotificationsReopened($aEvent)
  637. {
  638. return $this->_serviceGetNotificationsByAction($aEvent, 'reopened');
  639. }
  640. public function serviceGetNotificationsExpired($aEvent)
  641. {
  642. return $this->_serviceGetNotificationsByAction($aEvent, 'expired');
  643. }
  644. public function serviceGetNotificationsAssigned($aEvent)
  645. {
  646. return $this->_serviceGetNotificationsByAction($aEvent, 'assigned');
  647. }
  648. protected function _serviceGetNotificationsByAction($aEvent, $sAction)
  649. {
  650. $CNF = &$this->_oConfig->CNF;
  651. $aResult = parent::serviceGetNotificationsPost($aEvent);
  652. if(empty($aResult) || !is_array($aResult))
  653. return $aResult;
  654. $aResult['entry_author'] = $aEvent['object_owner_id'];
  655. $aResult['entry_author_name'] = '';
  656. if(($oAuthor = BxDolProfile::getInstance($aResult['entry_author'])) !== false)
  657. $aResult['entry_author_name'] = $oAuthor->getDisplayName();
  658. $sLangKey = '_bx_tasks_txt_notification_' . $sAction;
  659. if((int)$aEvent['object_privacy_view'] < 0)
  660. $sLangKey .= '_in_context';
  661. $aResult['lang_key'] = _t($sLangKey);
  662. return $aResult;
  663. }
  664. public function serviceCheckAllowedManageInContext($iContextPid)
  665. {
  666. if(!$this->isAllowManageByContext($iContextPid))
  667. return false;
  668. return true;
  669. }
  670. public function serviceCheckAllowedManage($iContentId)
  671. {
  672. if(!$this->isAllowManage($iContentId))
  673. return false;
  674. return true;
  675. }
  676. public function serviceCheckAllowedComplete($iContentId)
  677. {
  678. if(!$this->serviceCheckAllowedManage($iContentId))
  679. return false;
  680. return !$this->isCompleted($iContentId);
  681. }
  682. public function serviceCheckAllowedUncomplete($iContentId)
  683. {
  684. if(!$this->serviceCheckAllowedManage($iContentId))
  685. return false;
  686. return $this->isCompleted($iContentId);
  687. }
  688. public function serviceIsCompleted($iContentId)
  689. {
  690. return $this->isCompleted($iContentId);
  691. }
  692. public function serviceIsUncompleted($iContentId)
  693. {
  694. return !$this->isCompleted($iContentId);
  695. }
  696. public function serviceIsAllowBadges($iContentId)
  697. {
  698. if (!$this->isAllowManage($iContentId))
  699. return false;
  700. if (!$this->serviceIsBadgesAvaliable())
  701. return false;
  702. return true;
  703. }
  704. public function serviceEntityAssignments($iContentId = 0, $bAsArray = false)
  705. {
  706. if(!$iContentId)
  707. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  708. if(!$iContentId)
  709. return false;
  710. $CNF = &$this->_oConfig->CNF;
  711. $aProfiles = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])->getConnectedInitiators($iContentId);
  712. if($bAsArray)
  713. return $aProfiles;
  714. $mixedResult = $this->_oTemplate->entryAssignments($aProfiles);
  715. return $this->_bIsApi ? [
  716. bx_api_get_block('task_assignments', $mixedResult)
  717. ] : $mixedResult;
  718. }
  719. public function serviceEntityTimer($iContentId = 0)
  720. {
  721. if(!$iContentId)
  722. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  723. if(!$iContentId)
  724. return false;
  725. $mixedResult = $this->_oTemplate->entryTimer($iContentId, $this->_iProfileId);
  726. return $this->_bIsApi ? [
  727. bx_api_get_block('task_timer', $mixedResult)
  728. ] : $mixedResult;
  729. }
  730. public function serviceCheckAllowedCommentsTask($iContentId, $sObjectComments)
  731. {
  732. $CNF = &$this->_oConfig->CNF;
  733. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  734. if($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  735. return false;
  736. return parent::serviceCheckAllowedCommentsTask($iContentId, $sObjectComments);
  737. }
  738. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  739. {
  740. $CNF = &$this->_oConfig->CNF;
  741. //negative id used in comments for reports
  742. if($iContentId < 0)
  743. return CHECK_ACTION_RESULT_ALLOWED;
  744. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  745. if($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  746. return false;
  747. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  748. }
  749. /**
  750. * @page service Service Calls
  751. * @section bx_tasks Tasks
  752. * @subsection bx_tasks-page_blocks Page Blocks
  753. * @subsubsection bx_tasks-calendar calendar
  754. *
  755. * @code bx_srv('bx_tasks', 'calendar', [...]); @endcode
  756. *
  757. * Shows tasks calendar baced on die date
  758. *
  759. * @param $aData additional data to point which events to show, leave empty to show all events, specify event's ID in 'event' array key to show calendar for one event only, specify context's ID in 'context_id' array key to show calendar for one context events only. If only one event is specified then it will show calendar only if it's repeating event.
  760. * @param $sTemplate template to use to show calendar, or leave empty for default template, possible options: calendar.html, calendar_compact.html
  761. * @return HTML string with calendar to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML. On error empty string is returned.
  762. *
  763. * @see BxTasksModule::serviceCalendar
  764. */
  765. /**
  766. * @ref bx_tasks-calendar "calendar"
  767. */
  768. public function serviceCalendar($aData = array(), $sTemplate = 'calendar.html')
  769. {
  770. if (!$this->isAllowView($aData['context_id']))
  771. return;
  772. $o = new BxTemplCalendar(array(
  773. 'eventSources' => array (
  774. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'calendar_data', $aData),
  775. ),
  776. ), $this->_oTemplate);
  777. return $o->display($sTemplate);
  778. }
  779. public function serviceGetCalendarEntries($iProfileId)
  780. {
  781. $CNF = &$this->_oConfig->CNF;
  782. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  783. $aData = $oConn->getConnectedInitiators($iProfileId);
  784. $aData2 = array(0);
  785. foreach($aData as $iProfileId2) {
  786. $oProfile = BxDolProfile::getInstance($iProfileId2);
  787. array_push($aData2, $oProfile->getContentId());
  788. }
  789. $aSQLPart['where'] = " AND " . $CNF['TABLE_ENTRIES'] . ".`" . $CNF['FIELD_ID'] . "` IN(" . implode(',', $aData2) . ")";
  790. return $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), null, $aSQLPart);
  791. }
  792. public function serviceBrowseHome($aParams = [])
  793. {
  794. $sContent = '';
  795. if(($iContextPid = bx_process_input(bx_get('context_pid'), BX_DATA_INT))) {
  796. $sContent = $this->serviceBrowseTasks($iContextPid);
  797. if($sContent && ($oProfile = BxDolProfile::getInstance($iContextPid)) !== false)
  798. return [
  799. 'title' => bx_replace_markers(_t('_bx_tasks_page_block_title_entries_in_context'), [
  800. 'display_name' => $oProfile->getDisplayName(),
  801. 'profile_link' => $oProfile->getUrl()
  802. ]),
  803. 'content' => $sContent
  804. ];
  805. }
  806. else
  807. $sContent = $this->serviceBrowseTasksByProfile();
  808. return $sContent ?: MsgBox(_t('_Empty'));
  809. }
  810. public function serviceBrowseContext($iProfileId = 0, $aParams = [])
  811. {
  812. if(!$iProfileId)
  813. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  814. if(!$iProfileId)
  815. return '';
  816. return $this->serviceBrowseTasks ($iProfileId, $aParams);
  817. }
  818. public function serviceBrowseTasks($iContextId = 0, $aParams = [])
  819. {
  820. if(!$this->isAllowView($iContextId))
  821. return $this->_bIsApi ? [] : '';
  822. $mixedResult = $this->_oTemplate->getEntriesList($iContextId, $aParams);
  823. return $this->_bIsApi ? [
  824. bx_api_get_block('tasks_list', $mixedResult)
  825. ] : $mixedResult;
  826. }
  827. public function serviceBrowseTasksByProfile($iProfileId = 0, $aParams = [])
  828. {
  829. if(!$iProfileId && $this->_iProfileId)
  830. $iProfileId = $this->_iProfileId;
  831. return $this->_oTemplate->getEntriesList(0, array_merge($aParams, [
  832. 'for_profile' => $iProfileId
  833. ]));
  834. }
  835. /**
  836. * Common methods
  837. */
  838. public function getModuleTitle($sName)
  839. {
  840. $sResult = $sName;
  841. if(($_sTitle = '_' . $sName) && ($sTitle = _t($_sTitle)) && strcmp($_sTitle, $sTitle) != 0)
  842. $sResult = $sTitle;
  843. else if(($aModule = $this->_oModule->_oDb->getModuleByName($sName)) && is_array($aModule))
  844. $sResult = $aModule['title'] ?? _t('_undefined');
  845. return $sResult;
  846. }
  847. public function getAssignees()
  848. {
  849. $aResults = [];
  850. if(($oProfile = BxDolProfile::getInstance()) !== false && ($aIds = $this->_oDb->getTimeTracks(['sample' => 'assignees'])))
  851. foreach($aIds as $iId)
  852. $aResults[] = ['key' => $iId, 'value' => $oProfile->getDisplayName($iId)];
  853. return $aResults;
  854. }
  855. public function getPreLists()
  856. {
  857. $CNF = &$this->_oConfig->CNF;
  858. $aResults = [];
  859. if(($aPreLists = $this->_oDb->getPreLists(['sample' => 'all'])) && is_array($aPreLists))
  860. foreach($aPreLists as $aPreList)
  861. $aResults[$aPreList['name']] = _t($aPreList['title']);
  862. return $aResults;
  863. }
  864. public function getContexts()
  865. {
  866. $aContexts = [];
  867. $aModules = bx_srv('system', 'get_modules_by_type', ['context', ['name_as_key' => true]]);
  868. foreach($aModules as $sModule => $aModule)
  869. $aContexts[$sModule] = ($_sTitle = '_' . $sModule) && ($sTitle = _t($_sTitle)) && strcmp($_sTitle, $sTitle) != 0 ? $sTitle : $aModule['title'];
  870. return $aContexts;
  871. }
  872. public function getContextAuthorId($iContextPid)
  873. {
  874. $iContextAuthorPid = 0;
  875. if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false)
  876. $iContextAuthorPid = bx_srv($oContext->getModule(), 'get_author', [$oContext->getContentId()]);
  877. return $iContextAuthorPid;
  878. }
  879. public function getContextMembers($iContextPid)
  880. {
  881. $aMembers = [];
  882. if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false) {
  883. $aPids = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
  884. foreach($aPids as $iPid)
  885. $aMembers[$iPid] = $oContext->getDisplayName($iPid);
  886. }
  887. return $aMembers;
  888. }
  889. public function getContextEntries($iContextPid)
  890. {
  891. $CNF = &$this->_oConfig->CNF;
  892. $aEntries = [];
  893. if(($aTasks = $this->_oDb->getTasks($iContextPid)) && is_array($aTasks))
  894. foreach($aTasks as $aTask)
  895. $aEntries[$aTask[$CNF['FIELD_ID']]] = $aTask[$CNF['FIELD_TITLE']];
  896. return $aEntries;
  897. }
  898. public function getTimer($iContentId, $iProfileId)
  899. {
  900. return $this->_oDb->getTimers(['sample' => 'content_profile_ids', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
  901. }
  902. public function getTimersByAuthor($iProfileId, $bActive = false)
  903. {
  904. return $this->_oDb->getTimers(['sample' => 'profile_id', 'profile_id' => $iProfileId, 'active' => $bActive]);
  905. }
  906. public function stopTimerByAuthor($iProfileId)
  907. {
  908. $aTimer = $this->getTimersByAuthor($iProfileId, true);
  909. if(!$aTimer || !is_array($aTimer))
  910. return false;
  911. return $this->updateTimerById($aTimer['id'], [
  912. 'started' => 0,
  913. 'duration' => $aTimer['duration'] + (time() - $aTimer['started']),
  914. ]);
  915. }
  916. public function updateTimerById($iId, $aSet)
  917. {
  918. return $this->_oDb->updateTimer($aSet, ['id' => (int)$iId]) !== false;
  919. }
  920. public function onPublished($iContentId)
  921. {
  922. parent::onPublished($iContentId);
  923. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  924. if(!$aContentInfo)
  925. return;
  926. $CNF = &$this->_oConfig->CNF;
  927. if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0) {
  928. $iContextId = abs($iContextId);
  929. $mixedRepo = $this->ghGetRepository($iContextId);
  930. if($mixedRepo !== false && ($sMl = 'bx_github') && ($sMd = 'create_issue') && bx_is_srv($sMl, $sMd)) {
  931. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  932. $aFldLoc2Repo = [
  933. $CNF['FIELD_STICKERS'] => 'labels',
  934. $CNF['FIELD_TYPE'] => 'type',
  935. ];
  936. $aGhFields = [];
  937. foreach($aFldLoc2Repo as $sLocField => $sRepoField)
  938. if(($sLocValue = $aContentInfo[$sLocField] ?? false))
  939. switch($sLocField) {
  940. case $CNF['FIELD_STICKERS']:
  941. $aStickers = $this->getStickers($sLocValue, $iContextId);
  942. if($aStickers && is_array($aStickers)) {
  943. $aGhFields[$sRepoField] = [];
  944. foreach($aStickers as $aSticker)
  945. $aGhFields[$sRepoField][] = $aSticker['title'];
  946. }
  947. break;
  948. case $CNF['FIELD_TYPE']:
  949. $aGhFields[$sRepoField] = $this->getType($sLocValue, $iContextId);
  950. break;
  951. default:
  952. $aGhFields[$sRepoField] = $sLocValue;
  953. }
  954. $aIssue = bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $aContentInfo[$CNF['FIELD_TITLE']], $aContentInfo[$CNF['FIELD_TEXT']], $aGhFields]);
  955. if($aIssue && is_array($aIssue) && ($iNumber = (int)($aIssue['number'] ?? 0)) != 0 && ($sUrl = $aIssue['html_url'] ?? '') != '') {
  956. $this->_oDb->updateEntriesBy([
  957. $CNF['FIELD_GH_ISSUE'] => $iNumber,
  958. $CNF['FIELD_GH_ISSUE_URL'] => $sUrl,
  959. ], [$CNF['FIELD_ID'] => $iContentId]);
  960. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
  961. 'ghi_link' => $sUrl,
  962. 'ghi_number' => $iNumber
  963. ]]);
  964. }
  965. }
  966. }
  967. }
  968. public function onExpired($iContentId)
  969. {
  970. $CNF = &$this->_oConfig->CNF;
  971. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  972. if(!$aContentInfo)
  973. return;
  974. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  975. if($oConnection) {
  976. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  977. if(!empty($aProfileIds) && is_array($aProfileIds))
  978. foreach($aProfileIds as $iProfileId){
  979. /**
  980. * @hooks
  981. * @hookdef hook-bx_tasks-expired 'bx_tasks', 'expired' - hook on task unassigned to profile
  982. * - $unit_name - equals `bx_tasks`
  983. * - $action - equals `expired`
  984. * - $object_id - task id
  985. * - $sender_id - not used
  986. * - $extra_params - array of additional params with the following array keys:
  987. * - `object_author_id` - [int] profile_id for task's author
  988. * - `privacy_view` - [string] privacy view value
  989. * @hook @ref hook-bx_tasks-expired
  990. */
  991. bx_alert($this->getName(), 'expired', $iContentId, false, array(
  992. 'object_author_id' => $iProfileId,
  993. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  994. ));
  995. }
  996. }
  997. }
  998. public function isAllowView($iContextId)
  999. {
  1000. if(!($oContext = BxDolProfile::getInstance($iContextId)) || $oContext->checkAllowedProfileView($iContextId) !== CHECK_ACTION_RESULT_ALLOWED)
  1001. return false;
  1002. return true;
  1003. }
  1004. public function isAllowAdd($iContextId)
  1005. {
  1006. if(!($oContext = BxDolProfile::getInstance($iContextId)) || $oContext->checkAllowedPostInProfile($iContextId) !== CHECK_ACTION_RESULT_ALLOWED)
  1007. return false;
  1008. return true;
  1009. }
  1010. public function isAllowManageByContext($iContextId)
  1011. {
  1012. if(isAdmin())
  1013. return true;
  1014. $oProfileContext = BxDolProfile::getInstance($iContextId);
  1015. if(BxDolService::call($oProfileContext->getModule(), 'is_admin', array($iContextId)))
  1016. return true;
  1017. return false;
  1018. }
  1019. public function isAllowEdit($mixedContent)
  1020. {
  1021. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  1022. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  1023. return true;
  1024. return false;
  1025. }
  1026. public function isAllowManage($mixedContent)
  1027. {
  1028. $CNF = &$this->_oConfig->CNF;
  1029. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  1030. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  1031. return true;
  1032. if($this->isAllowManageByContext(abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']])))
  1033. return true;
  1034. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  1035. $iLoggedId = bx_get_logged_profile_id();
  1036. $aProfileIds = $oConnection->getConnectedInitiators($aContentInfo[$CNF['FIELD_ID']]);
  1037. if(!empty($aProfileIds) && is_array($aProfileIds) && in_array($iLoggedId, $aProfileIds))
  1038. return true;
  1039. }
  1040. return false;
  1041. }
  1042. /**
  1043. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1044. */
  1045. public function checkAllowedManage ($aDataEntry, $isPerformAction = false)
  1046. {
  1047. return $this->isAllowManage($aDataEntry) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  1048. }
  1049. public function isCompleted($iContentId)
  1050. {
  1051. $CNF = &$this->_oConfig->CNF;
  1052. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1053. return (bool)$aContentInfo[$CNF['FIELD_COMPLETED']];
  1054. }
  1055. public function complete($iContentId, $iCompleted)
  1056. {
  1057. $CNF = &$this->_oConfig->CNF;
  1058. $iCompleted = (int)$iCompleted;
  1059. $this->_oDb->updateEntriesBy([$CNF['FIELD_COMPLETED'] => $iCompleted], [$CNF['FIELD_ID'] => (int)$iContentId]);
  1060. $sModule = $this->getName();
  1061. $sAction = !$iCompleted ? 'reopened' : 'completed';
  1062. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1063. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1064. /**
  1065. * @hooks
  1066. * @hookdef hook-bx_tasks-completed 'bx_tasks', 'completed' - hook on task unassigned to profile
  1067. * - $unit_name - equals `bx_tasks`
  1068. * - $action - can be `completed` or `reopened`
  1069. * - $object_id - task id
  1070. * - $sender_id - not used
  1071. * - $extra_params - array of additional params with the following array keys:
  1072. * - `object_author_id` - [int] profile_id for task's author
  1073. * - `privacy_view` - [string] privacy view value
  1074. * @hook @ref hook-bx_tasks-completed
  1075. */
  1076. bx_alert($sModule, $sAction, $iContentId, false, array(
  1077. 'object_author_id' => $iContentAuthor,
  1078. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  1079. ));
  1080. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  1081. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  1082. if(!empty($aProfileIds) && is_array($aProfileIds))
  1083. foreach($aProfileIds as $iProfileId) {
  1084. if($iProfileId == $iContentAuthor)
  1085. continue;
  1086. bx_alert($sModule, $sAction, $iContentId, false, array(
  1087. 'object_author_id' => $iProfileId,
  1088. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  1089. ));
  1090. }
  1091. }
  1092. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_' . ($iCompleted ? '' : 'un') . 'completed']);
  1093. if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepo = $this->ghGetRepository(abs($iContextId))) !== false) {
  1094. $sModule = 'bx_github';
  1095. $sMethod = ($iCompleted ? 'close' : 'reopen') . '_issue';
  1096. if(bx_is_srv($sModule, $sMethod) && ($iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']]) != 0) {
  1097. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1098. bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue]);
  1099. }
  1100. }
  1101. return true;
  1102. }
  1103. public function logActivity($iContentId, $aMessage)
  1104. {
  1105. $CNF = &$this->_oConfig->CNF;
  1106. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1107. if(!$oCmts || !$oCmts->isEnabled())
  1108. return false;
  1109. if(($oAuthor = BxDolProfile::getInstance()) !== false)
  1110. $aMessage['markers'] = array_merge($aMessage['markers'] ?? [], [
  1111. 'author_link' => $oAuthor->getUrl(),
  1112. 'author_name' => $oAuthor->getDisplayName(),
  1113. ]);
  1114. return $oCmts->addAuto($aMessage);
  1115. }
  1116. public function ghGetRepository($iContextId)
  1117. {
  1118. $mixedRepo = $this->_oDb->getContextRepository($iContextId);
  1119. if($mixedRepo === false)
  1120. return false;
  1121. return [
  1122. $mixedRepo['gh_username'],
  1123. $mixedRepo['gh_repository'],
  1124. $mixedRepo['gh_app_id'] ? [$this->_iProfileId, (int)$mixedRepo['gh_app_id']] : $this->_iProfileId
  1125. ];
  1126. }
  1127. public function ghUpdateIssue($mixedContent, $aGhFields = [])
  1128. {
  1129. $aContentInfo = is_array($mixedContent) ? $mixedContent : $this->_oDb->getContentInfoById((int)$mixedContent);
  1130. if(!$aContentInfo || !is_array($aContentInfo))
  1131. return false;
  1132. $CNF = &$this->_oConfig->CNF;
  1133. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1134. $iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1135. if($iContextId >= 0)
  1136. return false;
  1137. $mixedRepo = $this->ghGetRepository(abs($iContextId));
  1138. if($mixedRepo === false)
  1139. return false;
  1140. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1141. $iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']];
  1142. $sMl = 'bx_github';
  1143. if($aGhFields && ($sMd = 'update_issue') && bx_is_srv($sMl, $sMd))
  1144. if(bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue, $aGhFields]) !== false)
  1145. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
  1146. 'ghi_link' => $aContentInfo[$CNF['FIELD_GH_ISSUE_URL']],
  1147. 'ghi_number' => $iGhIssue
  1148. ]]);
  1149. return true;
  1150. }
  1151. public function getStickers($mixedValues, $iContextId = 0)
  1152. {
  1153. $CNF = &$this->_oConfig->CNF;
  1154. $aValues = is_array($mixedValues) ? $mixedValues : BxDolFormCheckerHelper::displaySet($mixedValues);
  1155. $aResults = [];
  1156. if($iContextId) {
  1157. $aStickers = $this->_oDb->getPreValues([
  1158. 'sample' => 'context_list',
  1159. 'context_id' => $iContextId,
  1160. 'list' => 'sticker'
  1161. ]);
  1162. foreach($aValues as $sValue)
  1163. if(($aSticker = $aStickers[$sValue] ?? false))
  1164. $aResults[] = [
  1165. 'title' => $aSticker['title'],
  1166. 'color' => $aSticker['color']
  1167. ];
  1168. }
  1169. if(!$aResults) {
  1170. $aStickers = BxDolForm::getDataItems($CNF['OBJECT_PRE_LIST_STICKERS']);
  1171. foreach($aValues as $sValue)
  1172. $aResults[] = [
  1173. 'title' => $aStickers[$sValue],
  1174. 'color' => ''
  1175. ];
  1176. }
  1177. return $aResults;
  1178. }
  1179. public function getType($mixedValue, $iContextId = 0)
  1180. {
  1181. $sResult = '';
  1182. if($iContextId) {
  1183. $aType = $this->_oDb->getPreValues([
  1184. 'sample' => 'context_list_value',
  1185. 'context_id' => $iContextId,
  1186. 'list' => 'type',
  1187. 'value' => $mixedValue
  1188. ]);
  1189. if($aType && is_array($aType))
  1190. $sResult = $aType['title'];
  1191. }
  1192. if(!$sResult && ($sTypeTitle = $this->_oConfig->getTypeTitle($mixedValue)) != '')
  1193. $sResult = _t($sTypeTitle);
  1194. return $sResult;
  1195. }
  1196. public function applyFilter($iContextId, $iFilterId)
  1197. {
  1198. $sCookieKey = $this->_oConfig->CNF['COOKIE_SETTING_KEY'];
  1199. $aFilters = [];
  1200. if(isset($_COOKIE[$sCookieKey]))
  1201. $aFilters = json_decode($_COOKIE[$sCookieKey], true);
  1202. if(($iFilterId = (int)$iFilterId) != 0)
  1203. $aFilters[$iContextId] = $iFilterId;
  1204. else
  1205. unset($aFilters[$iContextId]);
  1206. bx_setcookie($sCookieKey, json_encode($aFilters), time() + 60 * 60 * 24 * 365);
  1207. }
  1208. /**
  1209. * Internal methods
  1210. */
  1211. protected function _onEditProperty($aContentInfo, $sProperty, &$oForm)
  1212. {
  1213. $CNF = &$this->_oConfig->CNF;
  1214. $aPropLoc2Repo = [
  1215. $CNF['FIELD_TYPE'] => 'type',
  1216. ];
  1217. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1218. $mixedValue = $oForm->getCleanValue($CNF['FIELD_' . strtoupper($sProperty)]);
  1219. if(($sMethod = 'get' . bx_gen_method_name($sProperty) . 'Title') && method_exists($this->_oConfig, $sMethod))
  1220. $mixedValue = $this->_oConfig->$sMethod($mixedValue);
  1221. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_' . $sProperty, 'markers' => ['value' => $mixedValue]]);
  1222. if(($sPropRepo = $aPropLoc2Repo[$sProperty] ?? false))
  1223. $this->ghUpdateIssue($aContentInfo, [
  1224. $sPropRepo => _t($mixedValue)
  1225. ]);
  1226. }
  1227. protected function _onEditState($aContentInfo, &$oForm)
  1228. {
  1229. $CNF = &$this->_oConfig->CNF;
  1230. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1231. $iState = $oForm->getCleanValue($CNF['FIELD_STATE']);
  1232. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_state', 'markers' => ['value' => $this->_oConfig->getStateTitle($iState)]]);
  1233. $iCompleted = (int)$this->_oConfig->isCompleted($iState);
  1234. if($iCompleted != (int)$this->_oConfig->isCompleted($aContentInfo[$CNF['FIELD_STATE']]))
  1235. $this->complete($iContentId, $iCompleted);
  1236. }
  1237. protected function _getFilterConditions($iContextId = 0, $aItems = [])
  1238. {
  1239. $iJoins = 0;
  1240. $aResult = [
  1241. 'join' => [],
  1242. 'where' => []
  1243. ];
  1244. if(count($aItems) > 1) {
  1245. $aResult['where'] = ['grp' => true, 'o' => 'AND', 'cnds' => []];
  1246. foreach($aItems as $aItem)
  1247. if(($mixedCnd = $this->_getFilterCondition($iContextId, $aItem)) !== false) {
  1248. if(isset($mixedCnd['join'])) {
  1249. $iJoins++;
  1250. $aResult['join'][] = $mixedCnd['join'];
  1251. }
  1252. if(isset($mixedCnd['where']))
  1253. $aResult['where']['cnds'][] = $mixedCnd['where'];
  1254. }
  1255. }
  1256. else {
  1257. $mixedCnd = $this->_getFilterCondition($iContextId, reset($aItems));
  1258. if(isset($mixedCnd['join'])) {
  1259. $iJoins++;
  1260. $aResult['join'][] = $mixedCnd['join'];
  1261. }
  1262. if(isset($mixedCnd['where']))
  1263. $aResult['where'] = $mixedCnd['where'];
  1264. }
  1265. if($iJoins == 1)
  1266. $aResult['join'] = reset($aResult['join']);
  1267. else if($iJoins > 1)
  1268. $aResult['join'] = ['grp' => true, 'cnds' => $aResult['join']];
  1269. return $aResult;
  1270. }
  1271. protected function _getFilterCondition($iContextId = 0, $aItem = [])
  1272. {
  1273. $sMethod = '_getFilterCondition' . bx_gen_method_name($aItem['f']);
  1274. if(method_exists($this, $sMethod))
  1275. return $this->$sMethod($iContextId, $aItem);
  1276. $mixedV = $mixedO = false;
  1277. if(!($bArray = is_array($aItem['v'])) || count($aItem['v']) == 1) {
  1278. $mixedV = $bArray ? reset($aItem['v']) : $aItem['v'];
  1279. $mixedO = '=';
  1280. }
  1281. else {
  1282. $mixedV = $aItem['v'];
  1283. $mixedO = 'IN';
  1284. }
  1285. if(!$mixedV || !$mixedO)
  1286. return false;
  1287. return [
  1288. 'where' => ['cnd' => true, 't' => 'te', 'f' => $aItem['f'], 'v' => $mixedV, 'o' => $mixedO]
  1289. ];
  1290. }
  1291. protected function _getFilterConditionInitialMembers ($iContextId = 0, $aItem = [])
  1292. {
  1293. $CNF = &$this->_oConfig->CNF;
  1294. return [
  1295. 'join' => ['cnd' => true, 'j' => 'LEFT', 'tj' => $CNF['TABLE_ASSIGNMENTS'], 'taj' => 'ta', 'fj' => 'content', 'tam' => 'te', 'fm' => 'id'],
  1296. 'where' => ['cnd' => true, 't' => 'ta', 'f' => 'initiator', 'v' => $aItem['v'], 'o' => '=']
  1297. ];
  1298. }
  1299. protected function _getFilterForm($iContextId = 0)
  1300. {
  1301. $CNF = &$this->_oConfig->CNF;
  1302. $sJsObject = $this->_oConfig->getJsObject('tasks');
  1303. $aFieldToList = [
  1304. $CNF['FIELD_TYPE'] => $CNF['OBJECT_PRE_LIST_TYPES'],
  1305. $CNF['FIELD_PRIORITY'] => $CNF['OBJECT_PRE_LIST_PRIORITIES'],
  1306. $CNF['FIELD_ESTIMATE'] => $CNF['OBJECT_PRE_LIST_ESTIMATES'],
  1307. $CNF['FIELD_STATE'] => $CNF['OBJECT_PRE_LIST_STATES']
  1308. ];
  1309. $aForm = [
  1310. 'form_attrs' => [
  1311. 'id' => 'bx-tasks-filter-add',
  1312. 'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'create_filter/' . $iContextId,
  1313. 'method' => BX_DOL_FORM_METHOD_DEFAULT
  1314. ],
  1315. 'params' => [
  1316. 'db' => [
  1317. 'table' => $CNF['TABLE_FILTERS'],
  1318. 'key' => 'id',
  1319. 'uri' => '',
  1320. 'uri_title' => '',
  1321. 'submit_name' => 'do_apply'
  1322. ],
  1323. ],
  1324. 'inputs' => [
  1325. $CNF['FIELD_AUTHOR'] => [
  1326. 'type' => 'radio_set',
  1327. ],
  1328. $CNF['FIELD_INITIAL_MEMBERS'] => [
  1329. 'type' => 'radio_set',
  1330. ],
  1331. $CNF['FIELD_TYPE'] => [
  1332. 'type' => 'checkbox_set',
  1333. ],
  1334. $CNF['FIELD_PRIORITY'] => [
  1335. 'type' => 'checkbox_set',
  1336. ],
  1337. $CNF['FIELD_ESTIMATE'] => [
  1338. 'type' => 'checkbox_set',
  1339. ],
  1340. $CNF['FIELD_STATE'] => [
  1341. 'type' => 'checkbox_set',
  1342. ],
  1343. 'save_me' => [
  1344. 'type' => 'switcher',
  1345. 'name' => 'save_me',
  1346. 'caption' => _t('_bx_tasks_form_f_input_save_me'),
  1347. 'value' => 'on',
  1348. 'attrs' => [
  1349. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1350. ]
  1351. ],
  1352. 'save_all' => [
  1353. 'type' => 'switcher',
  1354. 'name' => 'save_all',
  1355. 'caption' => _t('_bx_tasks_form_f_input_save_all'),
  1356. 'value' => 'on',
  1357. 'attrs' => [
  1358. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1359. ]
  1360. ],
  1361. 'title' => [
  1362. 'type' => 'text',
  1363. 'name' => 'title',
  1364. 'caption' => _t('_bx_tasks_form_f_input_title'),
  1365. 'value' => '',
  1366. 'required' => '0',
  1367. 'tr_attrs' => [
  1368. 'class' => 'bx-tasks-ffi-hidden'
  1369. ]
  1370. ],
  1371. 'controls' => [
  1372. 'name' => 'controls',
  1373. 'type' => 'input_set',
  1374. [
  1375. 'type' => 'submit',
  1376. 'name' => 'do_apply',
  1377. 'value' => _t('_bx_tasks_form_f_input_apply'),
  1378. ], [
  1379. 'type' => 'reset',
  1380. 'name' => 'do_cancel',
  1381. 'value' => _t('_bx_tasks_form_f_input_cancel'),
  1382. 'attrs' => [
  1383. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1384. 'class' => 'bx-def-margin-sec-left',
  1385. ],
  1386. ]
  1387. ]
  1388. ]
  1389. ];
  1390. foreach($aForm['inputs'] as $sName => $aInput) {
  1391. if(isset($aInput['name']))
  1392. continue;
  1393. $aForm['inputs'][$sName] = array_merge($aForm['inputs'][$sName], [
  1394. 'name' => $sName,
  1395. 'caption' => _t('_bx_tasks_form_f_input_' . $sName),
  1396. 'value' => '',
  1397. 'values' => []
  1398. ]);
  1399. if(($sList = $aFieldToList[$sName] ?? false) && ($aList = BxDolForm::getDataItems($sList))) {
  1400. if(isset($aList['']))
  1401. unset($aList['']);
  1402. $aForm['inputs'][$sName]['values'] = $aList;
  1403. }
  1404. }
  1405. $oContext = false;
  1406. $sContextModule = '';
  1407. if($iContextId && ($oContext = BxDolProfile::getInstance($iContextId)) !== false)
  1408. $sContextModule = $oContext->getModule();
  1409. foreach([$CNF['FIELD_AUTHOR'], $CNF['FIELD_INITIAL_MEMBERS']] as $sK)
  1410. if(isset($aForm['inputs'][$sK])) {
  1411. $aForm['inputs'][$sK]['values']['{logged_pid}'] = _t('_bx_tasks_txt_flt_user_current');
  1412. if($oContext !== false) {
  1413. $aMembers = bx_srv($sContextModule, 'fans', [$oContext->getContentId(), true]);
  1414. foreach($aMembers as $iMember)
  1415. if(($iMember != $this->_iProfileId) && ($oMember = BxDolProfile::getInstance($iMember)) !== false && !($oMember instanceof BxDolProfileUndefined))
  1416. $aForm['inputs'][$sK]['values'][$iMember] = $oMember->getDisplayName();
  1417. }
  1418. }
  1419. if(!$oContext || !bx_srv($sContextModule, 'is_admin', [$iContextId, $this->_iProfileId]))
  1420. unset($aForm['inputs']['save_all']);
  1421. return new BxTemplFormView($aForm);
  1422. }
  1423. }
  1424. /** @} */