BxTasksConfig.php 16 KB

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