Exemple #1
0
 public function actionAdd()
 {
     if (User::thisUser()->reputation < School::MIN_REPUTATION_SCHOOL_CREATE) {
         return Yii::$app->getResponse()->redirect(Url::home());
     }
     $school = new School();
     if ($school->load(Yii::$app->request->post())) {
         $schoolPost = Yii::$app->request->post('School');
         $school->country = $schoolPost['country'];
         $school->description = \yii\helpers\HtmlPurifier::process($school->description, []);
         $school->user_id = Yii::$app->user->identity->getId();
         $school->date = strtotime(date('Y-m-d'));
         $school->like_count = 0;
         $school->show_count = 0;
         if ($school->save()) {
             // Добавляем теги
             $tagsArr = explode(',', Yii::$app->request->post('tags'));
             $school->saveTags($tagsArr);
             // Добавляем картинки к записи
             $imgs = Yii::$app->request->post('imgs');
             if (!empty($imgs) && is_array($imgs)) {
                 $school->saveImgs($imgs);
             } else {
                 $school->saveImgs([]);
             }
             $school->saveLocations(Yii::$app->request->post('location'));
             return Yii::$app->getResponse()->redirect($school->getUrl());
         }
     }
     Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL);
     return $this->render('add', ['school' => $school]);
 }