Beispiel #1
0
 /**
  * Metodo llamado por la función INDEX.
  * @return array
  */
 protected function dataIndex()
 {
     $terms = Terms::selectAll();
     $output = [];
     if ($terms !== \FALSE) {
         $output = $terms->getAll();
     }
     return ['terms' => $output];
 }
Beispiel #2
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];
 }