157 lines
3.6 KiB
PHP
157 lines
3.6 KiB
PHP
<?php
|
|
|
|
class Publication extends ObjectModel
|
|
{
|
|
public $id;
|
|
|
|
public $id_publication;
|
|
|
|
public $id_block_ads;
|
|
public $id_shop;
|
|
public $date_from;
|
|
public $date_to;
|
|
public $date_add;
|
|
public $date_upd;
|
|
|
|
public $pages = null;
|
|
public $pages_infos = null;
|
|
|
|
public static $definition = array(
|
|
'table' => 'ads_publication',
|
|
'primary' => 'id_publication',
|
|
'multilang' => true,
|
|
'fields' => array(
|
|
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'content' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isAnything'),
|
|
'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
|
'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
|
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
|
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
|
),
|
|
);
|
|
|
|
public function getInfos($page_name = null)
|
|
{
|
|
if(!Validate::isLoadedObject($this))
|
|
$this->pages_infos = array();
|
|
|
|
if($this->pages_infos === null)
|
|
{
|
|
$array_tmp = array();
|
|
|
|
$sql = 'SELECT *
|
|
FROM '._DB_PREFIX_.'ads_publication_other
|
|
WHERE id_publication = '.(int)$this->id.'';
|
|
|
|
$infos = Db::getInstance()->executeS($sql);
|
|
foreach($infos as $info)
|
|
{
|
|
$array_tmp[$info['page_name']] = $info['id_free'];
|
|
}
|
|
|
|
$this->pages_infos = $array_tmp;
|
|
}
|
|
|
|
if(empty($page_name))
|
|
return $this->pages_infos;
|
|
|
|
if(isset($this->pages_infos[$page_name]))
|
|
return $this->pages_infos[$page_name];
|
|
|
|
return array();
|
|
}
|
|
|
|
public function getSelectedPages()
|
|
{
|
|
if(!Validate::isLoadedObject($this))
|
|
$this->pages = array();
|
|
if($this->pages === null)
|
|
{
|
|
$sql = 'SELECT page_name
|
|
FROM '._DB_PREFIX_.'ads_publication_page
|
|
WHERE id_publication = '.(int)$this->id;
|
|
|
|
$pages = Db::getInstance()->executeS($sql);
|
|
$pages = array_map(function($line){ return $line['page_name']; }, $pages);
|
|
$this->pages = $pages;
|
|
}
|
|
|
|
return $this->pages;
|
|
}
|
|
|
|
public function setPages($pages = array())
|
|
{
|
|
$this->pages = $pages;
|
|
|
|
if(Validate::isLoadedObject($this))
|
|
{
|
|
Db::getInstance()->execute('
|
|
DELETE FROM '._DB_PREFIX_.'ads_publication_page
|
|
WHERE id_publication = '.$this->id);
|
|
|
|
$req = array();
|
|
foreach($pages as $page_name)
|
|
$req[] = array(
|
|
'id_publication' => $this->id,
|
|
'page_name' => $page_name
|
|
);
|
|
|
|
Db::getInstance()->insert('ads_publication_page', $req);
|
|
}
|
|
}
|
|
|
|
public function setPageInfo($page_name, $infos)
|
|
{
|
|
$this->pages_infos[$page_name] = $infos;
|
|
|
|
if(Validate::isLoadedObject($this))
|
|
{
|
|
Db::getInstance()->execute('
|
|
DELETE FROM '._DB_PREFIX_.'ads_publication_other
|
|
WHERE id_publication = '.$this->id.'
|
|
AND page_name = '.pSQL($page_name));
|
|
|
|
$req = array();
|
|
foreach($infos as $info)
|
|
$req[] = array(
|
|
'id_publication' => $this->id,
|
|
'page_name' => $page_name,
|
|
'id_free' => $info
|
|
);
|
|
|
|
Db::getInstance()->insert('ads_publication_other', $req);
|
|
}
|
|
}
|
|
|
|
public static function getAllPages()
|
|
{
|
|
return array(
|
|
'index',
|
|
'postcms', //Article
|
|
'categorycms', //Category d'article
|
|
'postedito', //Article mise en forme différent
|
|
);
|
|
}
|
|
|
|
public static function getPageNameTranslated($page_name)
|
|
{
|
|
$array = array(
|
|
'index' => 'Page d\'accueil',
|
|
'postcms' => 'Article', //Article
|
|
'categorycms' => 'Catégorie d\'article', //Category d'article
|
|
'postedito' => 'Edito', //Article mise en forme différent
|
|
);
|
|
|
|
return isset($array[$page_name]) ? $array[$page_name] : $page_name;
|
|
}
|
|
|
|
public static function getPageNeedInfos()
|
|
{
|
|
return array(
|
|
'postcms',
|
|
'categorycms',
|
|
'postedito'
|
|
);
|
|
}
|
|
|
|
} |