/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tees::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'course_id' => $this->course_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'color', $this->color]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTees() { return $this->hasOne(Tees::className(), ['id' => 'tees_id']); }
use common\models\Hole; use common\models\Course; use common\models\Tees; use common\models\Competition; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\helpers\Url; use kartik\detail\DetailView; /* @var $this yii\web\View */ /* @var $model app\models\Tees */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('igolf', 'Facilities'), 'url' => ['facility/index']]; $this->params['breadcrumbs'][] = ['label' => $model->course->facility->name, 'url' => ['facility/view', 'id' => $model->course->facility_id]]; $this->params['breadcrumbs'][] = ['label' => $model->course->name, 'url' => ['course/view', 'id' => $model->course->id]]; $this->params['breadcrumbs'][] = $this->title . ' (' . Yii::t('igolf', ucfirst($model->color)) . ')'; ?> <div class="tees-view"> <?php echo DetailView::widget(['model' => $model, 'panel' => ['heading' => '<h2>' . $model->name . '</h2>'], 'labelColOptions' => ['style' => 'width: 30%'], 'attributes' => [['attribute' => 'course_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'label' => Yii::t('igolf', 'Course'), 'items' => ArrayHelper::map(Course::find()->asArray()->all(), 'id', 'name'), 'value' => $model->course->name], 'name', ['attribute' => 'color', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Yii::$app->params['tees_colors'], 'value' => Yii::t('igolf', ucfirst($model->color))], 'par', ['attribute' => 'holes', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => array(18 => '18', 9 => '9')], ['attribute' => 'gender', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Tees::getLocalizedConstants('GENDER_')], ['attribute' => 'category', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Tees::getLocalizedConstants('CATEGORY_')], ['attribute' => 'front_back', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Tees::getLocalizedConstants('TEE_'), 'visible' => $model->holes == 9], 'course_rating', 'slope_rating']]); ?> <?php //TabularForm requires that dataProvider is build from Model::find() $dataProvider = new ActiveDataProvider(['query' => $model->getHoles()]); echo $this->render('../hole/_updates', ['dataProvider' => $dataProvider, 'tees' => $model]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getTees() { return $this->hasMany(Tees::className(), ['course_id' => 'id']); }
/** * Finds the Tees model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tees the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tees::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'holes')->dropDownList(array(18 => '18', 9 => '9')); ?> <?php echo $form->field($model, 'gender')->dropDownList(['' => ''] + Competition::getLocalizedConstants('GENDER_')); ?> <?php echo $form->field($model, 'category')->dropDownList(['' => ''] + Tees::getLocalizedConstants('CATEGORY_')); ?> <?php echo $form->field($model, 'front_back')->dropDownList(['' => ''] + Tees::getLocalizedConstants('TEE_')); ?> <?php echo $form->field($model, 'course_rating')->textInput(['maxlength' => 20]); ?> <?php echo $form->field($model, 'slope_rating')->textInput(['maxlength' => 20]); ?> <?php echo $form->field($model, 'color')->dropDownList(Yii::$app->params['tees_colors']); ?>
/** * @return \yii\db\ActiveQuery */ public function getTees() { return Tees::find()->andWhere(['id' => $this->tees_id]); }