BxTasksModule.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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->ghGetRepository($iContextId);
  892. if($mixedRepo !== false && ($sMl = 'bx_github') && ($sMd = 'create_issue') && bx_is_srv($sMl, $sMd)) {
  893. list($sGhUsername, $sGhRepository, $mixedAuth) = $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, $mixedAuth, $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 isAllowEdit($mixedContent)
  982. {
  983. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  984. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  985. return true;
  986. return false;
  987. }
  988. public function isAllowManage($mixedContent)
  989. {
  990. $CNF = &$this->_oConfig->CNF;
  991. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  992. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  993. return true;
  994. if($this->isAllowManageByContext(abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']])))
  995. return true;
  996. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  997. $iLoggedId = bx_get_logged_profile_id();
  998. $aProfileIds = $oConnection->getConnectedInitiators($aContentInfo[$CNF['FIELD_ID']]);
  999. if(!empty($aProfileIds) && is_array($aProfileIds) && in_array($iLoggedId, $aProfileIds))
  1000. return true;
  1001. }
  1002. return false;
  1003. }
  1004. /**
  1005. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1006. */
  1007. public function checkAllowedManage ($aDataEntry, $isPerformAction = false)
  1008. {
  1009. return $this->isAllowManage($aDataEntry) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  1010. }
  1011. public function isCompleted($iContentId)
  1012. {
  1013. $CNF = &$this->_oConfig->CNF;
  1014. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1015. return (bool)$aContentInfo[$CNF['FIELD_COMPLETED']];
  1016. }
  1017. public function complete($iContentId, $iCompleted)
  1018. {
  1019. $CNF = &$this->_oConfig->CNF;
  1020. $iCompleted = (int)$iCompleted;
  1021. $this->_oDb->updateEntriesBy([$CNF['FIELD_COMPLETED'] => $iCompleted], [$CNF['FIELD_ID'] => (int)$iContentId]);
  1022. $sModule = $this->getName();
  1023. $sAction = !$iCompleted ? 'reopened' : 'completed';
  1024. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1025. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1026. /**
  1027. * @hooks
  1028. * @hookdef hook-bx_tasks-completed 'bx_tasks', 'completed' - hook on task unassigned to profile
  1029. * - $unit_name - equals `bx_tasks`
  1030. * - $action - can be `completed` or `reopened`
  1031. * - $object_id - task id
  1032. * - $sender_id - not used
  1033. * - $extra_params - array of additional params with the following array keys:
  1034. * - `object_author_id` - [int] profile_id for task's author
  1035. * - `privacy_view` - [string] privacy view value
  1036. * @hook @ref hook-bx_tasks-completed
  1037. */
  1038. bx_alert($sModule, $sAction, $iContentId, false, array(
  1039. 'object_author_id' => $iContentAuthor,
  1040. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  1041. ));
  1042. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  1043. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  1044. if(!empty($aProfileIds) && is_array($aProfileIds))
  1045. foreach($aProfileIds as $iProfileId) {
  1046. if($iProfileId == $iContentAuthor)
  1047. continue;
  1048. bx_alert($sModule, $sAction, $iContentId, false, array(
  1049. 'object_author_id' => $iProfileId,
  1050. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  1051. ));
  1052. }
  1053. }
  1054. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_' . ($iCompleted ? '' : 'un') . 'completed']);
  1055. if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepo = $this->ghGetRepository(abs($iContextId))) !== false) {
  1056. $sModule = 'bx_github';
  1057. $sMethod = ($iCompleted ? 'close' : 'reopen') . '_issue';
  1058. if(bx_is_srv($sModule, $sMethod) && ($iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']]) != 0) {
  1059. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1060. bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue]);
  1061. }
  1062. }
  1063. return true;
  1064. }
  1065. public function logActivity($iContentId, $aMessage)
  1066. {
  1067. $CNF = &$this->_oConfig->CNF;
  1068. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1069. if(!$oCmts || !$oCmts->isEnabled())
  1070. return false;
  1071. if(($oAuthor = BxDolProfile::getInstance()) !== false)
  1072. $aMessage['markers'] = array_merge($aMessage['markers'] ?? [], [
  1073. 'author_link' => $oAuthor->getUrl(),
  1074. 'author_name' => $oAuthor->getDisplayName(),
  1075. ]);
  1076. return $oCmts->addAuto($aMessage);
  1077. }
  1078. public function ghGetRepository($iContextId)
  1079. {
  1080. $mixedRepo = $this->_oDb->getContextRepository($iContextId);
  1081. if($mixedRepo === false)
  1082. return false;
  1083. return [
  1084. $mixedRepo['gh_username'],
  1085. $mixedRepo['gh_repository'],
  1086. $mixedRepo['gh_app_id'] ? [$this->_iProfileId, (int)$mixedRepo['gh_app_id']] : $this->_iProfileId
  1087. ];
  1088. }
  1089. public function ghUpdateIssue($mixedContent, $aGhFields = [])
  1090. {
  1091. $aContentInfo = is_array($mixedContent) ? $mixedContent : $this->_oDb->getContentInfoById((int)$mixedContent);
  1092. if(!$aContentInfo || !is_array($aContentInfo))
  1093. return false;
  1094. $CNF = &$this->_oConfig->CNF;
  1095. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1096. $iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1097. if($iContextId >= 0)
  1098. return false;
  1099. $mixedRepo = $this->ghGetRepository(abs($iContextId));
  1100. if($mixedRepo === false)
  1101. return false;
  1102. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1103. $iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']];
  1104. $sMl = 'bx_github';
  1105. if($aGhFields && ($sMd = 'update_issue') && bx_is_srv($sMl, $sMd))
  1106. if(bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue, $aGhFields]) !== false)
  1107. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
  1108. 'ghi_link' => $aContentInfo[$CNF['FIELD_GH_ISSUE_URL']],
  1109. 'ghi_number' => $iGhIssue
  1110. ]]);
  1111. return true;
  1112. }
  1113. public function getStickers($mixedValues, $iContextId = 0)
  1114. {
  1115. $CNF = &$this->_oConfig->CNF;
  1116. $aValues = is_array($mixedValues) ? $mixedValues : BxDolFormCheckerHelper::displaySet($mixedValues);
  1117. $aResults = [];
  1118. if($iContextId) {
  1119. $aStickers = $this->_oDb->getPreValues([
  1120. 'sample' => 'context_list',
  1121. 'context_id' => $iContextId,
  1122. 'list' => 'sticker'
  1123. ]);
  1124. foreach($aValues as $sValue)
  1125. if(($aSticker = $aStickers[$sValue] ?? false))
  1126. $aResults[] = [
  1127. 'title' => $aSticker['title'],
  1128. 'color' => $aSticker['color']
  1129. ];
  1130. }
  1131. if(!$aResults) {
  1132. $aStickers = BxDolForm::getDataItems($CNF['OBJECT_PRE_LIST_STICKERS']);
  1133. foreach($aValues as $sValue)
  1134. $aResults[] = [
  1135. 'title' => $aStickers[$sValue],
  1136. 'color' => ''
  1137. ];
  1138. }
  1139. return $aResults;
  1140. }
  1141. public function getType($mixedValue, $iContextId = 0)
  1142. {
  1143. $sResult = '';
  1144. if($iContextId) {
  1145. $aType = $this->_oDb->getPreValues([
  1146. 'sample' => 'context_list_value',
  1147. 'context_id' => $iContextId,
  1148. 'list' => 'type',
  1149. 'value' => $mixedValue
  1150. ]);
  1151. if($aType && is_array($aType))
  1152. $sResult = $aType['title'];
  1153. }
  1154. if(!$sResult && ($sTypeTitle = $this->_oConfig->getTypeTitle($mixedValue)) != '')
  1155. $sResult = _t($sTypeTitle);
  1156. return $sResult;
  1157. }
  1158. public function applyFilter($iContextId, $iFilterId)
  1159. {
  1160. $sCookieKey = $this->_oConfig->CNF['COOKIE_SETTING_KEY'];
  1161. $aFilters = [];
  1162. if(isset($_COOKIE[$sCookieKey]))
  1163. $aFilters = json_decode($_COOKIE[$sCookieKey], true);
  1164. if(($iFilterId = (int)$iFilterId) != 0)
  1165. $aFilters[$iContextId] = $iFilterId;
  1166. else
  1167. unset($aFilters[$iContextId]);
  1168. bx_setcookie($sCookieKey, json_encode($aFilters), time() + 60 * 60 * 24 * 365);
  1169. }
  1170. /**
  1171. * Internal methods
  1172. */
  1173. protected function _onEditProperty($aContentInfo, $sProperty, &$oForm)
  1174. {
  1175. $CNF = &$this->_oConfig->CNF;
  1176. $aPropLoc2Repo = [
  1177. $CNF['FIELD_TYPE'] => 'type',
  1178. ];
  1179. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1180. $mixedValue = $oForm->getCleanValue($CNF['FIELD_' . strtoupper($sProperty)]);
  1181. if(($sMethod = 'get' . bx_gen_method_name($sProperty) . 'Title') && method_exists($this->_oConfig, $sMethod))
  1182. $mixedValue = $this->_oConfig->$sMethod($mixedValue);
  1183. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_' . $sProperty, 'markers' => ['value' => $mixedValue]]);
  1184. if(($sPropRepo = $aPropLoc2Repo[$sProperty] ?? false))
  1185. $this->ghUpdateIssue($aContentInfo, [
  1186. $sPropRepo => _t($mixedValue)
  1187. ]);
  1188. }
  1189. protected function _onEditState($aContentInfo, &$oForm)
  1190. {
  1191. $CNF = &$this->_oConfig->CNF;
  1192. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1193. $iState = $oForm->getCleanValue($CNF['FIELD_STATE']);
  1194. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_state', 'markers' => ['value' => $this->_oConfig->getStateTitle($iState)]]);
  1195. $iCompleted = (int)$this->_oConfig->isCompleted($iState);
  1196. if($iCompleted != (int)$this->_oConfig->isCompleted($aContentInfo[$CNF['FIELD_STATE']]))
  1197. $this->complete($iContentId, $iCompleted);
  1198. }
  1199. protected function _getFilterConditions($iContextId = 0, $aItems = [])
  1200. {
  1201. $iJoins = 0;
  1202. $aResult = [
  1203. 'join' => [],
  1204. 'where' => []
  1205. ];
  1206. if(count($aItems) > 1) {
  1207. $aResult['where'] = ['grp' => true, 'o' => 'AND', 'cnds' => []];
  1208. foreach($aItems as $aItem)
  1209. if(($mixedCnd = $this->_getFilterCondition($iContextId, $aItem)) !== false) {
  1210. if(isset($mixedCnd['join'])) {
  1211. $iJoins++;
  1212. $aResult['join'][] = $mixedCnd['join'];
  1213. }
  1214. if(isset($mixedCnd['where']))
  1215. $aResult['where']['cnds'][] = $mixedCnd['where'];
  1216. }
  1217. }
  1218. else {
  1219. $mixedCnd = $this->_getFilterCondition($iContextId, reset($aItems));
  1220. if(isset($mixedCnd['join'])) {
  1221. $iJoins++;
  1222. $aResult['join'][] = $mixedCnd['join'];
  1223. }
  1224. if(isset($mixedCnd['where']))
  1225. $aResult['where'] = $mixedCnd['where'];
  1226. }
  1227. if($iJoins == 1)
  1228. $aResult['join'] = reset($aResult['join']);
  1229. else if($iJoins > 1)
  1230. $aResult['join'] = ['grp' => true, 'cnds' => $aResult['join']];
  1231. return $aResult;
  1232. }
  1233. protected function _getFilterCondition($iContextId = 0, $aItem = [])
  1234. {
  1235. $sMethod = '_getFilterCondition' . bx_gen_method_name($aItem['f']);
  1236. if(method_exists($this, $sMethod))
  1237. return $this->$sMethod($iContextId, $aItem);
  1238. $mixedV = $mixedO = false;
  1239. if(!($bArray = is_array($aItem['v'])) || count($aItem['v']) == 1) {
  1240. $mixedV = $bArray ? reset($aItem['v']) : $aItem['v'];
  1241. $mixedO = '=';
  1242. }
  1243. else {
  1244. $mixedV = $aItem['v'];
  1245. $mixedO = 'IN';
  1246. }
  1247. if(!$mixedV || !$mixedO)
  1248. return false;
  1249. return [
  1250. 'where' => ['cnd' => true, 't' => 'te', 'f' => $aItem['f'], 'v' => $mixedV, 'o' => $mixedO]
  1251. ];
  1252. }
  1253. protected function _getFilterConditionInitialMembers ($iContextId = 0, $aItem = [])
  1254. {
  1255. $CNF = &$this->_oConfig->CNF;
  1256. return [
  1257. 'join' => ['cnd' => true, 'j' => 'LEFT', 'tj' => $CNF['TABLE_ASSIGNMENTS'], 'taj' => 'ta', 'fj' => 'content', 'tam' => 'te', 'fm' => 'id'],
  1258. 'where' => ['cnd' => true, 't' => 'ta', 'f' => 'initiator', 'v' => $aItem['v'], 'o' => '=']
  1259. ];
  1260. }
  1261. protected function _getFilterForm($iContextId = 0)
  1262. {
  1263. $CNF = &$this->_oConfig->CNF;
  1264. $sJsObject = $this->_oConfig->getJsObject('tasks');
  1265. $aFieldToList = [
  1266. $CNF['FIELD_TYPE'] => $CNF['OBJECT_PRE_LIST_TYPES'],
  1267. $CNF['FIELD_PRIORITY'] => $CNF['OBJECT_PRE_LIST_PRIORITIES'],
  1268. $CNF['FIELD_ESTIMATE'] => $CNF['OBJECT_PRE_LIST_ESTIMATES'],
  1269. $CNF['FIELD_STATE'] => $CNF['OBJECT_PRE_LIST_STATES']
  1270. ];
  1271. $aForm = [
  1272. 'form_attrs' => [
  1273. 'id' => 'bx-tasks-filter-add',
  1274. 'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'create_filter/' . $iContextId,
  1275. 'method' => BX_DOL_FORM_METHOD_DEFAULT
  1276. ],
  1277. 'params' => [
  1278. 'db' => [
  1279. 'table' => $CNF['TABLE_FILTERS'],
  1280. 'key' => 'id',
  1281. 'uri' => '',
  1282. 'uri_title' => '',
  1283. 'submit_name' => 'do_apply'
  1284. ],
  1285. ],
  1286. 'inputs' => [
  1287. $CNF['FIELD_AUTHOR'] => [
  1288. 'type' => 'radio_set',
  1289. ],
  1290. $CNF['FIELD_INITIAL_MEMBERS'] => [
  1291. 'type' => 'radio_set',
  1292. ],
  1293. $CNF['FIELD_TYPE'] => [
  1294. 'type' => 'checkbox_set',
  1295. ],
  1296. $CNF['FIELD_PRIORITY'] => [
  1297. 'type' => 'checkbox_set',
  1298. ],
  1299. $CNF['FIELD_ESTIMATE'] => [
  1300. 'type' => 'checkbox_set',
  1301. ],
  1302. $CNF['FIELD_STATE'] => [
  1303. 'type' => 'checkbox_set',
  1304. ],
  1305. 'save_me' => [
  1306. 'type' => 'switcher',
  1307. 'name' => 'save_me',
  1308. 'caption' => _t('_bx_tasks_form_f_input_save_me'),
  1309. 'value' => 'on',
  1310. 'attrs' => [
  1311. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1312. ]
  1313. ],
  1314. 'save_all' => [
  1315. 'type' => 'switcher',
  1316. 'name' => 'save_all',
  1317. 'caption' => _t('_bx_tasks_form_f_input_save_all'),
  1318. 'value' => 'on',
  1319. 'attrs' => [
  1320. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1321. ]
  1322. ],
  1323. 'title' => [
  1324. 'type' => 'text',
  1325. 'name' => 'title',
  1326. 'caption' => _t('_bx_tasks_form_f_input_title'),
  1327. 'value' => '',
  1328. 'required' => '0',
  1329. 'tr_attrs' => [
  1330. 'class' => 'bx-tasks-ffi-hidden'
  1331. ]
  1332. ],
  1333. 'controls' => [
  1334. 'name' => 'controls',
  1335. 'type' => 'input_set',
  1336. [
  1337. 'type' => 'submit',
  1338. 'name' => 'do_apply',
  1339. 'value' => _t('_bx_tasks_form_f_input_apply'),
  1340. ], [
  1341. 'type' => 'reset',
  1342. 'name' => 'do_cancel',
  1343. 'value' => _t('_bx_tasks_form_f_input_cancel'),
  1344. 'attrs' => [
  1345. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1346. 'class' => 'bx-def-margin-sec-left',
  1347. ],
  1348. ]
  1349. ]
  1350. ]
  1351. ];
  1352. foreach($aForm['inputs'] as $sName => $aInput) {
  1353. if(isset($aInput['name']))
  1354. continue;
  1355. $aForm['inputs'][$sName] = array_merge($aForm['inputs'][$sName], [
  1356. 'name' => $sName,
  1357. 'caption' => _t('_bx_tasks_form_f_input_' . $sName),
  1358. 'value' => '',
  1359. 'values' => []
  1360. ]);
  1361. if(($sList = $aFieldToList[$sName] ?? false) && ($aList = BxDolForm::getDataItems($sList))) {
  1362. if(isset($aList['']))
  1363. unset($aList['']);
  1364. $aForm['inputs'][$sName]['values'] = $aList;
  1365. }
  1366. }
  1367. $oContext = false;
  1368. $sContextModule = '';
  1369. if($iContextId && ($oContext = BxDolProfile::getInstance($iContextId)) !== false)
  1370. $sContextModule = $oContext->getModule();
  1371. foreach([$CNF['FIELD_AUTHOR'], $CNF['FIELD_INITIAL_MEMBERS']] as $sK)
  1372. if(isset($aForm['inputs'][$sK])) {
  1373. $aForm['inputs'][$sK]['values']['{logged_pid}'] = _t('_bx_tasks_txt_flt_user_current');
  1374. if($oContext !== false) {
  1375. $aMembers = bx_srv($sContextModule, 'fans', [$oContext->getContentId(), true]);
  1376. foreach($aMembers as $iMember)
  1377. if(($iMember != $this->_iProfileId) && ($oMember = BxDolProfile::getInstance($iMember)) !== false && !($oMember instanceof BxDolProfileUndefined))
  1378. $aForm['inputs'][$sK]['values'][$iMember] = $oMember->getDisplayName();
  1379. }
  1380. }
  1381. if(!$oContext || !bx_srv($sContextModule, 'is_admin', [$iContextId, $this->_iProfileId]))
  1382. unset($aForm['inputs']['save_all']);
  1383. return new BxTemplFormView($aForm);
  1384. }
  1385. }
  1386. /** @} */