BxTasksModule.php 81 KB

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