/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CmsMealPlan::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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'is_active' => $this->is_active, 'sort_order' => $this->sort_order]); $query->andFilterWhere(['like', 'cms_pages_lang.title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'identifier', $this->identifier])->andFilterWhere(['like', 'code_id', $this->code_id]); $query->joinWith(['cmsMealplanLangs' => function ($query) { $query->where(['language' => Yii::$app->language]); }]); return $dataProvider; }
private function getMealPlansList() { return CmsMealPlan::find()->orderBy('sort_order, created_at ASC')->asArray()->all(); }
/** * Finds the CmsMealPlan model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CmsMealPlan the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CmsMealPlan::find()->where(['id' => $id])->multilingual()->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model backend\models\GeneralSettings */ /* @var $form yii\widgets\ActiveForm */ $plan_items = ArrayHelper::map(\backend\models\CmsMealPlan::find()->all(), 'id', 'title'); $update_freq_items = []; for ($week = 0; $week < 7; $week++) { $update_freq_items[$week] = date('D', time('Mon') + $week * 24 * 3600); } ?> <div class="general-settings-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($modelPlanId, 'value')->dropDownList($plan_items, ['name' => 'values[mealplan_current_id]'])->label('Current Meal Plan'); ?> <?php echo $form->field($modelPlanFreq, 'value')->dropDownList($update_freq_items, ['name' => 'values[mealplan_update_freq]'])->label('Meal Plan Update Frequency'); ?>