Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * Zwracane są sformatowane wartości na podstawie headerMappings przy użyciu lokalizacji
  * @param boolean $format - czy wartośći mają być formatowane do wyświetlenia na stronie
  * @return array - wynik
  */
 public function toArray($format = true)
 {
     $array = parent::toArray();
     if (!$format) {
         return $array;
     }
     $formatter = new Logic_View_Helper_Formatter();
     $formatOptions = array('locale' => Zend_Registry::get('Zend_Locale'));
     foreach ($this->headerMappings as $key => $row) {
         if (isset($row['format']) and $row['format'] === 'currency') {
             $array[$key] = Zend_Locale_Format::toFloat($array[$key], array('locale' => 'pl_PL', 'precision' => 2));
             continue;
         }
         $array[$key] = isset($row['format']) ? $formatter->Formatter($array[$key], $row['format']) : $array[$key];
     }
     return $array;
 }
 /**
  * Defined by Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (is_array($value)) {
         require_once 'Zend/Date.php';
         $date = new Zend_Date($value, $this->_options['locale']);
         return $date->toString($this->_options['date_format']);
     } else {
         if ($this->_options['precision'] === 0) {
             return Zend_Locale_Format::toInteger($value, $this->_options);
         } else {
             if ($this->_options['precision'] === null) {
                 return Zend_Locale_Format::toFloat($value, $this->_options);
             }
         }
     }
     return Zend_Locale_Format::toNumber($value, $this->_options);
 }
Пример #5
0
    /**
     * Test toFloat()/toNumber() when a different setlocale() is in effect,
     * where the locale does not use '.' as the decimal place separator.
     * expected string
     */
    public function testToFloatSetlocale()
    {
        setlocale(LC_ALL, 'fr_FR@euro'); // test setup

        //var_dump( setlocale(LC_NUMERIC, '0')); // this is the specific setting of interest
        $locale_fr = new Zend_Locale('fr_FR');
        $locale_en = new Zend_Locale('en_US');
        $params_fr = array('precision' => 2, 'locale' => $locale_fr);
        $params_en = array('precision' => 2, 'locale' => $locale_en);
        $myFloat = 1234.5;
        $test1 = Zend_Locale_Format::toFloat($myFloat, $params_fr);
        $test2 = Zend_Locale_Format::toFloat($myFloat, $params_en);
        $this->assertEquals("1 234,50", $test1);
        $this->assertEquals("1,234.50", $test2);
        // placing tearDown here (i.e. restoring locale) won't work, if test already failed/aborted above.
    }
Пример #6
0
 /**
  * Renders the decimal ranges.
  *
  * @param int $range
  * @param float $value
  * @return string
  */
 protected function _renderDecimalRanges($range, $value)
 {
     /** @var $attributes Mage_Catalog_Model_Resource_Eav_Attribute */
     $attributes = $this->getAttributeModel();
     if ($attributes->getFrontendInput() == 'price') {
         return parent::_renderDecimalRanges($range, $value);
     }
     $from = ($value - 1) * $range;
     $to = $value * $range;
     if ($from != $to) {
         $to -= 0.01;
     }
     $to = Zend_Locale_Format::toFloat($to, array('locale' => Mage::helper('nanowebg_elasticsearch')->getLocale()));
     return Mage::helper('catalog')->__('%s - %s', $from, $to);
 }
Пример #7
0
 public function testShortNotation()
 {
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(0.12345));
     $options = array('locale' => 'de');
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
     $this->assertEquals('0,75', Zend_Locale_Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2)));
     $this->assertTrue(Zend_Locale_Format::isNumber(',12345', array('locale' => 'de_AT')));
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(0.12345));
     $options = array('locale' => 'de');
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
     $options = array('locale' => 'ar_QA');
     $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
     $this->assertTrue(Zend_Locale_Format::isFloat(',12345', array('locale' => 'de_AT')));
     $this->assertEquals(0, Zend_Locale_Format::getInteger(0.1234567));
     $options = array('locale' => 'de');
     $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
     $this->assertEquals('0', Zend_Locale_Format::toInteger(0.123, array('locale' => 'de')));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0', Zend_Locale_Format::toInteger(0.12345, $options));
     $this->assertFalse(Zend_Locale_Format::isInteger(',12345', array('locale' => 'de_AT')));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0,567', Zend_Locale_Format::toNumber(0.5669999999999999, $options));
 }
Пример #8
0
 /**
  * test positive float seperation language locale precision
  * expected integer
  */
 public function testFloatRegionSeperatedPositiveFloatPrecAdd()
 {
     $value = Zend_Locale_Format::toFloat(1234567.12345, 7, 'de_AT');
     $this->assertEquals($value, '1.234.567,12345', "value 1.234.567,12345 expected");
 }
Пример #9
0
 /**
  * Test toFloat()/toNumber() when a different setlocale() is in effect,
  * where the locale does not use '.' as the decimal place separator.
  * expected string
  */
 public function testToFloatSetlocale()
 {
     // test still has problems in some environments
     // That's not clear if it's environment, PHP or ZF problem
     // mark this test as skipped
     $this->markTestSkipped('Float conversin is skipped because of incorrect behavior in some environments');
     return;
     setlocale(LC_ALL, 'fr_FR@euro');
     // test setup
     //var_dump( setlocale(LC_NUMERIC, '0')); // this is the specific setting of interest
     $locale_fr = new Zend_Locale('fr_FR');
     $locale_en = new Zend_Locale('en_US');
     $params_fr = array('precision' => 2, 'locale' => $locale_fr);
     $params_en = array('precision' => 2, 'locale' => $locale_en);
     $myFloat = 1234.5;
     $test1 = Zend_Locale_Format::toFloat($myFloat, $params_fr);
     $test2 = Zend_Locale_Format::toFloat($myFloat, $params_en);
     $this->assertEquals("1 234,50", $test1);
     $this->assertEquals("1,234.50", $test2);
     // placing tearDown here (i.e. restoring locale) won't work, if test already failed/aborted above.
 }
Пример #10
0
 /**
  * test toFloat
  * expected string
  */
 public function testToFloat()
 {
     $this->assertEquals(Zend_Locale_Format::toFloat(0), '0', "string 0 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(0, 'de'), '0', "string 0 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(0, 'de_AT'), '0', "string 0 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567, 'de_AT'), '-1.234.567', "string -1.234.567 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567, 'de_AT'), '1.234.567', "string 1.234.567 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(0.1234567, 'de_AT'), '0,1234567', "string 0,1234567 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567.12345, 'de_AT'), '-1.234.567,12345', "string -1.234.567,12345 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567.12345, 'de_AT'), '1.234.567,12345', "value 1.234.567,12345 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567.12345, 'ar_QA'), '1234567٫12345', "value 1234567٫12345 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567.12345, 'ar_QA'), '1234567٫12345-', "value 1234567٫12345- expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567.12345, 'dz_BT'), '12,34,567.12345', "value 12,34,567.12345 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567.12345, 'mk_MK'), '-(1.234.567,12345)', "value -(1.234.567,12345) expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(0, 2, 'de_AT'), '0,00', "value 0 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567, 2, 'de_AT'), '-1.234.567,00', "value -1.234.567 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567, 2, 'de_AT'), '1.234.567,00', "value 1.234.567 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(0.1234567, 2, 'de_AT'), '0,12', "value 0,12 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(-1234567.12345, 2, 'de_AT'), '-1.234.567,12', "value -1.234.567,12 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567.12345, 2, 'de_AT'), '1.234.567,12', "value 1.234.567,12 expected");
     $this->assertEquals(Zend_Locale_Format::toFloat(1234567.12345, 7, 'de_AT'), '1.234.567,1234500', "value 1.234.567,12345 expected");
 }
Пример #11
0
 private function insertDiet()
 {
     $this->position++;
     $data = $this->getBasicData();
     $data['ID_POZ'] = '';
     $data['NUMER_POZYCJI'] = $this->position;
     $data['PARAMETR'] = 'PB';
     $data['SYMBOL_KONTA'] = $this->tetaEmployeerAccounts->KONTO_DIET;
     $data['OPIS_POZYCJI'] = $this->delegation->deleg_no . ' DELEGACJA - DIETA';
     $data['KWOTA_WN'] = str_replace(".", ",", $this->delegation->getDiet());
     $data['KWOTA_MA'] = Zend_Locale_Format::toFloat(0.0);
     if ($this->delegation->getDiet() > 0.0) {
         $this->modelTetaImport->insert($data);
     } else {
         $this->position--;
     }
 }