BxTasksModule.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. * Tasks module
  12. */
  13. class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
  14. {
  15. function __construct(&$aModule)
  16. {
  17. parent::__construct($aModule);
  18. $CNF = &$this->_oConfig->CNF;
  19. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  20. $CNF['FIELD_PUBLISHED'],
  21. $CNF['FIELD_ALLOW_COMMENTS']
  22. ));
  23. }
  24. /**
  25. * Action methods
  26. */
  27. /**
  28. * Get possible recipients for start conversation form
  29. */
  30. public function actionAjaxGetInitialMembers ()
  31. {
  32. $sTerm = bx_get('term');
  33. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  34. header('Content-Type:text/javascript; charset=utf-8');
  35. echo(json_encode($a));
  36. }
  37. public function actionSetCompleted($iContentId, $iValue)
  38. {
  39. if (!$this->isAllowManage($iContentId))
  40. return;
  41. $CNF = &$this->_oConfig->CNF;
  42. $this->_oDb->updateEntriesBy(array($CNF['FIELD_COMPLETED'] => $iValue), array($CNF['FIELD_ID'] => (int)$iContentId));
  43. $sActionName = 'completed';
  44. if($iValue == '0')
  45. $sActionName = 'reopened';
  46. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  47. $iContentAuthor = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  48. bx_alert($this->getName(), $sActionName, $iContentId, false, array(
  49. 'object_author_id' => $iContentAuthor,
  50. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  51. ));
  52. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  53. if($oConnection) {
  54. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  55. if(!empty($aProfileIds) && is_array($aProfileIds))
  56. foreach($aProfileIds as $iProfileId) {
  57. if($iProfileId == $iContentAuthor)
  58. continue;
  59. bx_alert($this->getName(), $sActionName, $iContentId, false, array(
  60. 'object_author_id' => $iProfileId,
  61. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  62. ));
  63. }
  64. }
  65. echo 'ok';
  66. }
  67. public function actionSetFilterValue($iListId, $sValue)
  68. {
  69. $CNF = &$this->_oConfig->CNF;
  70. $aTmp = array();
  71. if (isset($_COOKIE[$CNF['COOKIE_SETTING_KEY']]))
  72. $aTmp = json_decode($_COOKIE[$CNF['COOKIE_SETTING_KEY']], true);
  73. if ($sValue != '')
  74. $aTmp[$iListId] = $sValue;
  75. else
  76. unset($aTmp[$iListId]);
  77. bx_setcookie($CNF['COOKIE_SETTING_KEY'], json_encode($aTmp), time() + 60*60*24*365);
  78. }
  79. public function actionProcessTaskListForm($iContextId, $iId)
  80. {
  81. if (!$this->isAllowAdd(-$iContextId))
  82. return;
  83. $CNF = &$this->_oConfig->CNF;
  84. $oForm = null;
  85. $sPopupTitle = "";
  86. $aContentInfo = array();
  87. if ($iId == 0){
  88. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_LIST_ENTRY'], $CNF['OBJECT_FORM_LIST_ENTRY_DISPLAY_ADD']);
  89. $sPopupTitle = _t('_bx_tasks_form_list_entry_display_add');
  90. }
  91. else{
  92. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_LIST_ENTRY'], $CNF['OBJECT_FORM_LIST_ENTRY_DISPLAY_EDIT']);
  93. $aContentInfo = $this->_oDb->getList($iId);
  94. $sPopupTitle = _t('_bx_tasks_form_list_entry_display_edit');
  95. }
  96. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'process_task_list_form/' . $iContextId . '/' . $iId . '/';
  97. if (!$oForm)
  98. return '';
  99. $oForm->initChecker($aContentInfo, array());
  100. if($oForm->isSubmittedAndValid()) {
  101. if ($iId == 0){
  102. $aValsToAdd['context_id'] = $iContextId;
  103. $iId = $oForm->insert($aValsToAdd);
  104. }
  105. else{
  106. $iId = $oForm->update($iId);
  107. }
  108. return echoJson(array(
  109. 'eval' => $this->_oConfig->getJsObject('tasks') . '.reloadData(oData, ' . $iContextId . ')',
  110. ));
  111. }
  112. else {
  113. $sContent = $this->_oTemplate->parseHtmlByName('popup_form.html', array(
  114. 'form_id' => $oForm->getId(),
  115. 'form' => $oForm->getCode(true)
  116. ));
  117. if (!$oForm->isSubmitted()){
  118. echo $sContent;
  119. return;
  120. }
  121. return echoJson(array('form' => $sContent, 'form_id' => $oForm->getId()));;
  122. }
  123. }
  124. public function actionDeleteTaskList($iId, $iContextId)
  125. {
  126. if (!$this->isAllowManageByContext($iContextId))
  127. return;
  128. $this->_oDb->deleteList($iId);
  129. echoJson(array(
  130. 'context_id' => $iContextId,
  131. ));
  132. }
  133. public function actionProcessTaskForm($iContextId, $iListId)
  134. {
  135. if (!$this->isAllowAdd(-$iContextId))
  136. return;
  137. $CNF = &$this->_oConfig->CNF;
  138. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  139. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'process_task_form/' . $iContextId . '/' . $iListId . '/';
  140. if (!$oForm)
  141. return '';
  142. $oForm->initChecker();
  143. if($oForm->isSubmittedAndValid()) {
  144. $aValsToAdd[$CNF['FIELD_ALLOW_VIEW_TO']] = $iContextId;
  145. $aValsToAdd[$CNF['FIELD_TASKLIST']] = $iListId;
  146. $iContentId = $oForm->insert($aValsToAdd);
  147. $this->onPublished($iContentId);
  148. return echoJson(array(
  149. 'eval' => $this->_oConfig->getJsObject('tasks') . '.reloadData(oData, ' . $iContextId . ')',
  150. ));
  151. }
  152. else {
  153. $sContent = $this->_oTemplate->parseHtmlByName('popup_form.html', array(
  154. 'form_id' => $oForm->getId(),
  155. 'form' => $oForm->getCode(true)
  156. ));
  157. if (!$oForm->isSubmitted()){
  158. echo $sContent;
  159. return;
  160. }
  161. return echoJson(array('form' => $sContent, 'form_id' => $oForm->getId()));;
  162. }
  163. }
  164. public function actionCalendarData()
  165. {
  166. // check permissions
  167. $aSQLPart = array();
  168. $iContextId = (int)bx_get('context_id');
  169. if (!$this->isAllowView($iContextId))
  170. return;
  171. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  172. if($iContextId){
  173. $aSQLPart = $oPrivacy ? $oPrivacy->getContentByGroupAsSQLPart(- $iContextId) : array();
  174. }
  175. // get entries
  176. $aEntries = $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), bx_get('event'), $aSQLPart);
  177. header('Content-Type: application/json; charset=utf-8');
  178. echo json_encode($aEntries);
  179. }
  180. /**
  181. * Data for Timeline module
  182. */
  183. public function serviceGetTimelineData()
  184. {
  185. $sModule = $this->_aModule['name'];
  186. return array(
  187. 'handlers' => array(
  188. 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' => ''),
  189. 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' => ''),
  190. 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' => ''),
  191. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  192. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  193. ),
  194. 'alerts' => array(
  195. array('unit' => $sModule, 'action' => 'added'),
  196. array('unit' => $sModule, 'action' => 'completed'),
  197. array('unit' => $sModule, 'action' => 'reopened'),
  198. array('unit' => $sModule, 'action' => 'edited'),
  199. array('unit' => $sModule, 'action' => 'deleted'),
  200. )
  201. );
  202. }
  203. /**
  204. * Entry task for Timeline module
  205. */
  206. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  207. {
  208. $CNF = &$this->_oConfig->CNF;
  209. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  210. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  211. return $aResult;
  212. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  213. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  214. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  215. return $aResult;
  216. }
  217. public function serviceGetTimelineCompleted($aEvent, $aBrowseParams = array())
  218. {
  219. $CNF = &$this->_oConfig->CNF;
  220. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  221. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_completed');
  222. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  223. return $aResult;
  224. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  225. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  226. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  227. return $aResult;
  228. }
  229. public function serviceGetTimelineReopened($aEvent, $aBrowseParams = array())
  230. {
  231. $CNF = &$this->_oConfig->CNF;
  232. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  233. $aResult['sample_action'] = $aResult['content']['sample_action'] = _t('_bx_tasks_txt_action_reopened');
  234. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  235. return $aResult;
  236. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  237. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  238. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  239. return $aResult;
  240. }
  241. public function serviceGetNotificationsData()
  242. {
  243. $sModule = $this->_aModule['name'];
  244. $sEventPrivacy = $sModule . '_allow_view_event_to';
  245. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  246. $sEventPrivacy = '';
  247. $aResult = parent::serviceGetNotificationsData();
  248. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  249. 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),
  250. 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),
  251. 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),
  252. 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),
  253. array('group' => $sModule . '_assign', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'unassigned'),
  254. ));
  255. $aResult['settings'] = array_merge($aResult['settings'], array(
  256. array('group' => 'content', 'unit' => $sModule, 'action' => 'completed', 'types' => array('personal', 'follow_member', 'follow_context')),
  257. array('group' => 'content', 'unit' => $sModule, 'action' => 'reopened', 'types' => array('personal', 'follow_member', 'follow_context')),
  258. array('group' => 'content', 'unit' => $sModule, 'action' => 'expired', 'types' => array('personal')),
  259. array('group' => 'content', 'unit' => $sModule, 'action' => 'assigned', 'types' => array('personal')),
  260. ));
  261. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  262. array('unit' => $sModule, 'action' => 'completed'),
  263. array('unit' => $sModule, 'action' => 'reopened'),
  264. array('unit' => $sModule, 'action' => 'expired'),
  265. array('unit' => $sModule, 'action' => 'assigned'),
  266. array('unit' => $sModule, 'action' => 'unassigned'),
  267. ));
  268. return $aResult;
  269. }
  270. public function serviceGetNotificationsCompleted($aEvent)
  271. {
  272. return $this->_serviceGetNotificationsByAction($aEvent, 'completed');
  273. }
  274. public function serviceGetNotificationsReopened($aEvent)
  275. {
  276. return $this->_serviceGetNotificationsByAction($aEvent, 'reopened');
  277. }
  278. public function serviceGetNotificationsExpired($aEvent)
  279. {
  280. return $this->_serviceGetNotificationsByAction($aEvent, 'expired');
  281. }
  282. public function serviceGetNotificationsAssigned($aEvent)
  283. {
  284. return $this->_serviceGetNotificationsByAction($aEvent, 'assigned');
  285. }
  286. protected function _serviceGetNotificationsByAction($aEvent, $sAction)
  287. {
  288. $CNF = &$this->_oConfig->CNF;
  289. $aResult = parent::serviceGetNotificationsPost($aEvent);
  290. if(empty($aResult) || !is_array($aResult))
  291. return $aResult;
  292. $aResult['entry_author'] = $aEvent['object_owner_id'];
  293. $aResult['entry_author_name'] = '';
  294. if(($oAuthor = BxDolProfile::getInstance($aResult['entry_author'])) !== false)
  295. $aResult['entry_author_name'] = $oAuthor->getDisplayName();
  296. $sLangKey = '_bx_tasks_txt_notification_' . $sAction;
  297. if((int)$aEvent['object_privacy_view'] < 0)
  298. $sLangKey .= '_in_context';
  299. $aResult['lang_key'] = _t($sLangKey);
  300. return $aResult;
  301. }
  302. public function serviceIsCompleted($iContentId)
  303. {
  304. if (!$this->serviceIsAllowManage($iContentId))
  305. return false;
  306. $CNF = &$this->_oConfig->CNF;
  307. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  308. return $aContentInfo[$CNF['FIELD_COMPLETED']] ? false: true;
  309. }
  310. public function serviceIsUncompleted($iContentId)
  311. {
  312. if (!$this->serviceIsAllowManage($iContentId))
  313. return false;
  314. $CNF = &$this->_oConfig->CNF;
  315. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  316. return $aContentInfo[$CNF['FIELD_COMPLETED']] ? true : false;
  317. }
  318. public function serviceIsAllowManage($iContentId)
  319. {
  320. if (!$this->isAllowManage($iContentId))
  321. return false;
  322. return true;
  323. }
  324. public function serviceIsAllowBadges($iContentId)
  325. {
  326. if (!$this->isAllowManage($iContentId))
  327. return false;
  328. if (!$this->serviceIsBadgesAvaliable())
  329. return false;
  330. return true;
  331. }
  332. public function serviceEntityAssignments($iContentId = 0, $bAsArray = false)
  333. {
  334. if (!$iContentId)
  335. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  336. if (!$iContentId)
  337. return false;
  338. $mixedResult = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTION'])->getConnectedContent($iContentId);
  339. if(!$bAsArray) {
  340. $s = '';
  341. foreach ($mixedResult as $mixedProfile) {
  342. $bProfile = is_array($mixedProfile);
  343. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  344. if(!$oProfile)
  345. continue;
  346. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  347. if($bProfile && is_array($mixedProfile['info']))
  348. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  349. $s .= $oProfile->getUnit(0, $aUnitParams);
  350. }
  351. $mixedResult = $s;
  352. if (!$mixedResult)
  353. return MsgBox(_t('_sys_txt_empty'));
  354. }
  355. return $mixedResult;
  356. }
  357. public function serviceCheckAllowedCommentsTask($iContentId, $sObjectComments)
  358. {
  359. $CNF = &$this->_oConfig->CNF;
  360. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  361. if ($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  362. return false;
  363. return parent::serviceCheckAllowedCommentsTask($iContentId, $sObjectComments);
  364. }
  365. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  366. {
  367. $CNF = &$this->_oConfig->CNF;
  368. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  369. if ($aContentInfo[$CNF['FIELD_ALLOW_COMMENTS']] == 0)
  370. return false;
  371. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  372. }
  373. /**
  374. * @page service Service Calls
  375. * @section bx_tasks Tasks
  376. * @subsection bx_tasks-page_blocks Page Blocks
  377. * @subsubsection bx_tasks-calendar calendar
  378. *
  379. * @code bx_srv('bx_tasks', 'calendar', [...]); @endcode
  380. *
  381. * Shows tasks calendar baced on die date
  382. *
  383. * @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.
  384. * @param $sTemplate template to use to show calendar, or leave empty for default template, possible options: calendar.html, calendar_compact.html
  385. * @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.
  386. *
  387. * @see BxTasksModule::serviceCalendar
  388. */
  389. /**
  390. * @ref bx_tasks-calendar "calendar"
  391. */
  392. public function serviceCalendar($aData = array(), $sTemplate = 'calendar.html')
  393. {
  394. if (!$this->isAllowView($aData['context_id']))
  395. return;
  396. $o = new BxTemplCalendar(array(
  397. 'eventSources' => array (
  398. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'calendar_data', $aData),
  399. ),
  400. ), $this->_oTemplate);
  401. return $o->display($sTemplate);
  402. }
  403. public function serviceGetCalendarEntries($iProfileId)
  404. {
  405. $CNF = &$this->_oConfig->CNF;
  406. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  407. $aData = $oConn->getConnectedInitiators($iProfileId);
  408. $aData2 = array(0);
  409. foreach($aData as $iProfileId2){
  410. $oProfile = BxDolProfile::getInstance($iProfileId2);
  411. array_push($aData2, $oProfile->getContentId());
  412. }
  413. $aSQLPart['where'] = " AND " . $CNF['TABLE_ENTRIES'] . ".`" . $CNF['FIELD_ID'] . "` IN(" . implode(',', $aData2) . ")";
  414. return $this->_oDb->getEntriesByDate(bx_get('start'), bx_get('end'), null, $aSQLPart);
  415. }
  416. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  417. {
  418. if(!$iProfileId)
  419. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  420. if(!$iProfileId)
  421. return '';
  422. return $this->serviceBrowseTasks (-$iProfileId, $aParams);
  423. }
  424. public function serviceBrowseTasks ($iContextId = 0, $aParams = array())
  425. {
  426. if (!$this->isAllowView(-$iContextId))
  427. return;
  428. $oProfileContext = BxDolProfile::getInstance(-$iContextId);
  429. $mixedResult = $oProfileContext->checkAllowedProfileView(-$iContextId);
  430. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  431. return false;
  432. $CNF = &$this->_oConfig->CNF;
  433. $this->_oTemplate->addCssJs();
  434. $aVars = array();
  435. $aLists = $this->_oDb->getLists($iContextId);
  436. $aListsVars = array();
  437. $oConn = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  438. $aFilterValues = array();
  439. if (isset($_COOKIE[$CNF['COOKIE_SETTING_KEY']]))
  440. $aFilterValues = json_decode($_COOKIE[$CNF['COOKIE_SETTING_KEY']], true);
  441. $bAllowAdd = $this->isAllowAdd(-$iContextId);
  442. $bAllowManage = $this->isAllowManageByContext(-$iContextId);
  443. foreach($aLists as $aList) {
  444. $aTasks = $this->_oDb->getTasks($iContextId, $aList['id']);
  445. $aTasksVars = array();
  446. foreach($aTasks as $aTask) {
  447. $aMembers = $oConn->getConnectedContent($aTask[$CNF['FIELD_ID']]);
  448. $aMembersVars = array();
  449. foreach($aMembers as $iMember) {
  450. $oProfile = BxDolProfile::getInstance($iMember);
  451. $aMembersVars[] = array('info' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')));
  452. }
  453. $aTasksVars[] = array(
  454. 'id' => $aTask[$CNF['FIELD_ID']],
  455. 'title' => $aTask[$CNF['FIELD_TITLE']],
  456. 'created' => bx_time_js($aTask[$CNF['FIELD_ADDED']]),
  457. 'class' => $aTask[$CNF['FIELD_COMPLETED']] == 1 ? 'completed' : 'uncompleted',
  458. 'due' => $aTask[$CNF['FIELD_DUEDATE']] > 0 ? bx_time_js($aTask[$CNF['FIELD_DUEDATE']]) : '',
  459. 'bx_repeat:members' => $aMembersVars,
  460. 'badges' => $this->serviceGetBadges($aTask[$CNF['FIELD_ID']], true),
  461. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aTask[$CNF['FIELD_ID']])),
  462. 'object' => $this->_oConfig->getJsObject('tasks'),
  463. 'bx_if:allow_manage' => array(
  464. 'condition' => $bAllowManage,
  465. 'content' => array(
  466. 'id' => $aTask[$CNF['FIELD_ID']],
  467. 'object' => $this->_oConfig->getJsObject('tasks'),
  468. 'checked' => $aTask[$CNF['FIELD_COMPLETED']] == 1 ? 'checked' : '',
  469. )
  470. ),
  471. 'bx_if:deny_manage' => array(
  472. 'condition' => !$bAllowManage,
  473. 'content' => array(
  474. 'id' => $aTask[$CNF['FIELD_ID']],
  475. 'checked' => $aTask[$CNF['FIELD_COMPLETED']] == 1 ? 'checked' : '',
  476. )
  477. ),
  478. );
  479. }
  480. $sClass = $sCompleted = $sAll = "";
  481. if (isset($aFilterValues[$aList[$CNF['FIELD_ID']]])){
  482. $sClass = $aFilterValues[$aList[$CNF['FIELD_ID']]];
  483. if ($sClass == 'completed')
  484. $sCompleted= 'selected';
  485. if ($sClass == 'all')
  486. $sAll = 'selected';
  487. }
  488. $aListsVars[] = array(
  489. 'bx_if:allow_edit_list' => array(
  490. 'condition' => $bAllowAdd,
  491. 'content' => array(
  492. 'title' => $aList[$CNF['FIELD_TITLE']],
  493. 'context_id' => $iContextId,
  494. 'list_id' => $aList[$CNF['FIELD_ID']],
  495. 'object' => $this->_oConfig->getJsObject('tasks'),
  496. )
  497. ),
  498. 'bx_if:allow_add' => array(
  499. 'condition' => $bAllowAdd,
  500. 'content' => array(
  501. 'context_id' => $iContextId,
  502. 'list_id' => $aList[$CNF['FIELD_ID']],
  503. 'object' => $this->_oConfig->getJsObject('tasks'),
  504. )
  505. ),
  506. 'bx_if:allow_delete_list' => array(
  507. 'condition' => $bAllowManage,
  508. 'content' => array(
  509. 'context_id' => $iContextId,
  510. 'list_id' => $aList[$CNF['FIELD_ID']],
  511. 'object' => $this->_oConfig->getJsObject('tasks'),
  512. )
  513. ),
  514. 'bx_if:deny_edit_list' => array(
  515. 'condition' => !$bAllowAdd,
  516. 'content' => array(
  517. 'title' => $aList[$CNF['FIELD_TITLE']],
  518. )
  519. ),
  520. 'id' => $aList['id'],
  521. 'bx_repeat:tasks' => $aTasksVars,
  522. 'context_id' => $iContextId,
  523. 'list_id' => $aList[$CNF['FIELD_ID']],
  524. 'object' => $this->_oConfig->getJsObject('tasks'),
  525. 'class' => $sClass,
  526. 'completed' => $sCompleted,
  527. 'all' => $sAll,
  528. );
  529. }
  530. $aVars = array(
  531. 'bx_repeat:task_lists' => $aListsVars,
  532. 'bx_if:allow_add_list' => array(
  533. 'condition' => $bAllowAdd,
  534. 'content' => array(
  535. 'context_id' => $iContextId,
  536. 'object' => $this->_oConfig->getJsObject('tasks'),
  537. )
  538. ),
  539. );
  540. $this->_oTemplate->addJs(array(
  541. 'jquery-ui/jquery-ui.min.js',
  542. 'tasks.js',
  543. 'modules/base/general/js/|forms.js'
  544. ));
  545. return $this->_oTemplate->getJsCode('tasks', array('t_confirm_block_deletion' => _t('_bx_tasks_confirm_tasklist_deletion'))) . $this->_oTemplate->parseHtmlByName('browse_tasks.html', $aVars);
  546. }
  547. /**
  548. * Common methods
  549. */
  550. public function onExpired($iContentId)
  551. {
  552. $CNF = &$this->_oConfig->CNF;
  553. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  554. if(!$aContentInfo)
  555. return;
  556. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  557. if($oConnection) {
  558. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  559. if(!empty($aProfileIds) && is_array($aProfileIds))
  560. foreach($aProfileIds as $iProfileId)
  561. bx_alert($this->getName(), 'expired', $iContentId, false, array(
  562. 'object_author_id' => $iProfileId,
  563. 'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]
  564. ));
  565. }
  566. }
  567. function isAllowView($iContextId)
  568. {
  569. $oProfileContext = BxDolProfile::getInstance($iContextId);
  570. $mixedResult = $oProfileContext->checkAllowedProfileView($iContextId);
  571. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  572. return false;
  573. return true;
  574. }
  575. function isAllowAdd($iContextId)
  576. {
  577. $oProfileContext = BxDolProfile::getInstance($iContextId);
  578. $mixedResult = $oProfileContext->checkAllowedPostInProfile($iContextId);
  579. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  580. return false;
  581. return true;
  582. }
  583. function isAllowManageByContext($iContextId)
  584. {
  585. if(isAdmin())
  586. return true;
  587. $oProfileContext = BxDolProfile::getInstance($iContextId);
  588. if(BxDolService::call($oProfileContext->getModule(), 'is_admin', array($iContextId)))
  589. return true;
  590. }
  591. function isAllowManage($iContentId)
  592. {
  593. $CNF = &$this->_oConfig->CNF;
  594. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  595. $bRv = $this->isAllowManageByContext(-$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  596. if ($bRv)
  597. return $bRv;
  598. if ($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  599. return true;
  600. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  601. if($oConnection) {
  602. $aProfileIds = $oConnection->getConnectedContent($iContentId);
  603. if(!empty($aProfileIds) && is_array($aProfileIds)){
  604. if (in_array(bx_get_logged_profile_id(), $aProfileIds))
  605. return true;
  606. }
  607. }
  608. return false;
  609. }
  610. }
  611. /** @} */