Browse Source

#33 - Views remake and integration into Notes module.

AntonLV 13 years ago
parent
commit
e732e209ef

+ 244 - 0
inc/classes/BxDolView.php

@@ -0,0 +1,244 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
+ */
+
+bx_import('BxDolViewQuery');
+
+define ('BX_DOL_VIEW_OLD_VIEWS', 3 * 86400); ///< views older than this number of seconds will be deleted automatically
+
+/**
+ * Track any object views automatically
+ *
+ * Add record to sys_object_view table to track object views,
+ * to record view just create this class instance with your object id, 
+ * for example:
+ * @code
+ *  BxDolView::getObjectInstance('my_system', 25); // 25 - is object id
+ * @endcode
+ *
+ * Description of sys_object_view table fields:
+ * @code
+ *  `name` - system name, it is better to use unique module prefix here, lowercase and all spaces are underscored
+ *  `table_track` - table to track views
+ *  `period` - period in secs to update next views, default is 86400(1 day)
+ *  `is_on` - is the system activated
+ *  `trigger_table` - table where you need to update views field
+ *  `trigger_field_id` - table field id to unique determine object
+ *  `trigger_field_count` - table field where total view number is stored
+ *  `class_name` - your custom class name, if you overrride default class
+ *  `class_file` - your custom class path
+ * @endcode
+ *
+ * Structure of the track table is the following:
+ * @code
+ *  CREATE TABLE `my_views_track` (
+ *      `object_id` int(11) NOT NULL default '0', -- this field type must be exact as your object id type
+ *      `viewer_id` int(11) NOT NULL default '0', -- viewer profile id
+ *      `viewer_nip` int(11) unsigned NOT NULL default '0', -- viewer ip address to track guest views
+ *      `date` int(11) NOT NULL default '0', -- timestamp of last recorded view
+ *      KEY `id` (`object_id`,`viewer_id`,`viewer_nip`)
+ *  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+ * @endcode
+ *
+ */
+class BxDolView extends BxDol
+{
+    var $_iId = 0;    ///< item id to be viewed
+    var $_sSystem = ''; ///< current view system name
+    var $_aSystem = array (); ///< current view system array
+
+    var $_oQuery = null;
+
+    /**
+     * Constructor
+     */
+    function BxDolView($sSystem, $iId, $iInit = 1)
+    {
+    	parent::__construct();
+
+    	$this->_aSystems = $this->getSystems();
+        if(!isset($this->_aSystems[$sSystem]))
+			return;
+
+        $this->_sSystem = $sSystem;
+		$this->_aSystem = $this->_aSystems[$sSystem];
+
+		if(!$this->isEnabled()) 
+			return;
+
+        $this->_oQuery = new BxDolViewQuery($this);
+
+        if($iInit)
+        	$this->init($iId);
+    }
+
+   /**
+     * 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, $isMakeView = true) 
+    {
+    	if(isset($GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId]))
+            return $GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId];
+
+        $aSystems = self::getSystems();
+        if(!isset($aSystems[$sSys]))
+            return null;
+
+        bx_import('BxTemplView');
+        $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']);
+            else
+                bx_import($sClassName);
+        }
+
+        $o = new $sClassName($sSys, $iId, true);
+        return ($GLOBALS['bxDolClasses']['BxDolView!' . $sSys . $iId] = $o);
+    }
+
+	public static function &getSystems()
+    {
+        if(!isset($GLOBALS['bx_dol_vote_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 init($iId)
+    {
+    	if(!$this->isEnabled()) 
+        	return;
+
+        if(empty($this->_iId) && $iId)
+			$this->setId($iId);
+    }
+
+	public function getSystemId()
+    {
+        return $this->_aSystem['id'];
+    }
+
+    public function getSystemName()
+    {
+        return $this->_sSystem;
+    }
+
+	public function getSystemInfo()
+    {
+        return $this->_aSystem;
+    }
+
+    public function getId()
+    {
+        return $this->_iId;
+    }
+
+    public function setId($iId)
+    {
+        if($iId == $this->getId())
+        	return;
+
+        $this->_iId = $iId;
+    }
+
+    public function isEnabled ()
+    {
+        return $this->_aSystem && (int)$this->_aSystem['is_on'] == 1;
+    }
+
+	function doView()
+    {
+        if(!$this->isEnabled()) 
+        	return false;
+
+		$iObjectId = $this->getId();
+		$iAuthorId = $this->_getAuthorId();
+		$sAuthorIp = $this->_getAuthorIp();
+
+        if($this->_oQuery->doView($iObjectId, $iAuthorId, $sAuthorIp)) {
+            $this->_triggerView();
+
+            $oZ = new BxDolAlerts($this->_sSystem, 'view', $iObjectId, $iAuthorId);
+            $oZ->alert();
+
+            return true;
+        }
+
+        return false;
+    }
+
+    function onObjectDelete($iObjectId = 0)
+    {
+    	$this->_oQuery->deleteObjectViews($iObjectId ? $iObjectId : $this->getId());
+    }
+
+	protected function _getAuthorId ()
+    {
+        return isMember() ? bx_get_logged_profile_id() : 0;
+    }
+
+    protected function _getAuthorIp ()
+    {
+        return $_SERVER['REMOTE_ADDR'];
+    }
+
+	protected function _triggerView()
+    {
+        if(!$this->_aSystem['trigger_table'])
+			return false;
+
+        $iId = $this->getId();
+        if(!$iId)
+            return false;
+
+        return $this->_oQuery->updateTriggerTable($iId);
+    }
+}
+
+/** @} */ 

+ 76 - 0
inc/classes/BxDolViewQuery.php

@@ -0,0 +1,76 @@
+<?php
+/**
+ * @package     Dolphin Core
+ * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
+ */
+defined('BX_DOL') or die('hack attempt');
+
+bx_import('BxDolDb');
+
+/**
+ * @see BxDolView
+ */
+class BxDolViewQuery extends BxDolDb
+{
+	protected $_oModule;
+
+    protected $_sTableTrack;
+    protected $_sTriggerTable;
+    protected $_sTriggerFieldId;
+    protected $_sTriggerFieldCount;
+
+    protected $_iPeriod;
+
+    public function __construct(&$oModule)
+    {
+        parent::BxDolDb();
+
+        $this->_oModule = $oModule;
+
+    	$aSystem = $this->_oModule->getSystemInfo();
+        $this->_sTableTrack = $aSystem['table_track'];
+        $this->_sTriggerTable = $aSystem['trigger_table'];
+        $this->_sTriggerFieldId = $aSystem['trigger_field_id'];
+        $this->_sTriggerFieldCount = $aSystem['trigger_field_count'];
+
+        $this->_iPeriod = (int)$aSystem['period'];
+    }
+
+    public function doView($iObjectId, $iAuthorId, $sAuthorIp)
+    {
+    	$iAuthorNip = ip2long($sAuthorIp);
+
+    	if($iAuthorId)
+            $sWhere = $this->prepare(" AND `viewer_id` = ? ", $iAuthorId);
+        else
+            $sWhere = $this->prepare(" AND `viewer_id` = '0' AND `viewer_nip` = ? ", $iAuthorNip);
+
+        $sQuery = $this->prepare("SELECT `date` FROM `{$this->_sTableTrack}` WHERE `object_id` = ? $sWhere", $iObjectId);
+		$iDate = (int)$this->getOne($sQuery);
+        $iDateNow = time();
+
+        if(!$iDate) {
+            $sQuery = $this->prepare("INSERT IGNORE INTO `{$this->_sTableTrack}` SET `object_id` = ?, `viewer_id` = ?, `viewer_nip` = ?, `date` = ?", $iObjectId, $iAuthorId, $iAuthorNip, $iDateNow);
+            return (int)$this->query($sQuery) > 0;
+        }
+
+        if(($iDateNow - $iDate) > $this->_iPeriod) {
+            $sQuery = $this->prepare("UPDATE `{$this->_sTableTrack}` SET `date` = ? WHERE `object_id` = ? AND `viewer_id` = ? AND `viewer_nip` = ?", $iDateNow, $iObjectId, $iAuthorId, $iAuthorNip);
+        	return (int)$this->query($sQuery) > 0;
+        }
+    }
+
+	function deleteObjectViews($iObjectId)
+    {
+        $sQuery = $this->prepare("DELETE FROM {$this->_sTableTrack} WHERE `object_id` = ?", $iObjectId);
+        $this->query ($sQuery);
+
+        $this->query ("OPTIMIZE TABLE {$this->_sTableTrack}");
+    }
+
+	public function updateTriggerTable($iObjectId) {
+        $sQuery = $this->prepare("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldCount}` = `{$this->_sTriggerFieldCount}` + 1 WHERE `{$this->_sTriggerFieldId}` = ?", $iObjectId);
+        return (int)$this->query($sQuery) > 0;
+    }
+}

+ 0 - 174
inc/classes/BxDolViews.php

@@ -1,174 +0,0 @@
-<?php defined('BX_DOL') or die('hack attempt');
-/**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup    DolphinCore Dolphin Core
- * @{
- */
-
-define ('BX_OLD_VIEWS', 3*86400); ///< views older than this number of seconds will be deleted automatically
-
-/** 
- * @page objects 
- * @section views_counter Views Counter
- * @ref BxDolViews
- */
-
-/**
- * Track any object views automatically
- *
- * Add record to sys_object_views table to track object views,
- * to record view just create this class instance with your object id, 
- * for example:
- * @code
- *  new BxDolViews('my_system', 25); // 25 - is object id
- * @endcode
- *
- * Description of sys_object_views table fields:
- * @code
- *  `name` - system name, it is better to use unique module prefix here, lowercase and all spaces are underscored
- *  `table_track` - table to track views
- *  `period` - period in secs to update next views, default is 86400(1 day)
- *  `trigger_table` - table where you need to update views field
- *  `trigger_field_id` - table field id to unique determine object
- *  `trigger_field_views` - table field where total view number is stored
- *  `is_on` - is the system activated
- * @endcode
- *
- *  Structure of the track table is the following:
- * @code
- *  CREATE TABLE `my_views_track` (
- *      `id`, -- this field type must be exact as your object id type
- *      `viewer` int(10) unsigned NOT NULL, -- viewer profile id
- *      `ip` int(10) unsigned NOT NULL, -- viewer ip address to track guest views
- *      `ts` int(10) unsigned NOT NULL, -- timestamp of last recorded view
- *      KEY `id` (`id`,`viewer`,`ip`)
- *  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- * @endcode
- *
- */
-class BxDolViews extends BxDol
-{
-    var $_iId = 0;    ///< item id to be viewed
-    var $_sSystem = ''; ///< current view system name
-    var $_aSystem = array (); ///< current view system array
-
-    /**
-     * Constructor
-     */
-    function BxDolViews($sSystem, $iId, $isMakeView = true)
-    {
-        $aSystems = $this->getAllSystems ();
-        if (!isset($aSystems[$sSystem]))
-            return;
-        $this->_aSystem = $aSystems[$sSystem];
-        $this->_sSystem = $sSystem;
-        if (!$this->isEnabled())
-            return;
-        $this->_iId = $iId;
-        if ($isMakeView)
-            $this->makeView();
-    }
-
-    function makeView ()
-    {
-        if (!$this->isEnabled()) return false;
-
-        $oDb = BxDolDb::getInstance();
-        $iMemberId = getLoggedId();
-        $sIp = $_SERVER['REMOTE_ADDR'];
-        $iTime = time();
-
-        if ($iMemberId)
-            $sWhere = $oDb->prepare(" AND `viewer` = ? ", $iMemberId);
-        else
-            $sWhere = $oDb->prepare(" AND `viewer` = '0' AND `ip` = INET_ATON(?) ", $sIp);
-
-        $sQuery = $oDb->prepare("SELECT `ts` FROM `{$this->_aSystem['table_track']}` WHERE `id` = ? $sWhere", $this->getId());
-        $iTs = (int)($oDb->getOne($sQuery));
-
-        $iRet = 0;
-        if (!$iTs) {
-            $sQuery = $oDb->prepare("INSERT IGNORE INTO `{$this->_aSystem['table_track']}` SET `id` = ?, `viewer` = ?, `ip` = INET_ATON(?), `ts` = ?", $this->getId(), $iMemberId, $sIp, $iTime);
-            $iRet = $oDb->query($sQuery);
-        } elseif (($iTime - $iTs) > $this->_aSystem['period']) {
-            $sQuery = $oDb->prepare("UPDATE `{$this->_aSystem['table_track']}` SET `ts` = ? WHERE `id` = ? AND `viewer` = ? AND `ip` = INET_ATON(?)", $iTime, $this->getId(), $iMemberId, $sIp);
-            $iRet = $oDb->query($sQuery);
-        }
-
-        if ($iRet) {
-            $this->_triggerView();
-
-            $oZ = new BxDolAlerts($this->_sSystem, 'view', $this->getId(), $iMemberId);
-            $oZ->alert();
-
-            return true;
-        }
-
-        return false;
-    }
-
-    function getId ()
-    {
-        return $this->_iId;
-    }
-
-    function isEnabled ()
-    {
-        return $this->_aSystem && $this->_aSystem['is_on'];
-    }
-
-    function getSystemName()
-    {
-        return $this->_sSystem;
-    }
-
-    function getAllSystems () {
-        $oDb = BxDolDb::getInstance();
-        return $oDb->fromCache('sys_objects_views', 'getAllWithKey', 'SELECT * FROM `sys_objects_views`', 'name');
-    }
-
-    /**
-     * call this function when associated object is deleted
-     */
-    function onObjectDelete ($iId = 0)
-    {
-        $iId = (int) $iId;
-
-        $oDb = BxDolDb::getInstance();
-
-        $sQuery = $oDb->prepare("DELETE FROM `{$this->_aSystem['table_track']}` WHERE `id` = ?", $iId ? $iId : $this->getId());
-        $oDb->query($sQuery);
-
-        $oDb->query("OPTIMIZE TABLE `{$this->_aSystem['table_track']}`");
-    }
-
-    /**
-     * it is called on cron every day or similar period
-     */
-    function maintenance () {
-        $oDb = BxDolDb::getInstance();
-        $iTime = time() - BX_OLD_VIEWS;
-        $aSystems = $this->getAllSystems ();
-        $iDeletedRecords = 0;
-        foreach ($aSystems as $aSystem) {
-            if (!$aSystem['is_on'])
-                continue;
-            $sQuery = $oDb->prepare("DELETE FROM `{$aSystem['table_track']}` WHERE `ts` < ?", $iTime);
-            $iCount = $oDb->query($sQuery);
-            if ($iCount)
-                $oDb->query("OPTIMIZE TABLE `{$aSystem['table_track']}`");
-            $iDeletedRecords += $iCount;
-        }
-        return $iDeletedRecords;
-    }
-
-    function _triggerView() {
-        $oDb = BxDolDb::getInstance();
-        $sQuery = $oDb->prepare("UPDATE `{$this->_aSystem['trigger_table']}` SET `{$this->_aSystem['trigger_field_views']}` = `{$this->_aSystem['trigger_field_views']}` + 1 WHERE `{$this->_aSystem['trigger_field_id']}` = ?", $this->getId());
-        return $oDb->query($sQuery);
-    }
-}
-
-/** @} */ 

+ 6 - 4
install/sql/v70.sql

@@ -5,7 +5,7 @@
 -- --------------------------------------------------------
 
 SET NAMES 'utf8';
-DROP TABLE IF EXISTS `sys_categories`, `sys_keys`, `sys_objects_editor`, `sys_objects_captcha`, `sys_objects_social_sharing`, `sys_objects_categories`, `sys_objects_cmts`, `sys_cmts_images`, `sys_cmts_images_preview`, `sys_cmts_images2entries`, `sys_email_templates`, `sys_options`, `sys_options_cats`, `sys_ip_list`, `sys_ip_members_visits`, `sys_localization_categories`, `sys_localization_keys`, `sys_localization_languages`, `sys_localization_string_params`, `sys_localization_strings`, `sys_acl_actions`, `sys_acl_actions_track`, `sys_acl_matrix`, `sys_acl_level_prices`, `sys_acl_levels`, `sys_sessions`, `sys_acl_levels_members`, `sys_objects_search`, `sys_stat_site`, `sys_alerts`, `sys_alerts_handlers`, `sys_injections`, `sys_injections_admin`, `sys_modules`, `sys_modules_file_tracks`, `sys_permalinks`, `sys_objects_privacy`, `sys_privacy_defaults`, `sys_privacy_groups`, `sys_privacy_members`, `sys_tags`, `sys_objects_tag`, `sys_transactions`, `sys_objects_auths`, `sys_objects_vote`, `sys_objects_views`, `sys_cron_jobs`, `sys_dnsbl_rules`, `sys_dnsbl_block_log`, `sys_dnsbluri_zones`, `sys_menu_mobile`, `sys_menu_mobile_pages`, `sys_objects_storage`, `sys_objects_uploader`, `sys_storage_user_quotas`, `sys_storage_tokens`, `sys_storage_ghosts`, `sys_storage_mime_types`, `sys_objects_transcoder_images`, `sys_transcoder_images_files`, `sys_transcoder_images_filters`,`sys_accounts`,`sys_profiles`;
+DROP TABLE IF EXISTS `sys_categories`, `sys_keys`, `sys_objects_editor`, `sys_objects_captcha`, `sys_objects_social_sharing`, `sys_objects_categories`, `sys_objects_cmts`, `sys_cmts_images`, `sys_cmts_images_preview`, `sys_cmts_images2entries`, `sys_email_templates`, `sys_options`, `sys_options_cats`, `sys_ip_list`, `sys_ip_members_visits`, `sys_localization_categories`, `sys_localization_keys`, `sys_localization_languages`, `sys_localization_string_params`, `sys_localization_strings`, `sys_acl_actions`, `sys_acl_actions_track`, `sys_acl_matrix`, `sys_acl_level_prices`, `sys_acl_levels`, `sys_sessions`, `sys_acl_levels_members`, `sys_objects_search`, `sys_stat_site`, `sys_alerts`, `sys_alerts_handlers`, `sys_injections`, `sys_injections_admin`, `sys_modules`, `sys_modules_file_tracks`, `sys_permalinks`, `sys_objects_privacy`, `sys_privacy_defaults`, `sys_privacy_groups`, `sys_privacy_members`, `sys_tags`, `sys_objects_tag`, `sys_transactions`, `sys_objects_auths`, `sys_objects_vote`, `sys_objects_view`, `sys_cron_jobs`, `sys_dnsbl_rules`, `sys_dnsbl_block_log`, `sys_dnsbluri_zones`, `sys_menu_mobile`, `sys_menu_mobile_pages`, `sys_objects_storage`, `sys_objects_uploader`, `sys_storage_user_quotas`, `sys_storage_tokens`, `sys_storage_ghosts`, `sys_storage_mime_types`, `sys_objects_transcoder_images`, `sys_transcoder_images_files`, `sys_transcoder_images_filters`,`sys_accounts`,`sys_profiles`;
 ALTER DATABASE DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
 
 
@@ -1121,15 +1121,17 @@ CREATE TABLE `sys_alerts` (
 -- --------------------------------------------------------
 
 
-CREATE TABLE `sys_objects_views` (
+CREATE TABLE `sys_objects_view` (
   `id` int(11) NOT NULL auto_increment,
   `name` varchar(32) NOT NULL,
   `table_track` varchar(32) NOT NULL,
   `period` int(11) NOT NULL default '86400',
+  `is_on` tinyint(4) NOT NULL default '1',
   `trigger_table` varchar(32) NOT NULL,
   `trigger_field_id` varchar(32) NOT NULL,
-  `trigger_field_views` varchar(32) NOT NULL,
-  `is_on` tinyint(4) NOT NULL default '1',
+  `trigger_field_count` varchar(32) NOT NULL,
+  `class_name` varchar(32) NOT NULL default '',
+  `class_file` varchar(256) NOT NULL default '',
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 

+ 1 - 0
modules/boonex/notes/classes/BxNotesConfig.php

@@ -28,6 +28,7 @@ class BxNotesConfig extends BxDolModuleConfig {
 
     public static $OBJECT_STORAGE = 'bx_notes_photos';
     public static $OBJECT_IMAGES_TRANSCODER_PREVIEW = 'bx_notes_preview';
+    public static $OBJECT_VIEWS = 'bx_notes';
     public static $OBJECT_VOTES = 'bx_notes';
     public static $OBJECT_COMMENTS = 'bx_notes';
     public static $OBJECT_PRIVACY_VIEW = 'bx_notes_allow_view_to';

+ 9 - 0
modules/boonex/notes/classes/BxNotesFormNote.php

@@ -133,6 +133,15 @@ class BxNotesFormNote extends BxTemplFormView {
 
         // delete db record
 
+        bx_import('BxDolView');
+		BxDolView::getObjectInstance(BxNotesConfig::$OBJECT_VIEWS, $iContentId)->onObjectDelete();
+
+		bx_import('BxDolVote');
+		BxDolVote::getObjectInstance(BxNotesConfig::$OBJECT_VOTES, $iContentId)->onObjectDelete();
+
+		bx_import('BxDolCmts');
+		BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $iContentId)->onObjectDelete();
+
         return parent::delete($iContentId);
     }
 

+ 4 - 0
modules/boonex/notes/classes/BxNotesModule.php

@@ -99,6 +99,10 @@ class BxNotesModule extends BxDolModule {
             $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
         if (!$iContentId)
             return false;
+
+		bx_import('BxDolView');
+		BxDolView::getObjectInstance(BxNotesConfig::$OBJECT_VIEWS, $iContentId)->doView();
+
         bx_import('NoteForms', $this->_aModule);
         $oProfileForms = new BxNotesNoteForms($this);
         return $oProfileForms->viewDataEntry((int)$iContentId);

+ 4 - 7
modules/boonex/notes/install/sql/disable.sql

@@ -1,6 +1,5 @@
 
 -- SETTINGS
-
 SET @iTypeId = (SELECT `ID` FROM `sys_options_types` WHERE `name` = 'bx_notes' LIMIT 1);
 SET @iCategId = (SELECT `ID` FROM `sys_options_categories` WHERE `type_id` = @iTypeId LIMIT 1);
 DELETE FROM `sys_options` WHERE `category_id` = @iCategId;
@@ -8,7 +7,6 @@ DELETE FROM `sys_options_categories` WHERE `type_id` = @iTypeId;
 DELETE FROM `sys_options_types` WHERE `id` = @iTypeId;
 
 -- STORAGES & TRANSCODERS
-
 DELETE FROM `sys_objects_storage` WHERE `object` = 'bx_notes_photos' OR `object` = 'bx_notes_photos_resized';
 DELETE FROM `sys_storage_tokens` WHERE `object` = 'bx_notes_photos' OR `object` = 'bx_notes_photos_resized';
 
@@ -18,22 +16,18 @@ DELETE FROM `sys_transcoder_images_files` WHERE `transcoder_object` = 'bx_notes_
 TRUNCATE TABLE `bx_notes_photos_resized`; 
 
 -- PAGES
-
 DELETE FROM `sys_objects_page` WHERE `module` = 'bx_notes';
 DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_notes' OR `object` IN('bx_notes_create_note', 'bx_notes_edit_note', 'bx_notes_view_note', 'bx_notes_view_note_comments', 'bx_notes_home', 'bx_notes_featured', 'bx_notes_author');
 
 -- MENU
-
 DELETE FROM `sys_objects_menu` WHERE `module` = 'bx_notes';
 DELETE FROM `sys_menu_sets` WHERE `module` = 'bx_notes';
 DELETE FROM `sys_menu_items` WHERE `module` = 'bx_notes' OR `set_name` IN('bx_notes_view', 'bx_notes_submenu', 'bx_notes_view_submenu', 'bx_notes_my');
 
 -- PRIVACY 
-
 DELETE FROM `sys_objects_privacy` WHERE `object` = 'bx_notes_allow_view_to';
 
 -- ACL
-
 DELETE `sys_acl_actions`, `sys_acl_matrix` FROM `sys_acl_actions`, `sys_acl_matrix` WHERE `sys_acl_matrix`.`IDAction` = `sys_acl_actions`.`ID` AND `sys_acl_actions`.`Module` = 'bx_notes';
 DELETE FROM `sys_acl_actions` WHERE `Module` = 'bx_notes';
 
@@ -41,4 +35,7 @@ DELETE FROM `sys_acl_actions` WHERE `Module` = 'bx_notes';
 DELETE FROM `sys_objects_cmts` WHERE `Name`='bx_notes';
 
 -- VOTES
-DELETE FROM `sys_objects_vote` WHERE `Name`='bx_notes';
+DELETE FROM `sys_objects_vote` WHERE `Name`='bx_notes';
+
+-- VIEWS
+DELETE FROM `sys_objects_view` WHERE `Name`='bx_notes';

+ 7 - 2
modules/boonex/notes/install/sql/enable.sql

@@ -257,5 +257,10 @@ INSERT INTO `sys_objects_cmts` (`Name`, `Table`, `CharsPostMin`, `CharsPostMax`,
 
 
 -- VOTES
-INSERT INTO `sys_objects_vote`(`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
-('bx_notes', 'bx_notes_votes', 'bx_notes_votes_track', '604800', '1', '1', '1', '1', 'bx_notes_posts', 'id', 'rate', 'votes', '', '');
+INSERT INTO `sys_objects_vote` (`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
+('bx_notes', 'bx_notes_votes', 'bx_notes_votes_track', '604800', '1', '1', '1', '1', 'bx_notes_posts', 'id', 'rate', 'votes', '', '');
+
+
+-- VIEWS
+INSERT INTO `sys_objects_view` (`name`, `table_track`, `period`, `is_on`, `trigger_table`, `trigger_field_id`, `trigger_field_count`, `class_name`, `class_file`) VALUES 
+('bx_notes', 'bx_notes_views_track', '86400', '1', 'bx_notes_posts', 'id', 'views', '', '');

+ 10 - 0
modules/boonex/notes/install/sql/install.sql

@@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS `bx_notes_posts` (
   `title` varchar(255) NOT NULL,
   `text` text NOT NULL,
   `summary` text NOT NULL,
+  `views` int(11) NOT NULL default '0',
   `rate` float NOT NULL default '0',
   `votes` int(11) NOT NULL default '0',
   `comments` int(11) NOT NULL default '0',
@@ -86,6 +87,15 @@ CREATE TABLE IF NOT EXISTS `bx_notes_votes_track` (
   KEY `vote` (`object_id`, `author_nip`)
 ) ENGINE=MYISAM DEFAULT CHARSET=utf8;
 
+-- TABLE: VIEWS
+CREATE TABLE `bx_notes_views_track` (
+  `object_id` int(11) NOT NULL default '0',
+  `viewer_id` int(11) NOT NULL default '0',
+  `viewer_nip` int(11) unsigned NOT NULL default '0',
+  `date` int(11) NOT NULL default '0',
+  KEY `id` (`object_id`,`viewer_id`,`viewer_nip`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
 -- FORMS
 INSERT INTO `sys_objects_form`(`object`, `module`, `title`, `action`, `form_attrs`, `table`, `key`, `uri`, `uri_title`, `submit_name`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 
 ('bx_notes', 'bx_notes', '_bx_notes_form_note', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_notes_posts', 'id', '', '', 'do_submit', '', 0, 1, 'BxNotesFormNote', 'modules/boonex/notes/classes/BxNotesFormNote.php');

+ 3 - 1
modules/boonex/notes/install/sql/uninstall.sql

@@ -16,8 +16,10 @@ DROP TABLE IF EXISTS `bx_notes_cmts`;
 DROP TABLE IF EXISTS `bx_notes_votes`;
 DROP TABLE IF EXISTS `bx_notes_votes_track`;
 
--- FORMS
+-- TABLE: VIEWS
+DROP TABLE IF EXISTS `bx_notes_views_track`;
 
+-- FORMS
 DELETE FROM `sys_objects_form` WHERE `module` = 'bx_notes';
 
 DELETE FROM `sys_form_displays` WHERE `module` = 'bx_notes';

+ 22 - 0
modules/boonex/uni/data/template/system/scripts/BxTemplView.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * @package     Dolphin Core
+ * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
+ */
+defined('BX_DOL') or die('hack attempt');
+
+bx_import('BxBaseView');
+
+/**
+ * @see BxDolView
+ */
+class BxTemplView extends BxBaseView
+{
+    function __construct($sSystem, $iId, $iInit = 1)
+    {
+		parent::__construct($sSystem, $iId, $iInit);
+    }
+}
+
+/** @} */ 

+ 22 - 0
template/scripts/BxBaseView.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * @package     Dolphin Core
+ * @copyright   Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * @license     CC-BY - http://creativecommons.org/licenses/by/3.0/
+ */
+defined('BX_DOL') or die('hack attempt');
+
+bx_import('BxDolView');
+
+/**
+ * @see BxDolView
+ */
+class BxBaseView extends BxDolView
+{
+    public function __construct($sSystem, $iId, $iInit = 1)
+    {
+        parent::__construct($sSystem, $iId, $iInit);
+    }
+}
+
+/** @} */