Add some classes and fix some bugs in class Theme
This commit is contained in:
parent
eac6118532
commit
99f86c6b28
1 changed files with 36 additions and 9 deletions
|
@ -5,19 +5,20 @@ if(!defined('ONYX')) exit;
|
||||||
class Theme
|
class Theme
|
||||||
{
|
{
|
||||||
var $id = null;
|
var $id = null;
|
||||||
var $title;
|
var $name;
|
||||||
|
|
||||||
function Theme($id=null)
|
function Theme($id=null)
|
||||||
{
|
{
|
||||||
if (!empty($id))
|
if (!empty($id))
|
||||||
{
|
{
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$res = $db->unique_query("SELECT id, title
|
$res = $db->unique_query("SELECT id, name
|
||||||
FROM themes WHERE id=" . intval($id));
|
FROM themes WHERE id=" . intval($id));
|
||||||
|
|
||||||
if (!empty($res))
|
if (!empty($res))
|
||||||
{
|
{
|
||||||
$this->title = $res['title'];
|
$this->id = $res['id'];
|
||||||
|
$this->name = $res['name'];
|
||||||
}
|
}
|
||||||
$db->deconnexion();
|
$db->deconnexion();
|
||||||
}
|
}
|
||||||
|
@ -25,22 +26,22 @@ class Theme
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
{
|
{
|
||||||
$title = $this->title;
|
$name = $this->name;
|
||||||
|
|
||||||
$db = new BDD();
|
$db = new BDD();
|
||||||
$db->escape($title);
|
$db->escape($name);
|
||||||
|
|
||||||
if (empty($this->id))
|
if (empty($this->id))
|
||||||
{
|
{
|
||||||
$db->query("INSERT INTO themes
|
$db->query("INSERT INTO themes
|
||||||
VALUES (NULL, '".$title."');");
|
VALUES (NULL, '".$name."');");
|
||||||
$this->id = $db->insert_id();
|
$this->id = $db->insert_id();
|
||||||
$aff = ($this->id > 0);
|
$aff = ($this->id > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->query("UPDATE themes
|
$db->query("UPDATE themes
|
||||||
SET title = '".$title."'
|
SET name = '".$name."'
|
||||||
WHERE id = ".intval($this->id));
|
WHERE id = ".intval($this->id));
|
||||||
$aff = $db->affected();
|
$aff = $db->affected();
|
||||||
}
|
}
|
||||||
|
@ -49,9 +50,9 @@ class Theme
|
||||||
return ($aff == 1);
|
return ($aff == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_title()
|
function get_name()
|
||||||
{
|
{
|
||||||
return $this->title;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_id()
|
function get_id()
|
||||||
|
@ -59,6 +60,17 @@ class Theme
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_nbExercices()
|
||||||
|
{
|
||||||
|
$db = new BDD();
|
||||||
|
$res = $db->unique_query("SELECT count( id ) as nb_exercices FROM exercices
|
||||||
|
WHERE id_theme = ".$this->id."
|
||||||
|
GROUP BY id_theme");
|
||||||
|
$db->deconnexion();
|
||||||
|
|
||||||
|
return $res['nb_exercices'];
|
||||||
|
}
|
||||||
|
|
||||||
function add_exercice($exercice)
|
function add_exercice($exercice)
|
||||||
{
|
{
|
||||||
if (isset($exercice))
|
if (isset($exercice))
|
||||||
|
@ -68,4 +80,19 @@ class Theme
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_themes()
|
||||||
|
{
|
||||||
|
$db = new BDD();
|
||||||
|
$ids = $db->query("SELECT `id` FROM `themes`");
|
||||||
|
$db->deconnexion();
|
||||||
|
|
||||||
|
$array = array();
|
||||||
|
foreach ($ids as $id){
|
||||||
|
$array[] = new Theme($id['id']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue