Пример #1
0
 /**
  * Constructor
  * @param array $options
  * @param string $date
  */
 public function __construct(array $options = array(), $date = null)
 {
     parent::__construct($date);
     $this->_request = Zend_Controller_Front::getInstance()->getRequest();
     $this->setDate($date, "M yy");
     $this->setOptions($options);
     // Caching
     $cache = null;
     if (array_key_exists('autoCache', $options)) {
         if (extension_loaded('apc')) {
             $cache = Zend_Cache::factory('Core', 'apc');
         }
     } else {
         if (array_key_exists('cache', $options)) {
             $cache = $options['cache'];
         } else {
             if (Zend_Registry::isRegistered('SZend_Calendar_Cache')) {
                 $cache = Zend_Registry::get('SZend_Calendar_Cache');
             }
         }
     }
     if (null !== $cache) {
         if (!$cache instanceof Zend_Cache_Core) {
             throw new Zend_Exception('Instance of Zend_Cache expected');
         }
         $this->_date->setOptions(array('cache' => $cache));
     }
     $this->_generateWeeks();
     #$this->_weeks = $this->getCalendarMonthDayDataArray();
     $this->init();
 }
Пример #2
0
 /**
  * To init the view
  *
  * @return Zend_View $view
  */
 public function init()
 {
     $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400);
     $backendOptions = array('cache_dir' => PROJECT_ROOT . '/repository/cache/');
     if ('development' == APPLICATION_ENV) {
         $frontendOptions['caching'] = false;
         //关闭缓存
     } else {
         $classFileIncCache = $backendOptions['cache_dir'] . 'pluginLoaderCache.php';
         if (file_exists($classFileIncCache)) {
             include_once $classFileIncCache;
         }
         Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
     }
     $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_cache);
     //缓存Zend_Db_Table元数据
     Zend_Date::setOptions(array('cache' => $this->_cache));
     //缓存Zend_Date
     Zend_Translate::setCache($this->_cache);
     //缓存Zend_Translate
     Zend_Registry::set('cache', $this->_cache);
     // Return it, so that it can be stored by the bootstrap
     return $this->_cache;
 }
Пример #3
0
 protected function _initTranslation()
 {
     $cache = $this->_getCache('core');
     Zend_Translate::setCache($cache);
     Zend_Date::setOptions(array('cache' => $cache));
     Zend_Paginator::setCache($cache);
 }
Пример #4
0
 /**
  * Constructor
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     $this->_request = Zend_Controller_Front::getInstance()->getRequest();
     // Generate calendar timestamp
     if (array_key_exists('timestamp', $options)) {
         $timestamp = $options['timestamp'];
     } else {
         // Default date based on current
         $date = array('hour' => (int) date('h'), 'minute' => (int) date('i'), 'second' => (int) date('s'), 'month' => (int) date('m'), 'day' => (int) date('d'), 'year' => (int) date('Y'));
         // Timestamp from parameters
         if ($this->_request->getParam('second')) {
             $date['second'] = $this->_request->getParam('second');
         }
         if ($this->_request->getParam('minute')) {
             $date['minute'] = $this->_request->getParam('minute');
         }
         if ($this->_request->getParam('hour')) {
             $date['hour'] = $this->_request->getParam('hour');
         }
         if ($this->_request->getParam('day')) {
             $date['day'] = $this->_request->getParam('day');
         }
         if ($this->_request->getParam('month')) {
             $date['month'] = $this->_request->getParam('month');
         }
         if ($this->_request->getParam('year')) {
             $date['year'] = $this->_request->getParam('year');
         }
         // Finally merge with any date options
         $date = array_merge($date, array_key_exists('date', $options) ? $options['date'] : array());
         // Generate the timestamp
         $timestamp = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
     }
     $this->setDate($timestamp);
     $this->setOptions($options);
     // Caching
     $cache = null;
     if (array_key_exists('autoCache', $options)) {
         if (extension_loaded('apc')) {
             $cache = Zend_Cache::factory('Core', 'apc');
         }
     } else {
         if (array_key_exists('cache', $options)) {
             $cache = $options['cache'];
         } else {
             if (Zend_Registry::isRegistered('SZend_Calendar_Cache')) {
                 $cache = Zend_Registry::get('SZend_Calendar_Cache');
             }
         }
     }
     if (null !== $cache) {
         if (!$cache instanceof Zend_Cache_Core) {
             throw new Zend_Exception('Instance of Zend_Cache expected');
         }
         $this->_date->setOptions(array('cache' => $cache));
     }
     $this->_generateWeeks();
     $this->init();
 }
 public function viewCheckChuNhatThuBay($day = 0, $month = 0, $year = 0)
 {
     Zend_Date::setOptions(array('format_type' => 'php'));
     $date = new Zend_Date($day . '/' . $month . '/' . $year, 'd/m/Y');
     if ($date->toString('D') == 'CN' || $date->toString('D') == 'Th 7') {
         return 'class="error"';
     }
 }
Пример #6
0
 /**
  * 
  */
 protected function _initCacheDir()
 {
     $frontendOptions = array('lifetime' => 86400, 'automatic_serialization' => true, 'automatic_cleaning_factor' => 1);
     $backendOptions = array('cache_dir' => APPLICATION_PATH . '/cache');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     Zend_Date::setOptions(array('cache' => $cache));
 }
Пример #7
0
 /**
  * defaults to current date
  * we use php's formating here
  */
 public function renderDate($timestamp = null, $format = 'F j, Y')
 {
     if ($timestamp == null) {
         $timestamp = time();
     }
     Zend_Date::setOptions(array('format_type' => 'php'));
     $date = new Zend_Date($timestamp);
     return $date->toString($format);
 }
Пример #8
0
 /**
  * Presets flat data from subscription
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return AW_Sarp_Model_Subscription_Flat
  */
 public function setSubscription(AW_Sarp_Model_Subscription $Subscription)
 {
     Zend_Date::setOptions(array('extend_month' => true));
     // Fix Zend_Date::addMonth unexpected result
     if (!$Subscription->isInfinite()) {
         $expireDate = $Subscription->getDateExpire()->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
     } else {
         $expireDate = null;
     }
     if ($Subscription->getIsNew()) {
         $lastOrderAmount = $Subscription->getQuote()->getGrandTotal();
         $virtual = $Subscription->getQuote()->getIsVirtual();
     } else {
         $lastOrderAmount = $Subscription->getLastOrder()->getGrandTotal();
         $virtual = $Subscription->getLastOrder()->getIsVirtual();
     }
     if ($Subscription->isActive()) {
         $paymentOffset = $Subscription->getPeriod()->getPaymentOffset();
         // Get next payment date
         if (!$Subscription->getLastPaidDate()) {
             $nextPaymentDate = $Subscription->getLastOrder()->getCreatedAtStoreDate();
             $nextPaymentDate = $Subscription->getNextSubscriptionEventDate($Subscription->getDateStart());
             $nextDeliveryDate = clone $Subscription->getDateStart();
             $nextDeliveryDate->addDayOfYear(0 + floatval($paymentOffset));
         } else {
             $nextPaymentDate = $Subscription->getNextSubscriptionEventDate();
         }
         if ($paymentOffset) {
             if (!$Subscription->getLastPaidDate()) {
                 // No payments made yet
                 $lastOrderDate = clone $Subscription->getDateStart();
                 $lastOrderDate->addDayOfYear(0 - floatval($paymentOffset));
             } else {
                 $lastOrderDate = $Subscription->getLastOrder()->getCreatedAtStoreDate();
             }
             $probablyDeliveryDate = clone $lastOrderDate;
             $probablyDeliveryDate = $probablyDeliveryDate->addDayOfYear(floatval($paymentOffset));
             if ($probablyDeliveryDate->compare(new Zend_Date(), Zend_Date::DATE_SHORT) > 0) {
                 $nextDeliveryDate = clone $lastOrderDate;
             }
             $nextPaymentDate->addDayOfYear(0 - floatval($paymentOffset));
         }
         if (!isset($nextDeliveryDate)) {
             $nextDeliveryDate = clone $nextPaymentDate;
         }
         $nextDeliveryDate = $nextDeliveryDate->addDayOfYear(floatval($paymentOffset))->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
         $nextPaymentDate = $nextPaymentDate->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
     } else {
         // Drop next payment date if subscription is suspended
         $nextDeliveryDate = $nextPaymentDate = null;
     }
     $this->setSubscriptionId($Subscription->getId())->setCustomerName($Subscription->getCustomer()->getName())->setCustomerEmail($Subscription->getCustomer()->getEmail())->setFlatLastOrderStatus($Subscription->getLastOrder()->getStatus())->setFlatLastOrderAmount($lastOrderAmount)->setFlatLastOrderCurrencyCode($Subscription->getLastOrder()->getOrderCurrencyCode())->setFlatDateExpire($expireDate)->setHasShipping(1 - $virtual)->setFlatNextPaymentDate($nextPaymentDate)->setFlatNextDeliveryDate($nextDeliveryDate)->setProductsText($this->_convertProductsText($Subscription))->setProductsSku($this->_convertProductsSku($Subscription));
     $Subscription->setCustomerName($Subscription->getCustomer()->getName())->setCustomerEmail($Subscription->getCustomer()->getEmail())->setFlatLastOrderStatus($Subscription->getLastOrder()->getStatus())->setFlatLastOrderAmount($lastOrderAmount)->setFlatLastOrderCurrencyCode($Subscription->getLastOrder()->getOrderCurrencyCode())->setFlatDateExpire($expireDate)->setHasShipping(1 - $virtual)->setFlatNextPaymentDate($nextPaymentDate)->setFlatNextDeliveryDate($nextDeliveryDate)->setProductsText($this->_convertProductsText($Subscription))->setProductsSku($this->_convertProductsSku($Subscription));
     return $this;
 }
Пример #9
0
 public function format($format = 'Y-m-d', $language = null)
 {
     $needsZendDate = !!array_intersect(array('D', 'l', 'S', 'F', 'M', 'e'), str_split($format));
     if (!$needsZendDate) {
         return date($format, $this->_timestamp);
     } else {
         $date = new Zend_Date($this->_timestamp, Zend_Date::TIMESTAMP);
         $date->setOptions(array('format_type' => 'php'));
         $date->setLocale($language);
         return $date->toString($format);
     }
 }
 public function __construct()
 {
     Loader::library('3rdparty/Zend/Date');
     Loader::library('3rdparty/Zend/Translate');
     $this->setLocale(defined('ACTIVE_LOCALE') ? ACTIVE_LOCALE : 'en_US');
     Zend_Date::setOptions(array('format_type' => 'php'));
     $cache = Cache::getLibrary();
     if (is_object($cache)) {
         Zend_Translate::setCache($cache);
         Zend_Date::setOptions(array('cache' => $cache));
     }
 }
Пример #11
0
 /**
  * this helper renders a date picker (requires jquery date)
  *
  * @param string $name
  * @param timestamp $value
  *
  */
 public function datePicker($name, $value = null)
 {
     //format the timestamp
     if ($value > 0) {
         Zend_Date::setOptions(array('format_type' => 'php'));
         $date = new Zend_Date($value);
         $value = $date->toString('m-d-Y');
     } else {
         //we dont want any value that is not a valid date
         $value = null;
     }
     return $this->view->formText($name, $value, array('class' => 'date-picker'));
 }
Пример #12
0
 /**
  * Setup our cache
  */
 protected function _initAppCache()
 {
     $this->bootstrap('cachemanager');
     $metaCache = $this->getResource('cachemanager')->getCache('metadata');
     $dateCache = $this->getResource('cachemanager')->getCache('date');
     Zend_Db_Table_Abstract::setDefaultMetadataCache($metaCache);
     Zend_Date::setOptions(array('cache' => $dateCache));
     if ('production' === $this->getEnvironment()) {
         $classFileIncCache = APPLICATION_PATH . '/tmp/pluginLoaderCache.php';
         if (file_exists($classFileIncCache)) {
             include_once $classFileIncCache;
         }
         Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
     }
 }
 public function Nice($format = false)
 {
     if ($this->value) {
         if ($format === false) {
             if (self::$format_nice !== false) {
                 $format = self::$format_nice;
             } else {
                 $format = _t('ZENDDATE.DATETIMEFORMATNICE', 'd/m/Y H:i a');
             }
         }
         Zend_Date::setOptions(array('format_type' => 'php'));
         $ZD = new Zend_Date($this->value, i18n::get_locale());
         return $ZD->toString($format);
     }
 }
Пример #14
0
 public function processOldLogs()
 {
     $Date = new Zend_Date();
     Zend_Date::setOptions(array('extend_month' => true));
     $Date->sub(Mage::getStoreConfig(self::XML_PATH_LOGGER_STORE_DAYS), Zend_Date::DAY);
     $collection = $this->getCollection()->addOlderThanFilter($Date);
     if (Mage::getStoreConfig(self::XML_PATH_ENABLE_ARCHIVATION)) {
         $resourceSingleton = Mage::getResourceSingleton('aw_lib/logger');
         $sql = $resourceSingleton->getPartInsertSql('aw_lib_logger', $collection->getSelect());
         $resourceSingleton->createBackupFile($sql);
     }
     foreach ($collection as $entry) {
         $entry->delete();
     }
     return $this;
 }
Пример #15
0
 /**
  * Inizializza la cache per rendere più veloci le operazioni sulle date.
  *
  * @throws Zend_Exception
  */
 protected function _setCache()
 {
     $cache = null;
     if (isset($this->_options['autoCache']) && extension_loaded('apc')) {
         $cache = Zend_Cache::factory('Core', 'apc');
     } elseif (isset($this->_options['cache'])) {
         $cache = $this->_options['cache'];
     } elseif (Zend_Registry::isRegistered('Zwe_Calendar_Cache')) {
         $cache = Zend_Registry::get('Zwe_Calendar_Cache');
     }
     if (isset($cache)) {
         if (!$cache instanceof Zend_Cache_Core) {
             throw new Zend_Exception('Instance of Zend_Cache_Core expected');
         }
         $this->_date->setOptions(array('cache' => $cache));
     }
 }
Пример #16
0
 /**
  * Defined by Zend_Filter_Interface
  *
  * Returns the date formatted for the format defined with the constructor.
  * Will return the date for the 1970-1-1 if the passed argument
  * was not in a valid date-format.
  *
  * @param  mixed $value
  * @return integer
  */
 public function filter($value)
 {
     // get Zend_Date options
     $dateOptions = Zend_Date::setOptions();
     // set format type to iso
     Zend_Date::setOptions(array('format_type' => 'iso'));
     $inputFormat = $this->_inputFormat;
     $format = $this->_format;
     if ($inputFormat) {
         $inputFormat = Zend_Locale_Format::convertPhpToIsoFormat($inputFormat);
     }
     $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
     $d = $value;
     if (!is_numeric($value)) {
         $d = strtotime($value);
     }
     if ($d === false) {
         try {
             $date = new Zend_Date($value, $inputFormat);
         } catch (Zend_Date_Exception $e) {
             $date = new Zend_Date("1970-01-01 00:00:00");
         }
     } else {
         try {
             $date = new Zend_Date($d, Zend_Date::TIMESTAMP);
         } catch (Zend_Date_Exception $e) {
             $date = new Zend_Date("1970-01-01 00:00:00");
         }
     }
     $d = $date->get($format);
     Zend_Date::setOptions(array('format_type' => $dateOptions['format_type']));
     return $d;
 }
Пример #17
0
 /**
  * Deletes all old log records
  *
  * @return AW_Core_Helper_Logger
  */
 public function exorcise()
 {
     $Date = new Zend_Date();
     Zend_Date::setOptions(array('extend_month' => true));
     $Date->addDayOfYear(0 - (int) Mage::getStoreConfig('awall/awcore/logger_store_days'));
     foreach (Mage::getModel('awcore/logger')->getCollection()->addOlderThanFilter($Date) as $entry) {
         $entry->delete();
     }
     return $this;
 }
Пример #18
0
 public function testExtendedDst()
 {
     Zend_Date::setOptions(array('format_type' => 'iso'));
     $date = new Zend_Date();
     $date->setTimezone('UTC');
     $date->set('25-05-2050 12:00:00');
     $this->assertSame('2050-05-25 12:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
     $date->setTimezone('Europe/Warsaw');
     $this->assertSame('2050-05-25 14:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
     $date->setTimezone('UTC');
     $date->set('25-05-2020 12:00:00');
     $this->assertSame('2020-05-25 12:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
     $date->setTimezone('Europe/Warsaw');
     $this->assertSame('2020-05-25 14:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
 }
Пример #19
0
 /**
  * Generates next payment date
  * @param Zend_Date $CurrentDate
  * @return Zend_Date
  */
 public function getNextSubscriptionEventDate($CurrentDate = null)
 {
     Zend_Date::setOptions(array('extend_month' => true));
     // Fix Zend_Date::addMonth unexpected result
     if (!$CurrentDate instanceof Zend_Date) {
         if (is_null($CurrentDate)) {
             if (!($CurrentDate = $this->getLastPaidDate())) {
                 throw new AW_Sarp_Exception("Failed to detect last paid date");
             }
         } else {
             throw new AW_Sarp_Exception("getNextSubscriptionEventDate accepts only Zend_Date or null");
         }
     }
     switch ($this->getPeriod()->getPeriodType()) {
         case 'day':
             $method = 'addDayOfYear';
             break;
         case 'month':
             $method = 'addMonth';
             break;
         case 'week':
             $method = 'addWeek';
             break;
         case 'year':
             $method = 'addYear';
             break;
         default:
             throw new Mage_Core_Exception("Unknown subscription period #" . $this->getPeriod()->getId() . " for subscription #{$this->getId()}");
     }
     $CurrentDate = call_user_func(array($CurrentDate, $method), $this->getPeriod()->getPeriodValue());
     return $CurrentDate;
 }
Пример #20
0
	/** 
	 * Subsitute for the native date() function that adds localized date support
	 * This uses Zend's Date Object {@link http://framework.zend.com/manual/en/zend.date.constants.html#zend.date.constants.phpformats}
	 * @param string $mask
	 * @param int $timestamp
	 * @return string
	 */
	public function date($mask,$timestamp=false) {
		$loc = Localization::getInstance();
		if ($timestamp === false) {
			$timestamp = time();
		}
		
		if ($loc->getLocale() == 'en_US') {
			return date($mask, $timestamp);			
		}		

		$locale = new Zend_Locale(Localization::activeLocale());
		Zend_Date::setOptions(array('format_type' => 'php'));
		$cache = Cache::getLibrary();
		if (is_object($cache)) {
			Zend_Date::setOptions(array('cache'=>$cache));
		} 
		$date = new Zend_Date($timestamp, false, $locale);

		return $date->toString($mask);
	}
Пример #21
0
 public function initialize()
 {
     $this->initMode();
     $this->initAutoload();
     $this->initDatabaseTablesMetadataCache();
     $this->initDB();
     $this->initConfig();
     $this->initAuloadMP();
     //TODO: we will remove comments when zend fully implement localization for all exception messages.
     //Zend_Exception::localizeMessages(true);
     //Change Date format to PHP formats
     Zend_Date::setOptions(array('format_type' => 'php'));
     $this->initUser();
 }
Пример #22
0
 public function testSetOptions()
 {
     $options = Zend_Date::setOptions();
     $this->assertTrue(is_array($options));
     $this->assertEquals($options['format_type'], 'iso');
     Zend_Date::setOptions(array('format_type' => 'php'));
     $options = Zend_Date::setOptions();
     $this->assertEquals($options['format_type'], 'php');
     try {
         Zend_Date::setOptions(array('format_type' => 'non'));
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         Zend_Date::setOptions(array('unknown' => 'non'));
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
Пример #23
0
 public function chartAction()
 {
     // Disable layout and viewrenderer
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $viewer = Engine_Api::_()->user()->getViewer();
     // Get params
     $start = $this->_getParam('start');
     $offset = $this->_getParam('offset', 0);
     $type = $this->_getParam('type', 'all');
     $mode = $this->_getParam('mode');
     $chunk = $this->_getParam('chunk');
     $period = $this->_getParam('period');
     $periodCount = $this->_getParam('periodCount', 1);
     $campaign_ids = $this->_getParam('campaign_ids');
     // Validate chunk/period
     if (!$chunk || !in_array($chunk, $this->_periods)) {
         $chunk = Zend_Date::DAY;
     }
     if (!$period || !in_array($period, $this->_periods)) {
         $period = Zend_Date::MONTH;
     }
     if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) {
         die('whoops');
         return;
     }
     // Validate start
     if ($start && !is_numeric($start)) {
         $start = strtotime($start);
     }
     if (!$start) {
         $start = time();
     }
     // Fixes issues with month view
     Zend_Date::setOptions(array('extend_month' => true));
     // Get timezone
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     // Make start fit to period?
     $startObject = new Zend_Date($start);
     $startObject->setTimezone($timezone);
     $partMaps = $this->_periodMap[$period];
     foreach ($partMaps as $partType => $partValue) {
         $startObject->set($partValue, $partType);
     }
     // Do offset
     if ($offset != 0) {
         $startObject->add($offset, $period);
     }
     $arr_campaigns = array();
     if ($campaign_ids) {
         $arr_campaigns = explode(',', $campaign_ids);
     }
     // Get end time
     $endObject = new Zend_Date($startObject->getTimestamp());
     $endObject->setTimezone($timezone);
     $endObject->add($periodCount, $period);
     $endObject->sub(1, Zend_Date::SECOND);
     // Subtract one second
     $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads');
     if (count($arr_campaigns)) {
         $adList = $adTbl->fetchAll($adTbl->select()->from($adTbl->info("name"), 'ad_id')->where('campaign_id IN (?)', $arr_campaigns));
         $adList = $adList->toArray();
     } else {
         $adList = array();
     }
     // Get data
     $staTable = Engine_Api::_()->getDbtable('statistics', 'ynsocialads');
     $staName = $staTable->info('name');
     if ($type != "all") {
         $select = $staTable->select();
         // Get data
         if (count($adList)) {
             $select->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             if ($type != "all") {
                 $select->where('type = ?', $type);
             }
             $rawData = $staTable->fetchAll($select);
         } else {
             $rawData = array();
         }
         // Now create data structure
         $currentObject = clone $startObject;
         $nextObject = clone $startObject;
         $data = array();
         $dataLabels = array();
         $cumulative = 0;
         $previous = 0;
         do {
             $nextObject->add(1, $chunk);
             $currentObjectTimestamp = $currentObject->getTimestamp();
             $nextObjectTimestamp = $nextObject->getTimestamp();
             $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative;
             // Get everything that matches
             $currentPeriodCount = 0;
             foreach ($rawData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCount += 1;
                 }
             }
             // Now do stuff with it
             switch ($mode) {
                 default:
                 case 'normal':
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount;
                     break;
                 case 'cumulative':
                     $cumulative += $currentPeriodCount;
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative;
                     break;
                 case 'delta':
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount - $previous;
                     $previous = $currentPeriodCount;
                     break;
             }
             $currentObject->add(1, $chunk);
         } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
         // Remove some grid lines if there are too many
         $xsteps = 1;
         if (count($data) > 100) {
             $xsteps = ceil(count($data) / 100);
         }
         $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject);
         echo Zend_Json::encode(array('json' => $data, 'title' => $title));
     } else {
         $selectClick = $staTable->select();
         // Get data
         if (count($adList)) {
             $selectClick->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             $selectClick->where("type = 'click'");
             $clickData = $staTable->fetchAll($selectClick);
         } else {
             $clickData = array();
         }
         $selectImpression = $staTable->select();
         // Get data
         if (count($adList)) {
             $selectImpression->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             $selectImpression->where("type = 'impression'");
             $impressionData = $staTable->fetchAll($selectImpression);
         } else {
             $impressionData = array();
         }
         // Now create data structure
         $currentObject = clone $startObject;
         $nextObject = clone $startObject;
         $dataClick = array();
         $dataImpression = array();
         $dataLabels = array();
         $cumulativeClick = 0;
         $cumulativeIm = 0;
         $previousClick = 0;
         $previousIm = 0;
         do {
             $nextObject->add(1, $chunk);
             $currentObjectTimestamp = $currentObject->getTimestamp();
             $nextObjectTimestamp = $nextObject->getTimestamp();
             $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick;
             $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm;
             // Get everything that matches
             $currentPeriodCountClick = 0;
             foreach ($clickData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCountClick += 1;
                 }
             }
             $currentPeriodCountIm = 0;
             foreach ($impressionData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCountIm += 1;
                 }
             }
             // Now do stuff with it
             switch ($mode) {
                 default:
                 case 'normal':
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm;
                     break;
                 case 'cumulative':
                     $cumulativeClick += $currentPeriodCountClick;
                     $cumulativeIm += $currentPeriodCountIm;
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm;
                     break;
                 case 'delta':
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick - $previousClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm - $previousIm;
                     $previousClick = $currentPeriodCountClick;
                     $previousIm = $currentPeriodCountIm;
                     break;
             }
             $currentObject->add(1, $chunk);
         } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
         // Remove some grid lines if there are too many
         $xsteps = 1;
         if (count($dataClick) > 100) {
             $xsteps = ceil(count($dataClick) / 100);
         }
         $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject);
         echo Zend_Json::encode(array('json' => $dataClick, 'title' => $title, 'json2' => $dataImpression));
     }
     return true;
 }
 public function teardown()
 {
     Zend_Date::setOptions($this->_options);
 }
Пример #25
0
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return void
  */
 public function init()
 {
     Zend_Date::setOptions($this->getOptions());
 }
Пример #26
0
 protected function _initCache()
 {
     $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 7200, 'automatic_serialization' => true), array('cache_dir' => getcwd() . "/data/cache"));
     Zend_Db_Table::setDefaultMetadataCache($cache);
     Zend_Date::setOptions(array('cache' => $cache));
 }
Пример #27
0
$logger = new Zend_Log($writer);
/*
 * log file - end
 */
if (!is_writable('./tmp/cache')) {
    simpleInvoicesError('notWriteable', 'file', './tmp/cache');
}
/*
 * Zend Framework cache section - start
 * -- must come after the tmp dir writeable check
 */
$backendOptions = array('cache_dir' => './tmp/');
// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
//required for some servers
Zend_Date::setOptions(array('cache' => $cache));
// Active aussi pour Zend_Locale
/*
 * Zend Framework cache section - end
 */
$smarty = new Smarty();
$smarty->debugging = false;
//cache directory. Have to be writeable (chmod 777)
$smarty->compile_dir = "tmp/cache";
if (!is_writable($smarty->compile_dir)) {
    simpleInvoicesError("notWriteable", 'folder', $smarty->compile_dir);
    //exit("Simple Invoices Error : The folder <i>".$smarty -> compile_dir."</i> has to be writeable");
}
//adds own smarty plugins
$smarty->plugins_dir = array("plugins", "include/smarty_plugins");
//add stripslash smarty function
Пример #28
0
 public function chartDataAction()
 {
     // Disable layout and viewrenderer
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     // Get params
     $type = $this->_getParam('type');
     $start = $this->_getParam('start');
     $offset = $this->_getParam('offset', 0);
     $mode = $this->_getParam('mode');
     $chunk = $this->_getParam('chunk');
     $period = $this->_getParam('period');
     $periodCount = $this->_getParam('periodCount', 1);
     //$end = $this->_getParam('end');
     // Validate chunk/period
     if (!$chunk || !in_array($chunk, $this->_periods)) {
         $chunk = Zend_Date::DAY;
     }
     if (!$period || !in_array($period, $this->_periods)) {
         $period = Zend_Date::MONTH;
     }
     if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) {
         die('whoops');
         return;
     }
     // Validate start
     if ($start && !is_numeric($start)) {
         $start = strtotime($start);
     }
     if (!$start) {
         $start = time();
     }
     // Fixes issues with month view
     Zend_Date::setOptions(array('extend_month' => true));
     // Get timezone
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     $viewer = Engine_Api::_()->user()->getViewer();
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     // Make start fit to period?
     $startObject = new Zend_Date($start);
     $startObject->setTimezone($timezone);
     $partMaps = $this->_periodMap[$period];
     foreach ($partMaps as $partType => $partValue) {
         $startObject->set($partValue, $partType);
     }
     // Do offset
     if ($offset != 0) {
         $startObject->add($offset, $period);
     }
     // Get end time
     $endObject = new Zend_Date($startObject->getTimestamp());
     $endObject->setTimezone($timezone);
     $endObject->add($periodCount, $period);
     $endObject->sub(1, Zend_Date::SECOND);
     // Subtract one second
     // Get data
     $statsTable = Engine_Api::_()->getDbtable('statistics', 'core');
     $statsSelect = $statsTable->select()->where('type = ?', $type)->where('date >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('date < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('date ASC');
     $rawData = $statsTable->fetchAll($statsSelect);
     // Now create data structure
     $currentObject = clone $startObject;
     $nextObject = clone $startObject;
     $data = array();
     $dataLabels = array();
     $cumulative = 0;
     $previous = 0;
     do {
         $nextObject->add(1, $chunk);
         $currentObjectTimestamp = $currentObject->getTimestamp();
         $nextObjectTimestamp = $nextObject->getTimestamp();
         $data[$currentObjectTimestamp] = $cumulative;
         // Get everything that matches
         $currentPeriodCount = 0;
         foreach ($rawData as $rawDatum) {
             $rawDatumDate = strtotime($rawDatum->date);
             if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                 $currentPeriodCount += $rawDatum->value;
             }
         }
         // Now do stuff with it
         switch ($mode) {
             default:
             case 'normal':
                 $data[$currentObjectTimestamp] = $currentPeriodCount;
                 break;
             case 'cumulative':
                 $cumulative += $currentPeriodCount;
                 $data[$currentObjectTimestamp] = $cumulative;
                 break;
             case 'delta':
                 $data[$currentObjectTimestamp] = $currentPeriodCount - $previous;
                 $previous = $currentPeriodCount;
                 break;
         }
         $currentObject->add(1, $chunk);
     } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
     // Reprocess label
     $labelStrings = array();
     $labelDate = new Zend_Date();
     foreach ($data as $key => $value) {
         $labelDate->set($key);
         $labelStrings[] = $this->view->locale()->toDate($labelDate, array('size' => 'short'));
         //date('D M d Y', $key);
     }
     // Let's expand them by 1.1 just for some nice spacing
     $minVal = min($data);
     $maxVal = max($data);
     $minVal = floor($minVal * ($minVal < 0 ? 1.1 : 1 / 1.1) / 10) * 10;
     $maxVal = ceil($maxVal * ($maxVal > 0 ? 1.1 : 1 / 1.1) / 10) * 10;
     // Remove some labels if there are too many
     $xlabelsteps = 1;
     if (count($data) > 10) {
         $xlabelsteps = ceil(count($data) / 10);
     }
     // Remove some grid lines if there are too many
     $xsteps = 1;
     if (count($data) > 100) {
         $xsteps = ceil(count($data) / 100);
     }
     // Create base chart
     require_once 'OFC/OFC_Chart.php';
     // Make x axis labels
     $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
     $x_axis_labels->set_steps($xlabelsteps);
     $x_axis_labels->set_labels($labelStrings);
     // Make x axis
     $labels = new OFC_Elements_Axis_X();
     $labels->set_labels($x_axis_labels);
     $labels->set_colour("#416b86");
     $labels->set_grid_colour("#dddddd");
     $labels->set_steps($xsteps);
     // Make y axis
     $yaxis = new OFC_Elements_Axis_Y();
     $yaxis->set_range($minVal, $maxVal);
     $yaxis->set_colour("#416b86");
     $yaxis->set_grid_colour("#dddddd");
     // Make data
     $graph = new OFC_Charts_Line();
     $graph->set_values(array_values($data));
     $graph->set_colour("#5ba1cd");
     // Make title
     $locale = Zend_Registry::get('Locale');
     $translate = Zend_Registry::get('Zend_Translate');
     $titleStr = $translate->_('_CORE_ADMIN_STATS_' . strtoupper(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $type), '_')));
     $title = new OFC_Elements_Title($titleStr . ': ' . $this->view->locale()->toDateTime($startObject) . ' to ' . $this->view->locale()->toDateTime($endObject));
     $title->set_style("{font-size: 14px;font-weight: bold;margin-bottom: 10px; color: #777777;}");
     // Make full chart
     $chart = new OFC_Chart();
     $chart->set_bg_colour('#ffffff');
     $chart->set_x_axis($labels);
     $chart->add_y_axis($yaxis);
     $chart->add_element($graph);
     $chart->set_title($title);
     // Send
     $this->getResponse()->setBody($chart->toPrettyString());
 }
Пример #29
0
<?php

require 'Zend/Date.php';
Zend_Date::setOptions(array('format_type' => 'php'));
$date = Zend_Date::now();
$date1 = Zend_Date::now();
$date1->addMonth(1);
var_dump($date->compare($date1));
Пример #30
-1
 /**
  * @ZF-9085
  */
 public function testGettingMonthWhenUsingGNU()
 {
     Zend_Date::setOptions(array('format_type' => 'php'));
     $date = new Zend_Date(array('day' => 1, 'month' => 4, 'year' => 2008));
     $date2 = $date->getMonth();
     $result = $date2->toArray();
     $this->assertEquals(1970, $result['year']);
 }