public function getReply($boardId) { $b = Board::find($boardId, array('id', 'content')); $board = array(); if ($b !== null) { $board = $b->getAttributes(); } $r = BoardReply::where('board_id', '=', $boardId)->orderBy('created_at', 'desc')->first(array('tags', 'content')); $reply = array(); if ($r !== null) { $reply = $r->getAttributes(); } // prepare faq $faqs = ServiceFaq::where('type', '=', 'faq')->where('_parent', '<>', 'N')->orderBy('sort', 'desc')->get(array('id', 'title')); $items = array(); foreach ($faqs as $m) { $items[$m->id] = $m->title; } $tags = Arr::get($reply, 'tags', null); if ($tags == null) { $selected = $tags; } else { $selected = unserialize($tags); } return View::make('admin.board.view_reply', array('board' => $board, 'reply' => $reply, 'lblWidgetOptions' => array('elementId' => 'label-panel', 'fieldName' => 'labels[]', 'formTitle' => '常見問題標籤', 'items' => &$items, 'selected' => $selected))); }
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)); }