/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Google_Service_ShoppingContent_Product $shoppingProduct * @return Google_Service_ShoppingContent_Product */ public function convertAttribute($product, $shoppingProduct) { $effectiveDateFrom = $this->getGroupAttributeSalePriceEffectiveDateFrom(); $fromValue = $effectiveDateFrom->getProductAttributeValue($product); $effectiveDateTo = $this->getGroupAttributeSalePriceEffectiveDateTo(); $toValue = $effectiveDateTo->getProductAttributeValue($product); $from = $to = null; if (!empty($fromValue) && Zend_Date::isDate($fromValue, Zend_Date::ATOM)) { $from = new Zend_Date($fromValue, Zend_Date::ATOM); } if (!empty($toValue) && Zend_Date::isDate($toValue, Zend_Date::ATOM)) { $to = new Zend_Date($toValue, Zend_Date::ATOM); } $dateString = null; // if we have from an to dates, and if these dates are correct if (!is_null($from) && !is_null($to) && $from->isEarlier($to)) { $dateString = $from->toString(Zend_Date::ATOM) . '/' . $to->toString(Zend_Date::ATOM); } // if we have only "from" date, send "from" day if (!is_null($from) && is_null($to)) { $dateString = $from->toString('YYYY-MM-dd'); } // if we have only "to" date, use "now" date for "from" if (is_null($from) && !is_null($to)) { $from = new Zend_Date(); // if "now" date is earlier than "to" date if ($from->isEarlier($to)) { $dateString = $from->toString(Zend_Date::ATOM) . '/' . $to->toString(Zend_Date::ATOM); } } if (!is_null($dateString)) { $shoppingProduct->setSalePriceEffectiveDate($dateString); } return $shoppingProduct; }
/** * Set current attribute to entry (for specified product) * * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\Gdata\Gshopping\Entry $entry * @return \Magento\Framework\Gdata\Gshopping\Entry */ public function convertAttribute($product, $entry) { $effectiveDateFrom = $this->getGroupAttributeSalePriceEffectiveDateFrom(); $fromValue = $effectiveDateFrom->getProductAttributeValue($product); $effectiveDateTo = $this->getGroupAttributeSalePriceEffectiveDateTo(); $toValue = $effectiveDateTo->getProductAttributeValue($product); $from = $to = null; if (!empty($fromValue) && \Zend_Date::isDate($fromValue, \Zend_Date::ATOM)) { $from = new \Magento\Framework\Stdlib\DateTime\Date($fromValue, \Zend_Date::ATOM); } if (!empty($toValue) && \Zend_Date::isDate($toValue, \Zend_Date::ATOM)) { $to = new \Magento\Framework\Stdlib\DateTime\Date($toValue, \Zend_Date::ATOM); } $dateString = null; // if we have from an to dates, and if these dates are correct if (!is_null($from) && !is_null($to) && $from->isEarlier($to)) { $dateString = $from->toString(\Zend_Date::ATOM) . '/' . $to->toString(\Zend_Date::ATOM); } // if we have only "from" date, send "from" day if (!is_null($from) && is_null($to)) { $dateString = $from->toString('YYYY-MM-dd'); } // if we have only "to" date, use "now" date for "from" if (is_null($from) && !is_null($to)) { $from = new \Magento\Framework\Stdlib\DateTime\Date(); // if "now" date is earlier than "to" date if ($from->isEarlier($to)) { $dateString = $from->toString(\Zend_Date::ATOM) . '/' . $to->toString(\Zend_Date::ATOM); } } if (!is_null($dateString)) { $this->_setAttribute($entry, 'sale_price_effective_date', self::ATTRIBUTE_TYPE_TEXT, $dateString); } return $entry; }
public function isValidDate($controller, $fieldname, $textName, $dateString) { require_once 'Zend/Date.php'; $rtn = true; $parts = explode('-', $dateString); if (intval($parts[1]) > 12) { $rtn = false; } $parts = explode('-', $dateString); if (intval($parts[2]) > 31) { $rtn = false; } $parts = explode('-', $dateString); if (intval($parts[0]) > 2200) { $rtn = false; } $parts = explode('-', $dateString); if (intval($parts[0]) < 1900) { $rtn = false; } $rtn = $rtn and Zend_Date::isDate($dateString, 'Y-m-d'); if (!$rtn) { $this->addError($fieldname, $textName . ' ' . t('is not a valid date') . '.'); } return $rtn; }
/** * * @param array $filters * @return Zend_Db_Table_Rowset */ public function listByFilters($filters = array()) { $dbAudit = App_Model_DbTable_Factory::get('SysAudit'); $dbForm = App_Model_DbTable_Factory::get('SysForm'); $dbModule = App_Model_DbTable_Factory::get('SysModule'); $dbUser = App_Model_DbTable_Factory::get('SysUser'); $select = $dbAudit->select()->from(array('a' => $dbAudit))->setIntegrityCheck(false)->join(array('f' => $dbForm), 'f.id_sysform = a.fk_id_sysform', array('form', 'date_audit' => new Zend_Db_Expr('DATE_FORMAT( a.date_time, "%d/%m/%Y" )')))->join(array('m' => $dbModule), 'm.id_sysmodule = a.fk_id_sysmodule', array('module'))->join(array('u' => $dbUser), 'u.id_sysuser = a.fk_id_sysuser', array('name'))->order(array('date_time DESC')); $date = new Zend_Date(); if (!empty($filters['start_date']) && Zend_Date::isDate($filters['start_date'])) { $select->where('DATE( a.date_time ) >= ?', $date->set($filters['start_date'])->toString('yyyy-MM-dd')); } if (!empty($filters['finish_date']) && Zend_Date::isDate($filters['finish_date'])) { $select->where('DATE( a.date_time ) <= ?', $date->set($filters['finish_date'])->toString('yyyy-MM-dd')); } if (!empty($filters['fk_id_sysuser'])) { $select->where('a.fk_id_sysuser = ?', $filters['fk_id_sysuser']); } if (!empty($filters['fk_id_sysmodule'])) { $select->where('a.fk_id_sysmodule = ?', $filters['fk_id_sysmodule']); } if (!empty($filters['fk_id_sysform'])) { $select->where('a.fk_id_sysform = ?', $filters['fk_id_sysform']); } if (!empty($filters['description'])) { $select->where('a.description LIKE ?', '%' . $filters['description'] . '%'); } return $dbAudit->fetchAll($select); }
public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); if ($this->_format !== null or $this->_locale !== null) { require_once 'Zend/Date.php'; if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) { if ($this->_checkFormat($value) === false) { $this->_error(self::FALSEFORMAT); } else { $this->_error(self::INVALID); } return false; } } else { if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $valueString)) { $this->_error(self::NOT_YYYY_MM_DD); return false; } list($year, $month, $day) = sscanf($valueString, '%d-%d-%d'); if (!checkdate($month, $day, $year)) { $this->_error(self::INVALID); return false; } } return true; }
/** * Sets the internal value to ISO date format. * * @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 (empty($val)) { $this->dateField->setValue(null); $this->timeField->setValue(null); } else { // String setting is only possible from the database, so we don't allow anything but ISO format if (is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) { // split up in date and time string values. $valueObj = new Zend_Date($val, $this->getConfig('datavalueformat'), $this->locale); // set date either as array, or as string if ($this->dateField->getConfig('dmyfields')) { $this->dateField->setValue($valueObj->toArray()); } else { $this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'))); } // set time $this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'))); } elseif (is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) { $this->dateField->setValue($val['date']); $this->timeField->setValue($val['time']); } else { $this->dateField->setValue($val); $this->timeField->setValue($val); } } }
public function uploadAction() { if (isset($_FILES['importfile']) && !empty($_FILES['importfile']['name'])) { $content = file_get_contents($_FILES['importfile']['tmp_name']); $lines = explode("\n", $content); $persons = array(); //'BDAY' $state = 0; foreach ($lines as $line) { $line = str_replace("\r", "", $line); $pos = strpos($line, ':'); if ($pos === false) { continue; } $key = substr($line, 0, $pos); $value = substr($line, $pos + 1); switch ($state) { case 0: if ($key === 'BEGIN' && $value === 'VCARD') { $state = 1; $person = array(); } break; case 1: if ($key === 'END' && $value === 'VCARD') { $state = 0; $persons[] = $person; } else { if ($key === 'FN' || substr($key, 0, 3) === 'FN;') { $name = explode(' ', $value); $person['firstname'] = strip_tags($name[0]); $person['secondname'] = strip_tags($name[1]); } if ($key === 'BDAY' || substr($key, 0, 5) === 'BDAY;') { $value = substr($value, 0, 10); $date = new Zend_Date(); if ($date->isDate($value, 'yyyy-MM-dd')) { $date->set($value); $person['birthdate'] = $date->toString('yyyy-MM-dd'); } } } break; } } } foreach ($persons as $person) { if (isset($person['firstname']) && isset($person['secondname']) && isset($person['birthdate'])) { $user = new Bc_UserDTO(); $user->set('firstname', $person['firstname']); $user->set('secondname', $person['secondname']); $user->set('birthdate', $person['birthdate']); $user->save(); } } $this->_redirect('/'); }
/** * * Enter description here ... * @param unknown_type $time * @param unknown_type $format * @return ExecutionTime * @throws Exception */ public function addTime($time, $format = 'HH:mm:ss') { if (!\Zend_Date::isDate($time, $format)) { throw new \Exception('time invalid ' . $time); } $date = new \Zend_Date(); $date->set($time, $format); $this->dates[] = $date; return $this; }
/** * Filter date * * @param string $value * @return null|string */ public function filter($value) { if ($value) { $date = new Zend_Date($value, null, $this->_options['locale']); if (Zend_Date::isDate($value, $this->_options['date_format'], $this->_options['locale'])) { return $date->toString('yyyy-MM-dd'); } else { return $date->toString($this->_options['date_format']); } } return null; }
public function formatDate($date, $formatName, $formatStr = '') { if (!Zend_Date::isDate($date)) { return $date; } else { $date = new Zend_Date($date); if ($formatName != null && in_array($this->date_formats, $formatName)) { return $date->toString($this->date_formats[$formatName]); } else { if ($formatStr != null) { return $date->toString($formatStr); } } } }
/** * Render a date into a view using the given format, * it can be a textual representation or a Zend_Date object * * @param string|Zend_Date $date the date to format * @param string $outputFormat output format for the date * @param string $inputFormat input format of the given date, * used only if $date is a string * * @return string */ public function date($date, $outputFormat = Zend_Date::DATE_LONG, $inputFormat = null) { if (!$date instanceof Zend_Date) { // check for string type if (!is_string($date)) { throw new InvalidArgumentException("Input date must be string or Zend_Date"); } if (null == $inputFormat && Zend_Date::isDate($date, 'YYYY-mm-dd')) { // use database input format if is matched $inputFormat = Zend_Date::ISO_8601; } // build a zend date object $date = new Zend_Date($date, $inputFormat); } // return converted date return $date->get($outputFormat); }
public function getisvaliddateAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout()->disableLayout(); $dateText = $this->getRequest()->getParam('dateText'); $objSelectedDate = new Zend_Date($dateText, Zend_Date::ISO_8601); $objTodayDate = new Zend_Date(Zend_Date::now(), Zend_Date::ISO_8601); if ($objSelectedDate->isToday($dateText)) { echo 1; return; } if ($objSelectedDate->isEarlier($objTodayDate) || $objSelectedDate->isDate($dateText)) { echo 0; return; } echo 1; }
/** * Returns true if and only if $value meets the validation requirements * * If $value fails validation, then this method returns false, and * getMessages() will return an array of messages that explain why the * validation failed. * * @param mixed $value * @return boolean * @throws \Zend_Valid_Exception If validation of $value is impossible */ public function isValid($value, $context = null) { try { $date = new \Zend_Date($value, $this->getDateFormat()); } catch (\Zend_Date_Exception $e) { $this->_error(self::NOT_VALID_DATE, $value); return false; } $year = $date->get(\Zend_Date::YEAR); /** * Prevent extreme dates (also fixes errors when saving to the db) */ if ($year > 1850 && $year < 2200 && \Zend_Date::isDate($value, $this->getDateFormat())) { return true; } $this->_error(self::NOT_VALID_DATE, $value); return false; }
public function indexAction() { // Title $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Services Use"))); $config = Zend_Registry::get('config'); // Include Inpector class, for permission test include_once $config->system->path->base . "/inspectors/Permissions.php"; $test = new Permissions(); $response = $test->getTests(); $form = $this->getForm(); if ($this->_request->getPost()) { $formIsValid = $form->isValid($_POST); $formData = $this->_request->getParams(); $locale = Snep_Locale::getInstance()->getLocale(); if ($locale == 'en_US') { $format = 'yyyy-MM-dd'; } else { $format = Zend_Locale_Format::getDateFormat($locale); } $ini_date = explode(" ", $formData['period']['init_day']); $final_date = explode(" ", $formData['period']['till_day']); $ini_date_valid = Zend_Date::isDate($ini_date[0], $format); $final_date_valid = Zend_Date::isDate($final_date[0], $format); if (!$ini_date_valid) { $iniDateElem = $form->getSubForm('period')->getElement('init_day'); $iniDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } if (!$final_date_valid) { $finalDateElem = $form->getSubForm('period')->getElement('till_day'); $finalDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } if ($formIsValid) { $reportType = $formData['service']['out_type']; if ($reportType == 'csv') { $this->csvAction(); } else { $this->viewAction(); } } } $this->view->form = $form; }
protected function _getCurrentQuoteFieldValue($fieldName, $index = null) { $firstItem = $this->_getCurrentOrderOrQuote($index); if ($fieldName == 'delivery_date') { if (Zend_Date::isDate($firstItem->getData($fieldName), Zend_Date::ISO_8601)) { $dateTime = new Zend_Date($firstItem->getData($fieldName), Zend_Date::ISO_8601); return $dateTime->toString('yyyy-MM-dd'); } else { return; } } elseif ($fieldName == 'delivery_time') { if (Zend_Date::isDate($firstItem->getData('delivery_date'), Zend_Date::ISO_8601)) { $dateTime = new Zend_Date($firstItem->getData('delivery_date'), Zend_Date::ISO_8601); return explode(':', $dateTime->get(Zend_Date::TIME_SHORT)); } else { return; } } return $firstItem->getData($fieldName); }
function validate($validator) { $value = isset($_POST[$this->name . '_custom']) ? $_POST[$this->name . '_custom'] : null; if (!$value) { return true; } // no custom value, don't validate // Check that the current date with the date format is valid or not require_once 'Zend/Date.php'; $date = Zend_Date::now()->toString($value); $valid = Zend_Date::isDate($date, $value); if ($valid) { return true; } else { if ($validator) { $validator->validationError($this->name, _t('MemberDatetimeOptionsetField.DATEFORMATBAD', "Date format is invalid"), "validation", false); } return false; } }
/** * Get current attribute value for specified product * * @param \Magento\Catalog\Model\Product $product * @return null|string */ public function getProductAttributeValue($product) { if (is_null($this->getAttributeId())) { return null; } $productAttribute = $this->_gsProduct->getProductAttribute($product, $this->getAttributeId()); if (is_null($productAttribute)) { return null; } if ($productAttribute->getFrontendInput() == 'date' || $productAttribute->getBackendType() == 'date') { $value = $product->getData($productAttribute->getAttributeCode()); if (empty($value) || !\Zend_Date::isDate($value, \Zend_Date::ISO_8601)) { return null; } $date = new \Magento\Framework\Stdlib\DateTime\Date($value, \Zend_Date::ISO_8601); $value = $date->toString(\Zend_Date::ATOM); } else { $value = $productAttribute->getFrontend()->getValue($product); } return $value; }
/** * Get current attribute value for specified product * * @param Mage_Catalog_Model_Product $product * * @return null|string */ public function getProductAttributeValue($product) { if (is_null($this->getAttributeId())) { return null; } $productAttribute = Mage::helper('gshoppingv2/product')->getProductAttribute($product, $this->getAttributeId()); if (is_null($productAttribute)) { return null; } if ($productAttribute->getFrontendInput() == 'date' || $productAttribute->getBackendType() == 'date') { $value = $product->getData($productAttribute->getAttributeCode()); if (empty($value) || !Zend_Date::isDate($value, Zend_Date::ISO_8601)) { return null; } $date = new Zend_Date($value, Zend_Date::ISO_8601); $value = $date->toString(Zend_Date::ATOM); } else { $value = $productAttribute->getFrontend()->getValue($product); } return $value; }
public function indexAction() { // Title $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Call Ranking"))); $config = Zend_Registry::get('config'); $form = $this->getForm(); if ($this->_request->getPost()) { $formIsValid = $form->isValid($_POST); $formData = $this->_request->getParams(); $locale = Snep_Locale::getInstance()->getLocale(); if ($locale == 'en_US') { $format = 'yyyy-MM-dd'; } else { $format = Zend_Locale_Format::getDateFormat($locale); } $ini_date = explode(" ", $formData['period']['init_day']); $final_date = explode(" ", $formData['period']['till_day']); $ini_date_valid = Zend_Date::isDate($ini_date[0], $format); $final_date_valid = Zend_Date::isDate($final_date[0], $format); if (!$ini_date_valid) { $iniDateElem = $form->getSubForm('period')->getElement('init_day'); $iniDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } if (!$final_date_valid) { $finalDateElem = $form->getSubForm('period')->getElement('till_day'); $finalDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } $reportType = $formData['rank']['out_type']; if ($formIsValid) { if ($reportType == 'csv') { $this->csvAction(); } else { $this->viewAction(); } } } $this->view->form = $form; }
public function setValue($value) { switch ($value) { case self::TODAY: $value = date('Y-m-d H:i:s'); break; case self::TOMORROW: $value = date('Y-m-d H:i:s', time() + 86400); break; case self::TODAY_DATE: $value = date('Y-m-d'); break; case self::TODAY_TIME: $value = date('H:i:s'); break; default: if ($this->getParameter('format') && !\Zend_Date::isDate($value, $this->getParameter('format'))) { throw new Exception(array("VALUE_NOT_A_DATE", array($this->_id, $value))); } break; } parent::setValue($value); }
public function indexAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Reports"), $this->view->translate("Calls"))); $config = Zend_Registry::get('config'); include $config->system->path->base . "/inspectors/Permissions.php"; $test = new Permissions(); $response = $test->getTests(); $form = $this->getForm(); if ($this->_request->getPost()) { $formIsValid = $form->isValid($_POST); $locale = Snep_Locale::getInstance()->getLocale(); if ($locale == 'en_US') { $format = 'yyyy-MM-dd'; } else { $format = Zend_Locale_Format::getDateFormat($locale); } $ini_date = explode(" ", $_POST['period']['initDay']); $final_date = explode(" ", $_POST['period']['finalDay']); $ini_date_valid = Zend_Date::isDate($ini_date[0], $format); $final_date_valid = Zend_Date::isDate($final_date[0], $format); if (!$ini_date_valid) { $iniDateElem = $form->getSubForm('period')->getElement('initDay'); $iniDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } if (!$final_date_valid) { $finalDateElem = $form->getSubForm('period')->getElement('finalDay'); $finalDateElem->addError($this->view->translate('Invalid Date')); $formIsValid = false; } if ($formIsValid) { $this->createAction(); } } $this->view->form = $form; }
/** * Validates the set search filter * * @throws Exception * @return void */ private function _validateSearchFilter() { $searchFilterKeys = array_keys($this->_searchFilter); foreach ($searchFilterKeys as $searchFilterKey) { if (!in_array($searchFilterKey, $this->_supportedSearchFilterKeys)) { throw new Exception("Unsupported search filter '{$searchFilterKey}' provided"); } } if (!isset($this->_searchFilter['url'])) { throw new Exception("No mandatory search Url provided in search filter"); } if (!Zend_Uri::check($this->_searchFilter['url'])) { throw new Exception("Invalid Url provided in search filter"); } if (isset($this->_searchFilter['start']) || isset($this->_searchFilter['end'])) { if (!Zend_Date::isDate($this->_searchFilter['start'], 'yyyy/MM/dd') || !Zend_Date::isDate($this->_searchFilter['end'], 'yyyy/MM/dd')) { throw new Exception("Date search filter doesn't seem to be valid dates"); } $dateFormatPattern = '#^[0-9]{4}/[0-9]{2}/[0-9]{2}#'; if (!Zend_Validate::is($this->_searchFilter['start'], 'Regex', array('pattern' => $dateFormatPattern)) || !Zend_Validate::is($this->_searchFilter['end'], 'Regex', array('pattern' => $dateFormatPattern))) { throw new Exception("Date search filter doesn't follow the expected 'YYYY/MM/dd' format"); } } }
/** * Defined by Zend_Validate_Interface * * Returns true if $value is a valid date of the format YYYY-MM-DD * If optional $format or $locale is set the date format is checked * according to Zend_Date, see Zend_Date::isDate() * * @param string|array|Zend_Date $value * @return boolean */ public function isValid($value) { if (!is_string($value) && !is_int($value) && !is_float($value) && !is_array($value) && !$value instanceof Zend_Date) { $this->_error(self::INVALID); return false; } $this->_setValue($value); if ($this->_format !== null || $this->_locale !== null || is_array($value) || $value instanceof Zend_Date) { require_once 'Zend/Date.php'; if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) { if ($this->_checkFormat($value) === false) { $this->_error(self::FALSEFORMAT); } else { $this->_error(self::INVALID_DATE); } return false; } } else { if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value)) { $this->_error(self::NOT_YYYY_MM_DD); return false; } list($year, $month, $day) = sscanf($value, '%d-%d-%d'); if (!checkdate($month, $day, $year)) { $this->_error(self::INVALID_DATE); return false; } } return true; }
/** * Validate this field * * @param Validator $validator * @return bool */ public function validate($validator) { $value = $this->Value(); if (!$value) { return true; // no custom value, don't validate } // Check that the current date with the date format is valid or not require_once 'Zend/Date.php'; $date = Zend_Date::now()->toString($value); $valid = Zend_Date::isDate($date, $value); if ($valid) { return true; } // Fail $validator->validationError($this->getName(), _t('MemberDatetimeOptionsetField.DATEFORMATBAD', "Date format is invalid"), "validation"); return false; }
/** * * @param string $formatoSaida O formato que a data será retornada * @param string $umaData Uma data válida * @param string $formatoEntrada O formato em que a data será inserida * @return string Data formatada */ function formataData($formatoSaida = 'dd/MM/yyyy', $umaData = null, $formatoEntrada = self::FORMATO_DO_BANCO) { $data = $umaData && Zend_Date::isDate($umaData, $formatoEntrada) ? new Zend_Date($umaData, $formatoEntrada, 'pt_BR') : Zend_Date::now(); return $data->toString($formatoSaida); }
/** * Add not indexable fields to search * * @param array $fields * @return Mage_CatalogSearch_Model_Resource_Advanced_Collection */ public function addFieldsToFilter($fields) { if ($fields) { $previousSelect = null; $conn = $this->getConnection(); foreach ($fields as $table => $conditions) { foreach ($conditions as $attributeId => $conditionValue) { $select = $conn->select(); $select->from(array('t1' => $table), 'entity_id'); $conditionData = array(); if (!is_numeric($attributeId)) { $field = 't1.' . $attributeId; } else { $storeId = $this->getStoreId(); $onCondition = 't1.entity_id = t2.entity_id' . ' AND t1.attribute_id = t2.attribute_id' . ' AND t2.store_id=?'; $select->joinLeft(array('t2' => $table), $conn->quoteInto($onCondition, $storeId), array()); $select->where('t1.store_id = ?', 0); $select->where('t1.attribute_id = ?', $attributeId); if (array_key_exists('price_index', $this->getSelect()->getPart(Varien_Db_Select::FROM))) { $select->where('t1.entity_id = price_index.entity_id'); } $field = $this->getConnection()->getIfNullSql('t2.value', 't1.value'); } if (is_array($conditionValue)) { if (isset($conditionValue['in'])) { $conditionData[] = array('in' => $conditionValue['in']); } elseif (isset($conditionValue['in_set'])) { $conditionParts = array(); foreach ($conditionValue['in_set'] as $value) { $conditionParts[] = array('finset' => $value); } $conditionData[] = $conditionParts; } elseif (isset($conditionValue['like'])) { $conditionData[] = array('like' => $conditionValue['like']); } elseif (isset($conditionValue['from']) && isset($conditionValue['to'])) { $invalidDateMessage = Mage::helper('catalogsearch')->__('Specified date is invalid.'); if ($conditionValue['from']) { if (!Zend_Date::isDate($conditionValue['from'])) { Mage::throwException($invalidDateMessage); } if (!is_numeric($conditionValue['from'])) { $conditionValue['from'] = Mage::getSingleton('core/date')->gmtDate(null, $conditionValue['from']); if (!$conditionValue['from']) { $conditionValue['from'] = Mage::getSingleton('core/date')->gmtDate(); } } $conditionData[] = array('gteq' => $conditionValue['from']); } if ($conditionValue['to']) { if (!Zend_Date::isDate($conditionValue['to'])) { Mage::throwException($invalidDateMessage); } if (!is_numeric($conditionValue['to'])) { $conditionValue['to'] = Mage::getSingleton('core/date')->gmtDate(null, $conditionValue['to']); if (!$conditionValue['to']) { $conditionValue['to'] = Mage::getSingleton('core/date')->gmtDate(); } } $conditionData[] = array('lteq' => $conditionValue['to']); } } } else { $conditionData[] = array('eq' => $conditionValue); } foreach ($conditionData as $data) { $select->where($conn->prepareSqlCondition($field, $data)); } if (!is_null($previousSelect)) { $select->where('t1.entity_id IN (?)', new Zend_Db_Expr($previousSelect)); } $previousSelect = $select; } } $this->addFieldToFilter('entity_id', array('in' => new Zend_Db_Expr($select))); } return $this; }
/** * 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)); } } }
/** * @ZF-7454 */ public function testSetWithoutHourAtDSTChange() { $this->assertTrue(Zend_Date::isDate("23/05/2010", "dd/MM/yyyy", "it_IT")); $this->assertTrue(Zend_Date::isDate("24/05/2010", "dd/MM/yyyy", "it_IT")); }
public function saveAction() { try { $rule = $this->_initRule(); $request = new Varien_Object($this->_filterDateTime($this->getRequest()->getParams(), array('start_date', 'end_date'))); if (null !== $this->getRequest()->getParam('start_date', null) && !Zend_Date::isDate($request->getStartDate(), Varien_Date::DATETIME_INTERNAL_FORMAT)) { $request->setStartDate(null); throw new Exception('"From Date" field value is not valid datetime format.'); } if (null !== $this->getRequest()->getParam('end_date', null) && !Zend_Date::isDate($request->getEndDate(), Varien_Date::DATETIME_INTERNAL_FORMAT)) { $request->setEndDate(null); throw new Exception('"To Date" field value is not valid datetime format.'); } $this->_prepareDates($request)->_prepareConditions($request); $rule->addData($request->getData())->loadPost($request->getData())->save(); if (!$rule->getProductId() && $rule->getSimpleAction() == AW_Afptc_Model_Rule::BY_PERCENT_ACTION) { Mage::getSingleton('adminhtml/session')->addNotice($this->__('No action product specified')); } Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Rule successfully saved')); } catch (Exception $e) { $request->setBack(true); $this->_prepareDates($request); Mage::getSingleton('adminhtml/session')->addError($e->getMessage())->setFormActionData($request->getData()); } if ($request->getBack()) { return $this->_redirect('*/*/edit', array('id' => $rule->getId(), 'tab' => $request->getTab())); } return $this->_redirect('*/*/'); }
/** * Partner Statistic action method * This action returns all data for the partner statistic page * */ public function partnerStatisticAction() { $partnerId = Shopware()->Session()->partnerId; if (empty($partnerId)) { return $this->forward('index'); } $toDate = $this->Request()->toDate; $fromDate = $this->Request()->fromDate; //if a to date passed, format it over the \DateTime object. Otherwise create a new date with today if (empty($fromDate) || !Zend_Date::isDate($fromDate)) { $fromDate = new \DateTime(); $fromDate = $fromDate->sub(new DateInterval('P1M')); } else { $fromDate = new \DateTime($fromDate); } //if a to date passed, format it over the \DateTime object. Otherwise create a new date with today if (empty($toDate) || !Zend_Date::isDate($toDate)) { $toDate = new \DateTime(); } else { $toDate = new \DateTime($toDate); } $this->View()->partnerStatisticToDate = $toDate->format("d.m.Y"); $this->View()->partnerStatisticFromDate = $fromDate->format("d.m.Y"); //to get the right value cause 2012-02-02 is smaller than 2012-02-02 15:33:12 $toDate = $toDate->add(new DateInterval('P1D')); /** @var $repository \Shopware\Models\Partner\Repository */ $repository = Shopware()->Models()->Partner(); //get the information of the partner chart $userCurrencyFactor = Shopware()->Shop()->getCurrency()->getFactor(); $dataQuery = $repository->getStatisticChartQuery($partnerId, $fromDate, $toDate, $userCurrencyFactor); $this->View()->sPartnerOrderChartData = $dataQuery->getArrayResult(); $dataQuery = $repository->getStatisticListQuery(null, null, null, $partnerId, false, $fromDate, $toDate, $userCurrencyFactor); $this->View()->sPartnerOrders = $dataQuery->getArrayResult(); $dataQuery = $repository->getStatisticListQuery(null, null, null, $partnerId, true, $fromDate, $toDate, $userCurrencyFactor); $this->View()->sTotalPartnerAmount = $dataQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); }