/** * Metodo llamado por la funcion index. * @return array */ protected function dataIndex() { $posts = new Posts(); $users = new Users(); $comments = new Comments(); $categories = new Categories(); $lastPosts = $posts->lastData(5); $lastComments = $comments->lastData(5); foreach ($lastPosts as $value) { $title = $value->getPostTitle(); if (isset($title[30])) { $title = substr($title, 0, 30) . ' [...]'; } $value->setPostTitle($title); } foreach ($lastComments as $value) { //Borra las etiquetas html $contents = strip_tags($value->getCommentContents()); if (isset($contents[30])) { $contents = substr($contents, 0, 30) . ' [...]'; } $value->setCommentContents($contents); } return ['github' => $this->lastUpdateGitHub(), 'lastPosts' => $lastPosts, 'lastComments' => $lastComments, 'count' => ['post' => $posts->count(), 'page' => 0, 'category' => $categories->count(), 'comment' => $comments->count(), 'user' => $users->count()]]; }
/** * Metodo llamado por la función INDEX. * @return array */ protected function dataIndex() { $categories = Categories::selectAll(); $output = []; if ($categories !== \FALSE) { $output = $categories->getAll(); } return ['categories' => $output]; }
/** * Metodo llamado por la función UPDATE. * @param int $id * @return array */ protected function dataUpdate($id) { global $urlSite; $post = Post::selectByID($id); //En caso de que no exista. if (empty($post)) { Messages::addError('Error. La entrada no existe.'); header("Location: {$urlSite}" . 'admin/post'); exit; } $postID = $post->getID(); $outTerms = []; $outCategories = []; $categories = Categories::selectAll(); $terms = Terms::selectAll(); if ($terms !== \FALSE) { $outTerms = $terms->getAll(); } if ($categories !== \FALSE) { $outCategories = $categories->getAll(); } if (filter_input(\INPUT_POST, 'update')) { $dataInput = $this->getDataInput(); $update = new PostUpdate($post, $dataInput['postTitle'], $dataInput['postContents'], $dataInput['commentStatus'], $dataInput['postStatus']); //Si ocurre un error la función "$update->update()" retorna FALSE. if ($update->update()) { Messages::addSuccess('Entrada actualizada correctamente.'); $post = $update->getDataUpdate(); $this->updateRelationshipsCategories($dataInput['relationshipsCategoriesID'], $postID); $this->updateRelationshipsTerms($dataInput['relationshipsTermsID'], $postID); } else { Messages::addError('Error al actualizar la entrada.'); } } return ['relationshipsCategoriesID' => PostsCategories::selectByPostID($postID), 'relationshipsTermsID' => PostsTerms::selectByPostID($postID), 'terms' => $outTerms, 'categories' => $outCategories, 'post' => $post, 'actionUpdate' => \TRUE]; }