public function actionIndex($news_id = null)
 {
     $news_type = Yii::$app->request->get('news_types_id') ? NewsTypes::findOne(Yii::$app->request->get('news_types_id')) : false;
     $link = new Links();
     $news = new News();
     if ($news_type) {
         $news->news_types_id = $news_type->id;
     }
     if ($news_id) {
         $news = News::findOne($news_id);
         $link = Links::findOne($news->links_id);
         $news->date = $news->date !== null ? date('d.m.Y', strtotime($news->date)) : null;
         $news->date_range = $news->date_start && $news->date_finish ? date('d.m.Y', strtotime($news->date_start)) . ' - ' . date('d.m.Y', strtotime($news->date_finish)) : null;
         $news->full_text = Contents::findOne(['links_id' => $link->id, 'seq' => 1])->text;
         $news->prev_text = Contents::findOne(['links_id' => $link->id, 'seq' => 2])->text;
     }
     if (Yii::$app->request->isPost) {
         $link->load(Yii::$app->request->post());
         $link->parent = $news_type->links_id;
         $link->categories_id = $news_type->categories_id !== null ? $news_type->categories_id : $news_type->link->categories_id;
         $link->save();
         $news->load(Yii::$app->request->post());
         $news->links_id = $link->id;
         $news->save();
         if ($news->id) {
             $content = Contents::findOne(['links_id' => $link->id, 'seq' => 1]);
             if (!$content) {
                 $content = new Contents();
             }
             $content->links_id = $link->id;
             $content->seq = 1;
             $content->text = $news->full_text;
             $content->save();
             $parent_conten_id = $content->id;
             $content = Contents::findOne(['parent' => $parent_conten_id, 'seq' => 2]);
             if (!$content) {
                 $content = new Contents();
             }
             $content->links_id = $link->id;
             $content->parent = $parent_conten_id;
             $content->seq = 2;
             $content->text = $news->prev_text;
             $content->save();
         }
         Yii::$app->getSession()->setFlash('success', 'Изменения приняты');
         return $this->redirect(['', 'news' => 'ch', 'news_types_id' => $news->news_types_id, 'news_id' => $news->id]);
     }
     $news_list = News::find()->orderBy(['date' => SORT_DESC])->all();
     return $this->render('news', ['news_list' => $news_list, 'news_type' => $news_type, 'news_types' => NewsTypes::find()->orderBy(['name' => SORT_ASC])->all(), 'news' => $news, 'link' => $link]);
 }
Beispiel #2
0
 public function actionCatch($url = null)
 {
     $link = Links::findOne(['url' => '/' . $url]);
     if (!$link) {
         echo '404 Not found!';
         return false;
     }
     $this->layout = $link->layout->name;
     if ($link->description) {
         Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $link->description]);
     }
     if ($link->keywords) {
         Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $link->keywords]);
     }
     if (isset($link->id)) {
         $contents = Contents::find()->where(['links_id' => $link->id])->orderBy(['seq' => SORT_ASC])->all();
         for ($i = 0; $i < count($contents); $i++) {
             $contents[$i]->text = preg_replace_callback('/(\\{{)(\\S+)(}})/', "self::getModule", $contents[$i]->text);
             $contents[$i]->text = preg_replace_callback('/(\\[\\[)(\\S+)(]])/', "self::getWidget", $contents[$i]->text);
         }
     }
     return $this->render($link->view->name, ['link' => $link, 'contents' => $contents]);
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContents()
 {
     return $this->hasMany(Contents::className(), ['links_id' => 'id']);
 }
Beispiel #4
0
 private function addGood($item, $verificationCode)
 {
     $group = ShopGroups::findOne(['verification_code' => strval($item->{'Группы'}->{'Ид'})]);
     $good = ShopGoods::findOne(['verification_code' => $verificationCode]);
     if ($good) {
         $link = Links::findOne($good->links_id);
     }
     if (!isset($link)) {
         $link = new Links();
     }
     $translit = new Translit();
     $link->categories_id = Yii::$app->params['shop']['categoriesId'];
     $link->parent = $group->links_id;
     $link->anchor = strval(isset($item->{'НаименованиеНаСайте'}) && $item->{'НаименованиеНаСайте'} ? $item->{'НаименованиеНаСайте'} : $item->{'Наименование'});
     $link->name = isset($link->id) ? $translit->slugify($link->anchor, $link->tableName(), 'name', '-', $link->id) : $translit->slugify($link->anchor, $link->tableName(), 'name', '-', null);
     $link->level = $group->link->level + 1;
     $link->url = (new Links())->getPrefixUrl(Yii::$app->params['shop']['goodUrlPrefix'], $link->level, $group->links_id) . '/' . $link->name;
     $link->child_exist = 0;
     $link->seq = isset($link->id) ? $link->seq : Links::findLastSequence(Yii::$app->params['shop']['categoriesId'], $link->parent) + 1;
     $link->title = isset($link->id) ? $link->title : $link->anchor;
     $link->created_at = isset($link->id) ? $link->created_at : time();
     $link->updated_at = time();
     $link->state = $item->{'НеПубликуетсяНаСайте'} == 'истина' ? 0 : 1;
     $link->layouts_id = Yii::$app->params['shop']['good_layouts_id'];
     $link->views_id = Yii::$app->params['shop']['good_views_id'];
     $link->save();
     $content = Contents::findOne(['links_id' => $link->id]);
     if (!$content) {
         $content = new Contents();
         $content->links_id = $link->id;
         $content->seq = 1;
     }
     $content->text = strval($item->{'Описание'});
     $content->save();
     if (!$good) {
         $good = new ShopGoods();
         $good->shop_groups_id = $group->id;
         $good->verification_code = $verificationCode;
     }
     $good->links_id = $link->id;
     $shopUnit = ShopUnits::findOne(['name' => $item->{'БазоваяЕдиница'}]);
     if (!$shopUnit) {
         $shopUnit = new ShopUnits();
         $shopUnit->name = strval($item->{'БазоваяЕдиница'});
         $shopUnit->save();
     }
     $good->shop_units_id = $shopUnit->id;
     $good->name = strval($item->{'Наименование'});
     $good->code = preg_replace('/^\\D+0*/', '', $item->{'КодНоменклатуры'});
     $good->state = 1;
     $good->save();
     if ($item->{'Картинки'} && $item->{'Картинки'}->{'Картинка'}) {
         $this->addImage($item->{'Картинки'}->{'Картинка'}, Yii::$app->params['shop']['gallery']['good'], $link->id, $good->id);
     }
     return ['id' => $good->id, 'links_id' => $link->id];
 }
Beispiel #5
0
 private function addGood($item, $code)
 {
     $group = ShGroups::findOne(['code' => strval($item->{'Группы'}->{'Ид'})]);
     $good = ShGoods::findOne(['code' => $code]);
     $link = $good ? Links::findOne($good->links_id) : new Links();
     $link->categories_id = self::GOOD_CATEGORIES_ID;
     $link->parent = $group->links_id;
     $link->anchor = strval(isset($item->{'НаименованиеНаСайте'}) && $item->{'НаименованиеНаСайте'} ? $item->{'НаименованиеНаСайте'} : $item->{'Наименование'});
     $link->link_name = isset($item->{'URI'}) && $item->{'URI'} ? strval($item->{'URI'}) : $link->anchor2translit($link->anchor);
     $link_name = $link->link_name;
     $num = 1;
     if (isset($link->id)) {
         while (Links::findByUrlForLink($link->link_name, $link->id, $link->parent)) {
             $num += 1;
             $link->link_name = $link_name . '-' . $num;
         }
     } else {
         while (Links::findByUrl($link->link_name, $link->parent)) {
             $num += 1;
             $link->link_name = $link_name . '-' . $num;
         }
     }
     $link->level = $group->link->level + 1;
     $link->child_exist = 0;
     $link->url = $group->link->url . '/' . $link->link_name;
     $link->seq = isset($link->id) ? $link->seq : Links::findLastSequence(self::GOOD_CATEGORIES_ID, $link->parent) + 1;
     $link->title = isset($link->id) ? $link->title : $link->anchor;
     $link->created_at = isset($link->id) ? $link->created_at : time();
     $link->updated_at = time();
     $link->state = $item->{'НеПубликуетсяНаСайте'} == 'истина' ? 0 : 1;
     $link->layouts_id = self::GOOD_LAYOUT;
     $link->views_id = self::GOOD_VIEW;
     $link->content_nums = 1;
     $link->save();
     $content = Contents::findOne(['links_id' => $link->id]);
     if (!$content) {
         $content = new Contents();
         $content->links_id = $link->id;
         $content->seq = 1;
     }
     $content->content = strval($item->{'Описание'});
     $content->save();
     if (!$good) {
         $good = new ShGoods();
         $good->links_id = $link->id;
         $good->groups_id = $group->id;
         $good->code = $code;
     }
     $good->good = strval($item->{'Наименование'});
     $good->save();
     if ($item->{'Картинки'} && $item->{'Картинки'}->{'Картинка'}) {
         $this->addImage($link->id, $item->{'Картинки'}->{'Картинка'});
     }
     return ['id' => $good->id, 'links_id' => $link->id];
 }
 public function actionSaveContent($links_id, $categories_id = null)
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $contents = Contents::find()->where(['links_id' => $links_id])->orderBy(['seq' => SORT_ASC])->all();
         if (Yii::$app->request->post()) {
             foreach ($contents as $index => $content) {
                 if (Yii::$app->request->post('content-' . $index)) {
                     $contents[$index]->load(Yii::$app->request->post());
                     $contents[$index]->text = Yii::$app->request->post('content-' . $index);
                     $contents[$index]->save();
                 }
             }
         }
         return ['flash' => 'success', 'message' => 'Изменения приняты'];
     }
 }