Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Log_Helper_Data
  • Mage_Log_Model_Aggregation
  • Mage_Log_Model_Cron
  • Mage_Log_Model_Customer
  • Mage_Log_Model_Log
  • Mage_Log_Model_Mysql4_Aggregation
  • Mage_Log_Model_Mysql4_Customer
  • Mage_Log_Model_Mysql4_Log
  • Mage_Log_Model_Mysql4_Visitor
  • Mage_Log_Model_Mysql4_Visitor_Collection
  • Mage_Log_Model_Mysql4_Visitor_Online
  • Mage_Log_Model_Mysql4_Visitor_Online_Collection
  • Mage_Log_Model_Resource_Aggregation
  • Mage_Log_Model_Resource_Customer
  • Mage_Log_Model_Resource_Log
  • Mage_Log_Model_Resource_Visitor
  • Mage_Log_Model_Resource_Visitor_Collection
  • Mage_Log_Model_Resource_Visitor_Online
  • Mage_Log_Model_Resource_Visitor_Online_Collection
  • Mage_Log_Model_Visitor
  • Mage_Log_Model_Visitor_Online
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Log
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Log Aggregation Model
 29:  *
 30:  * @method Mage_Log_Model_Resource_Aggregation getResource()
 31:  * @method Mage_Log_Model_Resource_Aggregation _getResource()
 32:  *
 33:  * @category   Mage
 34:  * @package    Mage_Log
 35:  * @author     Magento Core Team <core@magentocommerce.com>
 36:  */
 37: class Mage_Log_Model_Aggregation extends Mage_Core_Model_Abstract
 38: {
 39: 
 40:     /**
 41:      * Last record data
 42:      *
 43:      * @var string
 44:      */
 45:     protected $_lastRecord;
 46: 
 47:     /**
 48:      * Init model
 49:      */
 50:     protected function _construct()
 51:     {
 52:         $this->_init('log/aggregation');
 53:     }
 54: 
 55:     /**
 56:      * Run action
 57:      */
 58:     public function run()
 59:     {
 60:         $this->_lastRecord = $this->_timestamp($this->_round($this->getLastRecordDate()));
 61:         foreach (Mage::app()->getStores(false) as $store) {
 62:             $this->_process($store->getId());
 63:         }
 64:     }
 65: 
 66:     /**
 67:      * Remove empty records before $lastDate
 68:      *
 69:      * @param  string $lastDate
 70:      * @return void
 71:      */
 72:     private function _removeEmpty($lastDate)
 73:     {
 74:         return $this->_getResource()->removeEmpty($lastDate);
 75:     }
 76: 
 77:     /**
 78:      * Process
 79:      *
 80:      * @param  int $store
 81:      * @return mixed
 82:      */
 83:     private function _process($store)
 84:     {
 85:         $lastDateRecord = null;
 86:         $start          = $this->_lastRecord;
 87:         $end            = time();
 88:         $date           = $start;
 89: 
 90:         while ($date < $end) {
 91:             $to = $date + 3600;
 92:             $counts = $this->_getCounts($this->_date($date), $this->_date($to), $store);
 93:             $data = array(
 94:                 'store_id'=>$store,
 95:                 'visitor_count'=>$counts['visitors'],
 96:                 'customer_count'=>$counts['customers'],
 97:                 'add_date'=>$this->_date($date)
 98:                 );
 99: 
100:             if ($counts['visitors'] || $counts['customers']) {
101:                 $this->_save($data, $this->_date($date), $this->_date($to));
102:             }
103: 
104:             $lastDateRecord = $date;
105:             $date = $to; 
106:         }
107:         return $lastDateRecord;
108:     }
109: 
110:     /**
111:      * Save log data
112:      *
113:      * @param  array $data
114:      * @param  string $from
115:      * @param  string $to
116:      */
117:     private function _save($data, $from, $to)
118:     {
119:         if ($logId = $this->_getResource()->getLogId($from, $to)) {
120:             $this->_update($logId, $data);
121:         } else {
122:             $this->_insert($data);
123:         }
124:     }
125: 
126:     private function _update($id, $data)
127:     {
128:         return $this->_getResource()->saveLog($data, $id);
129:     }
130: 
131:     private function _insert($data)
132:     {
133:         return $this->_getResource()->saveLog($data);
134:     }
135: 
136:     private function _getCounts($from, $to, $store)
137:     {
138:         return $this->_getResource()->getCounts($from, $to, $store);
139:     }
140: 
141:     public function getLastRecordDate()
142:     {
143:         $result = $this->_getResource()->getLastRecordDate();
144:         if (!$result)
145:             $result = $this->_date(strtotime('now - 2 months'));
146: 
147:         return $result;
148:     }
149: 
150:     private function _date($in, $offset = null)
151:     {
152:         $out = $in;
153:         if (is_numeric($in))
154:             $out = date("Y-m-d H:i:s", $in);
155:         return $out;
156:     }
157: 
158:     private function _timestamp($in, $offset = null)
159:     {
160:         $out = $in;
161:         if (!is_numeric($in))
162:             $out = strtotime($in);
163:         return $out;
164:     }
165: 
166:     /**
167:      * @param  $in
168:      * @return string
169:      */
170:     private function _round($in)
171:     {
172:         return date("Y-m-d H:00:00", $this->_timestamp($in));
173:     }
174: }
175: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0