Passed
Push — master ( 7ee1fc...2d537f )
by Anthony
03:35
created

Contenus::getPage()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 8.5806
c 1
b 0
f 0
cc 4
eloc 18
nc 4
nop 1
1
<?php
2
	namespace core\contenus;
3
4
	use core\App;
5
	use core\functions\ChaineCaractere;
6
	use core\RedirectError;
7
8
9
	class Contenus {
10
		//pour la table page
11
		protected $id_page;
12
		protected $titre;
13
		protected $contenu;
14
		protected $url;
15
		protected $meta_description;
16
		protected $balise_title;
17
		protected $parent;
18
19
20
21
		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
22
		public function __construct($url, $admin_contenu = null) {
23
			if ($admin_contenu === null) {
24
				$this->getPage($url);
25
			}
26
		}
27
		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
28
29
30
31
		//-------------------------- GETTER ----------------------------------------------------------------------------//
32
		//pour la table page
33
		public function getIdPage() {
34
			return $this->id_page;
35
		}
36
		public function getTitre() {
37
			return $this->titre;
38
		}
39
		public function getContenu() {
40
			return $this->contenu;
41
		}
42
		public function getUrl() {
43
			return $this->url;
44
		}
45
		public function getMetaDescription() {
46
			return $this->meta_description;
47
		}
48
		public function getBaliseTitle() {
49
			return $this->balise_title;
50
		}
51
		public function getParent() {
52
			return $this->parent;
53
		}
54
		
55
		/**
56
		 * @param $url
57
		 * function that get all content of a page
58
		 */
59
		private function getPage($url) {
60
			$dbc = \core\App::getDb();
61
			
62
			$query = $dbc->select()->from("page")->where("url", "=", $url)->get();
63
			
64
			if (RedirectError::testRedirect404($query, $url) === true) {
65
				foreach ($query as $obj) {
66
					$redirect = 0;
67
					if (ChaineCaractere::FindInString($url, "http://") === true) {
68
						$redirect = 1;
69
					}
70
					
71
					App::setValues(["contenus" => [
72
						"id_page" => $this->id_page = $obj->ID_page,
73
						"meta_description" => $this->meta_description = $obj->meta_description,
74
						"balise_title" => $this->balise_title = $obj->balise_title,
75
						"url" => $this->url = $obj->url,
76
						"titre" => $this->titre = $obj->titre,
77
						"contenu" => $this->contenu = $obj->contenu,
78
						"parent" => $this->parent = $obj->parent,
79
						"redirect_page" => $redirect,
80
						"bloc_editable" => $obj->bloc_editable
81
					]]);
82
				}
83
			}
84
		}
85
		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
86
87
88
89
		//-------------------------- SETTER ----------------------------------------------------------------------------//
90
		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
91
	}