| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | 	namespace modules\blog\app\controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	use core\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	class Article { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		//-------------------------- BUILDER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		public function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		//-------------------------- END BUILDER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 		//-------------------------- GETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		protected function getImageArticle($url_article) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 			$url_image = ROOT."modules/blog/images/".$url_article.".png"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			if (file_exists($url_image)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 				return WEBROOT."modules/blog/images/".$url_article.".png";; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 				return WEBROOT."modules/blog/images/fond-bloc.jpg"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		 * @param $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		 * function that return datein french format | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		protected function getDateFr($date) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			$mois = array("Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			$explode = explode("-", $date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$jour_d = $explode[2]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			$mois_d = $explode[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$annee_d = $explode[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			return $jour_d." ".$mois[$mois_d - 1]." ".$annee_d; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		private function getExtract($article) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			$article = substr(strip_tags($article), 0, 150)."..."; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			return $article; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		 * this function get last articles | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		public function getLastArticle() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			$nb_article = Blog::getArticleIndex(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			$query = $dbc->select() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 				->from("_blog_article") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 				->from("identite") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 				->where("_blog_article.ID_state", "=", 1, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 				->where("_blog_article.ID_identite", "=", "identite.ID_identite", "", true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 				->limit(0, $nb_article)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			 | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 65 |  | View Code Duplication | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 				$articles = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 				 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 					$articles[] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 						"id_article" => $obj->ID_article, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 						"title" => $obj->title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 						"url" => $obj->url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 						"image" => $this->getImageArticle($obj->url), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 						"article" => $this->getExtract($obj->article), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 						"pseudo" => $obj->pseudo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 						"publication_date" => $this->getDateFr($obj->publication_date), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 						"categories" => Blog::getCategory()->getCategoryArticle($obj->url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 					]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 				 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 				Blog::setValues(["articles" => $articles]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		 * function that get one article | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		public function getArticle() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			$param = Blog::$router_parameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			$query = $dbc->select()->from("_blog_article")->from("identite")->from("_blog_state") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 				->where("ID_article", "=", $param, "OR") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 				->where("url", "=", $param, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 				->where("_blog_article.ID_identite", "=", "identite.ID_identite", "AND", true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 				->where("_blog_article.ID_state", "=", "_blog_state.ID_state", "", true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 				->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			if ((is_array($query)) && (count($query) == 1)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 					$this->getExtract($obj->article); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 					 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 					Blog::setValues(["article" => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 						"id_article" => $obj->ID_article, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 						"title" => $obj->title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 						"url" => $obj->url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 						"article" => $obj->article, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 						"pseudo" => $obj->pseudo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 						"id_state" => $obj->ID_state, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 						"state" => $obj->state, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 						"publication_date" => $this->getDateFr($obj->publication_date), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 						"categories" => Blog::getCategory()->getCategoryArticle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 					]]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		 * function that get all categories of an article | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 120 |  |  | 		 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  | 		public function getCategoryArticle() { | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 			$dbc = App::getDb(); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  | 			$category = Blog::$router_parameter; | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 			 | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  | 			$query = $dbc->select() | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 				->from("_blog_article") | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 				->from("_blog_category") | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 				->from("_blog_article_category") | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 				->from("identite") | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  | 				->where("_blog_category.ID_category", "=", $category, "OR") | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  | 				->where("_blog_category.category", "=", $category, "AND") | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | 				->where("_blog_article.ID_state", "=", 1, "AND") | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 				->where("_blog_article_category.ID_article", "=", "_blog_article.ID_article", "AND", true) | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 				->where("_blog_article_category.ID_category", "=", "_blog_category.ID_category", "AND", true) | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 				->where("_blog_article.ID_identite", "=", "identite.ID_identite", "", true) | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 				->get(); | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 			 | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 138 |  | View Code Duplication | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  | 				$articles = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  | 				 | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 				foreach ($query as $obj) { | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 					$articles[] = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 						"id_article" => $obj->ID_article, | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  | 						"title" => $obj->title, | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  | 						"url" => $obj->url, | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  | 						"image" => $this->getImageArticle($obj->url), | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  | 						"article" => $this->getExtract($obj->article), | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 						"pseudo" => $obj->pseudo, | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 						"publication_date" => $this->getDateFr($obj->publication_date), | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 						"categories" => Blog::getCategory()->getCategoryArticle($obj->url) | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  | 					]; | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  | 				 | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  | 				Blog::setValues(["articles" => $articles]); | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 		//-------------------------- END GETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		//-------------------------- SETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 161 |  |  | 		//-------------------------- END SETTER ----------------------------------------------------------------------------//     | 
            
                                                        
            
                                    
            
            
                | 162 |  |  | 	} |