| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- class BxBaseReportsGrid extends BxTemplGrid
- {
- protected $_sParamsDivider;
-
- protected $_sFilter1Name;
- protected $_sFilter1Value;
- protected $_aFilter1Values;
- protected $sJsObject = 'oBxDolReportsManageTools';
-
- protected $_aReportSystemInfo;
-
- public function __construct($aInfo, $oTemplate = false)
- {
- parent::__construct($aInfo, $oTemplate);
-
- $this->_sParamsDivider = '#-#';
- $this->_sDefaultSortingOrder = 'DESC';
- $this->_sFilter1Name = 'filter1';
- $this->_aFilter1Values = array(
- '' => _t('_report_status_all'),
- 0 => _t('_report_status_new'),
- 1 => _t('_report_status_check_in'),
- 2 => _t('_report_status_check_out'),
- );
- $sFilter2 = bx_get($this->_sFilter1Name);
- if(!empty($sFilter2)) {
- $this->_sFilter1Value = bx_process_input($sFilter2);
- $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
- }
- $this->_aReportSystemInfo = [];
- if(($sObject = bx_get('object')) !== false)
- $this->setObject($sObject);
- }
- public function getCode($isDisplayHeader = true)
- {
- if(!$this->_aReportSystemInfo)
- return '';
- return $this->getJsCode() . parent::getCode($isDisplayHeader);
- }
-
- public function setObject($sObjectName)
- {
- $oReport = BxDolReport::getObjectInstance($sObjectName, 0, false);
- if(!$oReport->isProcessible())
- return;
- $this->_aReportSystemInfo = $oReport->getSystemInfo();
- $this->_aOptions['table'] = $this->_aReportSystemInfo['table_track'];
- $this->_aQueryAppend['object'] = $sObjectName;
- }
-
- public function getJsCode()
- {
- $aParams = array(
- 'sObjName' => $this->sJsObject,
- 'aHtmlIds' => array(),
- 'oRequestParams' => array(),
- 'sObjNameGrid' => 'sys_reports_administration'
- );
- return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->sJsObject . " = new BxDolReportsManageTools(" . json_encode($aParams) . ");");
- }
-
- public function performActionCheckIn()
- {
- $this->_performActionStatus(BX_DOL_REPORT_STASUS_IN_PROCESS, '_report_comment_check_in');
- }
-
- public function performActionCheckOut()
- {
- $this->_performActionStatus(BX_DOL_REPORT_STASUS_PROCESSED, '_report_comment_check_out');
- }
-
- private function _performActionStatus($iStatus, $sCmtsText)
- {
- $aIds = bx_get('ids');
-
- $iAffected = 0;
- $aIdsAffected = array ();
- foreach($aIds as $iId) {
- $oReport = BxDolReport::getObjectInstance($this->_aReportSystemInfo['name'], $iId, true);
- $oReport->changeStatusReport($iStatus, bx_get_logged_profile_id(), _t($sCmtsText));
- $aIdsAffected[] = $iId;
- $iAffected++;
- }
- echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => $mixedResult));
- }
-
-
- protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
- {
- return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
- }
-
- protected function _getCellNotes($mixedValue, $sKey, $aField, $aRow)
- {
- $mixedValue = '';
- if ($this->_aReportSystemInfo['object_comment'] && $this->_aReportSystemInfo['object_comment'] != ''){
-
- $oCmts = BxDolCmts::getObjectInstance($this->_aReportSystemInfo['object_comment'], $aRow['object_id']);
- if ($oCmts){
- $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['name']);
- $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . $aRow['object_id'] . "')"));
- }
- }
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getCellComments($mixedValue, $sKey, $aField, $aRow)
- {
- $mixedValue = '';
-
- if ($this->_aReportSystemInfo['object_comment'] && $this->_aReportSystemInfo['object_comment'] != ''){
-
- $oCmts = BxDolCmts::getObjectInstance($this->_aReportSystemInfo['object_comment'], -$aRow['id']);
- if ($oCmts){
- $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['name']);
- $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . - $aRow['id'] . "')"));
- }
- }
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
-
- protected function _getCellObject ($mixedValue, $sKey, $aField, $aRow)
- {
- $sTitle = $sUrl = '';
- if($this->_aReportSystemInfo['name'] == 'sys_cmts'){
- $oCmts = BxDolCmts::getObjectInstanceByUniqId($aRow['object_id']);
- if($oCmts) {
- $aCmts = $oCmts->getCommentsBy([
- 'type' => 'uniq_id',
- 'uniq_id' => $aRow['object_id']
- ]);
- $sTitle = $oCmts->getViewText($aCmts['cmt_id']);
- $sUrl = $oCmts->getViewUrl($aCmts['cmt_id']);
- }
- }
- else {
- $oContentInfo = BxDolContentInfo::getObjectInstance($this->_aReportSystemInfo['name']);
- if($oContentInfo) {
- $sTitle = $oContentInfo->getContentTitle($aRow['object_id']);
- $sUrl = $oContentInfo->getContentLink($aRow['object_id']);
- }
- }
-
- if($sTitle == '')
- $sTitle = _t('_undefined');
-
- if($sUrl != '')
- $sTitle = $this->_oTemplate->parseHtmlByName('account_link.html', array(
- 'href' => $sUrl,
- 'title' => bx_html_attribute($sTitle),
- 'content' => $sTitle
- ));
-
- return parent::_getCellDefault($sTitle, $sKey, $aField, $aRow);
- }
-
- protected function _getCellAuthor ($mixedValue, $sKey, $aField, $aRow)
- {
- if ($aRow['author_id'] > 0){
- $oProfile = BxDolProfile::getInstance($aRow['author_id']);
- if ($oProfile){
- $sProfile = $oProfile->getDisplayName();
- $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
- 'href' => $oProfile->getUrl(),
- 'title' => $sProfile,
- 'content' => $sProfile
- ));
- }
- else{
- $mixedValue = $aRow['profile_title'];
- }
- }
- else{
- $mixedValue = '';
- }
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
-
- protected function _getCellCheckedBy ($mixedValue, $sKey, $aField, $aRow)
- {
- if ($aRow['checked_by'] > 0){
- $oProfile = BxDolProfile::getInstance($aRow['checked_by']);
- if ($oProfile){
- $sProfile = $oProfile->getDisplayName();
- $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
- 'href' => $oProfile->getUrl(),
- 'title' => $sProfile,
- 'content' => $sProfile
- ));
- }
- else{
- $mixedValue = $aRow['profile_title'];
- }
- }
- else{
- $mixedValue = '';
- }
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
-
- protected function _getCellStatus ($mixedValue, $sKey, $aField, $aRow)
- {
- return parent::_getCellDefault(_t('_sys_txt_report_status_' . $mixedValue), $sKey, $aField, $aRow);
- }
-
- protected function _getActionCheckIn($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if($aRow["status"] == BX_DOL_REPORT_STASUS_IN_PROCESS)
- return '';
- return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
-
- protected function _getActionCheckOut($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- if ($aRow["checked_by"] != bx_get_logged_profile_id())
- return '';
-
- if($aRow["status"] != BX_DOL_REPORT_STASUS_IN_PROCESS)
- return '';
-
- return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
-
- protected function _getActionAudit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
- {
- $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=dashboard-audit&module=' . $this->_aReportSystemInfo['module_name'] . '&content_id=' . $aRow['object_id']));
- $a['attr'] = array_merge($a['attr'], array(
- "onclick" => "window.open('" . $sUrl . "','_self');"
- ));
- return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
- }
- protected function _getFilterControls()
- {
- return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
- }
- protected function _getFilterOnChange()
- {
- return $this->sJsObject . '.onChangeFilter(this)';
- }
- protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $mixedAddSelectOne = true, $bAsArray = false)
- {
- return parent::_getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, '_all', $bAsArray);
- }
- protected function _getDataSql ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
- {
- $this->_aOptions['source'] = "SELECT * FROM `" . $this->_aReportSystemInfo['table_track'] . "` " . $this->_aOptions['source'];
- if(strpos($sFilter, $this->_sParamsDivider) !== false)
- list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
- if(isset($this->_sFilter1Value) && $this->_sFilter1Value !== ''){
- $this->_aOptions['source'] .= " AND `status` = " . $this->_sFilter1Value;
- }
- return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
- }
- }
- /** @} */
|