66 lines
2.3 KiB
PHP
Executable File
66 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
class Response extends ObjectModel {
|
|
|
|
public $id;
|
|
public $id_response;
|
|
public $id_question;
|
|
public $title;
|
|
public $is_product;
|
|
public $is_lightbox;
|
|
public $text_lightbox;
|
|
|
|
public static $definition = array(
|
|
'table' => 'diag_response',
|
|
'primary' => 'id_response',
|
|
'multilang' => true,
|
|
'fields' => array(
|
|
'id_response' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'id_question' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'is_product' => array('type' => self::TYPE_INT, 'validate' => 'isBool'),
|
|
'is_lightbox' => array('type' => self::TYPE_INT, 'validate' => 'isBool'),
|
|
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString'),
|
|
'text_lightbox' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
|
|
),
|
|
);
|
|
|
|
|
|
public function getResponses($is_product = null, $is_lightbox = null, $id_question = FALSE, $id_lang = 1){
|
|
$collection = new Collection('Response', $id_lang);
|
|
|
|
if($is_product !== null)
|
|
$collection->where('is_product', '=', $is_product);
|
|
|
|
if($is_lightbox !== null)
|
|
$collection->where('is_lightbox', '=', $is_lightbox);
|
|
|
|
if($id_question){
|
|
$collection->where('id_question', '=', $id_question);
|
|
}
|
|
return $collection->getAll();
|
|
}
|
|
|
|
public function getInfosWithValues($type = 'product',$id_profil , $id_lang = 1){
|
|
if ($type == 'product'){
|
|
$sqlProducts = Db::getInstance()->executeS('
|
|
SELECT p.`id_product` as id, pl.`name` as content
|
|
FROM `'._DB_PREFIX_.'product` p
|
|
LEFT JOIN `'._DB_PREFIX_.'diag_profil_rep_prod` pp ON (p.`id_product` = pp.`id_product`)
|
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
|
|
WHERE pp.`id_response`='.(int)$this->id_response.' AND pp.`id_profil`='.(int)$id_profil.' AND pl.`id_lang`='.(int)$id_lang);
|
|
|
|
return $sqlProducts;
|
|
}
|
|
}
|
|
|
|
public static function getResponsesByQuestion($id_question, $id_lang){
|
|
$responses = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
|
SELECT rl.`title`, rl.`text_lightbox`, r.*
|
|
FROM '._DB_PREFIX_.'diag_response r
|
|
LEFT JOIN '._DB_PREFIX_.'diag_response_lang rl on (rl.`id_response` = r.`id_response`)
|
|
WHERE rl.`id_lang` = '.(int)$id_lang.' AND (r.`id_question` = '.$id_question.')
|
|
');
|
|
return $responses;
|
|
}
|
|
|
|
} |