BxTasksModule.php 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211
  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->spendBudgetByContentId($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. if($sType == 'administration' && (($bContextPid && !$this->isAllowManageByContext($iContextPid)) || (!$bContextPid && !($this->_isModerator() || $this->_isAdministrator()))))
  633. return ($sMsg = _t('_sys_txt_access_denied')) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg);
  634. $sGrid = $CNF['OBJECT_GRID_TIME_' . ($bContextPid ? 'CONTEXT_' : '') . strtoupper($sType)];
  635. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  636. if(!$oGrid)
  637. return $this->_bIsApi ? [] : '';
  638. if($bContextPid)
  639. $oGrid->setContextPid($iContextPid);
  640. if($this->_bIsApi)
  641. return [
  642. bx_api_get_block('grid', $oGrid->getCodeAPI())
  643. ];
  644. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  645. $this->_oTemplate->addCss(array_merge($aCssCalendar, ['manage_tools.css', 'time.css']));
  646. $this->_oTemplate->addJs(array_merge($aJsCalendar, ['modules/base/text/js/|manage_tools.js', 'time.js']));
  647. $this->_oTemplate->addJsTranslation(['_sys_grid_search']);
  648. $aResult = [
  649. 'content' => $this->_oTemplate->getJsCode('time', [
  650. 'sObjNameGrid' => $sGrid
  651. ]) . $oGrid->getCode()
  652. ];
  653. if(!$bContextPid)
  654. $aResult['menu'] = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU']);
  655. return $aResult;
  656. }
  657. public function serviceGetBlockTimers()
  658. {
  659. $mixedResult = $this->_oTemplate->getBlockTimers($this->_iProfileId);
  660. return $this->_bIsApi ? [
  661. bx_api_get_block('tasks_timers', $mixedResult)
  662. ] : $mixedResult;
  663. }
  664. public function serviceGetBlockManageBudget($sType = 'administration', $iContextPid = 0)
  665. {
  666. $CNF = &$this->_oConfig->CNF;
  667. $bContextPid = !empty($iContextPid);
  668. if(!$bContextPid)
  669. return $this->_bIsApi ? [] : '';
  670. if($sType == 'administration' && (($bContextPid && !$this->isAllowManageByContext($iContextPid)) || (!$bContextPid && !($this->_isModerator() || $this->_isAdministrator()))))
  671. return ($sMsg = _t('_sys_txt_access_denied')) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : MsgBox($sMsg);
  672. $sGrid = $CNF['OBJECT_GRID_BUDGET_' . ($bContextPid ? 'CONTEXT_' : '') . strtoupper($sType)];
  673. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  674. if(!$oGrid)
  675. return $this->_bIsApi ? [] : '';
  676. if($bContextPid)
  677. $oGrid->setContextPid($iContextPid);
  678. if($this->_bIsApi)
  679. return [
  680. bx_api_get_block('grid', $oGrid->getCodeAPI())
  681. ];
  682. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  683. $this->_oTemplate->addCss($aCssCalendar);
  684. $this->_oTemplate->addJs($aJsCalendar);
  685. $this->_oTemplate->addJsTranslation(['_sys_grid_search']);
  686. $aResult = [
  687. 'content' => $this->_oTemplate->getJsCode('budget', [
  688. 'sObjNameGrid' => $sGrid
  689. ]) . $oGrid->getCode()
  690. ];
  691. if(!$bContextPid)
  692. $aResult['menu'] = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU']);
  693. return $aResult;
  694. }
  695. public function serviceGetBlockBudget($iContextPid = 0)
  696. {
  697. if(!$iContextPid || !$this->isAllowManageByContext($iContextPid))
  698. return $this->_bIsApi ? [] : '';
  699. $aBudget = $this->_oDb->getBudget(['sample'=> 'context_id', 'context_id' => $iContextPid]);
  700. if(!$aBudget || !is_array($aBudget))
  701. return $this->_bIsApi ? [] : MsgBox(_t('_Empty'));
  702. $mixedResult = $this->_oTemplate->getBlockBudget($aBudget);
  703. return $this->_bIsApi ? [
  704. bx_api_get_block('tasks_budget', $mixedResult)
  705. ] : $mixedResult;
  706. }
  707. /**
  708. * Data for Timeline module
  709. */
  710. public function serviceGetTimelineData()
  711. {
  712. $sModule = $this->_aModule['name'];
  713. return array(
  714. 'handlers' => array(
  715. 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' => ''),
  716. 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' => ''),
  717. 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' => ''),
  718. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  719. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  720. ),
  721. 'alerts' => array(
  722. array('unit' => $sModule, 'action' => 'added'),
  723. array('unit' => $sModule, 'action' => 'completed'),
  724. array('unit' => $sModule, 'action' => 'reopened'),
  725. array('unit' => $sModule, 'action' => 'edited'),
  726. array('unit' => $sModule, 'action' => 'deleted'),
  727. )
  728. );
  729. }
  730. /**
  731. * Entry task for Timeline module
  732. */
  733. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  734. {
  735. $CNF = &$this->_oConfig->CNF;
  736. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  737. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  738. return $aResult;
  739. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  740. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  741. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  742. return $aResult;
  743. }
  744. public function serviceGetTimelineCompleted($aEvent, $aBrowseParams = array())
  745. {
  746. $CNF = &$this->_oConfig->CNF;
  747. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  748. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  749. return $aResult;
  750. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  751. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  752. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  753. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_completed');
  754. return $aResult;
  755. }
  756. public function serviceGetTimelineReopened($aEvent, $aBrowseParams = array())
  757. {
  758. $CNF = &$this->_oConfig->CNF;
  759. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  760. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  761. return $aResult;
  762. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  763. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  764. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  765. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_reopened');
  766. return $aResult;
  767. }
  768. public function serviceGetNotificationsData()
  769. {
  770. $sModule = $this->_aModule['name'];
  771. $sEventPrivacy = $sModule . '_allow_view_event_to';
  772. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  773. $sEventPrivacy = '';
  774. $aResult = parent::serviceGetNotificationsData();
  775. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  776. 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),
  777. 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),
  778. 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),
  779. 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),
  780. array('group' => $sModule . '_assign', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'unassigned'),
  781. ));
  782. $aResult['settings'] = array_merge($aResult['settings'], array(
  783. array('group' => 'content', 'unit' => $sModule, 'action' => 'completed', 'types' => array('personal', 'follow_member', 'follow_context')),
  784. array('group' => 'content', 'unit' => $sModule, 'action' => 'reopened', 'types' => array('personal', 'follow_member', 'follow_context')),
  785. array('group' => 'content', 'unit' => $sModule, 'action' => 'expired', 'types' => array('personal')),
  786. array('group' => 'content', 'unit' => $sModule, 'action' => 'assigned', 'types' => array('personal')),
  787. ));
  788. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  789. array('unit' => $sModule, 'action' => 'completed'),
  790. array('unit' => $sModule, 'action' => 'reopened'),
  791. array('unit' => $sModule, 'action' => 'expired'),
  792. array('unit' => $sModule, 'action' => 'assigned'),
  793. array('unit' => $sModule, 'action' => 'unassigned'),
  794. ));
  795. return $aResult;
  796. }
  797. public function serviceGetNotificationsCompleted($aEvent)
  798. {
  799. return $this->_serviceGetNotificationsByAction($aEvent, 'completed');
  800. }
  801. public function serviceGetNotificationsReopened($aEvent)
  802. {
  803. return $this->_serviceGetNotificationsByAction($aEvent, 'reopened');
  804. }
  805. public function serviceGetNotificationsExpired($aEvent)
  806. {
  807. return $this->_serviceGetNotificationsByAction($aEvent, 'expired');
  808. }
  809. public function serviceGetNotificationsAssigned($aEvent)
  810. {
  811. return $this->_serviceGetNotificationsByAction($aEvent, 'assigned');
  812. }
  813. protected function _serviceGetNotificationsByAction($aEvent, $sAction)
  814. {
  815. $CNF = &$this->_oConfig->CNF;
  816. $aResult = parent::serviceGetNotificationsPost($aEvent);
  817. if(empty($aResult) || !is_array($aResult))
  818. return $aResult;
  819. $aResult['entry_author'] = $aEvent['object_owner_id'];
  820. $aResult['entry_author_name'] = '';
  821. if(($oAuthor = BxDolProfile::getInstance($aResult['entry_author'])) !== false)
  822. $aResult['entry_author_name'] = $oAuthor->getDisplayName();
  823. $sLangKey = '_bx_tasks_txt_notification_' . $sAction;
  824. if((int)$aEvent['object_privacy_view'] < 0)
  825. $sLangKey .= '_in_context';
  826. $aResult['lang_key'] = _t($sLangKey);
  827. return $aResult;
  828. }
  829. public function serviceCheckAllowedManageInContext($iContextPid)
  830. {
  831. if(!$this->isAllowManageByContext($iContextPid))
  832. return false;
  833. return true;
  834. }
  835. public function serviceCheckAllowedManage($iContentId)
  836. {
  837. if(!$this->isAllowManage($iContentId))
  838. return false;
  839. return true;
  840. }
  841. public function serviceCheckAllowedComplete($iContentId)
  842. {
  843. if(!$this->serviceCheckAllowedManage($iContentId))
  844. return false;
  845. return !$this->isCompleted($iContentId);
  846. }
  847. public function serviceCheckAllowedUncomplete($iContentId)
  848. {
  849. if(!$this->serviceCheckAllowedManage($iContentId))
  850. return false;
  851. return $this->isCompleted($iContentId);
  852. }
  853. public function serviceIsCompleted($iContentId)
  854. {
  855. return $this->isCompleted($iContentId);
  856. }
  857. public function serviceIsUncompleted($iContentId)
  858. {
  859. return !$this->isCompleted($iContentId);
  860. }
  861. public function serviceIsAllowBadges($iContentId)
  862. {
  863. if (!$this->isAllowManage($iContentId))
  864. return false;
  865. if (!$this->serviceIsBadgesAvaliable())
  866. return false;
  867. return true;
  868. }
  869. public function serviceEntityTextBlock ($iContentId = 0)
  870. {
  871. if(!$iContentId)
  872. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  873. if(!$iContentId)
  874. return false;
  875. $CNF = &$this->_oConfig->CNF;
  876. $bAllowEdit = $this->isAllowEdit($iContentId);
  877. if($this->_bIsApi) {
  878. $aResult = parent::serviceEntityTextBlock($iContentId);
  879. if($bAllowEdit) {
  880. $aResult['0']['data']['editable'] = true;
  881. $aResult['0']['data']['params']['request_url'] = $this->_aModule['name'] . '/set_property/&params[]=' . $iContentId . '&params[]=';
  882. }
  883. return $aResult;
  884. }
  885. $sResult = '';
  886. if(!$bAllowEdit)
  887. $sResult = parent::serviceEntityTextBlock($iContentId);
  888. else
  889. $sResult = $this->serviceEntityEdit($iContentId, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_BODY']);
  890. return $sResult;
  891. }
  892. public function serviceEntityAssignments($iContentId = 0, $bAsArray = false)
  893. {
  894. if(!$iContentId)
  895. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  896. if(!$iContentId)
  897. return false;
  898. $CNF = &$this->_oConfig->CNF;
  899. $aProfiles = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])->getConnectedInitiators($iContentId);
  900. if($bAsArray)
  901. return $aProfiles;
  902. $mixedResult = $this->_oTemplate->entryAssignments($aProfiles);
  903. return $this->_bIsApi ? [
  904. bx_api_get_block('profiles_list', ['data' => $mixedResult])
  905. ] : $mixedResult;
  906. }
  907. public function serviceEntityTimer($iContentId = 0)
  908. {
  909. if(!$iContentId)
  910. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  911. if(!$iContentId)
  912. return false;
  913. $mixedResult = $this->_oTemplate->entryTimer($iContentId, $this->_iProfileId);
  914. return $this->_bIsApi ? [
  915. bx_api_get_block('task_timer', $mixedResult)
  916. ] : $mixedResult;
  917. }
  918. public function serviceCheckAllowedCommentsTask($iContentId, $sObjectComments)
  919. {
  920. $CNF = &$this->_oConfig->CNF;
  921. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  922. if($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  923. return false;
  924. return parent::serviceCheckAllowedCommentsTask($iContentId, $sObjectComments);
  925. }
  926. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  927. {
  928. $CNF = &$this->_oConfig->CNF;
  929. //negative id used in comments for reports
  930. if($iContentId < 0)
  931. return CHECK_ACTION_RESULT_ALLOWED;
  932. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  933. if($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  934. return false;
  935. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  936. }
  937. /**
  938. * @page service Service Calls
  939. * @section bx_tasks Tasks
  940. * @subsection bx_tasks-page_blocks Page Blocks
  941. * @subsubsection bx_tasks-calendar calendar
  942. *
  943. * @code bx_srv('bx_tasks', 'calendar', [...]); @endcode
  944. *
  945. * Shows tasks calendar baced on die date
  946. *
  947. * @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.
  948. * @param $sTemplate template to use to show calendar, or leave empty for default template, possible options: calendar.html, calendar_compact.html
  949. * @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.
  950. *
  951. * @see BxTasksModule::serviceCalendar
  952. */
  953. /**
  954. * @ref bx_tasks-calendar "calendar"
  955. */
  956. public function serviceCalendar($aData = array(), $sTemplate = 'calendar.html')
  957. {
  958. if (!$this->isAllowView($aData['context_id']))
  959. return;
  960. $o = new BxTemplCalendar(array(
  961. 'eventSources' => array (
  962. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'calendar_data', $aData),
  963. ),
  964. ), $this->_oTemplate);
  965. return $o->display($sTemplate);
  966. }
  967. public function serviceGetCalendarEntries($iProfileId)
  968. {
  969. $CNF = &$this->_oConfig->CNF;
  970. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  971. $aData = $oConn->getConnectedInitiators($iProfileId);
  972. $aData2 = array(0);
  973. foreach($aData as $iProfileId2) {
  974. $oProfile = BxDolProfile::getInstance($iProfileId2);
  975. array_push($aData2, $oProfile->getContentId());
  976. }
  977. $aSQLPart['where'] = " AND " . $CNF['TABLE_ENTRIES'] . ".`" . $CNF['FIELD_ID'] . "` IN(" . implode(',', $aData2) . ")";
  978. return $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), null, $aSQLPart);
  979. }
  980. public function serviceBrowseHome($aParams = [])
  981. {
  982. $CNF = &$this->_oConfig->CNF;
  983. $sContent = '';
  984. if(($iContextPid = bx_process_input(bx_get('context_pid'), BX_DATA_INT))) {
  985. $sContent = $this->serviceBrowseTasks($iContextPid);
  986. if($sContent && ($oProfile = BxDolProfile::getInstance($iContextPid)) !== false)
  987. return [
  988. 'title' => bx_replace_markers(_t('_bx_tasks_page_block_title_entries_in_context'), [
  989. 'display_name' => $oProfile->getDisplayName(),
  990. 'profile_link' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_CONTEXT_ENTRIES'], ['profile_id' => $iContextPid]))
  991. ]),
  992. 'content' => $sContent
  993. ];
  994. }
  995. else
  996. $sContent = $this->serviceBrowseTasksByProfile();
  997. return $sContent ?: MsgBox(_t('_Empty'));
  998. }
  999. public function serviceBrowseContext($iProfileId = 0, $aParams = [])
  1000. {
  1001. if(!$iProfileId)
  1002. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1003. if(!$iProfileId)
  1004. return '';
  1005. if($this->_bIsApi && is_string($aParams))
  1006. $aParams = bx_api_get_browse_params($aParams);
  1007. return $this->serviceBrowseTasks ($iProfileId, $aParams);
  1008. }
  1009. public function serviceBrowseTasks($iContextId = 0, $aParams = [])
  1010. {
  1011. if(!$this->isAllowView($iContextId))
  1012. return $this->_bIsApi ? [] : '';
  1013. $mixedResult = $this->_oTemplate->getEntriesList($iContextId, $aParams);
  1014. return $this->_bIsApi ? [
  1015. bx_api_get_block('tasks_list', $mixedResult)
  1016. ] : $mixedResult;
  1017. }
  1018. public function serviceBrowseTasksByProfile($iProfileId = 0, $aParams = [])
  1019. {
  1020. if(!$iProfileId && $this->_iProfileId)
  1021. $iProfileId = $this->_iProfileId;
  1022. $mixedResult = $this->_oTemplate->getEntriesList(0, array_merge($aParams, [
  1023. 'for_profile' => $iProfileId
  1024. ]));
  1025. return $this->_bIsApi ? [
  1026. bx_api_get_block('tasks_list', $mixedResult)
  1027. ] : $mixedResult;
  1028. }
  1029. /**
  1030. * Common methods
  1031. */
  1032. public function getModuleTitle($sName)
  1033. {
  1034. $sResult = $sName;
  1035. if(($_sTitle = '_' . $sName) && ($sTitle = _t($_sTitle)) && strcmp($_sTitle, $sTitle) != 0)
  1036. $sResult = $sTitle;
  1037. else if(($aModule = $this->_oDb->getModuleByName($sName)) && is_array($aModule))
  1038. $sResult = $aModule['title'] ?? _t('_undefined');
  1039. return $sResult;
  1040. }
  1041. public function getAssignees()
  1042. {
  1043. $aResults = [];
  1044. if(($oProfile = BxDolProfile::getInstance()) !== false && ($aIds = $this->_oDb->getTimeTracks(['sample' => 'assignees'])))
  1045. foreach($aIds as $iId)
  1046. $aResults[] = ['key' => $iId, 'value' => $oProfile->getDisplayName($iId)];
  1047. return $aResults;
  1048. }
  1049. public function getPreLists()
  1050. {
  1051. $CNF = &$this->_oConfig->CNF;
  1052. $aResults = [];
  1053. if(($aPreLists = $this->_oDb->getPreLists(['sample' => 'all'])) && is_array($aPreLists))
  1054. foreach($aPreLists as $aPreList)
  1055. $aResults[$aPreList['name']] = _t($aPreList['title']);
  1056. return $aResults;
  1057. }
  1058. public function getContexts()
  1059. {
  1060. $aContexts = [];
  1061. $aModules = bx_srv('system', 'get_modules_by_type', ['context', ['name_as_key' => true]]);
  1062. foreach($aModules as $sModule => $aModule)
  1063. $aContexts[$sModule] = ($_sTitle = '_' . $sModule) && ($sTitle = _t($_sTitle)) && strcmp($_sTitle, $sTitle) != 0 ? $sTitle : $aModule['title'];
  1064. return $aContexts;
  1065. }
  1066. public function getContextAuthorId($iContextPid)
  1067. {
  1068. $iContextAuthorPid = 0;
  1069. if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false)
  1070. $iContextAuthorPid = bx_srv($oContext->getModule(), 'get_author', [$oContext->getContentId()]);
  1071. return $iContextAuthorPid;
  1072. }
  1073. public function getContextMembers($iContextPid)
  1074. {
  1075. $aMembers = [];
  1076. if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false) {
  1077. $aPids = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
  1078. foreach($aPids as $iPid)
  1079. $aMembers[$iPid] = $oContext->getDisplayName($iPid);
  1080. }
  1081. return $aMembers;
  1082. }
  1083. public function getContextEntries($iContextPid)
  1084. {
  1085. $CNF = &$this->_oConfig->CNF;
  1086. $aEntries = [];
  1087. if(($aTasks = $this->_oDb->getTasks($iContextPid)) && is_array($aTasks))
  1088. foreach($aTasks as $aTask)
  1089. $aEntries[$aTask[$CNF['FIELD_ID']]] = $aTask[$CNF['FIELD_TITLE']];
  1090. return $aEntries;
  1091. }
  1092. public function getTimer($iContentId, $iProfileId)
  1093. {
  1094. return $this->_oDb->getTimers(['sample' => 'content_profile_ids', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
  1095. }
  1096. public function getTimersByAuthor($iProfileId, $bActive = false)
  1097. {
  1098. return $this->_oDb->getTimers(['sample' => 'profile_id', 'profile_id' => $iProfileId, 'active' => $bActive]);
  1099. }
  1100. public function pauseTimerByAuthor($iProfileId)
  1101. {
  1102. $aTimer = $this->getTimersByAuthor($iProfileId, true);
  1103. if(!$aTimer || !is_array($aTimer) || empty($aTimer['started']))
  1104. return false;
  1105. return $this->updateTimerById($aTimer['id'], [
  1106. 'started' => 0,
  1107. 'duration' => $aTimer['duration'] + (time() - $aTimer['started']),
  1108. ]);
  1109. }
  1110. public function updateTimerById($iId, $aSet)
  1111. {
  1112. return $this->_oDb->updateTimer($aSet, ['id' => (int)$iId]) !== false;
  1113. }
  1114. public function spendBudgetByContentId($iContentId, $iValue)
  1115. {
  1116. $bResult = false;
  1117. $iContextId = $this->_oDb->getContextId($iContentId);
  1118. if(!$iContextId)
  1119. return $bResult;
  1120. if(!$this->_oDb->isBudgetByContext($iContextId))
  1121. $bResult = $this->_oDb->insertBudget($iContextId, 0, $iValue);
  1122. else
  1123. $bResult = $this->_oDb->updateBudgetSpent($iContextId, $iValue);
  1124. return $bResult;
  1125. }
  1126. public function onPublished($iContentId)
  1127. {
  1128. parent::onPublished($iContentId);
  1129. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1130. if(!$aContentInfo)
  1131. return;
  1132. $CNF = &$this->_oConfig->CNF;
  1133. if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0) {
  1134. $iContextId = abs($iContextId);
  1135. $mixedRepo = $this->ghGetRepository($iContextId);
  1136. if($mixedRepo !== false && ($sMl = 'bx_github') && ($sMd = 'create_issue') && bx_is_srv($sMl, $sMd)) {
  1137. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1138. $aFldLoc2Repo = [
  1139. $CNF['FIELD_STICKERS'] => 'labels',
  1140. $CNF['FIELD_TYPE'] => 'type',
  1141. ];
  1142. $aGhFields = [];
  1143. foreach($aFldLoc2Repo as $sLocField => $sRepoField)
  1144. if(($sLocValue = $aContentInfo[$sLocField] ?? false))
  1145. switch($sLocField) {
  1146. case $CNF['FIELD_STICKERS']:
  1147. $aStickers = $this->getStickers($sLocValue, $iContextId);
  1148. if($aStickers && is_array($aStickers)) {
  1149. $aGhFields[$sRepoField] = [];
  1150. foreach($aStickers as $aSticker)
  1151. $aGhFields[$sRepoField][] = $aSticker['title'];
  1152. }
  1153. break;
  1154. case $CNF['FIELD_TYPE']:
  1155. $aGhFields[$sRepoField] = $this->getType($sLocValue, $iContextId);
  1156. break;
  1157. default:
  1158. $aGhFields[$sRepoField] = $sLocValue;
  1159. }
  1160. $aIssue = bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $aContentInfo[$CNF['FIELD_TITLE']], $aContentInfo[$CNF['FIELD_TEXT']], $aGhFields]);
  1161. if($aIssue && is_array($aIssue) && ($iNumber = (int)($aIssue['number'] ?? 0)) != 0 && ($sUrl = $aIssue['html_url'] ?? '') != '') {
  1162. $this->_oDb->updateEntriesBy([
  1163. $CNF['FIELD_GH_ISSUE'] => $iNumber,
  1164. $CNF['FIELD_GH_ISSUE_URL'] => $sUrl,
  1165. ], [$CNF['FIELD_ID'] => $iContentId]);
  1166. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
  1167. 'ghi_link' => $sUrl,
  1168. 'ghi_number' => $iNumber
  1169. ]]);
  1170. }
  1171. }
  1172. }
  1173. }
  1174. public function onExpired($iContentId)
  1175. {
  1176. $CNF = &$this->_oConfig->CNF;
  1177. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1178. if(!$aContentInfo)
  1179. return;
  1180. $sModule = $this->getName();
  1181. $sAction = 'expired';
  1182. $iPerformer = getParam('sys_profile_bot');
  1183. $sSource = $sModule . '_' . $sAction . '_' . $iContentId;
  1184. $sSourceMac = $sModule . '_' . $sAction . '_' . $iPerformer . '_' . time();
  1185. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  1186. if($oConnection) {
  1187. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  1188. if(!empty($aProfileIds) && is_array($aProfileIds))
  1189. foreach($aProfileIds as $iProfileId) {
  1190. /**
  1191. * @hooks
  1192. * @hookdef hook-bx_tasks-expired 'bx_tasks', 'expired' - hook on task unassigned to profile
  1193. * - $unit_name - equals `bx_tasks`
  1194. * - $action - equals `expired`
  1195. * - $object_id - task id
  1196. * - $sender_id - not used
  1197. * - $extra_params - array of additional params with the following array keys:
  1198. * - `object_author_id` - [int] profile_id for task's author
  1199. * - `privacy_view` - [string] privacy view value
  1200. * @hook @ref hook-bx_tasks-expired
  1201. */
  1202. bx_alert($sModule, $sAction, $iContentId, $iPerformer, [
  1203. 'object_author_id' => $iProfileId,
  1204. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
  1205. 'source' => $sSource,
  1206. 'source_mac' => $sSourceMac,
  1207. ]);
  1208. }
  1209. }
  1210. }
  1211. public function isAllowView($iContextId)
  1212. {
  1213. if(!($oContext = BxDolProfile::getInstance($iContextId)) || $oContext->checkAllowedProfileView($iContextId) !== CHECK_ACTION_RESULT_ALLOWED)
  1214. return false;
  1215. return true;
  1216. }
  1217. public function isAllowAdd($iContextId)
  1218. {
  1219. if(!($oContext = BxDolProfile::getInstance($iContextId)) || $oContext->checkAllowedPostInProfile($iContextId) !== CHECK_ACTION_RESULT_ALLOWED)
  1220. return false;
  1221. return true;
  1222. }
  1223. public function isAllowManageByContext($iContextId)
  1224. {
  1225. if(isAdmin())
  1226. return true;
  1227. $oProfileContext = BxDolProfile::getInstance($iContextId);
  1228. if(BxDolService::call($oProfileContext->getModule(), 'is_admin', array($iContextId)))
  1229. return true;
  1230. return false;
  1231. }
  1232. public function isAllowEdit($mixedContent)
  1233. {
  1234. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  1235. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  1236. return true;
  1237. return false;
  1238. }
  1239. public function isAllowManage($mixedContent)
  1240. {
  1241. $CNF = &$this->_oConfig->CNF;
  1242. $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
  1243. if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
  1244. return true;
  1245. if($this->isAllowManageByContext(abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']])))
  1246. return true;
  1247. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  1248. $iLoggedId = bx_get_logged_profile_id();
  1249. $aProfileIds = $oConnection->getConnectedInitiators($aContentInfo[$CNF['FIELD_ID']]);
  1250. if(!empty($aProfileIds) && is_array($aProfileIds) && in_array($iLoggedId, $aProfileIds))
  1251. return true;
  1252. }
  1253. return false;
  1254. }
  1255. /**
  1256. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1257. */
  1258. public function checkAllowedManage ($aDataEntry, $isPerformAction = false)
  1259. {
  1260. return $this->isAllowManage($aDataEntry) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
  1261. }
  1262. public function isCompleted($iContentId)
  1263. {
  1264. $CNF = &$this->_oConfig->CNF;
  1265. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1266. return (bool)$aContentInfo[$CNF['FIELD_COMPLETED']];
  1267. }
  1268. public function complete($iContentId, $iCompleted)
  1269. {
  1270. $CNF = &$this->_oConfig->CNF;
  1271. $iCompleted = (int)$iCompleted;
  1272. $this->_oDb->updateEntriesBy([$CNF['FIELD_COMPLETED'] => $iCompleted], [$CNF['FIELD_ID'] => (int)$iContentId]);
  1273. $sModule = $this->getName();
  1274. $sAction = !$iCompleted ? 'reopened' : 'completed';
  1275. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1276. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1277. $iPerformer = bx_get_logged_profile_id();
  1278. $sSource = $sModule . '_' . $sAction . '_' . $iContentId;
  1279. $sSourceMac = $sModule . '_' . $sAction . '_' . $iPerformer . '_' . time();
  1280. /**
  1281. * @hooks
  1282. * @hookdef hook-bx_tasks-completed 'bx_tasks', 'completed' - hook on task unassigned to profile
  1283. * - $unit_name - equals `bx_tasks`
  1284. * - $action - can be `completed` or `reopened`
  1285. * - $object_id - task id
  1286. * - $sender_id - not used
  1287. * - $extra_params - array of additional params with the following array keys:
  1288. * - `object_author_id` - [int] profile_id for task's author
  1289. * - `privacy_view` - [string] privacy view value
  1290. * @hook @ref hook-bx_tasks-completed
  1291. */
  1292. bx_alert($sModule, $sAction, $iContentId, $iPerformer, [
  1293. 'object_author_id' => $iContentAuthor,
  1294. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
  1295. 'source' => $sSource,
  1296. 'source_mac' => $sSourceMac,
  1297. ]);
  1298. if(($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION'])) !== false) {
  1299. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  1300. if(!empty($aProfileIds) && is_array($aProfileIds))
  1301. foreach($aProfileIds as $iProfileId) {
  1302. if($iProfileId == $iContentAuthor)
  1303. continue;
  1304. bx_alert($sModule, $sAction, $iContentId, $iPerformer, [
  1305. 'object_author_id' => $iProfileId,
  1306. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
  1307. 'source' => $sSource,
  1308. 'source_mac' => $sSourceMac,
  1309. ]);
  1310. }
  1311. }
  1312. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_' . ($iCompleted ? '' : 'un') . 'completed']);
  1313. if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepo = $this->ghGetRepository(abs($iContextId))) !== false) {
  1314. $sModule = 'bx_github';
  1315. $sMethod = ($iCompleted ? 'close' : 'reopen') . '_issue';
  1316. if(bx_is_srv($sModule, $sMethod) && ($iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']]) != 0) {
  1317. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1318. bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue]);
  1319. }
  1320. }
  1321. return true;
  1322. }
  1323. public function logActivity($iContentId, $aMessage)
  1324. {
  1325. $CNF = &$this->_oConfig->CNF;
  1326. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1327. if(!$oCmts || !$oCmts->isEnabled())
  1328. return false;
  1329. if(($oAuthor = BxDolProfile::getInstance()) !== false)
  1330. $aMessage['markers'] = array_merge($aMessage['markers'] ?? [], [
  1331. 'author_link' => $oAuthor->getUrl(),
  1332. 'author_name' => $oAuthor->getDisplayName(),
  1333. ]);
  1334. return $oCmts->addAuto($aMessage);
  1335. }
  1336. public function ghGetRepository($iContextId)
  1337. {
  1338. $mixedRepo = $this->_oDb->getContextRepository($iContextId);
  1339. if($mixedRepo === false)
  1340. return false;
  1341. return [
  1342. $mixedRepo['gh_username'],
  1343. $mixedRepo['gh_repository'],
  1344. $mixedRepo['gh_app_id'] ? [$this->_iProfileId, (int)$mixedRepo['gh_app_id']] : $this->_iProfileId
  1345. ];
  1346. }
  1347. public function ghUpdateIssue($mixedContent, $aGhFields = [])
  1348. {
  1349. $aContentInfo = is_array($mixedContent) ? $mixedContent : $this->_oDb->getContentInfoById((int)$mixedContent);
  1350. if(!$aContentInfo || !is_array($aContentInfo))
  1351. return false;
  1352. $CNF = &$this->_oConfig->CNF;
  1353. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1354. $iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1355. if($iContextId >= 0)
  1356. return false;
  1357. $mixedRepo = $this->ghGetRepository(abs($iContextId));
  1358. if($mixedRepo === false)
  1359. return false;
  1360. list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
  1361. $iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']];
  1362. $sMl = 'bx_github';
  1363. if($aGhFields && ($sMd = 'update_issue') && bx_is_srv($sMl, $sMd))
  1364. if(bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue, $aGhFields]) !== false)
  1365. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
  1366. 'ghi_link' => $aContentInfo[$CNF['FIELD_GH_ISSUE_URL']],
  1367. 'ghi_number' => $iGhIssue
  1368. ]]);
  1369. return true;
  1370. }
  1371. public function getStickers($mixedValues, $iContextId = 0)
  1372. {
  1373. $CNF = &$this->_oConfig->CNF;
  1374. $aValues = is_array($mixedValues) ? $mixedValues : BxDolFormCheckerHelper::displaySet($mixedValues);
  1375. $aResults = [];
  1376. if($iContextId) {
  1377. $aStickers = $this->_oDb->getPreValues([
  1378. 'sample' => 'context_list',
  1379. 'context_id' => $iContextId,
  1380. 'list' => 'sticker'
  1381. ]);
  1382. foreach($aValues as $sValue)
  1383. if(($aSticker = $aStickers[$sValue] ?? false))
  1384. $aResults[] = [
  1385. 'title' => $aSticker['title'],
  1386. 'color' => $aSticker['color']
  1387. ];
  1388. }
  1389. if(!$aResults) {
  1390. $aStickers = BxDolForm::getDataItems($CNF['OBJECT_PRE_LIST_STICKERS']);
  1391. foreach($aValues as $sValue)
  1392. $aResults[] = [
  1393. 'title' => $aStickers[$sValue],
  1394. 'color' => ''
  1395. ];
  1396. }
  1397. return $aResults;
  1398. }
  1399. public function getType($mixedValue, $iContextId = 0)
  1400. {
  1401. $sResult = '';
  1402. if($iContextId) {
  1403. $aType = $this->_oDb->getPreValues([
  1404. 'sample' => 'context_list_value',
  1405. 'context_id' => $iContextId,
  1406. 'list' => 'type',
  1407. 'value' => $mixedValue
  1408. ]);
  1409. if($aType && is_array($aType))
  1410. $sResult = $aType['title'];
  1411. }
  1412. if(!$sResult && ($sTypeTitle = $this->_oConfig->getTypeTitle($mixedValue)) != '')
  1413. $sResult = _t($sTypeTitle);
  1414. return $sResult;
  1415. }
  1416. public function applyFilter($iContextId, $iFilterId)
  1417. {
  1418. $sCookieKey = $this->_oConfig->CNF['COOKIE_SETTING_KEY'];
  1419. $aFilters = [];
  1420. if(isset($_COOKIE[$sCookieKey]))
  1421. $aFilters = json_decode($_COOKIE[$sCookieKey], true);
  1422. if(($iFilterId = (int)$iFilterId) != 0)
  1423. $aFilters[$iContextId] = $iFilterId;
  1424. else
  1425. unset($aFilters[$iContextId]);
  1426. bx_setcookie($sCookieKey, json_encode($aFilters), time() + 60 * 60 * 24 * 365);
  1427. }
  1428. public function setAssignments($iContentId, $aMembers)
  1429. {
  1430. $CNF = &$this->_oConfig->CNF;
  1431. $sModule = $this->getName();
  1432. $iPerformer = bx_get_logged_profile_id();
  1433. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  1434. if($this->_bIsApi && is_string($aMembers))
  1435. $aMembers = explode(',', $aMembers);
  1436. $aMembersCurrent = $oConn->getConnectedInitiators($iContentId);
  1437. $aMembersToAdd = [];
  1438. $aMembersToRemove = $aMembersCurrent;
  1439. if (is_array($aMembers)){
  1440. $aMembersToAdd = array_diff($aMembers, $aMembersCurrent);
  1441. $aMembersToRemove = array_diff($aMembersCurrent, $aMembers);
  1442. }
  1443. $iNow = time();
  1444. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1445. foreach($aMembersToAdd as $iProfileId){
  1446. $oConn->addConnection($iProfileId, $iContentId);
  1447. /**
  1448. * @hooks
  1449. * @hookdef hook-bx_tasks-assigned 'bx_tasks', 'assigned' - hook on task assigned to profile
  1450. * - $unit_name - equals `bx_tasks`
  1451. * - $action - equals `assigned`
  1452. * - $object_id - task id
  1453. * - $sender_id - not used
  1454. * - $extra_params - array of additional params with the following array keys:
  1455. * - `object_author_id` - [int] id for assigned profile
  1456. * - `privacy_view` - [string] privacy view value
  1457. * @hook @ref hook-bx_tasks-assigned
  1458. */
  1459. bx_alert($sModule, 'assigned', $iContentId, $iPerformer, [
  1460. 'object_author_id' => $iProfileId,
  1461. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
  1462. 'source' => $sModule . '_assigned_' . $iContentId,
  1463. 'source_mac' => $sModule . '_assigned_' . $iPerformer . '_' . $iNow,
  1464. ]);
  1465. }
  1466. foreach($aMembersToRemove as $iProfileId){
  1467. $oConn->removeConnection($iProfileId, $iContentId);
  1468. /**
  1469. * @hooks
  1470. * @hookdef hook-bx_tasks-unassigned 'bx_tasks', 'unassigned' - hook on task unassigned to profile
  1471. * - $unit_name - equals `bx_tasks`
  1472. * - $action - equals `unassigned`
  1473. * - $object_id - task id
  1474. * - $sender_id - not used
  1475. * - $extra_params - array of additional params with the following array keys:
  1476. * - `object_author_id` - [int] id for unassigned profile
  1477. * - `privacy_view` - [string] privacy view value
  1478. * @hook @ref hook-bx_tasks-unassigned
  1479. */
  1480. bx_alert($sModule, 'unassigned', $iContentId, $iPerformer, [
  1481. 'object_author_id' => $iProfileId,
  1482. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
  1483. 'source' => $sModule . '_unassigned_' . $iContentId,
  1484. 'source_mac' => $sModule . '_unassigned_' . $iPerformer . '_' . $iNow,
  1485. ]);
  1486. }
  1487. }
  1488. /**
  1489. * Internal methods
  1490. */
  1491. protected function _onEditProperty($aContentInfo, $sProperty, $mixedValue)
  1492. {
  1493. $CNF = &$this->_oConfig->CNF;
  1494. $aPropLoc2Repo = [
  1495. $CNF['FIELD_TYPE'] => 'type',
  1496. ];
  1497. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1498. if(($sMethod = 'get' . bx_gen_method_name($sProperty) . 'Title') && method_exists($this->_oConfig, $sMethod))
  1499. $mixedValue = $this->_oConfig->$sMethod($mixedValue);
  1500. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_' . $sProperty, 'markers' => ['value' => $mixedValue]]);
  1501. if(($sPropRepo = $aPropLoc2Repo[$sProperty] ?? false))
  1502. $this->ghUpdateIssue($aContentInfo, [
  1503. $sPropRepo => _t($mixedValue)
  1504. ]);
  1505. }
  1506. protected function _onEditState($aContentInfo, $iState)
  1507. {
  1508. $CNF = &$this->_oConfig->CNF;
  1509. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1510. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_state', 'markers' => ['value' => $this->_oConfig->getStateTitle($iState)]]);
  1511. $iCompleted = (int)$this->_oConfig->isCompleted($iState);
  1512. if($iCompleted != (int)$this->_oConfig->isCompleted($aContentInfo[$CNF['FIELD_STATE']]) || $iCompleted != (int)$aContentInfo[$CNF['FIELD_COMPLETED']])
  1513. $this->complete($iContentId, $iCompleted);
  1514. }
  1515. protected function _onEditInitialMembers($aContentInfo, $mixedIds)
  1516. {
  1517. $CNF = &$this->_oConfig->CNF;
  1518. if(is_string($mixedIds))
  1519. $mixedIds = explode(',', $mixedIds);
  1520. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1521. $aValue = [];
  1522. if(($oProfile = BxDolProfile::getInstance()) !== false)
  1523. foreach($mixedIds as $iId)
  1524. $aValue[] = $oProfile->getDisplayName($iId);
  1525. $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_edit_initial_members', 'markers' => ['value' => implode(', ', $aValue)]]);
  1526. $this->setAssignments($iContentId, $mixedIds);
  1527. }
  1528. protected function _getFilterConditions($iContextId = 0, $aItems = [])
  1529. {
  1530. $iJoins = 0;
  1531. $aResult = [
  1532. 'join' => [],
  1533. 'where' => []
  1534. ];
  1535. if(count($aItems) > 1) {
  1536. $aResult['where'] = ['grp' => true, 'o' => 'AND', 'cnds' => []];
  1537. foreach($aItems as $aItem)
  1538. if(($mixedCnd = $this->_getFilterCondition($iContextId, $aItem)) !== false) {
  1539. if(isset($mixedCnd['join'])) {
  1540. $iJoins++;
  1541. $aResult['join'][] = $mixedCnd['join'];
  1542. }
  1543. if(isset($mixedCnd['where']))
  1544. $aResult['where']['cnds'][] = $mixedCnd['where'];
  1545. }
  1546. }
  1547. else {
  1548. $mixedCnd = $this->_getFilterCondition($iContextId, reset($aItems));
  1549. if(isset($mixedCnd['join'])) {
  1550. $iJoins++;
  1551. $aResult['join'][] = $mixedCnd['join'];
  1552. }
  1553. if(isset($mixedCnd['where']))
  1554. $aResult['where'] = $mixedCnd['where'];
  1555. }
  1556. if($iJoins == 1)
  1557. $aResult['join'] = reset($aResult['join']);
  1558. else if($iJoins > 1)
  1559. $aResult['join'] = ['grp' => true, 'cnds' => $aResult['join']];
  1560. return $aResult;
  1561. }
  1562. protected function _getFilterCondition($iContextId = 0, $aItem = [])
  1563. {
  1564. $sMethod = '_getFilterCondition' . bx_gen_method_name($aItem['f']);
  1565. if(method_exists($this, $sMethod))
  1566. return $this->$sMethod($iContextId, $aItem);
  1567. $mixedV = $mixedO = false;
  1568. if(!($bArray = is_array($aItem['v'])) || count($aItem['v']) == 1) {
  1569. $mixedV = $bArray ? reset($aItem['v']) : $aItem['v'];
  1570. $mixedO = '=';
  1571. }
  1572. else {
  1573. $mixedV = $aItem['v'];
  1574. $mixedO = !($aItem['r'] ?? 0) ? 'IN' : 'NOT IN';
  1575. }
  1576. if(!$mixedV || !$mixedO)
  1577. return false;
  1578. return [
  1579. 'where' => ['cnd' => true, 't' => 'te', 'f' => $aItem['f'], 'v' => $mixedV, 'o' => $mixedO]
  1580. ];
  1581. }
  1582. protected function _getFilterConditionInitialMembers ($iContextId = 0, $aItem = [])
  1583. {
  1584. $CNF = &$this->_oConfig->CNF;
  1585. $mixedV = $mixedO = false;
  1586. if(!($bArray = is_array($aItem['v'])) || count($aItem['v']) == 1) {
  1587. $mixedV = $bArray ? reset($aItem['v']) : $aItem['v'];
  1588. $mixedO = '=';
  1589. }
  1590. else {
  1591. $mixedV = $aItem['v'];
  1592. $mixedO = !($aItem['r'] ?? 0) ? 'IN' : 'NOT IN';
  1593. }
  1594. return [
  1595. 'join' => ['cnd' => true, 'j' => 'LEFT', 'tj' => $CNF['TABLE_ASSIGNMENTS'], 'taj' => 'ta', 'fj' => 'content', 'tam' => 'te', 'fm' => 'id'],
  1596. 'where' => ['cnd' => true, 't' => 'ta', 'f' => 'initiator', 'v' => $mixedV, 'o' => $mixedO]
  1597. ];
  1598. }
  1599. protected function _getFilterForm($iContextId = 0)
  1600. {
  1601. $CNF = &$this->_oConfig->CNF;
  1602. $sJsObject = $this->_oConfig->getJsObject('tasks');
  1603. $aFieldToList = [
  1604. $CNF['FIELD_TYPE'] => $CNF['OBJECT_PRE_LIST_TYPES'],
  1605. $CNF['FIELD_PRIORITY'] => $CNF['OBJECT_PRE_LIST_PRIORITIES'],
  1606. $CNF['FIELD_ESTIMATE'] => $CNF['OBJECT_PRE_LIST_ESTIMATES'],
  1607. $CNF['FIELD_STATE'] => $CNF['OBJECT_PRE_LIST_STATES']
  1608. ];
  1609. $aForm = [
  1610. 'form_attrs' => [
  1611. 'id' => 'bx-tasks-filter-add',
  1612. 'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'create_filter/' . $iContextId,
  1613. 'method' => BX_DOL_FORM_METHOD_DEFAULT
  1614. ],
  1615. 'params' => [
  1616. 'db' => [
  1617. 'table' => $CNF['TABLE_FILTERS'],
  1618. 'key' => 'id',
  1619. 'uri' => '',
  1620. 'uri_title' => '',
  1621. 'submit_name' => 'do_apply'
  1622. ],
  1623. ],
  1624. 'inputs' => [
  1625. $CNF['FIELD_AUTHOR'] => [
  1626. 'type' => 'checkbox_set',
  1627. ],
  1628. $CNF['FIELD_INITIAL_MEMBERS'] => [
  1629. 'type' => 'checkbox_set',
  1630. ],
  1631. $CNF['FIELD_TYPE'] => [
  1632. 'type' => 'checkbox_set',
  1633. ],
  1634. $CNF['FIELD_PRIORITY'] => [
  1635. 'type' => 'checkbox_set',
  1636. ],
  1637. $CNF['FIELD_ESTIMATE'] => [
  1638. 'type' => 'checkbox_set',
  1639. ],
  1640. $CNF['FIELD_STATE'] => [
  1641. 'type' => 'checkbox_set',
  1642. ],
  1643. 'save_me' => [
  1644. 'type' => 'switcher',
  1645. 'name' => 'save_me',
  1646. 'caption' => _t('_bx_tasks_form_f_input_save_me'),
  1647. 'value' => 'on',
  1648. 'attrs' => [
  1649. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1650. ]
  1651. ],
  1652. 'save_all' => [
  1653. 'type' => 'switcher',
  1654. 'name' => 'save_all',
  1655. 'caption' => _t('_bx_tasks_form_f_input_save_all'),
  1656. 'value' => 'on',
  1657. 'attrs' => [
  1658. 'onchange' => $sJsObject . '.onChangeSave(this)'
  1659. ]
  1660. ],
  1661. 'title' => [
  1662. 'type' => 'text',
  1663. 'name' => 'title',
  1664. 'caption' => _t('_bx_tasks_form_f_input_title'),
  1665. 'value' => '',
  1666. 'required' => '0',
  1667. 'tr_attrs' => [
  1668. 'class' => 'bx-tasks-ffi-hidden'
  1669. ]
  1670. ],
  1671. 'controls' => [
  1672. 'name' => 'controls',
  1673. 'type' => 'input_set',
  1674. [
  1675. 'type' => 'submit',
  1676. 'name' => 'do_apply',
  1677. 'value' => _t('_bx_tasks_form_f_input_apply'),
  1678. ], [
  1679. 'type' => 'reset',
  1680. 'name' => 'do_cancel',
  1681. 'value' => _t('_bx_tasks_form_f_input_cancel'),
  1682. 'attrs' => [
  1683. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1684. 'class' => 'bx-def-margin-sec-left',
  1685. ],
  1686. ]
  1687. ]
  1688. ]
  1689. ];
  1690. foreach($aForm['inputs'] as $sName => $aInput) {
  1691. if(isset($aInput['name']))
  1692. continue;
  1693. $aForm['inputs'][$sName] = array_merge($aForm['inputs'][$sName], [
  1694. 'name' => $sName,
  1695. 'caption' => _t('_bx_tasks_form_f_input_' . $sName),
  1696. 'value' => '',
  1697. 'values' => []
  1698. ]);
  1699. if(($sList = $aFieldToList[$sName] ?? false) && ($aList = BxDolForm::getDataItems($sList))) {
  1700. if(isset($aList['']))
  1701. unset($aList['']);
  1702. $aForm['inputs'][$sName]['values'] = $aList;
  1703. }
  1704. }
  1705. $oContext = false;
  1706. $sContextModule = '';
  1707. if($iContextId && ($oContext = BxDolProfile::getInstance($iContextId)) !== false)
  1708. $sContextModule = $oContext->getModule();
  1709. foreach([$CNF['FIELD_AUTHOR'], $CNF['FIELD_INITIAL_MEMBERS']] as $sK){
  1710. if(!isset($aForm['inputs'][$sK]))
  1711. continue;
  1712. if($oContext !== false) {
  1713. $aForm['inputs'][$sK]['values']['{logged_pid}'] = _t('_bx_tasks_txt_flt_user_current');
  1714. $aMembers = bx_srv($sContextModule, 'fans', [$oContext->getContentId(), true]);
  1715. foreach($aMembers as $iMember)
  1716. if(($iMember != $this->_iProfileId) && ($oMember = BxDolProfile::getInstance($iMember)) !== false && !($oMember instanceof BxDolProfileUndefined))
  1717. $aForm['inputs'][$sK]['values'][$iMember] = $oMember->getDisplayName();
  1718. }
  1719. else
  1720. unset($aForm['inputs'][$sK]);
  1721. }
  1722. if(!$oContext || !bx_srv($sContextModule, 'is_admin', [$iContextId, $this->_iProfileId]))
  1723. unset($aForm['inputs']['save_all']);
  1724. return new BxTemplFormView($aForm);
  1725. }
  1726. protected function _getSaveFilterForm($iContextId = 0)
  1727. {
  1728. $CNF = &$this->_oConfig->CNF;
  1729. $aForm = [
  1730. 'form_attrs' => [
  1731. 'id' => 'bx-tasks-filter-save',
  1732. 'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'save_filter/' . $iContextId,
  1733. 'method' => BX_DOL_FORM_METHOD_DEFAULT
  1734. ],
  1735. 'params' => [
  1736. 'db' => [
  1737. 'table' => $CNF['TABLE_FILTERS'],
  1738. 'key' => 'id',
  1739. 'uri' => '',
  1740. 'uri_title' => '',
  1741. 'submit_name' => 'do_save'
  1742. ],
  1743. ],
  1744. 'inputs' => [
  1745. 'save_all' => [
  1746. 'type' => 'switcher',
  1747. 'name' => 'save_all',
  1748. 'caption' => _t('_bx_tasks_form_f_input_save_all'),
  1749. 'value' => 'on',
  1750. ],
  1751. 'title' => [
  1752. 'type' => 'text',
  1753. 'name' => 'title',
  1754. 'caption' => _t('_bx_tasks_form_f_input_title'),
  1755. 'value' => '',
  1756. 'required' => '0',
  1757. ],
  1758. 'controls' => [
  1759. 'name' => 'controls',
  1760. 'type' => 'input_set',
  1761. [
  1762. 'type' => 'submit',
  1763. 'name' => 'do_save',
  1764. 'value' => _t('_bx_tasks_form_f_input_save'),
  1765. ], [
  1766. 'type' => 'reset',
  1767. 'name' => 'do_cancel',
  1768. 'value' => _t('_bx_tasks_form_f_input_cancel'),
  1769. 'attrs' => [
  1770. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1771. 'class' => 'bx-def-margin-sec-left',
  1772. ],
  1773. ]
  1774. ]
  1775. ]
  1776. ];
  1777. $oContext = false;
  1778. $sContextModule = '';
  1779. if($iContextId && ($oContext = BxDolProfile::getInstance($iContextId)) !== false)
  1780. $sContextModule = $oContext->getModule();
  1781. if(!$oContext || !bx_srv($sContextModule, 'is_admin', [$iContextId, $this->_iProfileId]))
  1782. unset($aForm['inputs']['save_all']);
  1783. return new BxTemplFormView($aForm);
  1784. }
  1785. }
  1786. /** @} */