BxTasksConfig.php 15 KB

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