/** * Constructor. * @param string $postTitle Titulo. * @param string $postContents Contenido. * @param int $commentStatus Estado de los comentarios. * @param int $postStatus Estado. * @param int $userID Identificador del autor. */ public function __construct($postTitle, $postContents, $commentStatus, $postStatus, $userID) { parent::__construct(Post::getTableName(), self::$COLUMNS, self::$VALUES); $this->postTitle = $postTitle; $this->postContents = $postContents; $this->commentStatus = $commentStatus; $this->postStatus = $postStatus; $this->userID = $userID; }
/** * Metodo que obtiene todos los posts segun su fecha de actualización. * @param string $value Fecha. * @return Posts|bool Si es FALSE, no hay datos. */ public static function selectByUpdate($value) { $select = self::selectBy(Post::getTableName(), $value, Post::POST_UPDATE); return self::getInstanceData($select); }
/** * Metodo que obtiene el número de POST realializados. * @return int */ public function getCountPosts() { $db = DBController::getConnection(); $table = Post::getTableName(); $fetch = 'fetchAll'; $userIDPost = Post::USER_ID; $where = "{$userIDPost} = :{$userIDPost}"; $prepare = [DBController::prepareStatement(":{$userIDPost}", $this->getID(), \PDO::PARAM_INT)]; $columns = 'COUNT(*) AS count'; $select = $db->select($table, $fetch, $where, $prepare, $columns); return $select[0]['count']; }
/** * Metodo que obtiene el post con los datos actualizados. * @return Post */ public function getDataUpdate() { //Obtiene el primer dato el cual corresponde al id. $id = $this->prepareStatement[0]['value']; return Post::selectByID($id); }
/** * Constructor. * @param int $id Identificador. */ public function __construct($id) { parent::__construct($id, Post::getTableName()); }
/** * 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]; }