Example #1
0
 public function actionIndex()
 {
     //Get the wotd
     $wotd = AppConfig::findOne(1);
     $allWines = new Wines();
     $currentDateTime = new \DateTime("now", new \DateTimeZone('America/Chicago'));
     $wotdDateTime = new \DateTime($wotd->wotd_dt, new \DateTimeZone('America/Chicago'));
     $diff = $currentDateTime->diff($wotdDateTime);
     if ($diff->days > 0) {
         $wineOfTheDay = $allWines->getRandomWine(Yii::$app->params['wotdMinRating']);
         $wotd->wotd_id = $wineOfTheDay->id;
         $wotd->wotd_dt = $currentDateTime->format('Y-m-d H:i:s');
         $wotd->save();
     } else {
         $wineOfTheDay = $allWines->findOne($wotd->wotd_id);
         if (!isset($wineOfTheDay)) {
             $wineOfTheDay = $allWines->getRandomWine(Yii::$app->params['wotdMinRating']);
             $wotd->wotd_id = $wineOfTheDay->id;
             $wotd->wotd_dt = $currentDateTime->format('Y-m-d H:i:s');
             $wotd->save();
         }
     }
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     return $this->render('index', ['wineRecord' => $wineOfTheDay]);
 }
Example #2
0
 /**
  * @return	a wine CA record with a random wine selected with an overall 
  *			rating of $min_rating or greater
  */
 public function getRandomWine($min_rating)
 {
     $wineIDList = (new \yii\db\query())->select(['id'])->from('wines')->all();
     $wineID = $wineIDList[rand(0, sizeOf($wineIDList) - 1)];
     $wotd = Wines::findOne($wineID);
     if (!isset($wotd)) {
         return NULL;
     } else {
         return $wotd;
     }
 }
Example #3
0
 public function search($params)
 {
     $query = Wines::find();
     $query->joinWith(['winery', 'wineVarietal', 'appellation']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100], 'sort' => ['attributes' => ['winery_name' => ['asc' => ['winery_name' => SORT_ASC], 'desc' => ['winery_name' => SORT_DESC]], 'wine_year' => ['asc' => ['wine_year' => SORT_ASC], 'desc' => ['wine_year' => SORT_DESC]], 'varietal_name' => ['asc' => ['varietal_name' => SORT_ASC], 'desc' => ['varietal_name' => SORT_DESC]], 'wine_name' => ['asc' => ['wine_name' => SORT_ASC], 'desc' => ['wine_name' => SORT_DESC]], 'bottle_size' => ['asc' => ['bottle_size' => SORT_ASC], 'desc' => ['bottle_size' => SORT_DESC]], 'overall_rating' => ['asc' => ['overall_rating' => SORT_ASC], 'desc' => ['overall_rating' => SORT_DESC]]]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'winery_id' => $this->winery_id, 'appellation_id' => $this->appellation_id, 'wine_varietal_id' => $this->wine_varietal_id, 'overall_rating' => $this->overall_rating, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'wine_name', $this->wine_name])->andFilterWhere(['like', 'wine_year', $this->wine_year])->andFilterWhere(['like', 'bottle_size', $this->bottle_size])->andFilterWhere(['like', 'upc_barcode', $this->upc_barcode])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['appellations.app_name' => $this->app_name])->andFilterWhere(['wineries.winery_name' => $this->winery_name]);
     return $dataProvider;
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Wines::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, 'winery_id' => $this->winery_id, 'appellation_id' => $this->appellation_id, 'wine_varietal_id' => $this->wine_varietal_id, 'overall_rating' => $this->overall_rating, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'wine_name', $this->wine_name])->andFilterWhere(['like', 'wine_year', $this->wine_year])->andFilterWhere(['like', 'bottle_size', $this->bottle_size])->andFilterWhere(['like', 'upc_barcode', $this->upc_barcode])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWines()
 {
     return $this->hasMany(Wines::className(), ['winery_id' => 'id']);
 }
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWine()
 {
     return $this->hasOne(Wines::className(), ['id' => 'wine_id']);
 }
Example #7
0
<?php

use app\models\Cellars;
use app\models\Wines;
use app\models\Locations;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use kartik\widgets\ActiveForm;
use kartik\widgets\Select2;
use kartik\builder\Form;
use kartik\datecontrol\DateControl;
/**
 * @var yii\web\View $this
 * @var app\models\Cellarwines $model
 * @var yii\widgets\ActiveForm $form
 */
?>

<div class="cellarwines-form">

    <?php 
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL]);
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 1, 'attributes' => ['cellar_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Cellars::find()->orderBy('cellar_name')->asArray()->all(), 'id', 'cellar_name')], 'wine_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Wines::getListing()], 'quantity' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Quantity...']], 'cellar_loc_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Locations::find()->orderBy('loc_name')->asArray()->all(), 'id', 'loc_name')], 'rating' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Rating...']], 'created_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Created At...']], 'updated_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Updated At...']], 'cost' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Cost...', 'maxlength' => 10]]]]);
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
ActiveForm::end();
?>

</div>
Example #8
0
 /**
  * Finds the Wines model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Wines the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Wines::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }