diff --git a/Article.php b/Article.php
index 786f1c3..e5fd753 100644
--- a/Article.php
+++ b/Article.php
@@ -4,33 +4,23 @@ class Article {
private String $nom;
private String $desc;
private DateTime $date;
- private String $url;
-
- public function __construct(String $n, String $de, DateTime $da, String $u) {
- $this -> nom = $n;
- $this -> desc = $de;
- $this -> date = $da;
- $this -> url = $u;
+
+ public function __construct(String $n, String $de, DateTime $da) {
+ $this->nom = $n;
+ $this->desc = $de;
+ $this->date = $da;
}
- public function getArticleName() {
+ public function getArticleName() : String {
return $this -> nom;
}
- public function getArticleDescription() {
- return $this -> desc;
+ public function getArticleDescription() : String {
+ return $this->desc;
}
- public function getArticleDate() {
+ public function getArticleDate() : DateTime {
return $this -> date;
}
- public function getArticleUrl() {
- return $this -> url;
- }
-
- public function __toString()
- {
- return '
- ' .$this->getArticleName() . '
- ' .$this->getArticleDescription() . '
- ' .date_format($this->getArticleDate(), 'd M Y, H\hi') . '
- ' .$this->getArticleUrl() .'
';
- }
}
\ No newline at end of file
diff --git a/ArticleController.php b/ArticleController.php
new file mode 100644
index 0000000..830bb33
--- /dev/null
+++ b/ArticleController.php
@@ -0,0 +1,14 @@
+ nom = $n;
+ $this -> date = $d;
+ $this -> url = $u;
+ }
+
+ public function getArticleName() : String {
+ return $this -> nom;
+ }
+
+ public function getArticleDate() : DateTime {
+ return $this -> date;
+ }
+
+ public function getArticleUrl() : String {
+ return $this -> url;
+ }
+
+ public function __toString()
+ {
+ return '- ' .$this->getArticleName() . '
- ' .date_format($this->getArticleDate(), 'd M Y') . '
- ' .$this->getArticleUrl() .'
';
+ }
+}
\ No newline at end of file
diff --git a/RSSArticleManager.php b/RSSArticleManager.php
new file mode 100644
index 0000000..d6f74e7
--- /dev/null
+++ b/RSSArticleManager.php
@@ -0,0 +1,43 @@
+tabURL as $u) {
+ $rss = simplexml_load_file($u);
+ foreach ($rss->channel->item as $item){
+ $desc = "";
+ array_push($tabArticle, new RSSArticle($item->title, date_create($item->pubDate), $item->link));
+ }
+ }
+ return $tabArticle;
+ }
+
+ public function sortArticles(array $a) : array {
+ $tab = $a;
+ usort($tab, function($firstArticle, $secondArticle) { //sorting method of all articles
+ $testA = $firstArticle->getArticleDate();
+ $testB = $secondArticle->getArticleDate();
+ if ($testA == $testB) {
+ return 0;
+ }
+ return $testA > $testB ? -1 : 1;
+ });
+
+ return $tab;
+ }
+
+}
\ No newline at end of file
diff --git a/articles/article.txt b/articles/article.txt
new file mode 100644
index 0000000..d70e2ed
--- /dev/null
+++ b/articles/article.txt
@@ -0,0 +1,3 @@
+Titre
+Date
+Desc
\ No newline at end of file
diff --git a/index.php b/index.php
index bfcdd9e..4ff26cf 100644
--- a/index.php
+++ b/index.php
@@ -1,17 +1,11 @@
channel->item as $item){
-
- $desc = explode("", explode('', $item->description)[1]);
-
- array_push($tabArticle, new Article($item->title, $desc[0], date_create($item->pubDate), $item->link));
-}
+$am = new RSSArticleManager();
+$tabArticle = $am -> createArticles();
+$tabArticle = $am -> sortArticles($tabArticle);
?>
@@ -27,7 +21,7 @@ foreach ($rss->channel->item as $item){
';
foreach ($tabArticle as $a) {
echo $a.'
';
}