. */ /** * Diet Database Access Object. This class provides functionality to * load and save countries */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); require_once(FILESYSTEMROOTPATH."events/include/model/Diet.php"); class DietDao implements IDao { /** MySQL object */ private $mysql; /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } /** * Load a diet by id * * @param string name of the diet to be loaded * @return Diet containing the data of the requested diet, or NULL in case diet does not exist */ public function load($id) { $query = "SELECT `id`, `name`, `active`, `description` FROM ".EVENTS_MYSQL_INTRANET_DB.".`diets` WHERE `id`='".$id."'"; if( $this->mysql->query($query) ) { return new Diet ($this->mysql->fetchArray()); }else { return array(); } } /** * Load all active diets * * @return array of Diet */ public function loadActive() { $query = "SELECT `id`, `name`, `active`, `description` FROM ".EVENTS_MYSQL_INTRANET_DB.".`diets` WHERE `active`='1' ORDER BY `name`"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $ret[ $row['id'] ] = new Diet($row); } return $ret; }else { return array(); } } /** * Load all diets * * @return array of Diet */ public function loadAll() { $query = "SELECT `id`, `name`, `active`, `description` FROM ".EVENTS_MYSQL_INTRANET_DB.".`diets` ORDER BY `active` DESC, `name`"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $ret[ $row['id'] ] = new Diet($row); } return $ret; }else { return array(); } } /** * Save or update a diet * * @param Diet object with the diet data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $diet) { } } ?>