Skip to content

Commit

Permalink
#3252 - core
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Mar 19, 2021
1 parent 2dab4d0 commit d12f408
Show file tree
Hide file tree
Showing 21 changed files with 1,047 additions and 51 deletions.
62 changes: 61 additions & 1 deletion inc/classes/BxDolAuditGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ class BxDolAuditGrid extends BxTemplGrid
protected $_sFilter1Value;
protected $_aFilter1Values;

protected $_sFilterProfileName;
protected $_sFilterProfileValue;
protected $_aFilterProfileValues;

protected $_sFilterActionName;
protected $_sFilterActionValue;
protected $_aFilterActionValues;

protected $_sFilterFromDateName;
protected $_sFilterFromDateValue;

protected $_sFilterToDateName;
protected $_sFilterToDateValue;

public function __construct ($aOptions, $oTemplate = false)
{
$this->_sFilter1Name = 'module';
Expand All @@ -33,6 +47,39 @@ public function __construct ($aOptions, $oTemplate = false)
$this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
}

$this->_sFilterProfileName = 'profile';

$aProfiles = BxDolAuditQuery::getInstance()->getData(array('type' => 'profile_list'));
$this->_aFilterProfileValues[''] = _t('_sys_audit_filter_profile_select');
foreach($aProfiles as $iProfile){
$oProfile = BxDolProfile::getInstance($iProfile);
$this->_aFilterProfileValues[$iProfile] = $oProfile->getDisplayName();
}

$sFilterProfile = bx_get($this->_sFilterProfileName);
if(!empty($sFilterProfile)) {
$this->_sFilterProfileValue = bx_process_input($sFilterProfile);
$this->_aQueryAppend[$this->_sFilterProfileName] = $this->_sFilterProfileValue;
}

$this->_sFilterActionName = 'action';

$aActions = BxDolAuditQuery::getInstance()->getData(array('type' => 'action_list'));
$this->_aFilterActionValues[''] = _t('_sys_audit_filter_action_select');
foreach($aActions as $sAction){
$this->_aFilterActionValues[$sAction] = _t($sAction);
}

$sFilterAction = bx_get($this->_sFilterActionName);
if(!empty($sFilterAction)) {
$this->_sFilterActionValue = bx_process_input($sFilterAction);
$this->_aQueryAppend[$this->_sFilterActionName] = $this->_sFilterActionValue;
}

$this->_sFilterFromDateName = 'from_date';
$this->_sFilterToDateName = 'to_date';


parent::__construct ($aOptions, $oTemplate);

$this->_sParamsDivider = '#-#';
Expand All @@ -44,10 +91,23 @@ public function __construct ($aOptions, $oTemplate = false)
protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
{
if(strpos($sFilter, $this->_sParamsDivider) !== false)
list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
list($this->_sFilter1Value, $this->_sFilterProfileValue, $this->_sFilterActionValue, $this->_sFilterFromDateValue, $this->_sFilterToDateValue, $sFilter) = explode($this->_sParamsDivider, $sFilter);

if($this->_sFilter1Value != '')
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `content_module` = ?", $this->_sFilter1Value);

if($this->_sFilterProfileValue != '')
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `profile_id` = ?", $this->_sFilterProfileValue);

if($this->_sFilterActionValue != '')
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `action_lang_key` = ?", $this->_sFilterActionValue);

if($this->_sFilterFromDateValue != '')
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `added` > ?", strtotime($this->_sFilterFromDateValue));

if($this->_sFilterToDateValue != '')
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `added` <= ?", strtotime($this->_sFilterToDateValue));

if(bx_get('content_id') && is_numeric(bx_get('content_id')))
$this->_aOptions['source'] .= $this->oDb->prepareAsString(" AND `content_id` = ?", (int)bx_get('content_id'));
if(bx_get('actor_id') && is_numeric(bx_get('actor_id')))
Expand Down
87 changes: 87 additions & 0 deletions inc/classes/BxDolAuditQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php defined('BX_DOL') or die('hack attempt');
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

/**
* @see BxDolCategories
*/
class BxDolAuditQuery extends BxDolDb implements iBxDolSingleton
{
protected function __construct()
{
if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);

parent::__construct();
$this->_sTable = 'sys_audit';
}
/**
* Prevent cloning the instance
*/
public function __clone()
{
if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
}

/**
* Get singleton instance of the class
*/
public static function getInstance()
{
$sClass = __CLASS__;
if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
$GLOBALS['bxDolClasses'][__CLASS__] = new $sClass();

return $GLOBALS['bxDolClasses'][__CLASS__];
}

public function getData($aParams = array(), &$aItems = false)
{
$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));

$sSelectClause = "`sc`.*";
$sJoinClause = $sWhereClause = $sGroupClause = $sLimitClause = "";
$sOrderClause = "`sc`.`added` ASC";

if(isset($aParams['count_only']) && $aParams['count_only'] === true) {
$aMethod['name'] = 'getOne';
$sSelectClause = "COUNT(`sc`.`id`)";
}

switch($aParams['type']) {
case 'profile_list':
$aMethod['name'] = 'getColumn';
$sSelectClause = " DISTINCT `sc`.`profile_id`";

break;

case 'action_list':
$aMethod['name'] = 'getColumn';
$sSelectClause = " DISTINCT `sc`.`action_lang_key`";

break;
}

if(!empty($sGroupClause))
$sGroupClause = "GROUP BY " . $sGroupClause;

if(!empty($sOrderClause))
$sOrderClause = "ORDER BY " . $sOrderClause;

$aMethod['params'][0] = "SELECT " . $sSelectClause . "
FROM `" . $this->_sTable . "` AS `sc`" . $sJoinClause . "
WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause. " " . $sLimitClause;
$oRv = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
if ($aItems === false)
return $oRv;
$aItems = $oRv;
}
}

/** @} */
19 changes: 18 additions & 1 deletion inc/classes/BxDolReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
define('BX_DOL_REPORT_USAGE_INLINE', 'inline');
define('BX_DOL_REPORT_USAGE_DEFAULT', BX_DOL_REPORT_USAGE_BLOCK);

define('BX_DOL_REPORT_STASUS_NEW', 0);
define('BX_DOL_REPORT_STASUS_IN_PROCESS', 1);
define('BX_DOL_REPORT_STASUS_PROCESSED', 2);
/**
* Report any content
*
Expand Down Expand Up @@ -195,7 +198,7 @@ public function getStatCounter()
$aReport = $this->_oQuery->getReport($this->getId());
return $aReport['count'];
}

/**
* Actions functions
*/
Expand Down Expand Up @@ -243,6 +246,20 @@ public function isAllowedReportView($isPerformAction = false)

return $this->checkAction('report_view', $isPerformAction);
}

public function changeStatusReport($iStatus, $iAuthorId, $sCmtText)
{
$iId = $this->getId();
$aReport = $this->_oQuery->getDataById($iId);
if(!empty($this->_sObjectCmts) && ($oCmts = BxDolCmts::getObjectInstance($this->_sObjectCmts, $aReport['object_id']))) {
$oCmts->add(array(
'cmt_author_id' => $iAuthorId,
'cmt_parent_id' => 0,
'cmt_text' => $sCmtText
));
}
$this->_oQuery->changeStatusReport($iId, $iStatus, $iAuthorId);
}

public function msgErrAllowedReportView()
{
Expand Down
18 changes: 17 additions & 1 deletion inc/classes/BxDolReportQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ public function getSqlParts($sMainTable, $sMainField)
$aResult['fields'] = ", `{$this->_sTable}`.`count` as `report_count` ";
return $aResult;
}

public function getDataById($iId)
{
$sQuery = $this->prepare("SELECT * FROM `{$this->_sTableTrack}` WHERE `id` = ?", $iId);
return $this->getRow($sQuery);
}

public function getPerformedBy($iObjectId, $iStart = 0, $iPerPage = 0)
{
$sLimitClause = "";
if(!empty($iPerPage))
$sLimitClause = $this->prepareAsString(" LIMIT ?, ?", $iStart, $iPerPage);

$sQuery = $this->prepare("SELECT `author_id`, `type`, `text` FROM `{$this->_sTableTrack}` WHERE `object_id`=? ORDER BY `date` DESC" . $sLimitClause, $iObjectId);
$sQuery = $this->prepare("SELECT `author_id`, `type`, `text`, `id`, `date` FROM `{$this->_sTableTrack}` WHERE `object_id`=? ORDER BY `date` DESC" . $sLimitClause, $iObjectId);
return $this->getAll($sQuery);
}

Expand Down Expand Up @@ -95,6 +101,16 @@ protected function _deleteTrack($iObjectId, $iAuthorId)

return false;
}

public function changeStatusReport($iId, $iStatus, $iProfileId)
{
if ($iStatus != BX_DOL_REPORT_STASUS_IN_PROCESS)
$sQuery = $this->prepare("UPDATE `{$this->_sTableTrack}` SET `status` = ? WHERE `id` = ?", $iStatus, $iId);
else
$sQuery = $this->prepare("UPDATE `{$this->_sTableTrack}` SET `status` = ?, `checked_by` = ? WHERE `id` = ?", $iStatus, $iProfileId, $iId);
$this->query($sQuery);
}

}

/** @} */
15 changes: 14 additions & 1 deletion inc/js/classes/BxDolAuditManageTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,30 @@ function BxDolAuditManageTools(oOptions) {

BxDolAuditManageTools.prototype.onChangeFilter = function (oFilter) {
var $this = this;

var oFilter1 = $('#bx-grid-module-' + this._sObjNameGrid);
var sValueFilter1 = oFilter1.length > 0 ? oFilter1.val() : '';

var oFilterProfile = $('#bx-grid-profile-' + this._sObjNameGrid);
var sValueFilterProfile = oFilterProfile.length > 0 ? oFilterProfile.val() : '';

var oFilterAction = $('#bx-grid-action-' + this._sObjNameGrid);
var sValueFilterAction = oFilterAction.length > 0 ? oFilterAction.val() : '';

var oFilteFromDate = $('#bx-grid-from_date-' + this._sObjNameGrid);
var sValueFilterFromDate = oFilteFromDate.length > 0 ? oFilteFromDate.val() : '';

var oFilteToDate = $('#bx-grid-to_date-' + this._sObjNameGrid);
var sValueFilterToDate = oFilteToDate.length > 0 ? oFilteToDate.val() : '';

var oSearch = $('#bx-grid-search-' + this._sObjNameGrid);
var sValueSearch = oSearch.length > 0 ? oSearch.val() : '';
if (sValueSearch == _t('_sys_grid_search'))
sValueSearch = '';

clearTimeout($this._iSearchTimeoutId);
$this._iSearchTimeoutId = setTimeout(function () {
glGrids[$this._sObjNameGrid].setFilter(sValueFilter1 + $this._sParamsDivider + sValueSearch, true);
glGrids[$this._sObjNameGrid].setFilter(sValueFilter1 + $this._sParamsDivider + sValueFilterProfile + $this._sParamsDivider + sValueFilterAction + $this._sParamsDivider + sValueFilterFromDate + $this._sParamsDivider + sValueFilterToDate + $this._sParamsDivider + sValueSearch, true);
}, 500);
};
/** @} */
37 changes: 37 additions & 0 deletions inc/js/classes/BxDolReportsManageTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/

function BxDolReportsManageTools(oOptions) {
this._iSearchTimeoutId = false;
this._sObjNameGrid = oOptions.sObjNameGrid;
this._sObjName = oOptions.sObjName == undefined ? 'oBxDolReportsManageTools' : oOptions.sObjName;

this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
this._sParamsDivider = oOptions.sParamsDivider == undefined ? '#-#' : oOptions.sParamsDivider;

this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;

}

BxDolReportsManageTools.prototype.onChangeFilter = function (oFilter) {
var $this = this;
var oFilter1 = $('#bx-grid-filter1-' + this._sObjNameGrid);
var sValueFilter1 = oFilter1.length > 0 ? oFilter1.val() : '';
var oSearch = $('#bx-grid-search-' + this._sObjNameGrid);
var sValueSearch = oSearch.length > 0 ? oSearch.val() : '';
if (sValueSearch == _t('_sys_grid_search'))
sValueSearch = '';

clearTimeout($this._iSearchTimeoutId);
$this._iSearchTimeoutId = setTimeout(function () {
glGrids[$this._sObjNameGrid].setFilter(sValueFilter1 + $this._sParamsDivider + sValueSearch, true);
}, 500);
};
/** @} */
1 change: 0 additions & 1 deletion inc/js/classes/BxDolVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ BxDolVote.prototype.onVote = function(oLink, oData, onComplete)
return;

var oCounter = this._getCounter(oLink);
console.log(oCounter);
if(oCounter && oCounter.length > 0) {
oCounter.html(oData.countf);

Expand Down
16 changes: 16 additions & 0 deletions inc/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ function bx_get_notes(oSource, sModule, iContentId, oOptions, oVars) {
$(window).dolPopupAjax(oOptions);
}

function bx_get_report_comments(oSource, sModule, iContentId, oOptions, oVars) {
var oOptions = oOptions || {};
var oVars = oVars || {};

var oOptions = $.extend({}, $.fn.dolPopupDefaultOptions, {
id: sModule + '_report_comment_' + iContentId,
url: bx_append_url_params('modules/?r=' + sModule + '/report_comment/', $.extend({ content_id: iContentId }, oVars)),
closeOnOuterClick: false,
removeOnClose: true,
onBeforeShow: function (oPopup) {
$(oPopup).find('.bx-popup-close-wrapper').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
}
}, oOptions);

$(window).dolPopupAjax(oOptions);
}

function validateLoginForm(eForm) {
return true;
Expand Down
Loading

0 comments on commit d12f408

Please sign in to comment.