/**
  * Default view all wineries
  */
 public function actionCreate()
 {
     $wineList = Wines::model()->findByPk($id);
     $this->renderOutput($wineList);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Wines the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Wines::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemple #3
0
 /**
  * @return string the associated database table name
  */
 public function refreshRating($wine_id)
 {
     $newRatingAvg = 0;
     $currWine = Wines::model()->findByPk($wine_id);
     $wineInCellars = new CellarWines();
     $this->overall_rating = $newRatingAvg;
     // propogate the result of saving to the calling code
     return $currWine->save();
 }
 /**
  * Add an existing wine into the cellar
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the wine to be added
  */
 public function actionAddWine($wine_id)
 {
     $model = new CellarWines();
     $currentDateTime = new DateTime("now", new DateTimeZone('America/Chicago'));
     if (isset($_POST['CellarWines'])) {
         $model->attributes = $_POST['CellarWines'];
         $model->cellar_id = Yii::app()->session['cellar_id'];
         $model->wine_id = $wine_id;
         $model->create_dt = $currentDateTime->format('Y-m-d H:i:s');
         $model->update_dt = $currentDateTime->format('Y-m-d H:i:s');
         if ($model->save()) {
             $this->redirect(array('index', 'cellar_id' => $model->cellar_id));
         }
     } else {
         $selectedWine = Wines::model()->findByPk($wine_id);
         $model->cellar_id = Yii::app()->session['cellar_id'];
         $model->wine_id = $wine_id;
         $model->quantity = 0;
         $model->rating = $selectedWine->overall_rating;
         $model->cellar_loc_id = 1;
         $model->create_dt = $currentDateTime->format('Y-m-d H:i:s');
         $model->update_dt = $currentDateTime->format('Y-m-d H:i:s');
     }
     $this->render('update', array('model' => $model));
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     //        if (!isset($_GET['ajax']))
     //        {
     //            $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('update', 'id' => $model->id));
     //        }
 }