All pastes #375696 Raw Edit

Shidame

public php v1 · immutable
#375696 ·published 2007-02-28 15:11 UTC
rendered paste body
<?php/** * @author Jerome Izard * @version 1.2 * @package package_name  */class NewsObject{	public $id = NULL;	public $titre = NULL;	public $contenu = NULL;	public $auteur = NULL;	public $date = NULL;	public function __construct($array=NULL)	{		if (is_array($array))		{			foreach ($array as $key=>$val )			{				if ( property_exists($this, $key) ) $this->$key = $val;			}		}		$this->id = (int) $this->id;	}	public function checkFields()	{		if ( !isset($this->titre) ) throw new MyException ('Le champ titre n\'est pas rempli !');		if ( !isset($this->contenu) ) throw new MyException ('Le champ contenu n\'est pas rempli !');	}}class News{ 	private $db; 	private $flag = FALSE; 	 	public function __tostring() 	{ 		return 'toto'; 	} 	public function __construct() 	{		$this->db = singleton::getInstance('mysql','mysql'); 	} 	public function addNews(NewsObject $object) 	{		$objet->checkFields();		$this->db->query('INSERT INTO news (titre, contenu, auteur) VALUES (\''.$object->title.'\', \''.$object->content.'\', \''.$object->login.'\')'); 	} 	public function delNews($id) 	{ 		$this->db->query('DELETE FROM news WHERE id=\''.$id.'\' LIMIT 1'); 	} 	public function updateNews(NewsObject $object) 	{		$this->db->query('UPDATE news SET titre=\''.$object->title.'\', contenu=\''.$object->content.'\', auteur=\''.$object->login.'\',  WHERE id=\''.$object->id.'\''); 	} 	public function getSeveralNews($start, $limit) 	{ 		if (!$this->flag) 		{ 			$this->db->query('SELECT DATE_FORMAT(time,"%d-%m-%Y à %Hh%i") as date, titre, auteur, contenu, id FROM news ORDER BY id DESC LIMIT '.$start.', '.$limit.''); 			$this->flag = TRUE; 		} 		return $this->toObject($this->db->getArray()); 	} 	public function getOneNews($id) 	{ 		$this->db->query('SELECT DATE_FORMAT(time,"%d-%m-%Y à %Hh%i") as date, titre, auteur, contenu, id FROM news WHERE id = \''.$id.'\''); 		return $this->toObject($this->db->getArray()); 	} 	public function countAllNews() 	{		$this->db->query('SELECT COUNT(id) FROM news');		$data = $this->db->getRow();		return ((int)$data[0]);	}	private function toObject($array)	{		if ( $array == FALSE )		{			$this->flag = FALSE;			return FALSE;		}		else		{			return new NewsObject($array);		}	}}?>