1
0

BxTasksModule.php 62 KB

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