public function editArticle($id) { $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_rules('content', 'Content', 'trim|required'); if ($this->form_validation->run() == FALSE) { $artikel = Model\Portal\Article::withDrafts()->withPrivate()->findOrFail($id); $cat_ids = array_map(function ($cat) { return $cat->kategori_id; }, $this->Mod_category->getByArticle($id)); $data['artikel'] = $artikel; $data['categories_checkbox'] = (new Model\Portal\Category())->generateCheckbox(0, $cat_ids); $data['status'] = $this->status; $this->template->set('sidebar'); $this->template->set_layout('privatepage'); $this->template->build('edit', $data); } else { $artikel = array('title' => set_value('title'), 'content' => set_value('content', '', FALSE)); $categories = set_value('categories', array()); $status = set_value('status', 'draft'); $id = $this->Mod_sendarticle->edit($id, $artikel, $categories); $articleLib = new Library\Article\Article(); $articleLib->set($id); $featured_action = $this->input->post('featured[action]'); switch ($featured_action) { case 'upload': $featured_image = $this->input->post('featured[src]'); $desciption = $this->input->post('featured[description]'); $articleLib->setFeaturedImage($featured_image, $description); break; case 'remove': $articleLib->removeFeaturedImage(); default: break; } set_message_success('Artikel berhasil diperbarui.'); redirect('dashboard/editArticle/' . $id, 'refresh'); } }
public function edit($id) { $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_rules('content', 'Content', 'required'); $this->form_validation->set_rules('categories[]', 'Category', 'required'); if ($this->form_validation->run() == FALSE) { $artikel = Model\Portal\Article::withDrafts()->withPrivate()->findOrFail($id); keepValidationErrors(); $cat_ids = array_map(function ($cat) { return $cat->kategori_id; }, $this->M_kategori->getByArticle($id)); $tag_ids = array(); foreach ($this->M_tags->getByArticle($id) as $row) { $tag_ids[$row->tag] = $row->tag; } $data['artikel'] = $artikel; $data['categories_checkbox'] = $this->M_kategori->generateCheckbox(0, $cat_ids); $data['tags'] = $tag_ids; $data['status'] = $this->status; $this->template->build('edit', $data); } else { $artikel = array('title' => set_value('title'), 'content' => set_value('content', '', FALSE), 'status' => set_value('status')); $article = Model\Portal\Article::withDrafts()->withPrivate()->find($id); if ($article->editor_id == 0) { $artikel['editor_id'] = auth()->getUser()->id; } if (set_value('with_schedule', 0)) { $artikel['published'] = set_value('published'); } else { $artikel['published'] = '0000-00-00 00:00:00'; } $categories = set_value('categories', array()); $tags = set_value('tags', array()); $repo_library = new Library\Article\Article(); $repo_library->set($article); if ($this->input->post('featured[src]') && $this->input->post('featured[action]') == 'upload') { $repo_library->setFeaturedImage($this->input->post('featured[src]'), $this->input->post('featured[description]')); } elseif ($this->input->post('featured[action]') == 'remove') { $repo_library->removeFeaturedImage(); } if ($this->input->post('slider[src]') && $this->input->post('slider[action]') == 'upload') { $repo_library->setSliderImage($this->input->post('slider[src]')); } elseif ($this->input->post('slider[action]') == 'remove') { $repo_library->removeSliderImage(); } $id = $this->Mod_artikel->update($id, $artikel, $categories, $tags); set_message_success('Artikel berhasil diperbarui.'); redirect('article/edit/' . $id, 'refresh'); } }