BxTasksModule.php 63 KB

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