Created
October 29, 2012 12:42
-
-
Save rakotomandimby/3973303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ArticleModel | |
{ | |
public function __construct($id) | |
{ | |
$xml = new XMLReader(); | |
$tmp = $xml->open('encheres.xml'); | |
while($xml->read()) | |
{ | |
if(('item' == $xml->name) && ($xml->nodeType == XMLReader::ELEMENT) && ($id == $xml->getAttribute('id'))) | |
{ | |
// converti article en DOM | |
$node = $xml->expand(); | |
$an_article = new DomDocument(); | |
$this->article = $an_article->importNode($node,true); | |
$this->id = $id; | |
$this->name = $this->article->getElementsByTagName('name'); | |
$this->name = $this->name->item(0)->nodeValue; | |
$this->description = $this->article->getElementsByTagName('text'); | |
$this->description = $this->description->item(0)->nodeValue; | |
$this->data_for_view=array('id' => $this->id , 'name' => $this->name, 'decription' => $this->description); | |
break; | |
} | |
} | |
} | |
public static function getArticleIds() | |
{ | |
$xml = new XMLReader(); | |
$tmp = $xml->open('encheres.xml'); | |
while($xml->read()) | |
{ | |
if(('item' == $xml->name) && ($xml->nodeType == XMLReader::ELEMENT)) | |
{ | |
$result[]=$xml->getAttribute('id'); | |
} | |
} | |
return $result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ArticleView | |
{ | |
public function renderArticleIdList($article_id_array) | |
{ | |
$result = '<html><head></head><body>'; | |
$result .= '<ul>'; | |
foreach($article_id_array as $un_id) | |
{ | |
$result .= '<li><a href="?article='.$un_id.'">'.$un_id.'</a></li>'; | |
} | |
$result .= '</ul>'; | |
$result .= '</body></html>'; | |
return $result; | |
} | |
public function renderArticleDetail($article_detail_array) | |
{ | |
$result = '<html><head></head><body>'; | |
$result .= '<ul>'; | |
foreach($article_detail_array as $attribut => $valeur) | |
{ | |
$result .= '<li>'.$attribut.' : '.$valeur.'</li>'; | |
} | |
$result .= '</ul>'; | |
$result .= '</body></html>'; | |
return $result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('Model/ArticleModel.php'); | |
require_once('View/ArticleView.php'); | |
if($_REQUEST['q'] == 'liste-articles') | |
{ | |
$article_id_array=ArticleModel::getArticleIds(); | |
$view = new ArticleView(); | |
$output = $view->renderArticleIdList($article_id_array); | |
print $output; | |
} | |
elseif (isset($_REQUEST['article'])) | |
{ | |
$l_article = new ArticleModel($_REQUEST['article']); | |
$view = new ArticleView(); | |
$output = $view->renderArticleDetail($l_article->data_for_view); | |
print $output; | |
} | |
else | |
{print 'mauvais paramètres';} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment