public function getEventLan() { if (Yii::$app->language == 'ru') { return $this->hasOne(Event_ru::className(), ['event_id' => 'id']); } if (Yii::$app->language == 'en') { return $this->hasOne(Event_en::className(), ['event_id' => 'id']); } }
public function actionView($id) { $model = event::find()->where(['id' => $id])->one(); if (is_null($model)) { // 404 HTTP status will be returned throw new \yii\web\NotFoundHttpException(); } /* * Количество просмотров считается отдельно для русской и отдельно для английской версии */ $Event_ru = Event_ru::find()->where(['event_id' => $id])->one(); $Event_en = Event_en::find()->where(['event_id' => $id])->one(); if (Yii::$app->language == 'en') { $Event_en->visited++; $Event_en->save(); } elseif (Yii::$app->language == 'ru') { $Event_ru->visited++; $Event_ru->save(); } $photos = event_photo::find()->where(['event_id' => $id])->all(); //$photos = events_Photo::find(array('events_id' => $id)); return $this->render('view', ['model' => $model, 'photos' => $photos]); }
/** * Updates an existing event model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { /*$model = $this->findModel($id); $photos = new ActiveDataProvider([ 'query' => event_photo::find()-> where(['event_id'=>$id]), ]); if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->uploadphoto(UploadedFile::getInstances($model, 'images'), $model->id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, 'photos' => $photos, ]); }*/ $event = Event::find()->where(['id' => $id])->one(); $event_ru = Event_ru::find()->where(['event_id' => $id])->one(); $event_en = Event_en::find()->where(['event_id' => $id])->one(); $photos = new ActiveDataProvider(['query' => event_photo::find()->where(['event_id' => $id])]); if ($event->load(Yii::$app->request->post()) && $event_ru->load(Yii::$app->request->post()) && $event_en->load(Yii::$app->request->post())) { $event->author_id = Yii::$app->user->identity->id; if ($event->save()) { $this->uploadphoto(UploadedFile::getInstances($event, 'images'), $event->id); $event_ru->save(); $event_en->save(); } return $this->redirect(['update', 'id' => $event->id]); } else { return $this->render('update', ['event' => $event, 'event_ru' => $event_ru, 'event_en' => $event_en, 'photos' => $photos]); } }