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 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());
     }
 }