| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- * @defgroup Tasks Tasks
- * @ingroup UnaModules
- *
- * @{
- */
- require_once('BxTasksMenuTimer.php');
- class BxTasksTemplate extends BxBaseModTextTemplate
- {
- public function __construct(&$oConfig, &$oDb)
- {
- $this->MODULE = 'bx_tasks';
- parent::__construct($oConfig, $oDb);
- }
- public function getJsCode($sType, $aParams = [], $mixedWrap = true)
- {
- $aParams = array_merge([
- 'aHtmlIds' => $this->_oConfig->getHtmlIds()
- ], $aParams);
- return parent::getJsCode($sType, $aParams, $mixedWrap);
- }
- public function getJsCodeTimer($sType, $aParams = [], $mixedWrap = true)
- {
- $aParams = array_merge([
- 'aHtmlIds' => $this->_oConfig->getHtmlIds()
- ], $aParams);
- if(is_array($mixedWrap))
- return parent::getJsCode($sType, $aParams, [
- 'wrap' => true,
- 'mask' => "{var} {object} = new {class}({params}); {object}.init({content_id}, {profile_id}, {started});",
- 'mask_markers' => $mixedWrap
- ]);
- else
- parent::getJsCode($sType, $aParams, $mixedWrap);
- }
- public function getBlockMenuBrowse()
- {
- $CNF = &$this->_oConfig->CNF;
- $iProfileId = bx_get_logged_profile_id();
- $sMenuUse = '';
- if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_USE_TOOLS_SUBMENU'])) !== false)
- $sMenuUse = $oMenu->getCode();
- $sMenuManage = '';
- if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_MANAGE_TOOLS_SUBMENU'])) !== false)
- $sMenuManage = $oMenu->getCode();
- $sMenuBrowse = '';
- if(($oMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_BROWSE'])) !== false) {
- $oMenu->setProfileId($iProfileId);
- $sMenuBrowse = $oMenu->getCode();
- }
- return $this->parseHtmlByName('menu_browse.html', [
- 'menu_use' => $sMenuUse,
- 'bx_if:show_menu_manage' => [
- 'condition' => $sMenuManage != '',
- 'content' => [
- 'menu_manage' => $sMenuManage
- ]
- ],
- 'bx_if:show_menu_browse' => [
- 'condition' => $sMenuBrowse != '',
- 'content' => [
- 'menu_browse' => $sMenuBrowse
- ]
- ]
- ]);
- }
-
- /**
- * Use Gallery image for both because currently there is no Unit types with small thumbnails.
- */
- protected function getUnitThumbAndGallery ($aData)
- {
- list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
- return array($sPhotoGallery, $sPhotoGallery);
- }
-
- public function entryText ($aData, $sTemplateName = 'entry-text.html')
- {
- $CNF = &$this->_oConfig->CNF;
- $iContentId = (int)$aData[$CNF['FIELD_ID']];
- $sResult = '';
- if(!$this->_oModule->isAllowEdit($iContentId)) {
- $aVars = $this->getTmplVarsText($aData);
- $sResult = $this->parseHtmlByName($sTemplateName, $aVars);
- }
- else
- $sResult = $this->getModule()->serviceEntityEdit($iContentId, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_BODY']);
- return $sResult;
- }
- public function entryAssignments ($aProfiles)
- {
- $CNF = &$this->_oConfig->CNF;
- $aTmplVarsProfiles = [];
- foreach($aProfiles as $mixedProfile) {
- $bProfile = is_array($mixedProfile);
- $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
- if(!$oProfile)
- continue;
- $aUnitParams = ['template' => ['name' => 'unit', 'size' => 'thumb']];
- if($bProfile && is_array($mixedProfile['info']))
- $aUnitParams['template']['vars'] = $mixedProfile['info'];
- $aTmplVarsProfiles[] = [
- 'unit' => $oProfile->getUnit(0, $aUnitParams)
- ];
- }
- return $aTmplVarsProfiles ? $this->parseHtmlByName('entry-assignments.html', [
- 'bx_repeat:profiles' => $aTmplVarsProfiles
- ]) : MsgBox(_t('_sys_txt_empty'));
- }
- public function entryTimer ($iContentId, $iProfileId)
- {
- $this->addCss(['timer.css']);
- $this->addJs(['timer.js']);
- return $this->getTimer($iContentId, $iProfileId) . $this->getJsCodeTimer('timer', [], [
- 'content_id' => $iContentId,
- 'profile_id' => $iProfileId,
- 'started' => $this->_oDb->isTimerStarted($iContentId, $iProfileId),
- ]);
- }
- public function getBlockTimers ($iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $oModule = $this->getModule();
- $sJsObject = $this->_oConfig->getJsObject('timer');
- $aTimers = $this->_oDb->getTimers(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
- if(!$aTimers || !is_array($aTimers))
- return MsgBox(_t('_Empty'));
- $oPermalinks = BxDolPermalinks::getInstance();
- $aTmplVarsSections = [];
- foreach($aTimers as $aTimer) {
- $aContentInfo = $this->_oDb->getContentInfoById($aTimer['content_id']);
- if(!$aContentInfo && !is_array($aContentInfo))
- continue;
- $sContextType = $sContextTitle = $sContextUrl = '';
- if(($iAllowViewTo = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($oContext = BxDolProfile::getInstance(abs($iAllowViewTo))) !== false) {
- $sContextType = $oContext->getModule();
- $sContextTitle = $oContext->getDisplayName();
- $sContextUrl = $oContext->getUrl();
- }
- if(!isset($aTmplVarsSections[$sContextType]))
- $aTmplVarsSections[$sContextType] = [
- 'section_title' => $oModule->getModuleTitle($sContextType),
- 'bx_repeat:timers' => []
- ];
- $aTmplVarsSections[$sContextType]['bx_repeat:timers'][] = [
- 'bx_if:show_context' => [
- 'condition' => $sContextTitle && $sContextUrl,
- 'content' => [
- 'title' => $sContextTitle,
- 'url' => $sContextUrl
- ]
- ],
- 'content_title' => $aContentInfo[$CNF['FIELD_TITLE']],
- 'content_url' => bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
- 'timer' => $this->getTimer($aTimer['content_id'], $iProfileId),
- 'js_code_timer' => $sJsObject . '.init(' . $aTimer['content_id'] . ', ' . $iProfileId . ', ' . ($aTimer['started'] != 0 ? 1 : 0) . ');'
- ];
- }
- $this->addCss(['timer.css']);
- $this->addJs(['timer.js']);
- return $this->parseHtmlByName('browse_timers.html', [
- 'js_code' => $this->getJsCode('timer', [
- 'bMulti' => true
- ]),
- 'bx_repeat:sections' => array_values($aTmplVarsSections)
- ]);
- }
- public function getTimer ($iContentId, $iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $sPrefix = str_replace('_', '-', $this->_oConfig->getName());
- $sJsObject = $this->_oConfig->getJsObject('timer');
- $aTimer = $this->_oDb->getTimers(['sample' => 'content_profile_ids', 'content_id' => $iContentId, 'profile_id' => $iProfileId]);
- $bTimer = $aTimer && is_array($aTimer);
- $bStarted = $bTimer && (int)$aTimer['started'] > 0;
- $iHours = $iMinutes = $iSeconds = 0;
- if($bTimer) {
- $iDuration = (int)$aTimer['duration'];
- if($bStarted)
- $iDuration += time() - (int)$aTimer['started'];
- list($iHours, $iMinutes, $iSeconds) = $this->_oConfig->timeI2A($iDuration, true);
- }
- $oActions = new BxTasksMenuTimer([
- 'object' => $sPrefix . '_timer',
- 'template' => 'menu_custom_hor.html',
- 'menu_id' => $this->_oConfig->getHtmlIds('timer_actions'),
- 'persistent' => 0
- ]);
- $oActions->setParams($iContentId, $iProfileId);
- return $this->parseHtmlByName('entry-timer.html', [
- 'html_id' => $this->_oConfig->getHtmlIds('timer') . $iContentId . '-' . $iProfileId,
- 'hours' => sprintf("%02d", $iHours),
- 'minutes' => sprintf("%02d", $iMinutes),
- 'seconds' => sprintf("%02d", $iSeconds),
- 'actions' => $oActions->getCode()
- ]);
- }
-
- public function getEntriesList($iContextId = 0, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- $sJsObject = $this->_oConfig->getJsObject('tasks');
- $iLoggedId = bx_get_logged_profile_id();
- $oModule = $this->getModule();
- $bContext = !empty($iContextId);
- $bAllowAdd = $bContext && $oModule->isAllowAdd($iContextId);
- $aFilters = [];
- if(($sFilters = $_COOKIE[$CNF['COOKIE_SETTING_KEY']] ?? false))
- $aFilters = json_decode($sFilters, true);
- $iFilterSelected = $aParams['filter'] ?? ($aFilters[$iContextId] ?? 0);
- $sFilters = $this->_getEntriesFilters($iContextId, array_merge($aParams, ['filter_selected' => $iFilterSelected]));
-
- $this->addCssJs();
- $this->addJs([
- 'jquery-ui/jquery-ui.min.js',
- 'tasks.js',
- 'modules/base/general/js/|forms.js'
- ]);
- return $this->parseHtmlByName('browse_tasks.html', [
- 'object' => $sJsObject,
- 'context_id' => $iContextId,
- 'bx_if:show_filters' => [
- 'condition' => !empty($sFilters),
- 'content' => [
- 'object' => $sJsObject,
- 'context_id' => $iContextId,
- 'filters' => $sFilters
- ]
- ],
- 'bx_if:allow_add_list' => [
- 'condition' => $bAllowAdd,
- 'content' => [
- 'context_id' => $iContextId,
- 'object' => $sJsObject,
- ]
- ],
- 'bx_if:allow_manage_settings' => [
- 'condition' => $bContext,
- 'content' => [
- 'context_id' => $iContextId,
- ]
- ],
- 'tasks' => $this->getEntries($iContextId, array_merge($aParams, [
- 'filter' => $iFilterSelected,
- ])),
- 'js_code' => $this->getJsCode('tasks', ['t_confirm_block_deletion' => _t('_bx_tasks_txt_msg_confirm_tasklist_deletion')])
- ]);
- }
-
- public function getEntries($iContextId = 0, $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- $sJsObject = $this->_oConfig->getJsObject('tasks');
- $oModule = $this->getModule();
- $oPermalinks = BxDolPermalinks::getInstance();
- $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
- $aTypes = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_TYPES']);
- $aPriorities = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_PRIORITIES']);
- $aStates = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_STATES']);
- $bContext = !empty($iContextId);
- $bAllowAdd = $bContext && $oModule->isAllowAdd($iContextId);
- $bAllowManage = $bContext && $oModule->isAllowManageByContext($iContextId);
- $aLists = [];
- if(!$bContext) {
- $iProfile = $aParams['for_profile'] ?? bx_get_logged_profile_id();
- $aContexts = $this->_oModule->getContexts();
- foreach($aContexts as $sName => $sTitle) {
- $aIds = $this->_oModule->_oDb->getContextsIdsByType($sName, $iProfile);
- foreach($aIds as $iId) {
- $oContext = BxDolProfile::getInstance($iId);
- if(!$oContext)
- continue;
- $aLists[] = [
- 'id' => $sName,
- 'context_id' => $iId,
- 'title' => _t('_bx_tasks_txt_list_title', $oContext->getDisplayName(), $sTitle)
- ];
- }
- }
- }
- else
- $aLists = $this->_oDb->getLists($iContextId);
- $aParams = array_merge($aParams, [
- 'with_stats' => true
- ]);
- $aTmplVarsLists = [];
- foreach($aLists as $aList) {
- $iTasksContextId = $bContext ? $iContextId : ($aList['context_id'] ?? false);
- if(!$iTasksContextId)
- continue;
- $bTasksAllowManage = $bContext ? $bAllowManage : $oModule->isAllowManageByContext($iTasksContextId);
- $aTasks = $this->_oDb->getTasks($iTasksContextId, $bContext ? $aList['id'] : 0, $aParams);
- if(!$aTasks || !is_array($aTasks))
- continue;
- $aTmplVarsTasks = [];
- foreach($aTasks as $aTask) {
- $sTime = '';
- if(!empty($aTask['time_total']))
- $sTime = _t('_bx_tasks_txt_total', $this->_oConfig->timeI2S($aTask['time_total']) . (!empty($aTask['time']) ? ' (' . $this->_oConfig->timeI2S($aTask['time']) . ')' : ''));
- if(!empty($aTask['estimate']))
- $sTime .= ' ' . _t('_bx_tasks_txt_estimate', $this->_oConfig->timeI2S(60 * (int)$aTask['estimate']));
- $aMembers = $oConnection->getConnectedInitiators($aTask[$CNF['FIELD_ID']]);
- $aTmplVarsMembers = [];
- foreach($aMembers as $iMember)
- if(($oProfile = BxDolProfile::getInstance($iMember)) !== false && !($oProfile instanceof BxDolProfileUndefined))
- $aTmplVarsMembers[] = ['info' => $oProfile->getUnit(0, ['template' => 'unit_wo_info'])];
- $bCompleted = $aTask[$CNF['FIELD_COMPLETED']] == 1;
- $aTmplVarsTasks[] = [
- 'id' => $aTask[$CNF['FIELD_ID']],
- 'title' => bx_process_output($aTask[$CNF['FIELD_TITLE']]),
- 'created' => bx_time_js($aTask[$CNF['FIELD_ADDED']]),
- 'class' => $bCompleted ? 'completed' : 'uncompleted',
- 'due' => $aTask[$CNF['FIELD_DUE_DATE']] > 0 ? bx_time_js($aTask[$CNF['FIELD_DUE_DATE']]) : '',
- 'type' => $aTypes[$aTask[$CNF['FIELD_TYPE']]] ?? '',
- 'priority' => $aPriorities[$aTask[$CNF['FIELD_PRIORITY']]] ?? '',
- 'state' => $aStates[$aTask[$CNF['FIELD_STATE']]] ?? '',
- 'time' => $sTime,
- 'bx_repeat:members' => $aTmplVarsMembers,
- 'badges' => $oModule->serviceGetBadges($aTask[$CNF['FIELD_ID']], true),
- 'url' => bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aTask[$CNF['FIELD_ID']])),
- 'object' => $sJsObject,
- 'bx_if:allow_manage' => [
- 'condition' => $bTasksAllowManage,
- 'content' => [
- 'id' => $aTask[$CNF['FIELD_ID']],
- 'object' => $sJsObject,
- 'checked' => $bCompleted ? 'checked' : '',
- ]
- ],
- 'bx_if:deny_manage' => [
- 'condition' => !$bTasksAllowManage,
- 'content' => [
- 'id' => $aTask[$CNF['FIELD_ID']],
- 'checked' => $bCompleted ? 'checked' : '',
- ]
- ]
- ];
- }
- $sClass = $sCompleted = $sAll = "";
- if (isset($aFilterValues[$aList[$CNF['FIELD_ID']]])){
- $sClass = $aFilterValues[$aList[$CNF['FIELD_ID']]];
- if ($sClass == 'completed')
- $sCompleted= 'selected';
- if ($sClass == 'all')
- $sAll = 'selected';
- }
- $aTmplVarsAllowEditList = $aTmplVarsAllowAdd = [];
- if($bAllowAdd) {
- $aTmplVarsAllowEditList = [
- 'title' => $aList[$CNF['FIELD_TITLE']],
- 'context_id' => $iContextId,
- 'list_id' => $aList[$CNF['FIELD_ID']],
- 'object' => $sJsObject,
- ];
-
- $aTmplVarsAllowAdd = [
- 'context_id' => $iContextId,
- 'list_id' => $aList[$CNF['FIELD_ID']],
- 'object' => $sJsObject,
- ];
- }
-
- $aTmplVarsAllowDeleteList = [];
- if($bAllowManage) {
- $aTmplVarsAllowDeleteList = [
- 'context_id' => $iContextId,
- 'list_id' => $aList[$CNF['FIELD_ID']],
- 'object' => $sJsObject,
- ];
- }
- $aTmplVarsLists[] = [
- 'bx_if:allow_edit_list' => [
- 'condition' => $bAllowAdd,
- 'content' => $aTmplVarsAllowEditList
- ],
- 'bx_if:allow_add' => [
- 'condition' => $bAllowAdd,
- 'content' => $aTmplVarsAllowAdd
- ],
- 'bx_if:allow_delete_list' => [
- 'condition' => $bAllowManage,
- 'content' => $aTmplVarsAllowDeleteList
- ],
- 'bx_if:deny_edit_list' => [
- 'condition' => !$bAllowAdd,
- 'content' => [
- 'title' => $aList[$CNF['FIELD_TITLE']],
- ]
- ],
- 'bx_repeat:tasks' => $aTmplVarsTasks,
- 'context_id' => $iContextId,
- 'list_id' => $aList[$CNF['FIELD_ID']],
- 'object' => $sJsObject
- ];
- }
- return $this->parseHtmlByName('tasks.html', [
- 'html_id' => $this->_oConfig->getHtmlIds('tasks'),
- 'bx_repeat:task_lists' => $aTmplVarsLists,
- ]);
- }
- public function getStickers($aStickers)
- {
- $aTmplVarsStickers = [];
- foreach($aStickers as $aSticker)
- $aTmplVarsStickers[] = [
- 'title' => $aSticker['title'],
- 'bx_if:show_color' => [
- 'condition' => $aSticker['color'] != '',
- 'content' => [
- 'color' => $aSticker['color']
- ]
- ]
- ];
- return $this->parseHtmlByName('stickers.html', [
- 'bx_repeat:stickers' => $aTmplVarsStickers
- ]);
- }
- protected function _getEntriesFilters($iContextId = 0, $aParams = [])
- {
- $sJsObject = $this->_oConfig->getJsObject('tasks');
- $iLoggedId = bx_get_logged_profile_id();
- $this->_oDb->cleanFilters($iContextId, $iLoggedId);
- $aInput = [
- 'type' => 'select',
- 'name' => 'filters',
- 'value' => $aParams['filter_selected'] ?? 0,
- 'values' => [
- ['key' => 0, 'value' => _t('_bx_tasks_filter_title_select')]
- ],
- 'attrs' => [
- 'onchange' => $sJsObject . '.applyFilter(this, ' . $iContextId . ')'
- ]
- ];
- $aTypes = [
- '_bx_tasks_txt_flt_system' => ['sample' => 'active', 'context_id' => 0, 'author' => 0],
- '_bx_tasks_txt_flt_contextual' => ['sample' => 'active', 'context_id' => $iContextId, 'author' => 0],
- '_bx_tasks_txt_flt_my_permanent' => ['sample' => 'active', 'context_id' => $iContextId, 'author' => $iLoggedId, 'permanent' => 1],
- '_bx_tasks_txt_flt_my_temporary' => ['sample' => 'active', 'context_id' => $iContextId, 'author' => $iLoggedId, 'permanent' => 0]
- ];
- foreach($aTypes as $sTitle => $aType) {
- $aFilterItems = $this->_oDb->getFilters($aType);
- if($aFilterItems && is_array($aFilterItems)) {
- $aInput['values'][] = ['type' => 'group_header', 'value' => _t($sTitle)];
- foreach($aFilterItems as $aFilterItem)
- $aInput['values'][] = [
- 'key' => $aFilterItem['id'],
- 'value' => _t($aFilterItem['title'])
- ];
- $aInput['values'][] = ['type' => 'group_end'];
- }
- }
- $oForm = new BxTemplFormView([]);
- return $oForm->genInputSelect($aInput);
- }
- }
- /** @} */
|