2015-07-10 15:14:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CmsPsPost extends ObjectModel {
|
|
|
|
|
|
|
|
public $id_post;
|
|
|
|
public $id_category;
|
|
|
|
public $date_add;
|
|
|
|
public $date_upd;
|
|
|
|
public $active;
|
2015-07-28 10:33:55 +02:00
|
|
|
public $show_home;
|
|
|
|
public $trick;
|
2015-07-31 11:37:25 +02:00
|
|
|
public $note;
|
2015-07-10 15:14:26 +02:00
|
|
|
|
|
|
|
public $title;
|
|
|
|
public $slug;
|
|
|
|
public $intro;
|
|
|
|
public $content;
|
|
|
|
public $meta_title;
|
|
|
|
public $meta_desc;
|
|
|
|
|
2015-07-28 11:51:12 +02:00
|
|
|
public $img_size = array(
|
|
|
|
array(
|
|
|
|
'name' => 'small',
|
|
|
|
'width' => 400,
|
|
|
|
'height' => 240
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'big',
|
|
|
|
'width' => 770,
|
|
|
|
'height' => 500
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2015-07-10 15:14:26 +02:00
|
|
|
/**
|
|
|
|
* @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'),
|
2015-07-28 10:33:55 +02:00
|
|
|
'show_home' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
|
|
'trick' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
2015-07-31 11:37:25 +02:00
|
|
|
'note' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
2015-07-10 15:14:26 +02:00
|
|
|
|
|
|
|
// Lang fields
|
2015-07-29 16:58:18 +02:00
|
|
|
'title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'required' => TRUE),
|
2015-07-10 15:14:26 +02:00
|
|
|
'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);
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:58:18 +02:00
|
|
|
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();
|
2015-08-11 12:04:07 +02:00
|
|
|
return self::injectsData($posts);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associated data for each obj Post before display on Front
|
|
|
|
*
|
|
|
|
* @param array Array of CmsPsPost Object
|
|
|
|
* @return array array of post object with data associated
|
|
|
|
*/
|
|
|
|
public static function injectsData($articles) {
|
|
|
|
foreach ($articles as $key => $article) {
|
|
|
|
$article->new = $article->isNew();
|
2015-07-29 16:58:18 +02:00
|
|
|
}
|
2015-08-11 12:04:07 +02:00
|
|
|
|
|
|
|
return $articles;
|
2015-07-29 16:58:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isNew() {
|
|
|
|
$date = new DateTime();
|
2015-07-29 17:24:15 +02:00
|
|
|
$date->modify('-15 days');
|
2015-07-29 16:58:18 +02:00
|
|
|
$date_post = new DateTime($this->date_add);
|
|
|
|
|
|
|
|
if ($date_post > $date) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 12:04:07 +02:00
|
|
|
|
2015-07-10 15:14:26 +02:00
|
|
|
}
|
2015-07-29 16:58:18 +02:00
|
|
|
|