Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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);
 }
Example #3
0
 /**
  * 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'];
 }
Example #4
0
 /**
  * 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);
 }
Example #5
0
 /**
  * Constructor.
  * @param int $id Identificador.
  */
 public function __construct($id)
 {
     parent::__construct($id, Post::getTableName());
 }
Example #6
0
 /**
  * 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];
 }