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 getArticleAction($id = null) { try { $article = array('id' => null, 'status' => 1, 'isInSiderbar' => 0); if ($id != null) { $article = Wintness::find($id)->toArray(); if (empty($article)) { throw new Exception('Error request [10]'); } } $imgUploaderList = array('cover' => array('fieldName' => 'cover', 'items' => null), 'before' => array('fieldName' => 'img_before', 'items' => null), 'after' => array('fieldName' => 'img_after', 'items' => null), 'gallery' => array('fieldName' => 'gallery', 'items' => null)); foreach ($imgUploaderList as $key => $val) { $value = Arr::get($article, $val['fieldName'], null); $imgUploaderList[$key]['items'] = empty($value) ? array() : json_decode($value, true); } // detect is the request has tabs $rows = Tabs::where('type', '=', 'wintness')->where('item_id', '=', $article['id'])->orderBy('sort', 'asc')->get(array('title', 'content', 'sort')); $tabItems = array(); if (!empty($rows)) { foreach ($rows as $r) { $tabItems[] = $r->toArray(); } } else { if (($tabNames = Input::old('tabName', null)) !== null && ($tabContents = Input::old('tabContents', null)) !== null) { $order = 1; foreach ($tabNames as $key => $tab) { if (!isset($tabContents[$key])) { continue; } $tabItems[] = array('title' => $tab, 'content' => $tabContents[$key], 'sort' => $order); } } } $labelItmes = array('service' => array(), 'faq' => array()); $list = ServiceFaq::where("status", "=", 'Y')->where('_parent', '<>', 'N')->orderBy('_parent', 'desc')->orderBy('sort', 'desc')->orderBy('updated_at', 'desc')->get(array('id', 'title', 'type')); foreach ($list as $item) { $labelItmes[$item->type][$item->id] = $item->title; } $labelSelected = WintnessLabels::where('wid', '=', $article['id'])->lists('label_id'); return View::make('admin.wintness.view_article_action', array('article' => $article, 'labelItems' => &$labelItmes, 'labelSelected' => &$labelSelected, 'tabItems' => &$tabItems, 'imgUploaderList' => &$imgUploaderList)); } catch (Exception $e) { return Redirect::route('admin.wintness.article.list', array('errorMessage' => $e->getMessage())); } }
private function getNavigation($type) { $rows = \ServiceFaq::where('type', '=', $type)->where('status', '=', 'Y')->orderBy('_parent', 'desc')->orderBy('sort', 'desc')->orderBy('updated_at', 'desc')->get(); $navs = array(); if (sizeof($rows) == 0) { return $navs; } foreach ($rows as $r) { $p = $r->_parent; $id = $r->id; if ($p !== 'N') { if (isset($navs[$p])) { $navs[$p]['childs'][] = array('id' => $id, 'title' => $r->title); } } else { if (!isset($navs[$id])) { $navs[$id] = array('id' => $id, 'title' => $r->title, 'childs' => array()); } } } return $navs; }
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 getAjaxArticles() { try { $page = \Arr::get($_GET, 'page', null); $itemId = (int) \Arr::get($_GET, 'item', null); $keyword = \Arr::get($_GET, 'keyword', null); if (empty($page)) { throw new \Exception("Error request [10]"); } $page = (int) $page; $limit = 10; $offset = ($page - 1) * $limit; $cmd = \DB::table('wintness')->select('wintness.id', 'wintness.title', 'wintness.cover', 'wintness.background_color', 'wintness.description')->where('wintness.status', '=', '1')->orderBy('wintness.sort', 'desc')->orderBy('wintness.updated_at', 'desc')->skip($offset)->take($limit); if ($itemId >= 1) { $cmd = $cmd->join('wintness_labels', 'wintness.id', '=', 'wintness_labels.wid')->where('wintness_labels.label_id', '=', $itemId); } if (!empty($keyword)) { $format = '(`tabs`.`title` like "%s" or `tabs`.`content` like "%s" or `wintness`.`title` like "%s" or `wintness`.`description` like "%s")'; $keyword = '%' . $keyword . '%'; $cmd = $cmd->join('tabs', 'wintness.id', '=', 'tabs.item_id')->where('tabs.type', '=', 'wintness')->whereRaw(sprintf($format, $keyword, $keyword, $keyword, $keyword))->groupBy('wintness.id'); } $rows = $cmd->get(); $data = array(); if (!empty($rows)) { foreach ($rows as $row) { $cover = json_decode($row->cover, true); $row->cover = !empty($cover) ? $cover[0]['image'] : 'null'; $labels_service = \WintnessLabels::where('wid', '=', $row->id)->lists('label_id'); $services = null; if (!empty($labels_service)) { $services = \ServiceFaq::where('status', '=', 'Y')->where('type', '=', 'service')->whereIn('id', $labels_service)->get(array('id', 'title')); } $labelList = array(); if (!empty($services)) { foreach ($services as $idx => $label) { $label->link = \URL::route('frontend.service_faq.article', array('type' => 'service', 'id' => $label->id)); $labelList[] = $label->toArray(); } } $row->label_faq = $labelList; $row->description = \Text::preEllipsize($row->description, 46, 0.6); $data[] = (array) $row; } } return \Response::json(array('status' => 'ok', 'data' => $data, 'item' => $itemId)); } catch (Excpetion $e) { return \Response::json(array('status' => 'error', 'message' => $e->getMessage())); } }
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()); } }
<?php $servicefaq = ServiceFaq::where('status', '=', 'Y')->orderBy('type', 'asc')->orderBy('_parent', 'desc')->orderBy('sort', 'desc')->orderBy('updated_at', 'desc')->get(); $servicesFaqs = array('service' => array(), 'faq' => array()); foreach ($servicefaq as $item) { $key = $item->id; $parent = $item->_parent; $list = $servicesFaqs[$item->type]; if ($parent == 'N') { if (!isset($list[$key])) { $list[$key] = array('title' => $item->title, 'subItems' => array()); } } else { $list[$parent]['subItems'][] = $item; } $servicesFaqs[$item->type] = $list; } ?> <nav id="mainNav" role="navigation"> <ul class="lv0"> <li> <a href="#">關於煥儷</a> <ul class="subNav lv1"> @foreach (ArticlesController::getNav(1) as $article) <li><a href="{{ URL::to('articles/'.$article->id) }}">{{ $article->title }}</a></li> @endforeach </ul> </li> <li> <a href="#">服務項目</a> <ul class="subNav lv1">