<?php 
class GalleryPlugin
{
    private $table = "_plugin_gallery";
    
    private $database = DB_WARPIT_WEBCATI_BASE;
    
    private $data;
    
    private $db;
    
    private $images;
    
    public function __construct($db)
    {
        $this->db = $db;
    }
    
    public function load($idProject, $idQuestion)
    {
        $sql = "SELECT * FROM " . $this->database . "." . $this->table . "
            WHERE id_question = " . $idQuestion . " AND id_project = " . $idProject . " AND deleted = 0";
         $res= $this->db->SQLexecute($sql);
         $this->data = $this->db->fetchAssoc($res);
         
         if(empty($this->data))
         {
            $sql = "SELECT * FROM " .  $this->database . "._Plugin_label
            WHERE id_plugin = 6";
            $res= $this->db->SQLexecute($sql);
            while ($dat = $this->db->fetchAssoc($res)) {  
                $this->data[$dat['name']] = $dat['default_value'];
            }
         }
    }
    
    public function getImageArray()
    {
        if(empty($this->images) && isset($this->data['id_plugin_gallery']))
        {
            $sql = "SELECT * FROM " . $this->database . "._plugin_gallery_image  WHERE id_plugin_gallery = " . $this->getVal('id_plugin_gallery');
            $res= $this->db->SQLexecute($sql);
            while ($dat = $this->db->fetchAssoc($res)) {  
                $this->images[] = $dat['path'];
            }
        }
        return $this->images;
    }
    
    public function getVal($key)
    {
        return $this->data[$key];
    }
}

?>