1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
<?php
class Blog_post extends dbconnect{
private $_id_subscriber;
private $_id_b_post;
private $_content;
private $_chapo;
private $_date;
private $_last_modification_date;
public function hydrate(array $donnees)
{
foreach ($donnees as $key => $value)
{
$method = 'set'.ucfirst($key);
if (method_exists($this, $method))
{
$this->$method($value);
}
}
}
// Liste des getters
public function id_subscriber()
{
return $this->_id_subscriber;
}
public function id_b_post()
{
return $this->_id_b_post;
}
public function content()
{
return $this->_content;
}
public function chapo()
{
return $this->_chapo;
}
public function date()
{
return $this->_date;
}
public function last_modification_date()
{
return $this->_last_modification_date;
}
// Liste des setters
public function setId_subscriber($id_subscriber)
{
$id_subscriber = (int) $id_subscriber;
if ($id_subscriber > 0)
{
$this->_id_subscriber = $id_subscriber;
}
else
{
throw new Exception('Blog-post : Identifiant de l\'abonné incorrect');
}
}
public function setId_b_post($id_b_post)
{
$id_b_post = (int) $id_b_post;
if($id_b_post > 0)
{
$this->_id_b_post = $id_b_post;
}
else
{
throw new Exception('Blog-post : Identifiant du blog-post incorrect');
}
}
public function setContent($content)
{
if (is_string($content))
{
$this->_content = $content;
}
else
{
throw new Exception('Blog-post : Contenu incorrect');
}
}
public function setChapo($chapo)
{
if (is_string($chapo))
{
$this->_chapo = $chapo;
}
else
{
throw new Exception('Blog-post : Chapo non conforme');
}
}
//Setter non fonctionnel à refaire par REGEX
public function setDate($date)
{
$mois = date("n", strtotime($date));
$jour = date("j", strtotime($date));
$annee = date("y", strtotime($date));
if (checkdate($mois, $jour, $annee))
{
$this->_date = $date;
}
else
{
throw new Exception('Blog-post : Date non conforme');
}
}
//Setter non fonctionnel à refaire par REGEX
public function setLast_modification_date($last_date)
{
$mois = date("n", strtotime($last_date));
$jour = date("j", strtotime($last_date));
$annee = date("y", strtotime($last_date));
if (checkdate($mois, $jour, $annee)) // soit TRUE soit FALSE
{
$this->_last_modification_date = $last_date;
}
else
{
throw new Exception('Blog-post : Date de dernière modification non conforme');
}
}
//Getter list for other class
//Test de la fonction getSubscriber
//Récupération des FK
public function getSubscriber(Blog_post $post)
{
$get = $this->db->prepare(
'
SELECT id_subscriber, mail, first_name, last_name, password, type, validation, date
FROM subscribers WHERE (id_subscriber = :id_subscriber)
'
);
$get->bindvalue(':id_subscriber', $post->id_subscriber());
$get->execute();
$donnees = $get->fetch();
$bp = new Subscriber();
$bp->hydrate($donnees);
return $bp;
}
public function getComments($post)
{
$get = $this->db->prepare(
'
SELECT id_subscriber, content, id_state, date
FROM comments
WHERE (id_subscriber = :id_subscriber)
'
);
$get->bindvalue(':id_subscriber', $post->id_subscriber());
$get->execute();
while ($donnees = $get->fetch()){
$bp = new Subscriber();
$bp->hydrate($donnees);
$bps[] = $bp;
}
return $bps;
}
} |
Partager