Esempio n. 1
0
 /**
  * Finds the Prey model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Prey the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Prey::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Prey::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, 'raptor_id' => $this->raptor_id, 'prey_id' => $this->prey_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
Esempio n. 3
0
 /**
  * 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]);
 }
Esempio n. 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPreys()
 {
     return $this->hasMany(Prey::className(), ['raptor_id' => 'id']);
 }
Esempio n. 5
0
        return ['prey/delete', 'id' => $model->id];
    }
}, 'headerOptions' => ['style' => 'width: 80px;'], 'contentOptions' => ['style' => 'text-align: center; vertical-align: middle;']], 'prey.type']]);
Pjax::end();
?>


<?php 
$form = ActiveForm::begin(['id' => 'incident-prey-form']);
?>

<div class="incident-prey-form">
    <div class="row">
        <div class="col-lg-5">
            <?php 
echo $form->field($prey, 'prey_id')->dropDownList(ArrayHelper::map(Prey::preytypes(), 'id', 'type'), ['prompt' => '']);
?>
            <div class="form-group">
                <?php 
echo Html::submitButton('Create', ['class' => 'btn btn-success']);
?>
                <?php 
echo Html::a('Cancel', ['index'], ['class' => 'btn btn-success']);
?>
            </div>
        </div>
    </div> 
</div>

<?php 
ActiveForm::end();