92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
class CmsPsPost extends ObjectModel {
|
|
|
|
public $id_post;
|
|
public $id_category;
|
|
public $date_add;
|
|
public $date_upd;
|
|
public $active;
|
|
public $show_home;
|
|
public $trick;
|
|
|
|
public $title;
|
|
public $slug;
|
|
public $intro;
|
|
public $content;
|
|
public $meta_title;
|
|
public $meta_desc;
|
|
|
|
public $img_size = array(
|
|
array(
|
|
'name' => 'small',
|
|
'width' => 400,
|
|
'height' => 240
|
|
),
|
|
array(
|
|
'name' => 'big',
|
|
'width' => 770,
|
|
'height' => 500
|
|
)
|
|
);
|
|
|
|
/**
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'cmsps_posts',
|
|
'primary' => 'id_post',
|
|
'multilang' => TRUE,
|
|
'multilang_shop' => TRUE,
|
|
'fields' => array(
|
|
'id_category' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => TRUE),
|
|
'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'show_home' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'trick' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
|
|
// Lang fields
|
|
'title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'required' => TRUE),
|
|
'slug' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
'intro' => array('type' => self::TYPE_HTML, 'lang' => TRUE, 'validate' => 'isCleanHtml'),
|
|
'content' => array('type' => self::TYPE_HTML, 'lang' => TRUE, 'validate' => 'isCleanHtml'),
|
|
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
'meta_desc' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
|
|
'date_add' => array('type' => self::TYPE_DATE),
|
|
'date_upd' => array('type' => self::TYPE_DATE)
|
|
),
|
|
);
|
|
|
|
public function __construct($id = NULL, $id_lang = NULL, $id_shop = NULL) {
|
|
parent::__construct($id, $id_lang, $id_shop);
|
|
}
|
|
|
|
public static function getPostHome($id_lang, $limit = 14) {
|
|
$collection_post = new Collection('CmsPsPost', $id_lang);
|
|
$collection_post->where('show_home', '=', 1);
|
|
$collection_post->where('active', '=', 1);
|
|
$collection_post->orderBy('date_add', 'DESC');
|
|
$collection_post->setPageSize(14);
|
|
$posts = $collection_post->getResults();
|
|
|
|
foreach ($posts as $key => $post) {
|
|
$post->new = $post->isNew();
|
|
}
|
|
return $posts;
|
|
}
|
|
|
|
public function isNew() {
|
|
$date = new DateTime();
|
|
$date->modify('-15 days');
|
|
$date_post = new DateTime($this->date_add);
|
|
|
|
if ($date_post > $date) {
|
|
return TRUE;
|
|
} else {
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
}
|
|
|