| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?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
- *
- * @{
- */
- class BxTasksGridTimeAdministration extends BxTemplGrid
- {
- protected $_sModule;
- protected $_oModule;
- protected $_iContextPid;
- protected $_sParamsDivider;
- protected $_sFilter1Name;
- protected $_sFilter1Value;
- protected $_aFilter1Values;
- protected $_sFilter2Name;
- protected $_sFilter2Value;
- protected $_aFilter2Values;
- public function __construct ($aOptions, $oTemplate = false)
- {
- $this->_sModule = 'bx_tasks';
- $this->_oModule = BxDolModule::getInstance($this->_sModule);
- if(!$oTemplate)
- $oTemplate = $this->_oModule->_oTemplate;
- parent::__construct ($aOptions, $oTemplate);
- $this->_sDefaultSortingOrder = 'DESC';
- if(($iContextPid = bx_get('context_pid')) !== false)
- $this->setContextPid($iContextPid);
- $this->_sParamsDivider = '#-#';
- }
- public function setContextPid($iContextPid)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $this->_iContextPid = (int)$iContextPid;
- $this->_aQueryAppend['context_pid'] = $this->_iContextPid;
- /*
- * Filter by author_id
- */
- $this->_sFilter1Name = 'filter1';
- $this->_aFilter1Values = [];
- $this->_sFilter1Value = '';
- if($this->_sObject == $CNF['OBJECT_GRID_TIME_ADMINISTRATION']) {
- if(($oContext = BxDolProfile::getInstance($this->_iContextPid)) !== false) {
- $aPids = bx_srv($oContext->getModule(), 'fans', [$oContext->getContentId(), true]);
- foreach($aPids as $iPid)
- $this->_aFilter1Values[$iPid] = $oContext->getDisplayName($iPid);
- }
- if(($sFilter1 = bx_get($this->_sFilter1Name)) !== false) {
- $this->_sFilter1Value = bx_process_input($sFilter1);
- $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
- }
- }
- /*
- * Filter by object_id
- */
- $this->_sFilter2Name = 'filter2';
- $this->_aFilter2Values = [];
- $this->_sFilter2Value = '';
- $aTasks = $this->_oModule->_oDb->getTasks(-$this->_iContextPid);
- foreach($aTasks as $aTask)
- $this->_aFilter2Values[$aTask[$CNF['FIELD_ID']]] = $aTask[$CNF['FIELD_TITLE']];
- if(($sFilter2 = bx_get($this->_sFilter2Name)) !== false) {
- $this->_sFilter2Value = bx_process_input($sFilter2);
- $this->_aQueryAppend[$this->_sFilter2Name] = $this->_sFilter2Value;
- }
- }
- public function performActionCalculate()
- {
- $sAction = 'calculate';
- $aIds = $this->_getIds();
- if($aIds === false)
- return $this->_getActionResult([]);
- $iTotal = 0;
- foreach($aIds as $iId) {
- $aTrack = $this->_oModule->_oDb->getTimeTracks(['sample' => 'id', 'id' => $iId]);
- if(empty($aTrack) || !is_array($aTrack))
- continue;
- $iTotal += $aTrack['value'];
- }
- $sContent = BxTemplFunctions::getInstance()->transBox($this->_oModule->_oConfig->getHtmlIds('total_popup'), $this->_oModule->_oTemplate->parseHtmlByName('popup_total.html', [
- 'total' => $this->_oModule->_oConfig->timeI2S($iTotal)
- ]));
- return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => true]]]);
- }
- protected function _getCellAuthorId($mixedValue, $sKey, $aField, $aRow)
- {
- if($this->_bIsApi)
- return ['type' => 'profile', 'data' => BxDolProfile::getData($mixedValue)];
- if(($oProfile = BxDolProfile::getInstanceMagic($mixedValue)) !== false)
- $mixedValue = $oProfile->getUnit();
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
-
- protected function _getCellObjectId($mixedValue, $sKey, $aField, $aRow)
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sTitle = $aRow[$CNF['FIELD_TITLE']];
- if((int)$aField['chars_limit'] > 0)
- $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
- if($sTitle == '')
- $sTitle = _t('_sys_txt_no_title');
- $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $mixedValue));
-
- if($this->_bIsApi)
- return ['type' => 'link', 'data' => [
- 'text' => $aRow[$CNF['FIELD_TITLE']],
- 'url' => bx_api_get_relative_url($sUrl)
- ]];
-
- return parent::_getCellDefault($this->_getEntryLink($sTitle, $sUrl, $aRow), $sKey, $aField, $aRow);
- }
- protected function _getCellValue($mixedValue, $sKey, $aField, $aRow)
- {
- return parent::_getCellDefault($this->_oModule->_oConfig->timeI2S($mixedValue), $sKey, $aField, $aRow);
- }
- protected function _getCellValueDate($mixedValue, $sKey, $aField, $aRow)
- {
- return $this->_bIsApi ? [
- 'type' => 'time',
- 'data' => $mixedValue
- ] : parent::_getCellDefault($mixedValue ? bx_time_js($mixedValue, BX_FORMAT_DATE, true) : '', $sKey, $aField, $aRow);
- }
- protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if($this->_sObject == $CNF['OBJECT_GRID_TIME_ADMINISTRATION'])
- $isDisabled = true;
- return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getActionDelete($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- if($this->_sObject == $CNF['OBJECT_GRID_TIME_ADMINISTRATION'])
- $isDisabled = true;
- return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
-
- protected function _getFilterControls()
- {
- $this->__getFilterControls();
- $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
- $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
- $sContent .= $this->_getSearchInput();
- return $sContent;
- }
- protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
- {
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND ABS(`tt`.`allow_view_to`)=?", $this->_iContextPid);
- $aFilterParts = explode($this->_sParamsDivider, $sFilter);
- switch (substr_count($sFilter, $this->_sParamsDivider)) {
- case 1:
- list($this->_sFilter1Value, $sFilter) = $aFilterParts;
- break;
- case 2:
- list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilterParts;
- break;
- }
- if(!empty($this->_sFilter1Value))
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `ttt`.`author_id`=?", $this->_sFilter1Value);
- if(!empty($this->_sFilter2Value))
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `ttt`.`object_id`=?", $this->_sFilter2Value);
- return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
- }
- protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $bAddSelectOne = true)
- {
- if(empty($sFilterName))
- return '';
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
- $aInputValues = [];
- if($bAddSelectOne)
- $aInputValues[''] = _t($CNF['T']['filter_item_select_one_' . $sFilterName]);
- foreach($aFilterValues as $sKey => $sValue)
- $aInputValues[$sKey] = _t($sValue);
- $aInputModules = [
- 'type' => 'select',
- 'name' => $sFilterName,
- 'attrs' => [
- 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
- 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
- ],
- 'value' => $sFilterValue,
- 'values' => $aInputValues
- ];
- $oForm = new BxTemplFormView([]);
- return $oForm->genRow($aInputModules);
- }
- protected function _getSearchInput()
- {
- $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
- $aInputSearch = [
- 'type' => 'text',
- 'name' => 'search',
- 'attrs' => [
- 'id' => 'bx-grid-search-' . $this->_sObject,
- 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
- 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
- ]
- ];
- $oForm = new BxTemplFormView([]);
- return $oForm->genRow($aInputSearch);
- }
- protected function _getEntryLink($sTitle, $sUrl, $aRow)
- {
- return $this->_oTemplate->parseHtmlByName('title_link.html', [
- 'href' => $sUrl,
- 'title' => bx_html_attribute($sTitle),
- 'content' => bx_process_output($sTitle),
- 'target' => '_blank'
- ]);
- }
- protected function __getFilterControls()
- {
- parent::_getFilterControls();
- }
- protected function _getIds()
- {
- $aIds = bx_get('ids');
- if(!$aIds || !is_array($aIds)) {
- $iId = (int)bx_get('id');
- if(!$iId)
- return false;
- $aIds = [$iId];
- }
- return $aIds;
- }
- }
- /** @} */
|