本文整理汇总了PHP中Num类的典型用法代码示例。如果您正苦于以下问题:PHP Num类的具体用法?PHP Num怎么用?PHP Num使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Num类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_max_size
/**
*
* @param integer $size
*/
public function set_max_size($size)
{
if (empty($size)) {
$size = Num::bytes('1MiB');
}
$this->max_size = (int) $size;
}
示例2: __set
/**
* Override __set() to handle time.
*
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
if ($key === 'size_time' && !is_numeric($value)) {
$value = Num::seconds($value);
}
parent::__set($key, $value);
}
示例3: action_browse
/**
* Action: browse tracks
*/
public function action_browse()
{
$type = $this->request->param('music') == 'mixtapes' ? Model_Music_Track::TYPE_MIX : Model_Music_Track::TYPE_TRACK;
$genre = $this->request->param('genre');
// Load requested music
$limit = 25;
$music = Model_Music_Track::factory();
$count = $music->count_by_type($type, $genre);
// Build page
$this->view = View_Page::factory($type == Model_Music_Track::TYPE_MIX ? __('Mixtapes') : __('Tracks'));
// Set actions
$this->_set_page_actions();
$this->view->tab = $this->request->param('music');
// Filters
$this->view->add(View_Page::COLUMN_CENTER, $this->section_filters($this->request->param('music'), $genre));
// Pagination
$this->view->add(View_Page::COLUMN_CENTER, $pagination = $this->section_pagination($limit, $count));
$this->view->subtitle = __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0)));
// Browse
$tracks = $music->find_by_type($type, $genre, $limit, $pagination->offset);
$this->view->add(View_Page::COLUMN_CENTER, $this->section_browse($tracks));
// Pagination
$this->view->add(View_Page::COLUMN_CENTER, $pagination);
// New
$this->view->add(View_Page::COLUMN_RIGHT, $this->section_list($music->find_new(Model_Music_Track::TYPE_MIX, 10), __('New mixtapes')));
$this->view->add(View_Page::COLUMN_RIGHT, $this->section_list($music->find_new(Model_Music_Track::TYPE_TRACK, 10), __('New tracks')));
}
示例4: verbose
public function verbose($value)
{
$value = $this->value($value);
if ($this->decimals) {
$value = Num::format($value, $this->decimals);
}
return (string) $value;
}
示例5: currency
/**
* Get currency based on date. Used for currency chances such as Euro.
*
* @static
* @param float $amount
* @param integer $date
* @return string
*/
public static function currency($amount, $date = null)
{
static $change;
// Show decimals only if required
$amount = $amount == (int) $amount ? (int) $amount : Num::format($amount, 2, true);
// Finland switched to Euro on January 1st, 2002
if (!$change) {
$change = mktime(0, 0, 0, 1, 1, 2002);
}
$currency = !$date || $date >= $change ? '€' : 'mk';
return $amount . $currency;
}
示例6: content
/**
* Render view.
*
* @return string
*/
public function content()
{
ob_start();
// Title
if ($this->area->description) {
echo $this->area->description . '<hr>';
}
if ($this->area->topic_count) {
// Area has topics
$last_topic = $this->area->last_topic();
$last_poster = $last_topic->last_post()->author();
?>
<div class="media">
<div class="pull-left">
<?php
echo HTML::avatar($last_poster ? $last_poster['avatar'] : null, $last_poster ? $last_poster['username'] : null, false);
?>
</div>
<div class="media-body">
<small class="ago"><?php
echo HTML::time(Date::short_span($last_topic->last_posted, true, true), $last_topic->last_posted);
?>
</small>
<?php
echo $last_poster ? HTML::user($last_poster) : HTML::chars($last_topic->last_poster);
?>
<br>
<?php
echo HTML::anchor(Route::model($last_topic, '?page=last#last'), Forum::topic($last_topic), array('title' => HTML::chars($last_topic->name)));
?>
<br />
</div>
</div>
<small class="stats muted">
<i class="icon-comments"></i> <?php
echo Num::format($this->area->topic_count, 0);
?>
<i class="icon-comment"></i> <?php
echo Num::format($this->area->post_count, 0);
?>
</small>
<?php
} else {
// Empty area
echo __('No topics yet.');
}
return ob_get_clean();
}
示例7: rules
public function rules()
{
return ['amount' => function ($value) {
if ($value <= 0) {
return 'Еще нет средств на расход';
}
$amount = $this->model('Salary')->getReady();
$amount = intval($amount);
$value = intval($value);
if ($amount !== $value) {
return 'Сумма изменилась должно быть:' . \Num::format($amount);
}
}];
}
示例8: validate
public function validate(Jam_Validated $model, $attribute, $value)
{
if ($value and !$value->is_empty() and $value->source()) {
if ($error = $value->source()->error()) {
$model->errors()->add($attribute, 'uploaded_native', array(':message' => $error));
} elseif (!is_file($value->file())) {
$model->errors()->add($attribute, 'uploaded_is_file');
}
if ($this->only and !in_array(strtolower(pathinfo($value->filename(), PATHINFO_EXTENSION)), $this->valid_extensions())) {
$model->errors()->add($attribute, 'uploaded_extension', array(':extension' => join(', ', $this->valid_extensions())));
}
if ($this->minimum_size or $this->maximum_size or $this->exact_size) {
$size = @filesize($value->file());
if ($this->minimum_size and $minimum_size = Num::bytes($this->minimum_size) and (int) $size < (int) $minimum_size) {
$model->errors()->add($attribute, 'uploaded_minimum_size', array(':minimum_size' => $this->minimum_size));
}
if ($this->maximum_size and $maximum_size = Num::bytes($this->maximum_size) and (int) $size > (int) $maximum_size) {
$model->errors()->add($attribute, 'uploaded_maximum_size', array(':maximum_size' => $this->maximum_size));
}
if ($this->exact_size and $exact_size = Num::bytes($this->exact_size) and (int) $size !== (int) $exact_size) {
$model->errors()->add($attribute, 'uploaded_exact_size', array(':exact_size' => $this->exact_size));
}
}
if ($this->minimum_width or $this->minimum_height or $this->maximum_width or $this->maximum_height or $this->exact_width or $this->exact_height) {
$dims = @getimagesize($value->file());
if ($dims) {
list($width, $height) = $dims;
if ($this->exact_width and (int) $width !== (int) $this->exact_width) {
$model->errors()->add($attribute, 'uploaded_exact_width', array(':exact_width' => $this->exact_width));
}
if ($this->exact_height and (int) $height !== (int) $this->exact_height) {
$model->errors()->add($attribute, 'uploaded_exact_height', array(':exact_height' => $this->exact_height));
}
if ($this->minimum_width and (int) $width < (int) $this->minimum_width) {
$model->errors()->add($attribute, 'uploaded_minimum_width', array(':minimum_width' => $this->minimum_width));
}
if ($this->minimum_height and (int) $height < (int) $this->minimum_height) {
$model->errors()->add($attribute, 'uploaded_minimum_height', array(':minimum_height' => $this->minimum_height));
}
if ($this->maximum_width and (int) $width > (int) $this->maximum_width) {
$model->errors()->add($attribute, 'uploaded_maximum_width', array(':maximum_width' => $this->maximum_width));
}
if ($this->maximum_height and (int) $height > (int) $this->maximum_height) {
$model->errors()->add($attribute, 'uploaded_maximum_height', array(':maximum_height' => $this->maximum_height));
}
}
}
}
}
示例9: rules
public function rules()
{
return ['out' => function ($value) {
$salary = $this->salary;
$out = $salary['out'] + $salary['balance'];
// должно быть всего выдано
$_balance = $this->getData('balance', 0);
if (!empty($value)) {
if ($value > $out) {
return 'нельзя выдать больше чем должно быть ' . \Num::format($out);
}
}
/*$summa = $value + $_balance;
if($summa != $out){
return 'Сумма Выдано + Осталось выдать НЕ Совпадает ('.\Num::format($out-$_balance).'), должно быть '.\Num::format($out);
}*/
}];
}
示例10: pretty_format
static function pretty_format($price, $valute = NULL, $discount = NULL)
{
if ($valute === 'LVL' or $valute === NULL) {
if ($discount !== NULL) {
return Num::format($price / 100 - $price / 100 * ($discount / 100), 2) . ' ls';
}
return Num::format($price / 100, 2) . ' Ls';
} elseif ($valute === 'EUR') {
if ($discount !== NULL) {
return '€' . Num::format(($price / 100 - $price / 100 * ($discount / 100)) / 0.7, 2);
}
return '€' . Num::format($price / 100 / 0.7, 2);
} elseif ($valute === 'USD') {
if ($discount !== NULL) {
return Num::format(($price / 100 - $price / 100 * ($discount / 100)) / 0.57, 2);
}
return '$ ' . Num::format($price / 100 / 0.57, 2);
}
}
示例11: topic
/**
* Get prefixed forum title.
*
* @static
* @param Model_Forum_Topic $topic
* @return string
*/
public static function topic(Model_Forum_Topic $topic)
{
$prefix = array();
// Private topic
if ($topic->recipient_count) {
$prefix[] = $topic->recipient_count > 2 ? '<i class="fa fa-group text-muted" title="' . __(':recipients recipients', array(':recipients' => Num::format($topic->recipient_count, 0))) . '"></i>' : '<i class="fa fa-envelope text-muted" title="' . __('Personal message') . '"></i>';
}
// Stickyness
if ($topic->sticky) {
$prefix[] = '<i class="fa fa-thumb-tack text-warning" title="' . __('Pinned') . '"></i>';
}
// Status
switch ($topic->status) {
case Model_Forum_Topic::STATUS_LOCKED:
$prefix[] = '<i class="fa fa-lock text-muted" title="' . __('Locked') . '"></i>';
break;
case Model_Forum_Topic::STATUS_SINK:
$prefix[] = '<i class="fa fa-unlock text-muted" title="' . __('Sink') . '"></i>';
break;
}
return implode(' ', $prefix) . ' ' . HTML::chars($topic->name);
}
示例12: render
/**
* Render view.
*
* @return string
*/
public function render()
{
ob_start();
$rating = $this->count ? $this->total / $this->count : 0;
?>
<span class="rating">
<?php
for ($r = 1; $r <= 5; $r++) {
?>
<i class="<?php
echo $rating >= $r - 0.5 ? 'icon-star' : 'icon-star-empty';
?>
icon-white" title="<?php
echo $r;
?>
"></i>
<?php
}
?>
<?php
if ($this->score) {
?>
<var title="<?php
echo __($this->count == 1 ? ':rates rating' : ':rates ratings', array(':rates' => $this->count));
?>
"><?php
echo Num::format($rating, 2);
?>
</var>
<?php
}
?>
</span>
<?php
return ob_get_clean();
}
示例13: file
/**
* Загрузка файла и сохранение в папку TMPPATH
*
* try
* {
* $filename = Upload::file($_FILES['file'], NULL, NULL, array('jpg', 'jpeg', 'gif', 'png'));
* $path = TMPPATH . $filename;
* }
* catch (Validation_Exception $e)
* {
* echo debug::vars($e->errors('validation'));
* }
*
* При указании строки в качестве параметра $file, будет произведена
* попытка загрузить файл по URL
*
* @param string|array $file
* @param string $directory Путь к каталогу, куда загружать файл
* @param string $filename Название файла (filename.ext)
* @param array $types Разрешенные типы файлов (При указании пустой строки, разрешены все файлы) array('jpg', '...')
* @param integer $max_size Максимальный размер загружаемого файла
* @return string|NULL Название файла.
* @throws Validation_Exception
*/
public static function file($file, $directory = NULL, $filename = NULL, array $types = array('jpg', 'jpeg', 'gif', 'png'), $max_size = NULL)
{
if (!is_array($file)) {
return Upload::from_url($file, $directory, $filename, $types);
}
if ($directory === NULL) {
$directory = TMPPATH;
}
if ($filename === NULL) {
$filename = uniqid();
} else {
if ($filename === TRUE) {
$filename = $file['name'];
}
}
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$filename_ext = pathinfo($filename, PATHINFO_EXTENSION);
if (empty($filename_ext)) {
$filename .= '.' . $ext;
}
if ($max_size === NULL) {
$max_size = Num::bytes('20MiB');
}
$validation = Validation::factory(array('file' => $file))->rules('file', array(array('Upload::valid'), array('Upload::size', array(':value', $max_size))));
if (!empty($types)) {
$validation->rule('file', 'Upload::type', array(':value', $types));
}
if (!$validation->check()) {
throw new Validation_Exception($validation);
}
if (!is_dir($directory)) {
mkdir($directory, 0777);
chmod($directory, 0777);
}
Upload::save($file, $filename, $directory, 0777);
return $filename;
}
示例14: save_base64_image
/**
* save_base64_image upload images with given path
*
* @param string $image [base64 encoded image]
* @return bool
*/
public function save_base64_image($image)
{
if (!$this->loaded()) {
return FALSE;
}
// Temporary save image
$image_data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $image));
$image_tmp = tmpfile();
$image_tmp_uri = stream_get_meta_data($image_tmp)['uri'];
file_put_contents($image_tmp_uri, $image_data);
$image = Image::factory($image_tmp_uri);
if (!in_array($image->mime, explode(',', 'image/' . str_replace(",", ",image/", core::config('image.allowed_formats'))))) {
Alert::set(Alert::ALERT, $image->mime . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats')));
return FALSE;
}
if (filesize($image_tmp_uri) > Num::bytes(core::config('image.max_image_size') . 'M')) {
Alert::set(Alert::ALERT, $image->mime . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size')));
return FALSE;
}
if (core::config('image.disallow_nudes') and $image->is_nude_image()) {
Alert::set(Alert::ALERT, $image->mime . ' ' . __('Seems a nude picture so you cannot upload it'));
return FALSE;
}
return $this->save_image_file($image_tmp_uri, $this->has_images + 1);
}
示例15: icon_value
/**
* Print icon with value
*
* @param integer|array $value :var => value
* @param string $singular title for singular value
* @param string $plural title for plural value
* @param string $class icon class
*/
public static function icon_value($value, $singular = '', $plural = '', $class = '')
{
$class = $class ? 'icon ' . $class : 'icon';
if (is_array($value)) {
$var = key($value);
$value = $value[$var];
}
if (is_numeric($value)) {
// Format number
$formatted = Num::format($value, 0);
$plural = $plural ? $plural : $singular;
$title = $singular && $plural ? ' title="' . __($value == 1 ? $singular : $plural, array($var => $formatted)) . '"' : '';
} else {
// Value is a string, no formatting
$formatted = HTML::chars($singular);
$title = '';
}
return '<var class="' . $class . '"' . $title . '>' . $formatted . '</var>';
}