Пример #1
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/disable_timestamp_timezone_adjustment')) {
             $dateObj = new Zend_Date();
             $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP);
         }
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/zend_date_gmt_offset')) {
                 // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, we replace + with - below if affected by this.
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
             } else {
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
             }
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
 public function Format($format = null, $localized = true)
 {
     if ($this->value) {
         $zendDate = new Zend_Date($this->getValue(), 'y-MM-dd');
         if ($localized) {
             $zendDate->setLocale(i18n::get_locale());
         }
         return $zendDate->toString($format);
     }
 }
Пример #3
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);
     }
 }
Пример #4
0
 /**
  * Imprime a data no formato correto
  *
  * @param date   $d      Data a ser impressa
  * @param string $format Formato da data
  * @param string $locale Localização da data
  *
  */
 public function getTime($d, $format = null, $locale = null)
 {
     // Define o formato
     if (!isset($format)) {
         $format = Zend_Date::ISO_8601;
     } elseif ($format == 'twitter') {
         $format = 'EEE MMM dd HH:mm:ss ZZZ yyyy';
         $locale = 'en_US';
     } elseif ($format == 'fb') {
         $format = 'EEE, MMM dd yyyy HH:mm:ss ZZZ';
         $locale = 'en_US';
     }
     // Cria a data
     $date = new Zend_Date($d, $format, $locale);
     $date->setLocale('pt_BR')->setTimezone('America/Sao_Paulo');
     if ($date->get('Y') == 0) {
         $date->set(date('Y'), 'Y');
     }
     //echo "<br/><b>$d  => " . $date->get('Y') .'</b>';
     // Calcula a diferença
     $now = time();
     $time = $now - $date->getTimestamp();
     // Formata a hora
     if ($time < 60) {
         $time .= ' segundos';
     } elseif ($time < 3600) {
         //60*60
         $time = round(floatval($time) / 60) . ' minutos';
     } elseif ($time < 7200) {
         //60*60*2
         $time = round(floatval($time) / 3660) . ' hora';
     } elseif ($time < 86400) {
         //60*60*24
         $time = round(floatval($time) / 3660) . ' horas';
     } elseif ($time < 604800) {
         //60*60*24*30
         $time = round(floatval($time) / 86400) . ' dias';
     } elseif ($time > 1209600 && $time <= 2592000) {
         //60*60*24*(7*4)
         $time = round(floatval($time) / 604800) . ' semanas';
     } elseif ($time > 2592000 && $time <= 5184000) {
         //60*60*24*30 && 60*60*24*30*2
         $time = round(floatval($time) / 2592000) . ' mês';
     } elseif ($time > 5184000 && $time < 31104000) {
         //60*60*24*30*2  && 60*60*24*30*12
         $time = round(floatval($time) / 2592000) . ' meses';
     } else {
         //if ($time < 31104000) { //60*60*24*30*12
         $time = ' mais de um ano (' . $date->toString() . ')';
     }
     return $time;
 }
Пример #5
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Пример #6
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, replace + with - below if you're affected by this.
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Пример #7
0
 public function getAudiences($options)
 {
     $success = true;
     $table = Engine_Api::_()->getItemTable('user');
     $userTableName = $table->info('name');
     $searchTable = Engine_Api::_()->fields()->getTable('user', 'search');
     $searchTableName = $searchTable->info('name');
     $targetAvailable = $searchTable->info('cols');
     $select = $table->select()->from($userTableName)->joinLeft($searchTableName, "`{$searchTableName}`.`item_id` = `{$userTableName}`.`user_id`", null)->where("{$userTableName}.search = ?", 1)->where("{$userTableName}.enabled = ?", 1);
     if ($options['birthdate']['min'] == '0') {
         $options['birthdate']['min'] = null;
     }
     if ($options['birthdate']['max'] == '0') {
         $options['birthdate']['max'] = null;
     }
     if ($options['gender'] == '0') {
         unset($options['gender']);
     }
     if ($options['profile_type'] == '0') {
         unset($options['profile_type']);
     }
     if (in_array('city', $targetAvailable)) {
         if (!empty($options['cities'])) {
             $cities = explode(',', $options['cities']);
             $trimmed_cities = array_map('trim', $cities);
             unset($options['cities']);
             if (count($trimmed_cities)) {
                 $select->where('city IN (?)', $trimmed_cities);
             }
         }
     }
     if (in_array('country', $targetAvailable)) {
         if (isset($options['countries'])) {
             $countries = $options['countries'];
             unset($options['countries']);
             if (count($countries)) {
                 $select->where('country IN (?)', $countries);
             }
         }
     }
     if (in_array('interests', $targetAvailable)) {
         if ($options['interests']) {
             $interests = explode(',', $options['interests']);
             $trimmed_interests = array_map('trim', $interests);
             unset($options['interests']);
             if (count($trimmed_interests)) {
                 $select->where('interests IN (?)', $trimmed_interests);
             }
         }
     }
     if ($options['birthday']) {
         $current = new Zend_Date();
         $current->setLocale();
         $select->where('birthdate = ?', $current->get('YYYY-MM-dd'));
     }
     if (isset($options['networks'])) {
         $networks = $options['networks'];
         if (count($networks)) {
             $membershipTbl = Engine_Api::_()->getDbtable('membership', 'network');
             $membershipTblName = $membershipTbl->info('name');
             $users = array();
             $newSelect = $membershipTbl->select()->from($membershipTblName, 'user_id')->where('resource_id IN (?)', $networks);
             $usersRes = $membershipTbl->fetchAll($newSelect);
             $usersRes = $usersRes->toArray();
             foreach ($usersRes as $user) {
                 $users[] = $user['user_id'];
             }
             if (count($user)) {
                 $select->where('user_id IN (?)', $users);
             } else {
                 $success = false;
             }
         }
     }
     $searchParts = Engine_Api::_()->fields()->getSearchQuery('user', $options);
     foreach ($searchParts as $k => $v) {
         $select->where("`{$searchTableName}`.{$k}", $v);
     }
     if ($success) {
         $result = $table->fetchAll($select);
         return $result;
     } else {
         return array();
     }
 }
Пример #8
0
 /**
  * test setLocale/getLocale
  */
 public function testSetLocale()
 {
     $date = new Zend_Date(0, 'de');
     $this->assertSame('de', $date->getLocale());
     $date->setLocale('en');
     $this->assertSame('en', $date->getLocale());
     $date->setLocale('en_XX');
     $this->assertSame('en', $date->getLocale());
     $date->setLocale('de_AT');
     $this->assertSame('de_AT', $date->getLocale());
     $locale = new Zend_Locale('ar');
     $date->setLocale($locale);
     $this->assertSame('ar', $date->getLocale());
     try {
         $date->setLocale('xx_XX');
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
Пример #9
0
 /**
  * @return Zend_Date
  */
 static function getDateService($date = null)
 {
     $locale = DevblocksPlatform::getLocaleService();
     $date = new Zend_Date($date);
     $date->setLocale($locale);
     return $date;
 }
Пример #10
0
 /**
  * Test accessors for _Locale member property of Zend_Date
  */
 public function testLocale()
 {
     $date = new Zend_Date(Zend_Date::now());
     $locale = new Zend_Locale('en_Us');
     $set = $date->setLocale($locale);
     $this->assertSame($date->getLocale(), $set);
 }
Пример #11
0
 public function indexAction()
 {
     if (!$this->_helper->requireUser->isValid()) {
         return;
     }
     $viewer = Engine_Api::_()->user()->getViewer();
     $sysTimezone = date_default_timezone_get();
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     $this->view->timezone = $timezone;
     if (null == ($campaign_id = $this->_getParam('campaign_id'))) {
         $campaign_id = 0;
     }
     if (null == ($ad_id = $this->_getParam('ad_id'))) {
         $ad_id = 0;
     }
     if (null == ($export = $this->_getParam('export'))) {
         $export = 0;
     }
     if (null == ($export_type = $this->_getParam('export_type'))) {
         $export_type = 'xls';
     }
     $this->view->form = $form = new Ynsocialads_Form_Report_Filter();
     $form->populate($this->_getAllParams());
     $values = $form->getValues();
     $this->view->formValues = $values;
     if ($this->_hasParam('end_date')) {
         $end = $this->_getParam('end_date');
         if ($end && !is_numeric($end)) {
             $end_date = strtotime($end);
         } else {
             if ($end) {
                 $end_date = $end;
             }
         }
         $end_date = new Zend_Date($end_date);
     } else {
         $end_date = new Zend_Date();
     }
     if ($this->_hasParam('start_date')) {
         $start = $this->_getParam('start_date');
         if ($start && !is_numeric($start)) {
             $start_date = strtotime($start);
         } else {
             if ($start) {
                 $start_date = $start;
             }
         }
         $start_date = new Zend_Date($start_date);
     } else {
         $start_date = new Zend_Date($end_date->getTimestamp());
         $start_date->sub(1, 'dd');
     }
     $form->start_date->setValue($start_date->setLocale()->get('MM/dd/yyyy'));
     $form->end_date->setValue($end_date->setLocale()->get('MM/dd/yyyy'));
     $end_date->setTimezone($sysTimezone);
     $start_date->setTimezone($sysTimezone);
     $campaignTbl = Engine_Api::_()->getItemTable('ynsocialads_campaign');
     $select = $campaignTbl->select()->where('user_id = ?', $viewer->getIdentity());
     $campaigns = $campaignTbl->fetchAll($select);
     foreach ($campaigns as $campaign) {
         $form->campaign_id->addMultiOption($campaign['campaign_id'], $campaign['title']);
     }
     $form->campaign_id->setValue($campaign_id);
     $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads');
     $adTotal = array();
     if ($campaign_id == 0) {
         $form->ad_id->setAttrib('disabled', 'disabled');
         foreach ($campaigns as $campaign) {
             $adList = $adTbl->fetchAll($adTbl->select()->where('campaign_id = ?', $campaign['campaign_id']));
             foreach ($adList as $ad) {
                 $adTotal[] = $ad->ad_id;
             }
         }
     } else {
         $ads = $adTbl->fetchAll($adTbl->select('ad_id')->where('campaign_id = ?', $campaign_id));
         foreach ($ads as $ad) {
             $form->ad_id->addMultiOption($ad['ad_id'], $ad['name']);
             if ($ad_id == 0) {
                 array_push($adTotal, $ad['ad_id']);
             }
         }
         if ($ad_id != 0) {
             $adTotal = array($ad_id);
         }
         $form->ad_id->setValue($ad_id);
     }
     $staTable = Engine_Api::_()->getDbtable('tracks', 'ynsocialads');
     $staName = $staTable->info('name');
     $select = $staTable->select();
     $select->where('ad_id IN (?)', $adTotal)->where('date >= ?', $start_date->get('yyyy-MM-dd'))->where('date <= ?', $end_date->get('yyyy-MM-dd'))->order('ad_id ASC');
     if (count($adTotal)) {
         $tracks = $staTable->fetchAll($select);
     } else {
         $tracks = array();
     }
     if ($export == 0) {
         $page = $this->_getParam('page', 1);
         $this->view->paginator = $paginator = Zend_Paginator::factory($tracks);
         $this->view->paginator->setItemCountPerPage(10);
         $this->view->paginator->setCurrentPageNumber($page);
         $this->_helper->content->setEnabled();
     } else {
         //export to file
         $filename = "/tmp/csv-" . date("m-d-Y") . ".csv";
         $realPath = realpath($filename);
         if (false === $realPath) {
             touch($filename);
             chmod($filename, 0777);
         }
         $filename = realpath($filename);
         $handle = fopen($filename, "w");
         $finalData[] = array(utf8_decode($this->view->translate('Date')), utf8_decode($this->view->translate('Ad')), utf8_decode($this->view->translate('Campaign')), utf8_decode($this->view->translate('Start Date')), utf8_decode($this->view->translate('End Date')), utf8_decode($this->view->translate('Running Date')), utf8_decode($this->view->translate('Reaches')), utf8_decode($this->view->translate('Impressions')), utf8_decode($this->view->translate('Clicks')), utf8_decode($this->view->translate('Unique Clicks')));
         foreach ($tracks as $item) {
             $ad = Engine_Api::_()->getItem('ynsocialads_ad', $item['ad_id']);
             $date = new Zend_Date(strtotime($item['date']));
             $finalData[] = array($date->setLocale()->get(Zend_Date::DATE_LONG), $ad->getTitle(), $ad->getCampaign()->getTitle(), $ad->start_date ? utf8_decode($ad->getStartDate()->setLocale()->get(Zend_Date::DATE_LONG)) : '', $ad->end_date ? utf8_decode($ad->getEndDate()->setLocale()->get(Zend_Date::DATE_LONG)) : '', $ad->getRunningDate()->setLocale()->get(Zend_Date::DATE_LONG), $item['reaches'], $item['impressions'], $item['clicks'], $item['unique_clicks']);
         }
         if ($export_type == 'xls') {
             $xls = new Ynsocialads_Api_ExcelExport('UTF-8', false, $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY'));
             $xls->addArray($finalData);
             $xls->generateXML('campaign' . $campaign_id . '_ad' . $ad_id . '_' . $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY'));
             exit;
         } else {
             foreach ($finalData as $finalRow) {
                 fputcsv($handle, $finalRow);
             }
             fclose($handle);
             $this->_helper->layout->disableLayout();
             $this->_helper->viewRenderer->setNoRender();
             $csvname = 'campaign' . $campaign_id . '_ad' . $ad_id . '_' . $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY') . '.csv';
             $this->getResponse()->setRawHeader("Content-Type: application/csv; charset=UTF-8")->setRawHeader("Content-Disposition: attachment; filename=" . $csvname)->setRawHeader("Content-Transfer-Encoding: binary")->setRawHeader("Expires: 0")->setRawHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0")->setRawHeader("Pragma: public")->setRawHeader("Content-Length: " . filesize($filename))->sendResponse();
             // fix for print out data
             readfile($filename);
             unlink($filename);
             exit;
         }
     }
 }
#!/usr/bin/php
<?php 
require_once dirname(__FILE__) . '/../../common.php';
$date = new Zend_Date();
$date->setLocale(LOCALE);
$phpLiveDocx = new Tis_Service_LiveDocx_MailMerge(USERNAME, PASSWORD);
$phpLiveDocx->setLocalTemplate('template.docx');
$phpLiveDocx->assign('software', 'ACE Downloader 2.8');
$phpLiveDocx->assign('licensee', 'Paul Peterson');
$phpLiveDocx->assign('company', 'Bresoft Ltd');
$phpLiveDocx->assign('date', $date->get(Zend_Date::DATE_LONG));
$phpLiveDocx->assign('time', $date->get(Zend_Date::TIME_LONG));
$phpLiveDocx->assign('city', 'Royal Tunbridge Wells');
$phpLiveDocx->assign('country', 'United Kingdom');
$phpLiveDocx->createDocument();
foreach ($phpLiveDocx->getDocumentFormats() as $format) {
    $documentFile = sprintf('document.%s', $format);
    printf('Retrieving %s version (%s)... ', strtoupper($format), $documentFile);
    $document = $phpLiveDocx->retrieveDocument($format);
    file_put_contents($documentFile, $document);
    print "DONE.\n";
}
unset($phpLiveDocx);
Пример #13
0
 public function getDate()
 {
     $dateObj = new Zend_Date($this->getCreatedAt(), Zend_Date::ISO_8601);
     $dateObj->setLocale(Mage::app()->getLocale()->getLocaleCode());
     return $dateObj->toString(Zend_Date::DATETIME_MEDIUM);
 }
Пример #14
0
 function localDate($date, $lang)
 {
     $date = new Zend_Date($date);
     $date->setLocale($lang);
     return $date->toString(Zend_Date::DATE_FULL);
 }