public function getArticle($type, $id) { $model = \ServiceFaq::find($id); if ($model === null) { return \Redirect::back(); } else { $parent = \ServiceFaq::find($model->_parent); } // Views if (\helper::views_cookie('service_faq', $id)) { $model->views = $model->views + 1; $model->save(); } $model->date = substr($model->created_at, 0, 10); // decode label and tab $lblIds = json_decode($model->labels, true); $labels = array(); if (!empty($lblIds)) { $labels = \ServiceFaq::orderBy('id', 'asc')->find($lblIds, array('id', 'title')); } $tabs = json_decode($model->tabs); if (empty($tabs)) { $tabs = array(); } $view = sprintf('aesthetics.%s.view_article', $type); return \View::make('aesthetics.serviceFaq.view_article', array('model' => &$model, 'parent' => &$parent, 'images' => \ServiceFaqImage::where('sid', '=', $model->id)->orderBy('sort', 'asc')->get(), 'labels' => &$labels, 'tabs' => &$tabs, 'navs' => $this->getNavigation($type), 'type' => $type)); }
public function getPost($postId) { // board $b = \Board::find($postId); if ($b === NULL) { return \Redirect::route('frontend.board.list'); } $b->count_num = $b->count_num + 1; $b->save(); $b->d = str_replace('-', '/', substr($b->created_at, 0, 10)); $isShowPost = false; if ($b->isPrivate == '0') { $isShowPost = true; } else { $user_id = \Auth::check() ? \Auth::user()->id : null; $isShowPost = $user_id === $b->user_id && $user_id !== null; } // fetch reply $br = \BoardReply::where('board_id', '=', $postId)->orderBy('created_at', 'desc')->first(array('tags', 'content', \DB::raw("date_format(created_at,'%Y/%m/%d') as d"))); $tags = array(); if ($br !== null) { $tagsId = unserialize($br->tags); $tags = \ServiceFaq::find($tagsId, array('id', 'title')); } // get next and previous $sql = 'select * from ' . '(select id, topic, created_at from board where created_at < ? and status = "1" order by created_at desc limit 0, 1) as T ' . 'union select * from ' . '(select id, topic, created_at from board where created_at > ? and status = "1" order by created_at asc limit 0, 1) as T order by id asc'; $rows = \DB::select($sql, array($b->created_at, $b->created_at)); $list = array('next' => null, 'prev' => null); foreach ($rows as &$r) { if ($r->created_at > $b->created_at) { $list['next'] = $r; } if ($r->created_at < $b->created_at) { $list['prev'] = $r; } } return \View::make('aesthetics.board.view_post', array('board' => &$b, 'list' => &$list, 'reply' => &$br, 'tags' => &$tags, 'isShowPost' => $isShowPost)); }
public function postWriteArticle($type) { $this->beforeAction($type); try { if (!isset($_POST['id'])) { throw new Exception("Error Processing Request [10]"); } $id = (int) Arr::get($_POST, 'id', null); if (empty($id)) { $model = new ServiceFaq(); } else { $model = ServiceFaq::find($id); if ($model == null) { throw new Exception("Error Processing Request [11]"); } } $labels = Input::get('labels', array()); $lblList = array(); foreach ($labels as $label) { $lblList[] = (int) $label; } $order = 0; $tabContents = Input::get('tabContents', array()); $tabs = array(); foreach (Input::get('tabName', array()) as $key => $tab) { if (!isset($tabContents[$key])) { continue; } $tabs[] = array('title' => $tab, 'content' => $tabContents[$key], 'sort' => $order); $order++; } //$model = new ServiceFaq; $model->type = $type; $model->title = Input::get('title'); $model->image = Input::get('image_path'); $model->content = Input::get('content'); $model->labels = json_encode($lblList); $model->tabs = json_encode($tabs); $model->status = Input::get('status'); $model->_parent = Input::get('category'); $model->created_at = time(); $model->updated_at = time(); $model->save(); # Handling Images $imgs = ServiceFaqImage::where('sid', '=', $model->id)->get(); $delImages = Arr::get($_POST, 'deleteImages', array()); if (sizeof($imgs) > 0) { $delLength = sizeof($delImages); foreach ($imgs as $img) { if ($delLength > 0 && in_array($img->id, $delImages)) { fps::getInstance()->delete($img->image); } $img->delete(); } } $order = 1; $imagesDesc = Input::get('imageDesc', array()); foreach (Input::get('images', array()) as $key => $image) { ServiceFaqImage::create(array('sid' => $model->id, 'image' => $image, 'text' => $imagesDesc[$key], 'sort' => $order)); $order++; } return Redirect::route('admin.service_faq.article.list', array('type' => $model->type, 'category' => $model->_parent, 'afterAction' => 1)); } catch (Exception $e) { return Redirect::back()->withInput()->withErrors($e->getMessage()); } }