/**
  * Finds the IncidentImage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return IncidentImage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = IncidentImage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Updates an existing Incident model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $incident = $this->findModel($id);
     $image = new File();
     $prey = new Prey();
     if (Yii::$app->request->isPost) {
         // Incident Form
         if (Yii::$app->request->post('Incident')) {
             if ($incident->load(Yii::$app->request->post()) && $incident->save()) {
                 Yii::$app->session->setFlash('success', 'The incident was successfully updated.');
                 return $this->redirect(['update', 'id' => $id]);
             }
         }
         // File Form
         if (Yii::$app->request->post('File')) {
             $image->file = UploadedFile::getInstance($image, 'file');
             if ($image->uploadFile()) {
                 // file is uploaded successfully
                 $incidentImage = new IncidentImage();
                 $incidentImage->file_id = $image->id;
                 $incidentImage->incident_id = $id;
                 $incidentImage->save();
                 Yii::$app->session->setFlash('success', 'The image was successfully uploaded.');
                 return $this->redirect(['update', 'id' => $id, 'photoID' => '']);
             }
             Yii::$app->session->setFlash('danger', 'Something went wrong.');
             return $this->redirect(['update', 'id' => $id, 'photoID' => '']);
         }
         // Prey Form
         if (Yii::$app->request->post('Prey')) {
             if ($prey->load(Yii::$app->request->post())) {
                 $prey->incident_id = $incident->id;
                 $prey->raptor_id = $incident->raptor_id;
                 if ($prey->save()) {
                     Yii::$app->session->setFlash('success', 'Prey for raptor <b>' . $incident->raptor->species_long . '</b> was successfully created.');
                     return $this->redirect(['update', 'id' => $id, 'preyID' => '']);
                 }
                 Yii::$app->session->setFlash('danger', 'Something went wrong.');
                 return $this->redirect(['update', 'id' => $id, 'preyID' => '']);
             }
         }
     }
     return $this->render('update', ['incident' => $incident, 'image' => $image, 'prey' => $prey]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $incidentid)
 {
     $query = IncidentImage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'incident_id' => $this->incident_id, 'file_id' => $this->file_id]);
     $query->andWhere(['incident_id' => $incidentid]);
     return $dataProvider;
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIncidentImages()
 {
     return $this->hasMany(IncidentImage::className(), ['file_id' => 'id']);
 }