Exemplo n.º 1
0
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $categ = Categories::find()->all();
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'categ' => $categ]);
     }
 }
Exemplo n.º 3
0
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(\Yii::$app->request->post())) {
         if (empty($model->logo)) {
             $model->logo = $model->default_news_icon;
         }
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Exemplo n.º 4
0
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->alias = mb_strtolower(strtr($model->title, Yii::$app->params['transliterate']));
         $model->date_create = Yii::$app->formatter->asTimestamp($model->date_create . ' 12:00');
         //            $model->date_create = date(time());
         $model->save();
         //            if(!empty($_FILES['UploadForm']['tmp_name']['file'])) {
         //                $model->attachImage($_FILES['UploadForm']['tmp_name']['file'],false);
         //                if($model->errors) {
         //                    var_dump($model->errors);
         //                    die;
         //                }
         //            }
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         //            $model-> category = Category::find()->all();
         //            var_dump($model);die;
         return $this->render('create', ['model' => $model, 'category' => Category::find()->all()]);
     }
 }
Exemplo n.º 5
0
 public function actionSave()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $model = new News();
         if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect('/news/view');
             } else {
                 throw new ForbiddenHttpException('Ошибка добавления новости!', 404);
             }
         }
         return $this->render('save', compact('model'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
Exemplo n.º 6
0
 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($sectionid)
 {
     $model = new News();
     // $sections = SecNews::find()->select(['id','header'])->asArray()->all();
     $sections = SecNews::find()->select(['id', 'header'])->all();
     $sections = ArrayHelper::map($sections, 'id', 'header');
     // echo "<pre>";
     // var_dump($a);
     // die;
     $params = ['prompt' => 'Выберите секцию…'];
     if (isset($sectionid)) {
         $params['options'] = [$sectionid => ['Selected' => 'selected']];
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'sections' => $sections, 'params' => $params]);
     }
 }
Exemplo n.º 7
0
 protected function createNews(PendingNews $pn)
 {
     if ($npn = Npn::findOne(["pending_news_id" => $pn->id])) {
         return $npn->news_id;
     }
     $news = new News();
     $news->title = NewsParserComponent::replace4byte($pn->title);
     $news->thumb = $pn->thumb_src;
     $news->status = "in_process";
     $news->cnt = 0;
     $news->created_at = new \yii\db\Expression('NOW()');
     $news->updated_at = new \yii\db\Expression('NOW()');
     if ($news->save()) {
         $this->linkNews($news->id, $pn->id);
         $news->status = "done";
         $news->save();
         if ($news->thumb && PageLoaderComponent::checkRemoteFile($news->thumb)) {
             $mq = new RabbitMQComponent();
             $mq->postMessage("image", "image", json_encode(["news_id" => $news->id, "src" => $news->thumb]));
             $mq->postMessage("twitter", "twitter", json_encode(["news_id" => $news->id, "src" => $news->thumb]));
         } else {
             if ($giData = PageLoaderComponent::load("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" . urlencode($news->title) . "&userip=127.0.0.1&imgsz=large")) {
                 $data = json_decode($giData);
                 if (isset($data->responseData->results[0])) {
                     $news->thumb = $data->responseData->results[0]->unescapedUrl;
                     $news->save();
                     $mq = new RabbitMQComponent();
                     $mq->postMessage("image", "image", json_encode(["news_id" => $news->id, "src" => $data->responseData->results[0]->unescapedUrl]));
                     $mq->postMessage("twitter", "twitter", json_encode(["news_id" => $news->id, "src" => $data->responseData->results[0]->unescapedUrl]));
                 }
             }
         }
     } else {
         print_r($news->getErrors());
     }
     return $news->id;
 }