isEnabled()) * return ''; * echo $o->getElementBlock(); * @endcode * * * @section acl Memberships/ACL: * - report * - report view * * * @section alerts Alerts: * Alerts type/unit - every module has own type/unit, it equals to ObjectName. * The following alerts are rised: * * - type: 'object name', action: doReport * - type: report, action: do * */ class BxDolReport extends BxDolObject { protected $_oTemplate; protected $_sBaseUrl; protected $_sFormObject; protected $_sFormDisplayPost; protected $_aTypes; protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false) { parent::__construct($sSystem, $iId, $iInit); if(empty($this->_sSystem)) return; $this->_oQuery = new BxDolReportQuery($this); if ($oTemplate) $this->_oTemplate = $oTemplate; else $this->_oTemplate = BxDolTemplate::getInstance(); $this->_sBaseUrl = BxDolPermalinks::getInstance()->permalink($this->_aSystem['base_url']); if(get_mb_substr($this->_sBaseUrl, 0, 4) != 'http') $this->_sBaseUrl = BX_DOL_URL_ROOT . $this->_sBaseUrl; $this->_sFormObject = 'sys_report'; $this->_sFormDisplayPost = 'sys_report_post'; $this->_aTypes = array('spam', 'scam', 'fraud', 'nude', 'other'); } /** * get reports object instanse * @param $sSys report object name * @param $iId associated content id, where report is available * @param $iInit perform initialization * @return null on error, or ready to use class instance */ public static function getObjectInstance($sSys, $iId, $iInit = true, $oTemplate = false) { if(isset($GLOBALS['bxDolClasses']['BxDolReport!' . $sSys . $iId])) return $GLOBALS['bxDolClasses']['BxDolReport!' . $sSys . $iId]; $aSystems = self::getSystems(); if(!isset($aSystems[$sSys])) return null; $sClassName = 'BxTemplReport'; if(!empty($aSystems[$sSys]['class_name'])) { $sClassName = $aSystems[$sSys]['class_name']; if(!empty($aSystems[$sSys]['class_file'])) require_once(BX_DIRECTORY_PATH_ROOT . $aSystems[$sSys]['class_file']); } $o = new $sClassName($sSys, $iId, $iInit, $oTemplate); return ($GLOBALS['bxDolClasses']['BxDolReport!' . $sSys . $iId] = $o); } public static function &getSystems() { $sKey = 'bx_dol_cache_memory_report_systems'; if(!isset($GLOBALS[$sKey])) $GLOBALS[$sKey] = BxDolDb::getInstance()->fromCache('sys_objects_report', 'getAllWithKey', ' SELECT `id` as `id`, `name` AS `name`, `table_main` AS `table_main`, `table_track` AS `table_track`, `is_on` AS `is_on`, `base_url` AS `base_url`, `trigger_table` AS `trigger_table`, `trigger_field_id` AS `trigger_field_id`, `trigger_field_author` AS `trigger_field_author`, `trigger_field_count` AS `trigger_field_count`, `class_name` AS `class_name`, `class_file` AS `class_file` FROM `sys_objects_report`', 'name'); return $GLOBALS[$sKey]; } public static function onAuthorDelete ($iAuthorId) { $aSystems = self::getSystems(); foreach($aSystems as $sSystem => $aSystem) self::getObjectInstance($sSystem, 0)->getQueryObject()->deleteAuthorEntries($iAuthorId); return true; } /** * Interface functions for outer usage */ public function getBaseUrl() { return $this->_replaceMarkers($this->_sBaseUrl); } public function getStatCounter() { $aReport = $this->_oQuery->getReport($this->getId()); return $aReport['count']; } /** * Actions functions */ public function actionReport() { return echoJson($this->_getReport()); } public function actionGetReportedBy() { if (!$this->isEnabled()) return ''; if(!$this->isAllowedReportView(true)) return $this->msgErrAllowedReportView(); return $this->_getReportedBy(); } /** * Permissions functions */ public function isAllowedReport($isPerformAction = false) { if(isAdmin()) return true; return $this->checkAction('report', $isPerformAction); } public function msgErrAllowedReport() { return $this->checkActionErrorMsg('report'); } public function isAllowedReportView($isPerformAction = false) { if(isAdmin()) return true; return $this->checkAction('report_view', $isPerformAction); } public function msgErrAllowedReportView() { return $this->checkActionErrorMsg('report_view'); } /** * Internal functions */ protected function _getIconDoReport($bPerformed) { return 'exclamation-circle'; } protected function _getTitleDoReport($bPerformed) { return '_report_do_report'; } protected function _getFormObject() { return BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost); } } /** @} */