/** * Returns a number in local specific format. * * @link http://framework.zend.com/manual/de/zend.locale.parsing.html * @param int|float $value * @param array $format * @return mixed */ function smarty_modifier_number($value, $format = array()) { if (empty($format['locale'])) { $format['locale'] = Enlight_Application::Instance()->Locale(); } return Zend_Locale_Format::toNumber($value, $format); }
/** * Return a value for get, using some validations from the table data. * * @param string $type Type of field. * @param mixed $value Value to transform. * * @return mixed Value of the var. */ public static function get($type, $value) { switch ($type) { case 'float': $value = Zend_Locale_Format::toFloat($value, array('precision' => 2)); break; case 'time': if (!empty($value)) { $value = date("H:i:s", Phprojekt_Converter_Time::utcToUser($value)); } break; case 'datetime': case 'timestamp': if (!empty($value)) { $value = date("Y-m-d H:i:s", Phprojekt_Converter_Time::utcToUser($value)); } break; case 'text': // Get html only if the text contain some html code if (preg_match("/([\\<])([^\\>]{1,})*([\\>])/i", $value)) { $value = stripslashes($value); } break; } return $value; }
public function createForm($id_hopdong) { $kh = new Model_Hopdong(); $hopdong = $kh->getWhereIdHopDong($id_hopdong); $this->setDisableLoadDefaultDecorators(true); $this->setDecorators(array(array('ViewScript', array('viewScript' => 'formnoindex/hopdong_layout.phtml')), 'Form')); $data = new My_Data(); $opMau = $data->getOptionMau(); $opLoaiVai = $data->getOptionLoaiVai(); $opNCC = $data->getOptionNCC(); $tenhopdong = $this->createElement('text', 'tenhopdong', array('decorators' => array('ViewHelper'))); $mota = $this->createElement('text', 'mota', array('decorators' => array('ViewHelper'))); $ngayky = $this->createElement('text', 'ngayky', array('decorators' => array('ViewHelper'))); $sotansoi = $this->createElement('text', 'sotansoi', array('decorators' => array('ViewHelper'))); $thanhtien = $this->createElement('text', 'thanhtien', array('decorators' => array('ViewHelper'))); $mamau = $this->createElement('select', 'mamau', array('multioptions' => $opMau, 'decorators' => array('ViewHelper'))); $maloaivai = $this->createElement('select', 'maloaivai', array('multioptions' => $opLoaiVai, 'decorators' => array('ViewHelper'))); $manhacungcap = $this->createElement('select', 'manhacungcap', array('multioptions' => $opNCC, 'decorators' => array('ViewHelper'))); $them = $this->createElement('submit', 'them', array('decorators' => array('ViewHelper'), 'label' => 'Chỉnh sửa')); $mydate = Zend_Locale_Format::getDate($hopdong['NgayKy'], array("date_format" => "yyyy.MM.dd")); $date_str = $mydate['day'] . "/" . $mydate['month'] . "/" . $mydate['year']; $tenhopdong->setAttrib('class', 'formEdit')->setValue($hopdong['TenHopDong']); $mota->setAttrib('class', 'formEdit')->setValue($hopdong['MoTa']); $ngayky->setAttrib('class', 'formEdit')->setValue($date_str); $sotansoi->setAttrib('class', 'formEdit')->setValue($hopdong['SoTanSoi']); $thanhtien->setAttrib('class', 'formEdit')->setValue($hopdong['ThanhTien']); $mamau->setAttrib('class', 'formEdit')->setValue($hopdong['MaMau']); $maloaivai->setAttrib('class', 'formEdit')->setValue($hopdong['MaLoaiVai']); $manhacungcap->setAttrib('class', 'formEdit')->setValue($hopdong['MaNhaCungCap']); $this->addElement($tenhopdong)->addElement($mota)->addElement($ngayky)->addElement($sotansoi)->addElement($thanhtien)->addElement($mamau)->addElement($maloaivai)->addElement($manhacungcap)->addElement($them); }
protected function startLocale() { require_once "Zend/Translate.php"; // silenciando strict até arrumar zend_locale date_default_timezone_set("America/Sao_Paulo"); $i18n = new Zend_Translate('gettext', $this->config->system->path->base . '/lang/pt_BR.mo', 'pt_BR'); Zend_Registry::set('i18n', $i18n); $translation_files = $this->config->system->path->base . "/lang/"; foreach (scandir($translation_files) as $filename) { // Todos os arquivos .php devem ser classes de descrição de modulos if (preg_match("/.*\\.mo\$/", $filename)) { $translation_id = basename($filename, '.mo'); if ($translation_id != "pt_BR") { $i18n->addTranslation($translation_files . "/{$filename}", $translation_id); } } } require_once "Zend/Locale.php"; if (Zend_Locale::isLocale($this->config->system->locale)) { $locale = $this->config->system->locale; } else { $locale = "pt_BR"; } Zend_Registry::set('Zend_Locale', new Zend_Locale($locale)); Zend_Locale::setDefault($locale); Zend_Locale_Format::setOptions(array("locale" => $locale)); $i18n->setLocale($locale); Zend_Registry::set("Zend_Translate", $i18n); $zend_validate_translator = new Zend_Translate_Adapter_Array($this->config->system->path->base . "/lang/Zend_Validate/{$locale}/Zend_Validate.php", $locale); Zend_Validate_Abstract::setDefaultTranslator($zend_validate_translator); }
/** * extracts the * @return type */ public function dataValue() { require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php"; $locale = new Zend_Locale(i18n::get_locale()); $number = Zend_Locale_Format::getNumber($this->value, array('locale' => $locale)); return $number; }
protected function _getValueToSaveFromPostData($postData) { $ret = parent::_getValueToSaveFromPostData($postData); $l = $this->_floatValidator->getLocale(); $ret = Zend_Locale_Format::getNumber($ret, array('locale' => $l)); return $ret; }
/** * Formats a given value * @see library/Bvb/Grid/Formatter/Bvb_Grid_Formatter_FormatterInterface::format() */ public function format($value) { if (!is_numeric($value)) { return $value; } return Zend_Locale_Format::toNumber($value, $this->_options); }
/** * return date in user timezone */ public function getUserDate() { // get user session $session = new Zend_Session_Namespace('user'); // return date with user timezone in locale format return $this->getDate($session->timezone)->toString(Zend_Locale_Format::getDateTimeFormat($session->language)); }
/** * Converts map array to microdata Object * * @param array $map map array returned by the generator * @return null|Varien_Object */ protected function _createRowObject($map) { if (empty($map['price']) || empty($map['availability']) || empty($map['title'])) { return null; } $microdata = new Varien_Object(); $microdata->setName($map['title']); $microdata->setId($map['id']); if (!empty($map['sale_price'])) { $price = $map['sale_price']; } else { $price = $map['price']; } $microdata->setPrice(Zend_Locale_Format::toNumber($price, array('precision' => 2, 'number_format' => '#0.00'))); $microdata->setCurrency(Mage::app()->getStore()->getCurrentCurrencyCode()); if ($map['availability'] == 'in stock') { $microdata->setAvailability('http://schema.org/InStock'); } else { $microdata->setAvailability('http://schema.org/OutOfStock'); } if (array_key_exists('condition', $map)) { if (strcasecmp('new', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/NewCondition'); } else { if (strcasecmp('used', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/UsedCondition'); } else { if (strcasecmp('refurbished', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/RefurbishedCondition'); } } } } return $microdata; }
public function getAnualPercentageRate($format = true) { $s = Zend_Locale_Format::toNumber($this->_anualPercentageRate, array('precision' => 2)); if ($format) { return $s . '%'; } else { return $s; } }
protected function getForm() { // Create object Snep_Form $form = new Snep_Form(); // Set form action $form->setAction($this->getFrontController()->getBaseUrl() . '/services-report/index'); $form_xml = new Zend_Config_Xml('./modules/default/forms/services_report.xml'); $config = Zend_Registry::get('config'); $period = new Snep_Form_SubForm($this->view->translate("Period"), $form_xml->period); $validatorDate = new Zend_Validate_Date(Zend_Locale_Format::getDateFormat(Zend_Registry::get('Zend_Locale'))); $locale = Snep_Locale::getInstance()->getLocale(); $now = Zend_Date::now(); if ($locale == 'en_US') { $now = $now->toString('YYYY-MM-dd HH:mm'); } else { $now = $now->toString('dd/MM/YYYY HH:mm'); } $yesterday = Zend_Date::now()->subDate(1); $initDay = $period->getElement('init_day'); $initDay->setValue($now); //$initDay->addValidator($validatorDate); $tillDay = $period->getElement('till_day'); $tillDay->setValue($now); //$tillDay->addValidator($validatorDate); $form->addSubForm($period, "period"); $exten = new Snep_Form_SubForm($this->view->translate("Extensions"), $form_xml->exten); $groupLib = new Snep_GruposRamais(); $groupsTmp = $groupLib->getAll(); $groupsData = array(); foreach ($groupsTmp as $key => $group) { switch ($group['name']) { case 'administrator': $groupsData[$this->view->translate('Administrators')] = $group['name']; break; case 'users': $groupsData[$this->view->translate('Users')] = $group['name']; break; case 'all': $groupsData[$this->view->translate('All')] = $group['name']; break; default: $groupsData[$group['name']] = $group['name']; } } $selectGroup = $exten->getElement('group_select'); $selectGroup->addMultiOption(null, '----'); foreach ($groupsData as $key => $value) { $selectGroup->addMultiOption($value, $key); } $selectGroup->setAttrib('onSelect', "enableField('exten-group_select', 'exten-exten_select');"); $form->addSubForm($exten, "exten"); $service = new Snep_Form_SubForm($this->view->translate("Services"), $form_xml->service); $form->addSubForm($service, "service"); $form->getElement('submit')->setLabel($this->view->translate("Show Report")); $form->removeElement("cancel"); return $form; }
/** * Retrieves formatted string of tax rate for user output * * @return string */ public function getFormattedTaxRate() { if ($this->getTaxRate() === null || $this->getProduct()->getTypeId() == 'bundle') { return ''; } $locale = Mage::app()->getLocale()->getLocaleCode(); $taxRate = Zend_Locale_Format::toFloat($this->getTaxRate(), array('locale' => $locale)); return $this->__('%s%%', $taxRate); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a floating-point value * * @todo http://framework.zend.com/issues/browse/ZF-2895 * @param string $value * @return boolean */ public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); if (!Zend_Locale_Format::isFloat($valueString, $this->_options)) { $this->_error(); return false; } return true; }
protected function createTimeFormatFieldForMember($member) { require_once 'Zend/Date.php'; $defaultTimeFormat = Zend_Locale_Format::getTimeFormat($member->Locale); $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm')); $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . ' (default)'; $field = new Member_DatetimeOptionsetField('TimeFormat', 'Time format', $timeFormatMap); $field->setValue($member->TimeFormat); return $field; }
/** * Extracts the number value from the localised string value * * @return string number value */ public function dataValue() { require_once "Zend/Locale/Format.php"; if (!$this->isNumeric()) { return 0; } $locale = new Zend_Locale($this->getLocale()); $number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale)); return $number; }
public function LocalizedToNormalized($value) { if (substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2) != 'en') { $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); } else { $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG); } $_options = array('locale' => Mage::app()->getLocale()->getLocaleCode(), 'date_format' => $dateFormatIso, 'precision' => null); return Zend_Locale_Format::getDate($value, $_options); }
public function getDateFormat() { if (!$this->_dateFormat) { if ($locale = $this->getLocale()) { $this->setDateFormat(\Zend_Locale_Format::getDateFormat($locale)); } else { $this->setDateFormat(\Zend_Date::DATE_SHORT); } } return $this->_dateFormat; }
public static function number($number, $precision = "", $locale = "") { global $config; $locale == "" ? $locale = new Zend_Locale($config->local->locale) : ($locale = $locale); $load_precision = $config->local->precision; $precision == "" ? $precision = $load_precision : ($precision = $precision); $formatted_number = Zend_Locale_Format::toNumber($number, array('precision' => $precision, 'locale' => $locale)); //trim zeros from decimal point if enabled //if ($config->local->trim_zeros == "y") { $formatted_number = rtrim(trim($formatted_number, '0'), '.'); } return $formatted_number; }
public static function checkDate($date, $format = '') { if (empty($format)) { if (Zend_Registry::isRegistered('date_format')) { $format = Zend_Registry::get('date_format'); } else { $format = self::MYSQL_DATE_FORMAT; } } return Zend_Locale_Format::checkDateFormat($date, array('date_format' => $format)); }
public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } $dateTimeFormatString = \Zend_Locale_Format::convertPhpToIsoFormat($platform->getDateTimeFormatString()); $val = new \Zend_Date($value, $dateTimeFormatString); if (!$val) { throw ConversionException::conversionFailed($value, $this->getName()); } return $val; }
public function validate($validator) { if (!$this->value && !$validator->fieldIsRequired($this->name)) { return true; } require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php"; $valid = Zend_Locale_Format::isNumber(trim($this->value), array('locale' => i18n::get_locale())); if (!$valid) { $validator->validationError($this->name, _t('NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field", array('value' => $this->value)), "validation"); return false; } return true; }
public function __toString() { $value = $this->getValue(); if (is_numeric($value)) { try { $locale = Zend_Registry::get("Zend_Locale"); } catch (Exception $e) { } if ($locale) { $value = Zend_Locale_Format::toNumber($value, array('locale' => $locale)); } } return $value . " " . $this->getUnit()->getAbbreviation(); }
/** * returns the value formatet in the current locales currency format * * @return string */ public function Currency($symbol = false) { require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php"; require_once THIRDPARTY_PATH . "/Zend/Currency.php"; if ($this->owner->value) { $locale = new Zend_Locale(i18n::get_locale()); $number = Zend_Locale_Format::toNumber($this->owner->value, array('locale' => $locale)); if ($symbol) { $symbol = new Zend_Currency($locale); $number = $symbol->getSymbol() . " " . $number; } return $number; } }
/** * @return string * @throws Zend_Locale_Exception */ public function Value() { if (!$this->isNumeric()) { return '0%'; } require_once "Zend/Locale/Format.php"; $locale = new Zend_Locale($this->getLocale()); // convert from the stored format to a real number so we can multiply $number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale)); $number *= 100.0; // convert back to string $val = Zend_Locale_Format::toNumber($number, array('locale' => $locale)); return $val . '%'; }
/** * * @return int|bool */ public function saveInformation() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { //if ( !$this->_validateClass() ) //return false; $date = new Zend_Date(); $this->_data['start_date'] = $date->set($this->_data['start_date'])->toString('yyyy-MM-dd'); $this->_data['schedule_finish_date'] = $date->set($this->_data['schedule_finish_date'])->toString('yyyy-MM-dd'); if (!empty($this->_data['real_finish_date'])) { $this->_data['real_finish_date'] = $date->set($this->_data['real_finish_date'])->toString('yyyy-MM-dd'); } if (!empty($this->_data['student_payment'])) { $this->_data['student_payment'] = Zend_Locale_Format::getFloat($this->_data['student_payment'], array('locale' => 'en_US')); } if (!empty($this->_data['subsidy'])) { $this->_data['subsidy'] = Zend_Locale_Format::getFloat($this->_data['subsidy'], array('locale' => 'en_US')); } if (empty($this->_data['id_fefpstudentclass'])) { $history = 'REJISTRU Klasse Formasaun - La Iha Proposta: %s'; $this->_data['active'] = 1; $filters = array('fk_id_fefpeduinstitution' => $this->_data['fk_id_fefpeduinstitution'], 'fk_id_perscholarity' => $this->_data['fk_id_perscholarity'], 'fk_id_dec' => $this->_data['fk_id_dec'], 'start_date' => $this->_data['start_date'], 'schedule_finish_date' => $this->_data['schedule_finish_date'], 'active' => 1); $classIdentic = $this->_dbTable->fetchAll($filters, array('id_fefpstudentclass DESC'))->current(); if (!empty($classIdentic)) { $start = 1; if (preg_match('/([0-9]+)$/i', $classIdentic->class_name, $match)) { $start = (int) $match[1] + 1; } $this->_data['class_name'] .= ' - ' . $start; } } else { unset($this->_data['fk_id_fefpeduinstitution'], $this->_data['fk_id_dec']); if (empty($this->_data['fk_id_perscholarity'])) { unset($this->_data['fk_id_perscholarity']); } $history = 'ATUALIZA Klasse Formasaun - La Iha Proposta: %s'; } $id = parent::_simpleSave(); $history = sprintf($history, $id); $this->_sysAudit($history); $dbAdapter->commit(); return $id; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a floating-point value * * @param string $value * @return boolean */ public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); try { if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) { $this->_error(); return false; } } catch (Zend_Locale_Exception $e) { $this->_error(); return false; } return true; }
public function createForm($id_cm) { $kh = new Model_Donxuat(); $donxuat = $kh->getWhere($id_cm); $this->setDisableLoadDefaultDecorators(true); $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/donxuat_layout.phtml')), 'Form')); $tendonxuat = $this->createElement('text', 'tendonxuat', array('decorators' => array('ViewHelper'))); $ngayxuat = $this->createElement('text', 'ngayxuat', array('decorators' => array('ViewHelper'))); $them = $this->createElement('submit', 'them', array('decorators' => array('ViewHelper'), 'label' => 'Chỉnh sửa')); $mydate = Zend_Locale_Format::getDate($donxuat[0]['NgayXuat'], array("date_format" => "yyyy.MM.dd")); $date_str = $mydate['day'] . "/" . $mydate['month'] . "/" . $mydate['year']; $tendonxuat->setAttrib('class', 'formEdit')->setValue($donxuat[0]['TenDonXuat']); $ngayxuat->setAttrib('class', 'formEdit')->setValue($date_str); $this->addElement($tendonxuat)->addElement($ngayxuat)->addElement($them); }
public function getTaxRateIDs($locale = null) { $taxrateDb = new Application_Model_DbTable_Taxrate(); $taxratesObject = $taxrateDb->fetchAll(); $taxrates = array(); if ($locale) { foreach ($taxratesObject as $taxrate) { $taxrates[$taxrate->id] = Zend_Locale_Format::toNumber($taxrate->rate, array('precision' => 1, 'locale' => $locale)) . ' %'; } } else { foreach ($taxratesObject as $taxrate) { $taxrates[$taxrate->id] = $taxrate->rate; } } return $taxrates; }
/** * add header */ protected function _addHeader() { $patterns = array('/\\{date\\}/', '/\\{user\\}/'); $replacements = array(Zend_Date::now()->toString(Zend_Locale_Format::getDateFormat($this->_locale), $this->_locale), Tinebase_Core::getUser()->accountDisplayName); $this->_currentRowIndex = 1; $columnId = 0; if ($this->_config->headers) { foreach ($this->_config->headers->header as $headerCell) { // replace data $value = preg_replace($patterns, $replacements, $headerCell); $this->_excelObject->getActiveSheet()->setCellValueByColumnAndRow(0, $this->_currentRowIndex, $value); $this->_currentRowIndex++; } $this->_currentRowIndex++; } if (isset($this->_config->header) && $this->_config->header) { $this->_addHead(); } }
public function createForm($id_donhang) { $kh = new Model_Donhang(); $donhang = $kh->getWhere($id_donhang); $this->setDisableLoadDefaultDecorators(true); $this->setDecorators(array(array('ViewScript', array('viewScript' => 'formnoindex/donhang_layout.phtml')), 'Form')); $tendonhang = $this->createElement('text', 'tendonhang', array('decorators' => array('ViewHelper'))); $ngaydathang = $this->createElement('text', 'ngaydathang', array('decorators' => array('ViewHelper'))); $tiendathang = $this->createElement('text', 'tiendathang', array('decorators' => array('ViewHelper'))); $sometvai = $this->createElement('text', 'sometvai', array('decorators' => array('ViewHelper'))); $them = $this->createElement('submit', 'them', array('decorators' => array('ViewHelper'), 'label' => 'Chỉnh sửa')); $tendonhang->setAttrib('class', 'textmedium')->setValue($donhang['TenDonHang']); $mydate = Zend_Locale_Format::getDate($donhang['NgayDat'], array("date_format" => "yyyy.MM.dd")); $date_str = $mydate['day'] . "/" . $mydate['month'] . "/" . $mydate['year']; $ngaydathang->setAttrib('class', 'textmedium')->setValue($date_str); $tiendathang->setAttrib('class', 'textmedium')->setValue($donhang['TienDatHang']); $sometvai->setAttrib('class', 'textmedium')->setValue($donhang['SoMetVai']); $this->addElement($tendonhang)->addElement($ngaydathang)->addElement($tiendathang)->addElement($sometvai)->addElement($them); }