public function getGabById($idGab, $bdd) { $liste = array(); $i = 0; $listePosts = $bdd->query('SELECT * FROM posts WHERE (id=' . $idGab . ') ORDER BY id DESC'); while ($item = $listePosts->fetch()) { $post = new Posts(); $post->hydrate($item['id'], $item['id_user'], $item['text'], $item['id_post_origin'], $item['likes'], $bdd); $liste[$i] = $post; $i++; } $this->setListePosts($liste); }
/** * Save post * * @param \Posts $post * @param $error * @return bool */ protected function _save(\Posts &$post, &$error) { $isDraft = $post->getIsDraft(); $input = $this->request()->post('post', 'ARRAY', array()); $post->hydrate($input); $post->setExcerpt(nl2br($post->getExcerpt())); $post->setIsDraft(false); $error = Plugin::applyFilters('verify_' . $post->getTaxonomy() . '_form_data', $error); if (!$post->getAuthor()) { $post->setAuthor($this->getSessionUser()->getName()); } if (!$post->isDraft() && !($post->getPublishTime() || $post->getPublishTime()->isEmpty())) { $post->setPublishTime(new DateTime()); } if (empty($error) && $post->save()) { $post = Plugin::applyFilters('handling_' . $post->getTaxonomy() . '_form_data', $post); if ($isDraft) { $this->dispatch('after_publish_' . $post->getTaxonomy() . '_post', new CMSBackendEvent($this, array('post' => $post))); } else { $this->dispatch('after_save_' . $post->getTaxonomy() . '_post', new CMSBackendEvent($this, array('post' => $post))); } return true; } else { foreach ($post->getValidationFailures() as $validationFailure) { $error[$validationFailure->getColumn()] = $validationFailure->getMessage(); } } return false; }
public function getAllMyGabs($bdd) { $i = 0; $listeGabs = new ListePosts(); $mesPosts = array(); $listePosts = $bdd->query('SELECT * FROM posts WHERE (id_user='******') ORDER BY id DESC'); while ($item = $listePosts->fetch()) { $post = new Posts(); $post->hydrate($item['id'], $item['id_user'], $item['text'], $item['id_post_origin'], $item['likes'], $bdd); $mesPosts[$i] = $post; $i++; } $listeGabs->setListePosts($mesPosts); if (isset($mesPosts)) { $this->setMesGabs($listeGabs); } }