示例#1
0
 public function admin_editPost($params)
 {
     /** @var $post Models\Posts */
     $view = Services\View::getInstance();
     if (isset($params["post"])) {
         $params["post_id"] = $this->savePost($params);
     }
     if (isset($params["post_id"]) && $params["post_id"] !== "new") {
         $post = Models\Posts::getById($params["post_id"]);
         if (!$post) {
             $post = Models\Posts::Factory(["postentries" => [], "id" => "", "title" => "", "created" => date("Y-m-d")]);
         }
         $post->entries = $post->getPostentries();
         foreach ($post->entries as $index => $entry) {
             /** @var $entry Models\PostEntry */
             $entry = Models\PostEntry::getById($entry);
             $post->entries[$index] = ["q" => $entry->getQuestion(), "p" => $entry->getPropositions(), "answer" => $entry->getAnswer(), "id" => $entry->getId()];
         }
     } else {
         $post = Models\Posts::Factory(["postentries" => "", "id" => "", "title" => "", "created" => date("Y-m-d")]);
     }
     $field = new Services\Fields("init");
     $field->text(["value" => $post->getTitle(), "slug" => "post_tilte", "id" => "post_tilte", "label" => "Nom du post"]);
     $field->hidden(["value" => $post->getId(), "slug" => "post_id", "id" => "post_id"]);
     return $this->content_page = $view->render("admin/subpages/edit_post.html", ["currentPostId" => $post->getId(), "isActive" => $post->isActive(), "field" => $field->render(), "entries" => isset($post->entries) ? $post->entries : []]);
 }