public function exchangeArray($data) { $float_filter = new \Zend\I18n\Filter\NumberFormat(); if (isset($data['category']['id'])) { $data['category_id'] = $data['category']['id']; } if (isset($data['currency']['id'])) { $data['currency_id'] = $data['currency']['id']; } $this->id = isset($data['id']) ? $data['id'] : null; $this->user_id = isset($data['user_id']) ? $data['user_id'] : null; $this->category_id = isset($data['category_id']) ? $data['category_id'] : null; $this->currency_id = isset($data['currency_id']) ? $data['currency_id'] : null; $this->category_name = isset($data['category_name']) ? $data['category_name'] : null; $this->category_slug = isset($data['category_slug']) ? $data['category_slug'] : null; $this->created = isset($data['created']) ? $data['created'] : null; $this->end_time = isset($data['end_time']) ? $data['end_time'] : null; $this->updated = isset($data['updated']) ? $data['updated'] : null; $this->views = isset($data['views']) ? $data['views'] : null; $this->price = isset($data['price']) ? $float_filter->filter($data['price']) : null; $this->buyout = isset($data['buyout']) ? $float_filter->filter($data['buyout']) : null; $this->bid = isset($data['bid']) ? $data['bid'] : null; $this->bid_count = isset($data['bid_count']) ? $data['bid_count'] : null; $this->slug = isset($data['slug']) ? $data['slug'] : null; $this->header = isset($data['header']) ? $data['header'] : null; $this->body = isset($data['body']) ? $data['body'] : null; $this->protection = isset($data['protection']) ? $data['protection'] : null; }
public function __invoke($item, $seek = 'label', $value = null, $options = array()) { $options = array_merge(array('km_convert_at' => 501), $options); if (is_string($item)) { try { $item = $this->numvalService->getItem($item); $item->setValue($value); } catch (\Exception $e) { return ''; } } elseif (!is_object($item)) { return ''; } $number_filter = new \Zend\I18n\Filter\NumberFormat("de_CH"); switch ($seek) { case 'label': return $item->getLabel(); break; case 'value': $val = $item->getValue(); $km = false; //km conversion if (in_array($item->getSi(), array('m'))) { if ($options['km_convert_at'] && $val >= $options['km_convert_at']) { $val = $val / 1000; $km = true; } } switch ($item->getSi()) { case 'm': $val = $number_filter->filter($val) . ' ' . ($km ? 'km' : 'm'); break; case 'm2': $val = $number_filter->filter($val) . ' ' . ($km ? 'km' : 'm') . '<sup>2</sup>'; break; case 'm3': $val = $number_filter->filter($val) . ' ' . ($km ? 'km' : 'm') . '<sup>3</sup>'; break; } return $val; break; case 'icon': return $item->getIcon(); break; case 'si': return $item->getSi(); break; } return ''; }
public function exchangeArray($data) { $float_filter = new \Zend\I18n\Filter\NumberFormat(); $this->id = isset($data['id']) ? $data['id'] : null; $this->auction_id = isset($data['auction_id']) ? $data['auction_id'] : 0; $this->user_id = isset($data['user_id']) ? $data['user_id'] : 0; $this->username = isset($data['username']) ? $data['username'] : ""; $this->bid = isset($data['bid']) ? (double) $float_filter->filter($data['bid']) : 0; $this->time = isset($data['time']) ? $data['time'] : 0; }
/** * Convert normalized integer, float or date values to localized string representation * * Subclasses can support localized input formats by overriding setData() * where this method can be used to preprocess specific fields. It accepts * strictly normalized input data: * * - Integers must contain only digits. * - Floats must contain only digits and at most 1 dot, but not at the end * of the string. * - Dates must be passed as \DateTime objects or ISO date strings. * * Invalid input data is returned unmodified. The attached input filter * should take care of it. * * @param mixed $value Normalized input value * @param string $type Data type (integer, float, date). Any other value will be ignored. * @return mixed Localized or unmodified value */ public function localize($value, $type) { switch ($type) { case 'integer': if (ctype_digit((string) $value)) { $value = \Zend\Filter\StaticFilter::execute((int) $value, 'NumberFormat', array('type' => \NumberFormatter::TYPE_INT32)); } break; case 'float': if ($value !== null and $value !== '' and preg_match('/^([0-9]+)?(\\.[0-9]+)?$/', $value)) { $numberFormat = new \Zend\I18n\Filter\NumberFormat(); $numberFormat->getFormatter()->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 100); $value = $numberFormat->filter((double) $value); } break; case 'date': $formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); if ($value instanceof \DateTime) { $value = $formatter->format($value); } elseif (\Zend\Validator\StaticValidator::execute($value, 'Date')) { $date = \DateTime::createFromFormat('Y-m-d', $value); if ($date) { $value = $formatter->format($date); } } break; } return $value; }