Skip to content

Commit

Permalink
Ticket #4148 - Build-in API support: Reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Nov 9, 2023
1 parent a85bfa4 commit 76a70f8
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 130 deletions.
49 changes: 45 additions & 4 deletions inc/classes/BxDolReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class BxDolReport extends BxDolObject
protected $_sTypesPreList;
protected $_aTypes;

protected $_aReport;

protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
{
parent::__construct($sSystem, $iId, $iInit);
Expand Down Expand Up @@ -115,6 +117,8 @@ protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false
$this->_aTypes = array_keys($aTypes);
else
$this->_aTypes = array('spam', 'scam', 'fraud', 'nude', 'other');

$this->_aReport = [];
}

/**
Expand Down Expand Up @@ -186,7 +190,7 @@ public static function onAuthorDelete ($iAuthorId)
*/
public function isUndo()
{
return (int)$this->_bUndo;
return (int)$this->_bUndo == 1;
}

public function getBaseUrl()
Expand All @@ -204,20 +208,25 @@ public function getCountByStatus($iStatus)
{
return $this->_oQuery->getReportsCountByStatus($iStatus);
}


public function getSocketName()
{
return $this->_sSystem . '_reports';
}

/**
* Actions functions
*/
public function actionReport()
{
return echoJson($this->_getReport());
return echoJson($this->report());
}

public function actionClearReport()
{
$this->_oQuery->clearReports($this->getId());
}

public function actionGetReportedBy()
{
if (!$this->isEnabled())
Expand Down Expand Up @@ -275,6 +284,38 @@ public function msgErrAllowedReportView()
/**
* Internal functions
*/
protected function _isCount($aVote = array())
{
if(empty($aReport))
$aReport = $this->_getReport();

return isset($aReport['count']) && (int)$aReport['count'] != 0;
}

protected function _getReport($iObjectId = 0, $bForceGet = false)
{
if(!empty($this->_aReport) && !$bForceGet)
return $this->_aReport;

if(empty($iObjectId))
$iObjectId = $this->getId();

$this->_aReport = $this->_oQuery->getReport($iObjectId);
return $this->_aReport;
}

protected function _isReport($iObjectId = 0, $bForceGet = false)
{
$aReport = $this->_getReport($iObjectId, $bForceGet);

return (int)$aReport['count'] > 0;
}

protected function _getTrack($iObjectId, $iAuthorId)
{
return $this->_oQuery->getTrack($iObjectId, $iAuthorId);
}

protected function _getIconDoReport($bPerformed)
{
return $bPerformed && $this->isUndo() ? 'exclamation-circle' : 'exclamation-circle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,12 @@ protected function _getMenuItemReport($aItem, $aParams = array())
$aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);

if($this->_bIsApi)
return $oObject->getElementApi($aObjectOptions);
return [
'id' => $aItem['id'],
'name' => $aItem['name'],
'display_type' => 'element',
'data' => $oObject->getElementApi($aObjectOptions)
];

$sResult = $oObject->getElementBlock($aObjectOptions);
if(empty($sResult))
Expand Down
Loading

0 comments on commit 76a70f8

Please sign in to comment.