Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

65 lines
2.3 KiB
PHP

<?php
class BlogPostSales extends ObjectModel {
public $id_sales_post;
public $key;
public $value;
public static $definition = array(
'table' => 'blog_post_sales',
'primary' => 'id_sales_post_sales',
'fields' => array(
'id_sales_post' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt','required' => true),
'key' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 24),
'value' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
)
);
public static function saveRelation($id_sales_post,$key,$data){
if(!is_numeric($id_sales_post) || empty($id_sales_post)) return false;
self::cleanRelation($id_sales_post,$key);
if(is_array($data) && count($data)){
foreach ($data as $value) {
$row = array('id_sales_post' => intval($id_sales_post),'key' => $key,'value' => $value);
Db::getInstance()->insert('blog_post_sales',$row);
}
}
return true;
}
public static function cleanRelation($id_sales_post,$key){
if(!is_numeric($id_sales_post) || empty($id_sales_post)) return false;
return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'blog_post_sales` WHERE `id_sales_post` = '.intval($id_sales_post).' AND `key` = "'.$key.'"');
}
public static function cleanPostRelations($id_sales_post){
if(!is_numeric($id_sales_post) || empty($id_sales_post)) return false;
return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'blog_post_sales` WHERE `id_sales_post` = '.intval($id_sales_post));
}
public static function cleanPostRelationKey($key,$id){
if(!is_numeric($id) || empty($id)) return false;
return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'blog_post_sales` WHERE `key` = "'.$key.'" AND `value` = '.intval($id));
}
public static function getRelation($id_sales_post,$key){
$values = array();
if(!is_numeric($id_sales_post) || empty($id_sales_post)) return $values;
$query = 'SELECT * FROM `' . _DB_PREFIX_ . 'blog_post_sales` pr WHERE pr.`key` = "'.$key.'" AND pr.`id_sales_post` = '.$id_sales_post;
$result = Db::getInstance()->ExecuteS($query);
if(is_array($result) && count($result)){
foreach($result as $row)
$values[] = $row['value'];
}
return $values;
}
}