<?php defined('SYSPATH') or die('No direct script access.');
/**
* Common model class.
*
* @package Sskin
* @category Model
* @author Sergey Yakovlev
* @copyright (c) 2012 Anterra Group
*/
class Model_Common extends ORM {
/**
* @var string|NULL Date format, eg: 'D, d M Y H:i:s'
*/
private static $format = NULL;
/**
* Gets the format specified in the options table
*
* @return string
*/
protected static function get_format(){
if (is_null(self::$format))
{
$options = ORM::factory('options')->where('name', '=', 'date_format')->find();
self::$format = $options->loaded() ? $options->val : 'd.m.Y';
}
return self::$format;
}
/**
* Gets the formated date string
*
* @param integer|NULL $timestamp Unix timestamp
* @return string Formated date string, eg: '24.09.2011'
*/
public function get_date($timestamp = NULL)
{
if(is_null($timestamp))
{
$timestamp = time();
}
return date(self::get_format(), (int)$timestamp);
}
}