Example #1
0
 public function getSavedTime()
 {
     $seconds = intval(Mage::helper('asyncindex')->getVariable('time'));
     $time = new Zend_Date();
     $time->setTime('00:00:00');
     $time->addSecond($seconds);
     return $time->toString('HH') . ' hr ' . $time->toString('mm') . ' min ' . $time->toString('ss') . ' sec';
 }
Example #2
0
 public function weeklystatsAction()
 {
     $this->disableLayout();
     $this->disableViewAutoRender();
     $type = $this->getParam('type');
     $end = new Zend_Date();
     $end->setTime('23:59:59');
     $date = new Zend_Date();
     $date->sub(6, Zend_Date::DAY);
     $date->setTime('00:00:01');
     //Build reference array
     $i = 0;
     //echo $end->getTimestamp(); echo "<br>";
     while ($i <= 6) {
         $referencearray[$date->get('dd-MM-YYYY')] = 0;
         $date->add(1, Zend_Date::DAY);
         $i++;
     }
     //Get the results array
     $start = new Zend_date();
     $start->sub(6, Zend_Date::DAY);
     $start->setTime('00:00:01');
     $stat = new \Object\Stats();
     $results = $stat->getStatistics($this->selectedLocation->getId(), $start, $end);
     $startoftheweek = $start->get('dd-MM-YYYY');
     //echo $start->getTimestamp(); echo "<br>";exit;
     foreach ($this->selectedLocation->getServings() as $serving) {
         //initiate orderarray and seatsarray
         $orderarray = $referencearray;
         $seatsarray = $referencearray;
         foreach ($results as $result) {
             $datein = date("d-m-Y", $result["date_start"]);
             if ($serving->getId() == $result['serving_id']) {
                 $servingid = $result['serving_id'];
                 if (array_key_exists($datein, $referencearray)) {
                     $orderarray[$datein] = $result["nbre"];
                     $seatsarray[$datein] = $result["couverts"];
                 }
             }
         }
         if ($type == 'seats') {
             $servingarray[$serving->getTitle()] = $seatsarray;
         } else {
             $servingarray[$serving->getTitle()] = $orderarray;
         }
     }
     $reponse = new Reponse();
     $reponse->data = $servingarray;
     $reponse->message = "TXT_STATS_SENT";
     $reponse->success = true;
     $this->render($reponse);
 }
Example #3
0
    public function portalAction()
    {
        $this->view->location = $this->selectedLocation;
        $servings = $this->selectedLocation->getServings();
        $this->view->count = count($servings);
        $start = new Zend_Date();
        $start->setTime("00:01:00");
        $end = new Zend_Date();
        $end->setTime("23:59:59");
        $this->view->reporttodaydata = $this->selectedLocation->getResource()->getRapportReservations($start, $end);
        $start->addDay(1);
        $end->addDay(1);
        $this->view->reporttomorrowdata = $this->selectedLocation->getResource()->getRapportReservations($start, $end);
        $this->view->servingarray = $servingarray;
        foreach ($servings as $serving) {
            $array['nbre'] = 0;
            $array['couverts'] = 0;
            $array['name'] = $serving->getTitle();
            foreach ($this->view->reporttodaydata as $report) {
                if ($report['serving_id'] == $serving->getId()) {
                    $array['nbre'] = $report['nbre'];
                    $array['couverts'] = $report['couverts'];
                }
            }
            $resulttoday[$serving->getId()] = $array;
        }
        $this->view->todayreport = $resulttoday;
        foreach ($servings as $serving) {
            $array['nbre'] = 0;
            $array['couverts'] = 0;
            $array['name'] = $serving->getTitle();
            foreach ($this->view->reporttomorrowdata as $report) {
                if ($report['serving_id'] == $serving->getId()) {
                    $array['nbre'] = $report['nbre'];
                    $array['couverts'] = $report['couverts'];
                }
            }
            $resulttomorrow[$serving->getId()] = $array;
        }
        $this->view->tomorrowreport = $resulttomorrow;
        $this->layout()->setLayout('portal');
        $this->view->headScript()->appendFile(PIMCORE_WEBSITE_LAYOUTS . '/assets/plugins/jquery.sparkline/jquery.sparkline.js');
        $this->view->headScript()->appendFile(PIMCORE_WEBSITE_LAYOUTS . '/assets/js/timepicker-form-elements.js');
        $this->view->headScript()->appendFile(PIMCORE_WEBSITE_LAYOUTS . '/assets/js/index.js');
        $this->view->headScript()->appendFile(PIMCORE_WEBSITE_LAYOUTS . '/assets/js/stats.js');
        $this->view->inlineScript()->appendScript('jQuery(document).ready(function() { 
					Main.init();
					StatisticsForm.init();
					Index.init();
				});', 'text/javascript', array('noescape' => true));
        // Disable CDATA comments
    }
 public function getTotal($type, $start = null, $end = null)
 {
     $select = new Zend_Db_Select($this->getAdapter());
     $select->from($this->info('name'), 'SUM(value) as sum')->where('type = ?', $type);
     // Can pass "today" into start
     $date = new Zend_Date();
     $date->setTimezone(Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'));
     switch ($start) {
         case 'day':
             $start = $date->setTime('00:00:00')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") + 1, gmdate("Y"));
             break;
         case 'week':
             $start = $date->setTime('00:00:00')->setWeekday(0)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") - gmdate('N') + 1, gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") - gmdate('N') + 1 + 7, gmdate("Y"));
             break;
         case 'month':
             $start = $date->setTime('00:00:00')->setDate(1)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n") + 1, gmdate("j"), gmdate("Y"));
             break;
         case 'year':
             $start = $date->setTime('00:00:00')->setDayOfYear(1)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y") + 1);
             break;
     }
     if (null !== $start) {
         $select->where('date >= ?', gmdate('Y-m-d H:i:s', $start));
     }
     if (null !== $end) {
         $select->where('date < ?', gmdate('Y-m-d H:i:s', $end));
     }
     $data = $select->query()->fetch();
     if (!isset($data['sum'])) {
         return 0;
     }
     return $data['sum'];
 }
Example #5
0
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     //insert field values
     if (count($object->getData('field')) > 0) {
         foreach ($object->getData('field') as $field_id => $value) {
             if (is_array($value)) {
                 $value = implode("\n", $value);
             }
             $field = Mage::getModel('webforms/fields')->load($field_id);
             if (strstr($field->getType(), 'date') && strlen($value) > 0) {
                 $date = new Zend_Date();
                 $date->setDate($value, $field->getDateFormat(), Mage::app()->getLocale()->getLocaleCode());
                 if ($field->getType() == 'datetime') {
                     $date->setTime($value, $field->getDateFormat(), Mage::app()->getLocale()->getLocaleCode());
                 }
                 $value = date($field->getDbDateFormat(), $date->getTimestamp());
             }
             if ($field->getType() == 'select/contact' && is_numeric($value)) {
                 $value = $field->getContactValueById($value);
             }
             if ($value == $field->getHint()) {
                 $value = '';
             }
             // create key
             $key = "";
             if ($field->getType() == 'file' || $field->getType() == 'image') {
                 $key = Mage::helper('webforms')->randomAlphaNum(6);
                 if ($object->getData('key_' . $field_id)) {
                     $key = $object->getData('key_' . $field_id);
                 }
             }
             $object->setData('key_' . $field_id, $key);
             $select = $this->_getReadAdapter()->select()->from($this->getTable('webforms/results_values'))->where('result_id = ?', $object->getId())->where('field_id = ?', $field_id);
             $result_value = $this->_getReadAdapter()->fetchAll($select);
             if (!empty($result_value[0])) {
                 $this->_getWriteAdapter()->update($this->getTable('webforms/results_values'), array("value" => $value, "key" => $key), "id = " . $result_value[0]['id']);
             } else {
                 $this->_getWriteAdapter()->insert($this->getTable('webforms/results_values'), array("result_id" => $object->getId(), "field_id" => $field_id, "value" => $value, "key" => $key));
             }
         }
     }
     Mage::dispatchEvent('webforms_result_save', array('result' => $object));
     return parent::_afterSave($object);
 }
Example #6
0
 public function testPhpFormatWithToString()
 {
     Zend_Date::setOptions(array('format_type' => 'php'));
     $date = new Zend_Date('10.10.2009 10:10:10');
     $this->assertEquals('10.10.2009 10:10:10', $date->toString("d.m.Y H:i:s"));
     $date->setTime("23:59:59");
     $this->assertEquals('10.10.2009 23:59:59', $date->toString("d.m.Y H:i:s"));
 }
Example #7
0
 /**
  * test looseBehaviour
  */
 public function testLoose()
 {
     $date = new Zend_Date(0, 'de');
     try {
         $date->set(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->set(10, 'de');
     $this->assertEquals($date->getTimestamp(), 10);
     try {
         $date->add(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->add(10, 'de');
     $this->assertEquals($date->getTimestamp(), 20);
     try {
         $date->sub(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->sub(10, 'de');
     $this->assertEquals($date->getTimestamp(), 10);
     try {
         $date->compare(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->equals(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isEarlier(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isLater(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
Example #8
0
 /**
  * Test for setTime
  */
 public function testSetTime()
 {
     $locale = new Zend_Locale('de_AT');
     $date = new Zend_Date(1234567890, null, $locale);
     $d2 = new Zend_Date(1234567899, null, $locale);
     $result = $date->setTime(Zend_Date::now());
     $this->assertTrue($result instanceof Zend_Date);
     $result = $date->setTime('10:20:30');
     $this->assertSame($result->get(Zend_Date::W3C), '2009-02-14T10:20:30+01:00');
     $this->assertSame($date->get(Zend_Date::W3C), '2009-02-14T10:20:30+01:00');
     $date->setTime('30-20-10', 'ss:mm:HH');
     $this->assertSame($date->get(Zend_Date::W3C), '2009-02-14T10:20:30+01:00');
     $date->setTime($d2);
     $this->assertSame($date->get(Zend_Date::W3C), '2009-02-14T00:31:39+01:00');
     $date = new Zend_Date(Zend_Date::now(), $locale);
     $t1 = $date->get(Zend_Date::TIMESTAMP);
     $date->setTime(Zend_Date::now());
     $t2 = $date->get(Zend_Date::TIMESTAMP);
     $diff = abs($t2 - $t1);
     $this->assertTrue($diff < 2, "Instance of Zend_Date has a significantly different time than returned by setTime(): {$diff} seconds");
 }
Example #9
0
 protected function mapDirectiveSalePriceEffectiveDate($params = array())
 {
     $map = $params['map'];
     $product = $this->getProduct();
     /* @var $product Mage_Catalog_Model_Product */
     $cell = "";
     if (!$this->hasSpecialPrice()) {
         return $cell;
     }
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     $fromDate->setDate(substr($product->getSpecialFromDate(), 0, 10), 'yyyy-MM-dd');
     $fromDate->setTime(substr($product->getSpecialFromDate(), 11, 8), 'HH:mm:ss');
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if (!is_empty_date($product->getSpecialToDate())) {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate(substr($product->getSpecialToDate(), 0, 10), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
     } else {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
         $toDate->add(7, Zend_Date::DAY);
     }
     $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601);
     return $cell;
 }
Example #10
0
 protected function mapDirectiveSalePriceEffectiveDate($params = array())
 {
     /** @var $product Mage_Catalog_Model_Product */
     $product = $this->getProduct();
     $assocMapArr = $this->getAssocMaps();
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     $cell = "";
     if (!$this->hasSpecialPrice($product, $this->getSpecialPrice($product))) {
         return $cell;
     }
     $has_default_qty = $this->_hasDefaultQty($assocMapArr);
     $display_min = $this->getConfigVar('grouped_price_display_mode', 'columns');
     if ($has_default_qty) {
         if ($display_min == RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_SUM_DEFAULT_QTY) {
             $product_from_date = $product_to_date = null;
             $from_time = -1;
             $to_time = PHP_INT_MAX;
             foreach ($assocMapArr as $assocMap) {
                 $associatedProduct = $assocMap->getProduct();
                 if ($associatedProduct->getQty() > 0) {
                     if ($assocMap->hasSpecialPrice($associatedProduct, $assocMap->getSpecialPrice($associatedProduct))) {
                         if ($assocMap->hasPriceByCatalogRules($associatedProduct)) {
                             // Current date to cdate + ttl
                             $fromDate = clone $cDate;
                             $fromDate->setTime('00:00:00', 'HH:mm:ss');
                             $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
                             if ($timezone) {
                                 $toDate->setTimezone($timezone);
                             }
                             $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
                             $toDate->setTime('23:59:59', 'HH:mm:ss');
                             $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
                             $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00');
                             $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59');
                         } else {
                             $compare_from_date = $associatedProduct->getSpecialFromDate();
                             $compare_to_date = $associatedProduct->getSpecialToDate();
                         }
                         if ($from_time < $this->dateToTime($compare_from_date)) {
                             $product_from_date = $compare_from_date;
                             $from_time = $this->dateToTime($product_from_date);
                         }
                         if (!is_empty_date($compare_to_date) && $to_time > $this->dateToTime($compare_to_date)) {
                             $product_to_date = $compare_to_date;
                             $to_time = $this->dateToTime($product_to_date);
                         }
                     }
                 }
             }
         } else {
             // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT
             $minAssocMap = $this->findMinimalPriceProduct($assocMapArr);
             if ($minAssocMap === false) {
                 return $cell;
             }
             $associatedProduct = $minAssocMap->getProduct();
             if ($minAssocMap->hasPriceByCatalogRules($associatedProduct)) {
                 // Current date to cdate + ttl
                 $fromDate = clone $cDate;
                 $fromDate->setTime('00:00:00', 'HH:mm:ss');
                 $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
                 if ($timezone) {
                     $toDate->setTimezone($timezone);
                 }
                 $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
                 $toDate->setTime('23:59:59', 'HH:mm:ss');
                 $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
                 $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00');
                 $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59');
             } else {
                 $compare_from_date = $associatedProduct->getSpecialFromDate();
                 $compare_to_date = $associatedProduct->getSpecialToDate();
             }
             $product_from_date = $compare_from_date;
             $product_to_date = $compare_to_date;
         }
     } else {
         // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT
         $minAssocMap = $this->findMinimalPriceProduct($assocMapArr);
         if ($minAssocMap === false) {
             return $cell;
         }
         $associatedProduct = $minAssocMap->getProduct();
         $product_from_date = $associatedProduct->getSpecialFromDate();
         $product_to_date = $associatedProduct->getSpecialToDate();
     }
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     if ($product_from_date) {
         $fromDate->setDate(substr($product_from_date, 0, 10), 'yyyy-MM-dd');
         $fromDate->setTime(substr($product_from_date, 11, 8), 'HH:mm:ss');
     }
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if (!is_empty_date($product_to_date)) {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate(substr($product_to_date, 0, 10), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
     } else {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
         $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
     }
     $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601);
     return $cell;
 }
Example #11
0
 public function toTimestamp($date, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
 {
     $dateFormat = Mage::app()->getLocale()->getDateFormat($format);
     $dateObj = new Zend_Date();
     if ($date) {
         try {
             $dateObj->setDate($date, $dateFormat);
         } catch (Exception $ex) {
             try {
                 $dateObj->setDate($date);
             } catch (Exception $ex) {
                 if ($timestamp = @strtotime($date)) {
                     $dateObj->setTimestamp($timestamp);
                 }
             }
         }
         $dateObj->setTime(0);
     }
     return $dateObj->getTimestamp();
 }
Example #12
0
 /**
  * 
  * @param array $filters
  * @return array
  */
 public function chartSentHour(array $filters = array())
 {
     $date = new Zend_Date();
     // Set the date to search the current month
     $filters['date_ini'] = $date->toString('yyyy-MM-dd');
     $filters['date_fin'] = $date->toString('yyyy-MM-dd');
     // Set the hour to search
     $filters['hour_ini'] = $date->setTime('00:00:00')->toString('HH:mm:ss');
     $filters['hour_fin'] = $date->setTime('23:59:59')->toString('HH:mm:ss');
     // Search just the sending successfully
     $filters['status'] = 'S';
     $sent = $this->sentByHours($filters);
     // Search the erros with errors
     $filters['status'] = 'E';
     $errors = $this->sentByHours($filters);
     $hours = array();
     foreach ($sent as $row) {
         $hours[] = $row->hour;
     }
     foreach ($errors as $row) {
         $hours[] = $row->hour;
     }
     $hours = array_fill_keys(array_unique($hours), array('errors' => 0, 'sent' => 0));
     foreach ($sent as $row) {
         $hours[$row->hour]['sent'] = $row->sent;
     }
     foreach ($errors as $row) {
         $hours[$row->hour]['errors'] = $row->sent;
     }
     $data = array('hours' => array_keys($hours), 'errors' => array(), 'sent' => array());
     foreach ($hours as $row) {
         $data['errors'][] = (int) $row['errors'];
         $data['sent'][] = (int) $row['sent'];
     }
     return $data;
 }
Example #13
0
 /**
  * Return interval (two GMT Zend_Date).
  *
  * @param $code
  * @param bool $timezone
  *
  * @return Varien_Object
  */
 public function getInterval($code, $timezone = false)
 {
     $timestamp = Mage::getSingleton('core/date')->gmtTimestamp();
     if ($timezone) {
         $timestamp = Mage::app()->getLocale()->date($timestamp);
     }
     $from = new Zend_Date($timestamp, null, Mage::app()->getLocale()->getLocaleCode());
     $to = clone $from;
     $dateInterval = null;
     switch ($code) {
         case self::TODAY:
             $from->setTime('00:00:00');
             $to->setTime('23:59:59');
             break;
         case self::YESTERDAY:
             $from->subDay(1)->setTime('00:00:00');
             $to->subDay(1)->setTime('23:59:59');
             break;
         case self::THIS_MONTH:
             $from->setDay(1)->setTime('00:00:00');
             $to->setDay(1)->addDay($to->get(Zend_Date::MONTH_DAYS) - 1)->setTime('23:59:59');
             break;
         case self::PREVIOUS_MONTH:
             $from->setDay(1)->subMonth(1)->setTime('00:00:00');
             $to->setDay(1)->setTime('23:59:59')->subMonth(1)->addDay($to->get(Zend_Date::MONTH_DAYS) - 1);
             break;
         case self::THIS_QUARTER:
             $month = intval($from->get(Zend_Date::MONTH) / 4) * 3 + 1;
             $from->setDay(1)->setMonth($month)->setTime('00:00:00');
             $to->setDay(1)->setMonth($month)->addMonth(3)->subDay(1)->setTime('23:59:59');
             break;
         case self::PREVIOUS_QUARTER:
             $month = intval($from->get(Zend_Date::MONTH) / 4) * 3 + 1;
             $from->setDay(1)->setMonth($month)->setTime('00:00:00')->subMonth(3);
             $to->setDay(1)->setMonth($month)->addMonth(3)->subDay(1)->setTime('23:59:59')->subMonth(3);
             break;
         case self::THIS_YEAR:
             $from->setDay(1)->setMonth(1)->setTime('00:00:00');
             $to->setDay(1)->setMonth(1)->addDay($to->get(Zend_Date::LEAPYEAR) ? 365 : 364)->setTime('23:59:59');
             break;
         case self::PREVIOUS_YEAR:
             $from->setDay(1)->setMonth(1)->setTime('00:00:00')->subYear(1);
             $to->setDay(1)->setMonth(1)->addDay($to->get(Zend_Date::LEAPYEAR) ? 365 : 364)->setTime('23:59:59')->subYear(1);
             break;
         case self::LAST_24H:
             $from->subDay(1);
             break;
         case self::THIS_WEEK:
             $weekday = $from->get(Zend_Date::WEEKDAY_DIGIT);
             #0-6
             $from->setTime('00:00:00')->subDay($weekday);
             $to->setTime('23:59:59')->addDay(6 - $weekday);
             break;
         case self::PREVIOUS_WEEK:
             $weekday = $from->get(Zend_Date::WEEKDAY_DIGIT);
             #0-6
             $from->setTime('00:00:00')->subDay($weekday)->subWeek(1);
             $to->setTime('23:59:59')->addDay(6 - $weekday)->subWeek(1);
             break;
         case self::LAST_7D:
             $from->subDay(7);
             break;
         case self::LAST_30D:
             $from->subDay(30);
             break;
         case self::LAST_3M:
             $from->subMonth(3);
             break;
         case self::LAST_12M:
             $from->subYear(1);
             break;
         case self::LIFETIME:
             $from->subYear(10);
             $to->addYear(10);
             break;
     }
     return new Varien_Object(array('from' => $from, 'to' => $to));
 }
Example #14
0
 /**
  * Sets the internal value to ISO date format, based on either a database value in ISO date format,
  * or a form submssion in the user date format. Uses the individual date and time fields
  * to take care of the actual formatting and value conversion.
  * 
  * Value setting happens *before* validation, so we have to set the value even if its not valid.
  * 
  * Caution: Only converts user timezones when value is passed as array data (= form submission).
  * Weak indication, but unfortunately the framework doesn't support a distinction between
  * setting a value from the database, application logic, and user input.
  * 
  * @param string|array $val String expects an ISO date format. Array notation with 'date' and 'time'
  *  keys can contain localized strings. If the 'dmyfields' option is used for {@link DateField},
  *  the 'date' value may contain array notation was well (see {@link DateField->setValue()}).
  */
 function setValue($val)
 {
     // If timezones are enabled, assume user data needs to be reverted to server timezone
     if ($this->getConfig('usertimezone')) {
         // Accept user input on timezone, but only when timezone support is enabled
         $userTz = is_array($val) && array_key_exists('timezone', $val) ? $val['timezone'] : null;
         if (!$userTz) {
             $userTz = $this->getConfig('usertimezone');
         }
         // fall back to defined timezone
     } else {
         $userTz = null;
     }
     if (empty($val)) {
         $this->value = null;
         $this->dateField->setValue(null);
         $this->timeField->setValue(null);
     } else {
         // Case 1: String setting from database, in ISO date format
         if (is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
             $this->value = $val;
         } elseif (is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) {
             $dataTz = date_default_timezone_get();
             // If timezones are enabled, assume user data needs to be converted to server timezone
             if ($userTz) {
                 date_default_timezone_set($userTz);
             }
             // Uses sub-fields to temporarily write values and delegate dealing with their normalization,
             // actual sub-field value setting happens later
             $this->dateField->setValue($val['date']);
             $this->timeField->setValue($val['time']);
             if ($this->dateField->dataValue() && $this->timeField->dataValue()) {
                 $userValueObj = new Zend_Date(null, null, $this->locale);
                 $userValueObj->setDate($this->dateField->dataValue(), $this->dateField->getConfig('datavalueformat'));
                 $userValueObj->setTime($this->timeField->dataValue(), $this->timeField->getConfig('datavalueformat'));
                 if ($userTz) {
                     $userValueObj->setTimezone($dataTz);
                 }
                 $this->value = $userValueObj->get($this->getConfig('datavalueformat'), $this->locale);
                 unset($userValueObj);
             } else {
                 // Validation happens later, so set the raw string in case Zend_Date doesn't accept it
                 $this->value = sprintf($this->getConfig('datetimeorder'), $val['date'], $val['time']);
             }
             if ($userTz) {
                 date_default_timezone_set($dataTz);
             }
         } else {
             $this->dateField->setValue($val);
             if (is_string($val)) {
                 $this->timeField->setValue($val);
             }
             $this->value = $val;
         }
         // view settings (dates might differ from $this->value based on user timezone settings)
         if (Zend_Date::isDate($this->value, $this->getConfig('datavalueformat'), $this->locale)) {
             $valueObj = new Zend_Date($this->value, $this->getConfig('datavalueformat'), $this->locale);
             if ($userTz) {
                 $valueObj->setTimezone($userTz);
             }
             // Set view values in sub-fields
             if ($this->dateField->getConfig('dmyfields')) {
                 $this->dateField->setValue($valueObj->toArray());
             } else {
                 $this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'), $this->locale));
             }
             $this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'), $this->locale));
         }
     }
 }
 /**
  * @param $product
  * @param $special_price
  * @param $rules
  * @return bool
  */
 public function hasSpecialPrice($product, $special_price, $rules = true)
 {
     if ($rules && $this->hasPriceByCatalogRules($product)) {
         return true;
     }
     if ($special_price <= 0) {
         return false;
     }
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     // From Date
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     $special_from_date = $product->getSpecialFromDate();
     if (is_empty_date($special_from_date)) {
         $special_from_date = $cDate->toString('yyyy-MM-dd HH:mm:ss');
     }
     $fromDate->setDate(substr($special_from_date, 0, 10), 'yyyy-MM-dd');
     $fromDate->setTime(substr($special_from_date, 11, 8), 'HH:mm:ss');
     // To Date
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $toDate->setTimezone($timezone);
     }
     $special_to_date = $product->getSpecialToDate();
     if (is_empty_date($special_to_date)) {
         $special_to_date = $cDate->toString('yyyy-MM-dd HH:mm:ss');
     }
     if (is_empty_date($special_to_date)) {
         $toDate->add(365, Zend_Date::DAY);
     }
     $toDate->setDate(substr($special_to_date, 0, 10), 'yyyy-MM-dd');
     $toDate->setTime(substr($special_to_date, 11, 8), 'HH:mm:ss');
     if (($fromDate->compare($cDate) == -1 || $fromDate->compare($cDate) == 0) && ($toDate->compare($cDate) == 1 || $toDate->compare($cDate) == 0)) {
         return true;
     }
     return false;
 }
 protected function _saveOrder($data)
 {
     $fieldNoEnc = array('customers_id', 'orders_id', 'date_purchased', 'last_modified', 'orders_date_finished', 'orders_products_id', 'osc_magento_id', 'products_id');
     $importModel = $this->getImportModel();
     $timezone = $importModel->getTimezone();
     $customerIdPair = $this->getCustomerIdPair();
     $importId = $importModel->getId();
     $websiteId = $this->getWebsiteModel()->getId();
     if ($data['customers_id'] > 0 && isset($this->_customerIdPair[$data['customers_id']])) {
         foreach ($data as $field => $value) {
             if (!in_array($field, $fieldNoEnc)) {
                 $data[$field] = $this->convert($value);
             }
         }
         if ($data['date_purchased']) {
             $preparePurchased = explode(' ', $data['date_purchased']);
             $dateFormat = 'YYYY-MM-dd HH:mm:ss';
             $datePurchased = new Zend_Date();
             $datePurchased->setTimezone($timezone);
             $datePurchased->setDate($preparePurchased[0], 'YYYY-MM-dd');
             $datePurchased->setTime($preparePurchased[1], 'HH:mm:ss');
             $datePurchased->setTimezone('GMT');
             $data['date_purchased'] = $datePurchased->toString($dateFormat);
         }
         if ($data['last_modified']) {
             $prepareModified = explode(' ', $data['last_modified']);
             $dateModified = new Zend_Date();
             $dateModified->setTimezone($timezone);
             $dateModified->setDate($prepareModified[0], 'YYYY-MM-dd');
             $dateModified->setTime($prepareModified[1], 'HH:mm:ss');
             $dateModified->setTimezone('GMT');
             $data['last_modified'] = $dateModified->toString($dateFormat);
         }
         if ($data['orders_date_finished']) {
             $prepareFinished = explode(' ', $data['orders_date_finished']);
             $dateFinished = new Zend_Date();
             $dateFinished->setTimezone($timezone);
             $dateFinished->setDate($prepareFinished[0], 'YYYY-MM-dd');
             $dateFinished->setTime($prepareFinished[1], 'HH:mm:ss');
             $dateFinished->setTimezone('GMT');
             $data['orders_date_finished'] = $dateFinished->toString($dateFormat);
         }
         $data['magento_customers_id'] = $this->_customerIdPair[$data['customers_id']];
         // get Magento CustomerId
         $data['import_id'] = $importId;
         $data['website_id'] = $websiteId;
         $data['orders_status'] = $data['orders_status_name'];
         unset($data['orders_status_name']);
         $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order'), $data);
         $oscMagentoId = $this->_getWriteAdapter()->lastInsertId();
         $this->_saveRows++;
         // Get orders products
         $select = "SELECT `orders_products_id`, `orders_id`, `products_id` ";
         $select .= ", `products_model`, `products_name`, `products_price`, `final_price` ";
         $select .= ", `products_tax`, `products_quantity` ";
         $select .= " FROM `{$this->getOscTable('orders_products')}` WHERE `orders_id`={$data['orders_id']}";
         if ($orderProducts = $this->_getForeignAdapter()->fetchAll($select)) {
             foreach ($orderProducts as $orderProduct) {
                 unset($orderProduct['orders_id']);
                 unset($orderProduct['orders_products_id']);
                 $orderProduct['osc_magento_id'] = $oscMagentoId;
                 foreach ($orderProduct as $field => $value) {
                     if (!in_array($field, $fieldNoEnc)) {
                         $orderProduct[$field] = $this->convert($value);
                     }
                 }
                 $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_products'), $orderProduct);
             }
         }
         // Get orders totals
         $select = "SELECT `orders_total_id`, `orders_id`, `title`, `text`, `value`, `class`, `sort_order` ";
         $select .= " FROM `{$this->getOscTable('orders_total')}` WHERE `orders_id`={$data['orders_id']} ORDER BY `sort_order`";
         if ($orderTotals = $this->_getForeignAdapter()->fetchAll($select)) {
             foreach ($orderTotals as $orderTotal) {
                 unset($orderTotal['orders_id']);
                 unset($orderTotal['orders_total_id']);
                 $orderTotal['osc_magento_id'] = $oscMagentoId;
                 $orderTotal['title'] = $this->convert($orderTotal['title']);
                 $orderTotal['text'] = $this->convert($orderTotal['text']);
                 $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_total'), $orderTotal);
             }
         }
         $defaultLanguage = $this->getOscDefaultLanguage();
         $defaultLanguageId = $defaultLanguage['id'];
         // Get orders status history
         $select = "SELECT `osh`.`orders_status_history_id`, `osh`.`orders_id`, `osh`.`orders_status_id` ";
         $select .= ", `os`.`orders_status_name` `orders_status`, `osh`.`date_added`, `osh`.`customer_notified`, `osh`.`comments` ";
         $select .= " FROM `{$this->getOscTable('orders_status_history')}` osh ";
         $select .= " LEFT JOIN `{$this->getOscTable('orders_status')}` os ON `os`.`orders_status_id`=`osh`.`orders_status_id` ";
         $select .= " AND `os`.`language_id`={$defaultLanguageId}";
         $select .= " WHERE `osh`.`orders_id`={$data['orders_id']}";
         if ($orderHistories = $this->_getForeignAdapter()->fetchAll($select)) {
             foreach ($orderHistories as $orderHistory) {
                 unset($orderHistory['orders_id']);
                 unset($orderHistory['orders_status_history_id']);
                 $orderHistory['osc_magento_id'] = $oscMagentoId;
                 $prepareAdded = explode(' ', $orderHistory['date_added']);
                 $dateFormat = 'YYYY-MM-dd HH:mm:ss';
                 $dateAdded = new Zend_Date();
                 $dateAdded->setTimezone($timezone);
                 $dateAdded->setDate($prepareAdded[0], 'YYYY-MM-dd');
                 $dateAdded->setTime($prepareAdded[1], 'HH:mm:ss');
                 $dateAdded->setTimezone('GMT');
                 $orderHistory['date_added'] = $dateAdded->toString($dateFormat);
                 $orderHistory['orders_status'] = $this->convert($orderHistory['orders_status']);
                 $orderHistory['comments'] = $this->convert($orderHistory['comments']);
                 $orderHistory['customer_notified'] = $this->convert($orderHistory['customer_notified']);
                 $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_history'), $orderHistory);
             }
         }
     } else {
         $this->_addErrors(Mage::helper('oscommerce')->__('Order #%s failed to import because the customer ID #%s associated with this order could not be found.', $data['orders_id'], $data['customers_id']));
     }
 }
 public function testToStringShouldEqualWithAndWithoutPhpFormat()
 {
     $date = new Zend_Date('22.05.2014');
     $date->setTime('12:00');
     $date->setTimezone('America/Los_Angeles');
     $this->assertEquals($date->toString(Zend_Date::ATOM), $date->toString(DateTime::ATOM, 'php'));
 }
 /**
  * @param $dataTime
  *
  * @return string
  */
 protected function _getEstimatedDate($dataTime)
 {
     $current = new \Zend_Date();
     $current->setTime(0);
     $nextNotificationDate = $current->add($dataTime['shipping'], \Zend_Date::HOUR);
     return $this->_timezone->formatDate('@' . $nextNotificationDate->getTimestamp());
 }
Example #19
0
 /**
  * @param array $params
  * @return string
  */
 protected function mapDirectiveSalePriceEffectiveDate($params = array())
 {
     /** @var $product Mage_Catalog_Model_Product */
     $product = $this->getProduct();
     $cell = "";
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     if ($this->hasPriceByCatalogRules($product)) {
         // Current date to cdate + ttl
         $fromDate = clone $cDate;
         $fromDate->setTime('00:00:00', 'HH:mm:ss');
         $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
         $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
         $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601);
         return $cell;
     }
     $special_from_date = $product->getSpecialFromDate();
     $special_to_date = $product->getSpecialToDate();
     if (!$this->hasSpecialPrice($product, $this->getSpecialPrice($product)) || empty($special_from_date) && empty($special_to_date)) {
         return $cell;
     }
     // From Date
     if (is_empty_date($special_from_date)) {
         $special_from_date = $cDate->toString('yyyy-MM-dd HH:mm:ss');
     }
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     $fromDate->setDate(substr($special_from_date, 0, 10), 'yyyy-MM-dd');
     $fromDate->setTime(substr($special_from_date, 11, 8), 'HH:mm:ss');
     // To Date
     if (is_empty_date($product->getSpecialToDate())) {
         $special_to_date = $cDate->toString('yyyy-MM-dd HH:mm:ss');
     }
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $toDate->setTimezone($timezone);
     }
     $toDate->setDate(substr($special_to_date, 0, 10), 'yyyy-MM-dd');
     $toDate->setTime('23:59:59', 'HH:mm:ss');
     if (is_empty_date($product->getSpecialToDate())) {
         $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
     }
     $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601);
     $this->_findAndReplace($cell, $params['map']['column']);
     return $cell;
 }