Ejemplo n.º 1
0
 public function sectionAction(request $req, $res)
 {
     $this->data['pageData'] = SectionFactory::getSectionWithRequest($req);
     $this->setRequestResult($req, $res);
     $this->data['subSections'] = Sections::getSubSections($this->data['pageData']->id);
     $this->data['pagesLinks'] = Pages::where('category_id', $this->data['pageData']->id)->get();
     $this->render('public\\main\\pages\\section_page.twig');
 }
Ejemplo n.º 2
0
 public function run()
 {
     $sections = Sections::find()->all();
     $str = "";
     foreach ($sections as $sec) {
         $a = Html::tag('a', $sec->title, ['href' => $sec->link]);
         $str .= Html::tag('p', $a);
     }
     return $str;
 }
Ejemplo n.º 3
0
 public function actionProduct($id = null)
 {
     $product = Products::find()->where(['id' => $id])->one();
     $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one();
     $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all();
     $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all();
     $model = new CommentForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $com = new Comments();
         $com->product_id = $id;
         $com->login = Yii::$app->session->get('login');
         $com->comment = $model->comment;
         $com->save();
         return $this->redirect(Yii::$app->request->referrer);
     }
     return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]);
 }
Ejemplo n.º 4
0
 protected function menuCreator()
 {
     $this->container->dispatcher->addListener('publiccontroller.menu.logic', function ($event) {
         $items = Sections::getAllGlobalActiveRaw()->where('show_in_menu', 1)->orderBy('sort', 'asc')->get();
         $name = '';
         if ($route = $event->getParams()->request->getAttribute('route')) {
             $name = $route->getName();
         }
         $args = $route->getArguments();
         $menu = $event->getParams()->menu;
         $sections = array_filter($menu, function ($e) {
             return (bool) $e['section'];
         });
         foreach ($sections as $k => $item) {
             $menu[$k]['current'] = (bool) ($name == 'page.sp' . $item['section'] && $args['pageCode'] == $item['code']);
             $menu[$k]['url'] = 'page.sp' . $item['section'];
         }
         foreach ($items as $item) {
             $menu[] = ['name' => $item->name_for_menu, 'current' => (bool) ($name == 'page.s' . $item->id), 'section' => $item->parent_id, 'code' => $item->code, 'id' => $item->id, 'url' => 'page.s' . $item->id];
         }
         $event->getParams()->menu = $menu;
     });
 }
Ejemplo n.º 5
0
 public function postDeleteSection(Request $request)
 {
     $section_id = $request->input('section_id');
     $input = ['section_id' => $section_id];
     $validator = validator::make($request->all(), ['section_id' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         DB::beginTransaction();
         try {
             $section = Sections::findOrFail($section_id);
             if (!$section->delete()) {
                 throw new ErrorException();
             }
             DB::commit();
         } catch (ModelNotFoundException $e) {
             DB::rollback();
             return ApiResponseClass::errorResponse('SomeThing Went Wrong. Please Try Again Later or Contact Support!!', $input);
         } catch (ErrorException $e) {
             DB::rollback();
             return ApiResponseClass::errorResponse('SomeThing Went Wrong. Please Try Again Later or Contact Support!!', $input);
         }
         return ApiResponseClass::successResponse($section, $input);
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
 }