server/onyx/include/common/Theme.class.php

99 lines
1.7 KiB
PHP
Raw Normal View History

2013-10-09 23:18:49 +00:00
<?php
if(!defined('ONYX')) exit;
2013-10-10 02:47:02 +00:00
class Theme
{
2013-10-10 03:52:48 +00:00
var $id = null;
var $name;
2013-10-09 23:18:49 +00:00
2013-10-10 02:47:02 +00:00
function Theme($id=null)
{
if (!empty($id))
{
$db = new BDD();
$res = $db->unique_query("SELECT id, name
2013-10-10 02:47:02 +00:00
FROM themes WHERE id=" . intval($id));
2013-10-09 23:18:49 +00:00
2013-10-10 02:47:02 +00:00
if (!empty($res))
{
$this->id = $res['id'];
$this->name = $res['name'];
2013-10-10 02:47:02 +00:00
}
$db->deconnexion();
}
}
2013-10-09 23:18:49 +00:00
2013-10-10 02:47:02 +00:00
function update()
{
$name = $this->name;
2013-10-10 02:47:02 +00:00
$db = new BDD();
$db->escape($name);
2013-10-10 02:47:02 +00:00
if (empty($this->id))
{
$db->query("INSERT INTO themes
VALUES (NULL, '".$name."');");
2013-10-10 02:47:02 +00:00
$this->id = $db->insert_id();
$aff = ($this->id > 0);
}
else
{
$db->query("UPDATE themes
SET name = '".$name."'
2013-10-09 23:18:49 +00:00
WHERE id = ".intval($this->id));
2013-10-10 02:47:02 +00:00
$aff = $db->affected();
}
$db->deconnexion();
return ($aff == 1);
}
2013-10-09 23:18:49 +00:00
function get_name()
2013-10-10 02:47:02 +00:00
{
return $this->name;
2013-10-10 02:47:02 +00:00
}
2013-10-10 02:47:02 +00:00
function get_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'];
}
2013-10-10 02:47:02 +00:00
function add_exercice($exercice)
{
if (isset($exercice))
{
$exercice->theme = $this;
return $exercice->update(true);
}
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;
}
2013-10-10 02:47:02 +00:00
}