_sSystem)) return; $this->_oQuery = new BxDolViewQuery($this); } /** * get votes object instanse * @param $sSys view object name * @param $iId associated content id, where vote is available * @param $iInit perform initialization * @return null on error, or ready to use class instance */ public static function getObjectInstance($sSys, $iId, $iInit = true) { if(isset($GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId])) return $GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId]; $aSystems = self::getSystems(); if(!isset($aSystems[$sSys])) return null; $sClassName = 'BxTemplView'; 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); return ($GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId] = $o); } public static function &getSystems() { if(!isset($GLOBALS['bx_dol_view_systems'])) $GLOBALS['bx_dol_view_systems'] = BxDolDb::getInstance()->fromCache('sys_objects_view', 'getAllWithKey', ' SELECT `id` as `id`, `name` AS `name`, `table_track` AS `table_track`, `period` AS `period`, `is_on` AS `is_on`, `trigger_table` AS `trigger_table`, `trigger_field_id` AS `trigger_field_id`, `trigger_field_count` AS `trigger_field_count`, `class_name` AS `class_name`, `class_file` AS `class_file` FROM `sys_objects_view`', 'name'); return $GLOBALS['bx_dol_view_systems']; } /** * it is called on cron every day or similar period to clean old votes */ public static function maintenance() { $iResult = 0; $oDb = BxDolDb::getInstance(); $aSystems = self::getSystems(); foreach($aSystems as $aSystem) { if(!$aSystem['is_on']) continue; $sQuery = $oDb->prepare("DELETE FROM `{$aSystem['table_track']}` WHERE `date` < (UNIX_TIMESTAMP() - ?)", BX_DOL_VIEW_OLD_VIEWS); $iDeleted = (int)$oDb->query($sQuery); if($iDeleted > 0) $oDb->query("OPTIMIZE TABLE `{$aSystem['table_track']}`"); $iResult += $iDeleted; } return $iResult; } public function actionGetViewedBy() { if (!$this->isEnabled()) return ''; return $this->_getViewedBy(); } public function doView() { if(!$this->isEnabled()) return false; $iObjectId = $this->getId(); $iAuthorId = $this->_getAuthorId(); $sAuthorIp = $this->_getAuthorIp(); if($this->_oQuery->doView($iObjectId, $iAuthorId, $sAuthorIp)) { $this->_trigger(); $oZ = new BxDolAlerts($this->_sSystem, 'view', $iObjectId, $iAuthorId); $oZ->alert(); return true; } return false; } /** * Permissions functions * * Note. The 'view' action is performed automatically and therefore the manual action is not allowed. */ public function isAllowedView($isPerformAction = false) { return false; } /** * Internal functions */ protected function _getIconDo() { return 'eye'; } protected function _getTitleDo() { return '_view_do_view'; } } /** @} */