BxTasksConfig.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. *
  6. * @defgroup Tasks Tasks
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolInformer');
  12. class BxTasksConfig extends BxBaseModTextConfig
  13. {
  14. protected $_aProperties;
  15. function __construct($aModule)
  16. {
  17. parent::__construct($aModule);
  18. $aMenuItems2Methods = array (
  19. 'approve' => 'checkAllowedApprove',
  20. 'edit-task' => 'checkAllowedEdit',
  21. 'edit-task-state' => 'checkAllowedManage',
  22. 'delete-task' => 'checkAllowedDelete',
  23. );
  24. $this->CNF = array_merge($this->CNF, array (
  25. // module icon
  26. 'ICON' => 'tasks',
  27. // database tables
  28. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'tasks',
  29. 'TABLE_LISTS' => $aModule['db_prefix'] . 'lists',
  30. 'TABLE_ASSIGNMENTS' => $aModule['db_prefix'] . 'assignments',
  31. 'TABLE_TIME' => $aModule['db_prefix'] . 'time',
  32. 'TABLE_TIME_TRACK' => $aModule['db_prefix'] . 'time_track',
  33. 'TABLE_TIMERS' => $aModule['db_prefix'] . 'timers',
  34. 'TABLE_POLLS' => '',
  35. 'TABLE_ENTRIES_FULLTEXT' => 'title_text',
  36. // database fields
  37. 'FIELD_ID' => 'id',
  38. 'FIELD_AUTHOR' => 'author',
  39. 'FIELD_ADDED' => 'added',
  40. 'FIELD_CHANGED' => 'changed',
  41. 'FIELD_PUBLISHED' => 'published',
  42. 'FIELD_TITLE' => 'title',
  43. 'FIELD_TEXT' => 'text',
  44. 'FIELD_TEXT_ID' => 'post-text',
  45. 'FIELD_TYPE' => 'type',
  46. 'FIELD_PRIORITY' => 'priority',
  47. 'FIELD_ESTIMATE' => 'estimate',
  48. 'FIELD_STATE' => 'state',
  49. 'FIELD_CATEGORY' => 'cat',
  50. 'FIELD_MULTICAT' => 'multicat',
  51. 'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
  52. 'FIELD_CF' => 'cf',
  53. 'FIELD_COVER' => 'covers',
  54. 'FIELD_PHOTO' => 'pictures',
  55. 'FIELD_VIDEO' => 'videos',
  56. 'FIELD_FILE' => 'files',
  57. 'FIELD_THUMB' => 'thumb',
  58. 'FIELD_ATTACHMENTS' => 'attachments',
  59. 'FIELD_VIEWS' => 'views',
  60. 'FIELD_COMMENTS' => 'comments',
  61. 'FIELD_STATUS' => 'status',
  62. 'FIELD_STATUS_ADMIN' => 'status_admin',
  63. 'FIELD_LABELS' => 'labels',
  64. 'FIELD_TASKLIST' => 'tasks_list',
  65. 'FIELD_INITIAL_MEMBERS' => 'initial_members',
  66. 'FIELD_DUE_DATE' => 'due_date',
  67. 'FIELD_EXPIRED' => 'expired',
  68. 'FIELD_COMPLETED' => 'completed',
  69. 'FIELD_ANONYMOUS' => 'anonymous',
  70. 'FIELD_ALLOW_COMMENTS' => 'allow_comments',
  71. 'FIELDS_WITH_KEYWORDS' => 'auto', // can be 'auto', array of fields or comma separated string of field names, works only when OBJECT_METATAGS is specified
  72. 'FIELDS_DELAYED_PROCESSING' => 'videos', // can be array of fields or comma separated string of field names
  73. // some params
  74. 'PARAM_MULTICAT_ENABLED' => true,
  75. 'PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES' => 'bx_tasks_auto_activation_for_categories',
  76. 'PARAM_POLL_ENABLED' => false,
  77. // page URIs
  78. 'URI_VIEW_ENTRY' => 'view-task',
  79. 'URI_ENTRIES_BY_CONTEXT' => 'tasks-context',
  80. 'URI_ADD_ENTRY' => 'create-task',
  81. 'URI_EDIT_ENTRY' => 'edit-task',
  82. 'URI_MANAGE_COMMON' => 'tasks-manage',
  83. 'URL_HOME' => 'page.php?i=tasks-home',
  84. 'URL_POPULAR' => 'page.php?i=tasks-popular',
  85. 'URL_TOP' => 'page.php?i=tasks-top',
  86. 'URL_UPDATED' => 'page.php?i=tasks-updated',
  87. 'URL_MANAGE_COMMON' => 'page.php?i=tasks-manage',
  88. 'URL_MANAGE_ADMINISTRATION' => 'page.php?i=tasks-administration',
  89. // some params
  90. 'PARAM_AUTO_APPROVE' => 'bx_tasks_enable_auto_approve',
  91. 'PARAM_CHARS_SUMMARY' => 'bx_tasks_summary_chars',
  92. 'PARAM_CHARS_SUMMARY_PLAIN' => 'bx_tasks_plain_summary_chars',
  93. 'PARAM_NUM_RSS' => 'bx_tasks_rss_num',
  94. 'PARAM_SEARCHABLE_FIELDS' => 'bx_tasks_searchable_fields',
  95. 'PARAM_PER_PAGE_BROWSE_SHOWCASE' => 'bx_tasks_per_page_browse_showcase',
  96. // objects
  97. 'OBJECT_STORAGE' => 'bx_tasks_covers',
  98. 'OBJECT_STORAGE_FILES' => 'bx_tasks_files',
  99. 'OBJECT_STORAGE_PHOTOS' => 'bx_tasks_photos',
  100. 'OBJECT_STORAGE_VIDEOS' => 'bx_tasks_videos',
  101. 'OBJECT_IMAGES_TRANSCODER_PREVIEW' => 'bx_tasks_preview',
  102. 'OBJECT_IMAGES_TRANSCODER_GALLERY' => 'bx_tasks_gallery',
  103. 'OBJECT_IMAGES_TRANSCODER_COVER' => 'bx_tasks_cover',
  104. 'OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES' => 'bx_tasks_preview_files',
  105. 'OBJECT_IMAGES_TRANSCODER_GALLERY_FILES' => 'bx_tasks_gallery_files',
  106. 'OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS' => 'bx_tasks_preview_photos',
  107. 'OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS' => 'bx_tasks_gallery_photos',
  108. 'OBJECT_VIDEOS_TRANSCODERS' => array(
  109. 'poster' => 'bx_tasks_videos_poster',
  110. 'poster_preview' => 'bx_tasks_videos_poster_preview',
  111. 'mp4' => 'bx_tasks_videos_mp4',
  112. 'mp4_hd' => 'bx_tasks_videos_mp4_hd'
  113. ),
  114. 'OBJECT_VIDEO_TRANSCODER_HEIGHT' => '480px',
  115. 'OBJECT_REPORTS' => 'bx_tasks',
  116. 'OBJECT_REPORTS_TIME' => 'bx_tasks_time',
  117. 'OBJECT_VIEWS' => 'bx_tasks',
  118. 'OBJECT_VOTES' => 'bx_tasks',
  119. 'OBJECT_REACTIONS' => 'bx_tasks_reactions',
  120. 'OBJECT_SCORES' => 'bx_tasks',
  121. 'OBJECT_FAVORITES' => 'bx_tasks',
  122. 'OBJECT_FEATURED' => 'bx_tasks',
  123. 'OBJECT_COMMENTS' => 'bx_tasks',
  124. 'OBJECT_NOTES' => 'bx_tasks_notes',
  125. 'OBJECT_CATEGORY' => 'bx_tasks_cats',
  126. 'OBJECT_CONNECTION' => 'bx_tasks_assignments',
  127. 'OBJECT_PRIVACY_VIEW' => 'bx_tasks_allow_view_to',
  128. 'OBJECT_FORM_ENTRY' => 'bx_tasks',
  129. 'OBJECT_FORM_ENTRY_DISPLAY_VIEW' => 'bx_tasks_entry_view',
  130. 'OBJECT_FORM_ENTRY_DISPLAY_ADD' => 'bx_tasks_entry_add',
  131. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT' => 'bx_tasks_entry_edit',
  132. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_BODY' => 'bx_tasks_entry_edit_body',
  133. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_TYPE' => 'bx_tasks_entry_edit_type',
  134. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_PRIORITY' => 'bx_tasks_entry_edit_priority',
  135. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_ESTIMATE' => 'bx_tasks_entry_edit_estimate',
  136. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_DUE_DATE' => 'bx_tasks_entry_edit_due_date',
  137. 'OBJECT_FORM_ENTRY_DISPLAY_EDIT_STATE' => 'bx_tasks_entry_edit_state',
  138. 'OBJECT_FORM_ENTRY_DISPLAY_DELETE' => 'bx_tasks_entry_delete',
  139. 'OBJECT_FORM_LIST_ENTRY' => 'bx_tasks_list',
  140. 'OBJECT_FORM_LIST_ENTRY_DISPLAY_ADD' => 'bx_tasks_list_entry_add',
  141. 'OBJECT_FORM_LIST_ENTRY_DISPLAY_EDIT' => 'bx_tasks_list_entry_edit',
  142. 'OBJECT_FORM_TIME' => 'bx_tasks_time',
  143. 'OBJECT_FORM_TIME_DISPLAY_ADD' => 'bx_tasks_time_add',
  144. 'OBJECT_FORM_TIME_DISPLAY_EDIT' => 'bx_tasks_time_edit',
  145. 'OBJECT_MENU_ENTRY_ATTACHMENTS' => 'bx_tasks_entry_attachments', // attachments menu in create/edit forms
  146. 'OBJECT_MENU_ACTIONS_VIEW_ENTRY' => 'bx_tasks_view', // actions menu on view entry page
  147. 'OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL' => 'bx_tasks_view_actions', // all actions menu on view entry page
  148. 'OBJECT_MENU_ACTIONS_MY_ENTRIES' => 'bx_tasks_my', // actions menu on my entries page
  149. 'OBJECT_MENU_SUBMENU_VIEW_ENTRY' => 'bx_tasks_view_submenu', // view entry submenu
  150. 'OBJECT_MENU_SUBMENU_VIEW_ENTRY_MAIN_SELECTION' => 'tasks-home', // first item in view entry submenu from main module submenu
  151. 'OBJECT_MENU_SNIPPET_META' => 'bx_tasks_snippet_meta', // menu for snippet meta info
  152. 'OBJECT_MENU_MANAGE_TOOLS' => 'bx_tasks_menu_manage_tools', //manage menu in content administration tools
  153. 'OBJECT_MENU_SUBMENU_VIEW_CONTEXT' => 'bx_tasks_view_context_submenu',
  154. 'OBJECT_MENU_MANAGE_TOOLS_SUBMENU' => 'bx_tasks_manage_tools_submenu',
  155. 'OBJECT_MENU_MANAGE_TOOLS' => 'bx_tasks_menu_manage_tools', //manage item menu in content administration tools
  156. 'OBJECT_MENU_BROWSE' => 'bx_tasks_browse',
  157. 'OBJECT_GRID_ADMINISTRATION' => 'bx_tasks_administration',
  158. 'OBJECT_GRID_COMMON' => 'bx_tasks_common',
  159. 'OBJECT_GRID_TIME_ADMINISTRATION' => 'bx_tasks_time_administration',
  160. 'OBJECT_GRID_TIME_COMMON' => 'bx_tasks_time_common',
  161. 'OBJECT_GRID_TIME_CONTEXT_ADMINISTRATION' => 'bx_tasks_time_context_administration',
  162. 'OBJECT_GRID_TIME_CONTEXT_COMMON' => 'bx_tasks_time_context_common',
  163. 'OBJECT_GRID_CATEGORIES' => 'bx_tasks_categories',
  164. 'OBJECT_UPLOADERS' => array('bx_tasks_simple', 'bx_tasks_html5'),
  165. 'OBJECT_CONTENT_INFO' => 'bx_tasks',
  166. 'OBJECT_CMTS_CONTENT_INFO' => 'bx_tasks_cmts',
  167. 'OBJECT_PRE_LIST_TYPES' => 'bx_tasks_types',
  168. 'OBJECT_PRE_LIST_PRIORITIES' => 'bx_tasks_priorities',
  169. 'OBJECT_PRE_LIST_STATES' => 'bx_tasks_states',
  170. 'BADGES_AVALIABLE' => true,
  171. 'COOKIE_SETTING_KEY' => 'bx_tasks_filters',
  172. // menu items which visibility depends on custom visibility checking
  173. 'MENU_ITEM_TO_METHOD' => array (
  174. 'bx_tasks_my' => array (
  175. 'create-task' => 'checkAllowedAdd',
  176. ),
  177. 'bx_tasks_view' => $aMenuItems2Methods,
  178. ),
  179. // informer messages
  180. 'INFORMERS' => array (
  181. 'approving' => array (
  182. 'name' => 'bx-tasks-approving',
  183. 'map' => array (
  184. 'pending' => array('msg' => '_bx_tasks_txt_msg_status_pending', 'type' => BX_INFORMER_ALERT),
  185. 'hidden' => array('msg' => '_bx_tasks_txt_msg_status_hidden', 'type' => BX_INFORMER_ERROR),
  186. ),
  187. ),
  188. 'processing' => array (
  189. 'name' => 'bx-tasks-processing',
  190. 'map' => array (
  191. 'awaiting' => array('msg' => '_bx_tasks_txt_processing_awaiting', 'type' => BX_INFORMER_ALERT),
  192. 'failed' => array('msg' => '_bx_tasks_txt_processing_failed', 'type' => BX_INFORMER_ERROR)
  193. ),
  194. ),
  195. 'scheduled' => array (
  196. 'name' => 'bx-tasks-scheduled',
  197. 'map' => array (
  198. 'awaiting' => array('msg' => '_bx_tasks_txt_scheduled_awaiting', 'type' => BX_INFORMER_ALERT),
  199. ),
  200. ),
  201. ),
  202. // some language keys
  203. 'T' => array (
  204. 'txt_sample_single' => '_bx_tasks_txt_sample_single',
  205. 'txt_sample_single_with_article' => '_bx_tasks_txt_sample_single_with_article',
  206. 'txt_sample_comment_single' => '_bx_tasks_txt_sample_comment_single',
  207. 'txt_sample_vote_single' => '_bx_tasks_txt_sample_vote_single',
  208. 'txt_sample_reaction_single' => '_bx_tasks_txt_sample_reaction_single',
  209. 'txt_sample_score_up_single' => '_bx_tasks_txt_sample_score_up_single',
  210. 'txt_sample_score_down_single' => '_bx_tasks_txt_sample_score_down_single',
  211. 'form_field_author' => '_bx_tasks_form_entry_input_author',
  212. 'form_field_covers_uploader_simple' => '_bx_tasks_form_entry_input_covers_uploader_simple_title',
  213. 'form_field_covers_uploader_html5' => '_bx_tasks_form_entry_input_covers_uploader_html5_title',
  214. 'grid_action_err_delete' => '_bx_tasks_grid_action_err_delete',
  215. 'grid_txt_account_manager' => '_bx_tasks_grid_txt_account_manager',
  216. 'filter_item_active' => '_bx_tasks_grid_filter_item_title_adm_active',
  217. 'filter_item_hidden' => '_bx_tasks_grid_filter_item_title_adm_hidden',
  218. 'filter_item_pending' => '_bx_tasks_grid_filter_item_title_adm_pending',
  219. 'filter_item_select_one_filter1' => '_bx_tasks_grid_filter_item_title_adm_select_one_filter1',
  220. 'filter_item_select_one_filter2' => '_bx_tasks_grid_filter_item_title_adm_select_one_filter2',
  221. 'filter_item_select_one_filter3' => '_bx_tasks_grid_filter_item_title_adm_select_one_filter3',
  222. 'menu_item_manage_my' => '_bx_tasks_menu_item_title_manage_my',
  223. 'menu_item_manage_all' => '_bx_tasks_menu_item_title_manage_all',
  224. 'txt_all_entries_by' => '_bx_tasks_txt_all_entries_by',
  225. 'txt_all_entries_in' => '_bx_tasks_txt_all_entries_in',
  226. 'txt_all_entries_by_author' => '_bx_tasks_page_title_browse_by_author',
  227. 'txt_all_entries_by_context' => '_bx_tasks_page_title_browse_by_context',
  228. 'txt_err_cannot_perform_action' => '_bx_tasks_txt_err_cannot_perform_action',
  229. ),
  230. ));
  231. $this->_aJsClasses = array_merge($this->_aJsClasses, [
  232. 'manage_tools' => 'BxTasksManageTools',
  233. 'categories' => 'BxDolCategories',
  234. 'tasks' => 'BxTasksView',
  235. 'time' => 'BxTasksTime',
  236. 'timer' => 'BxTasksTimer'
  237. ]);
  238. $this->_aJsObjects = array_merge($this->_aJsObjects, [
  239. 'manage_tools' => 'oBxTasksManageTools',
  240. 'categories' => 'oBxDolCategories',
  241. 'tasks' => 'oBxTasksView',
  242. 'time' => 'oBxTasksTime',
  243. 'timer' => 'oBxTasksTimer'
  244. ]);
  245. $this->_aGridObjects = [
  246. 'common' => $this->CNF['OBJECT_GRID_COMMON'],
  247. 'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
  248. 'time_common' => $this->CNF['OBJECT_GRID_TIME_COMMON'],
  249. 'time_administration' => $this->CNF['OBJECT_GRID_TIME_ADMINISTRATION'],
  250. 'time_context_common' => $this->CNF['OBJECT_GRID_TIME_CONTEXT_COMMON'],
  251. 'time_context_administration' => $this->CNF['OBJECT_GRID_TIME_CONTEXT_ADMINISTRATION'],
  252. ];
  253. $sPrefix = str_replace('_', '-', $this->_sName);
  254. $this->_aHtmlIds = array_merge($this->_aHtmlIds, [
  255. 'time_popup' => $sPrefix . '-time-popup',
  256. 'total_popup' => $sPrefix . '-total-popup',
  257. 'timer' => $sPrefix . '-timer-',
  258. 'timer_actions' => $sPrefix . '-timer-actions',
  259. ]);
  260. $this->_bAttachmentsInTimeline = true;
  261. $this->_aProperties = [
  262. $this->CNF['FIELD_TYPE'],
  263. $this->CNF['FIELD_PRIORITY'],
  264. $this->CNF['FIELD_ESTIMATE'],
  265. $this->CNF['FIELD_DUE_DATE'],
  266. $this->CNF['FIELD_STATE']
  267. ];
  268. }
  269. public function isCompleted($iState)
  270. {
  271. return in_array($iState, [BX_TASKS_STATE_CANCELLED, BX_TASKS_STATE_DUPLICATE, BX_TASKS_STATE_DONE]);
  272. }
  273. public function getProperties()
  274. {
  275. return $this->_aProperties;
  276. }
  277. public function getTypeTitle($iValue)
  278. {
  279. $aItems = BxDolFormQuery::getDataItems($this->CNF['OBJECT_PRE_LIST_TYPES'], false, BX_DATA_VALUES_ALL);
  280. return $aItems[$iValue]['LKey'] ?? '';
  281. }
  282. public function getPriorityTitle($iValue)
  283. {
  284. $aItems = BxDolFormQuery::getDataItems($this->CNF['OBJECT_PRE_LIST_PRIORITIES'], false, BX_DATA_VALUES_ALL);
  285. return $aItems[$iValue]['LKey'] ?? '';
  286. }
  287. public function getEstimateTitle($iValue)
  288. {
  289. return $this->timeI2S($iValue);
  290. }
  291. public function getDueDateTitle($iValue)
  292. {
  293. return bx_process_output($iValue, BX_DATA_DATE_TS);
  294. }
  295. public function getStateTitle($iValue)
  296. {
  297. $aItems = BxDolFormQuery::getDataItems($this->CNF['OBJECT_PRE_LIST_STATES'], false, BX_DATA_VALUES_ALL);
  298. return $aItems[$iValue]['LKey'] ?? '';
  299. }
  300. public function timeA2I($a)
  301. {
  302. if(!$a || !is_array($a) || count($a) != 2)
  303. return 0;
  304. $iH = (int)($a[0] ?? 0);
  305. if($iH < 0)
  306. $iH = 0;
  307. $iM = (int)($a[1] ?? 0);
  308. if($iM < 0)
  309. $iM = 0;
  310. else if($iM > 59)
  311. $iM = 59;
  312. return 60 * $iH + $iM;
  313. }
  314. public function timeS2I($s)
  315. {
  316. if(strpos($s, ':') === false)
  317. return 0;
  318. return $this->timeA2I(explode(':', $s));
  319. }
  320. public function timeI2A($i, $bUseSeconds = false)
  321. {
  322. if(!$bUseSeconds) {
  323. $iH = intdiv($i, 60);
  324. return [$iH, $i - 60 * $iH];
  325. }
  326. $iH = intdiv($i, 3600);
  327. $iM = intdiv($i - 3600 * $iH, 60);
  328. return [$iH, $iM, $i - 3600 * $iH - 60 * $iM];
  329. }
  330. public function timeI2S($i)
  331. {
  332. list($iH, $iM) = $this->timeI2A($i);
  333. return sprintf("%02d", $iH) . ':' . sprintf("%02d", $iM);
  334. }
  335. }
  336. /** @} */