/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Course::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'facility_id' => $this->facility_id, 'holes' => $this->holes]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Course::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'create_time' => $this->create_time]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $conditions = []) { $query = Course::find()->where($conditions); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); $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, 'user_id' => $this->user_id, 'course_terms' => $this->course_terms]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'video_url', $this->video_url])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * @return array id,name pairs */ public static function getCourseList($with_tees = false) { $models = Course::find()->all(); $list = []; foreach ($models as $model) { if ($with_tees) { if ($model->hasTees()) { $list[$model->id] = $model->facility->name . ', ' . $model->name; } } else { $list[$model->id] = $model->facility->name . ', ' . $model->name; } } return $list; }
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>
/** * php页面方法 */ public function actionPhps() { $data = Course::find()->all(); return $this->render('phps', ['data' => $data]); }
<?php use kartik\detail\DetailView; use yii\helpers\ArrayHelper; use common\models\Course; use common\models\Practice; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model app\models\Practice */ ?> <div class="practice-view"> <?php echo DetailView::widget(['model' => $model, 'panel' => ['heading' => '<h3>' . $this->title . '</h3>'], 'labelColOptions' => ['style' => 'width: 30%'], 'attributes' => [['attribute' => 'course_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'options' => ['id' => 'course-id'], 'items' => ArrayHelper::map(Course::find()->asArray()->all(), 'id', 'name'), 'value' => $model->course ? $model->course->name : ''], ['attribute' => 'tees_id', 'type' => DetailView::INPUT_DEPDROP, 'value' => $model->tees ? $model->tees->name : '', 'widgetOptions' => ['pluginOptions' => ['depends' => ['course-id'], 'placeholder' => 'Select...', 'url' => Url::to(['/golfer/practice/tees'])], 'data' => $model->tees ? [$model->tees_id => $model->tees->name] : []]], ['attribute' => 'start_time', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]]], ['attribute' => 'start_hole', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => array(1 => '1', 10 => '10')], ['attribute' => 'holes', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => array(18 => '18', 9 => '9')], 'handicap', ['attribute' => 'status', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Practice::getLocalizedConstants('STATUS_')]]]); ?> </div>
/* @var $this yii\web\View */ /* @var $model common\models\Season */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('igolf', 'Competitions'), 'url' => ['index']]; if ($bcs = $model->breadcrumbs()) { foreach ($bcs as $bc) { $this->params['breadcrumbs'][] = $bc; } } array_pop($this->params['breadcrumbs']); $this->params['breadcrumbs'][] = $this->title; ?> <div class="season-view"> <?php echo DetailView::widget(['model' => $model, 'panel' => ['heading' => '<h3>' . Yii::t('igolf', $model->competition_type) . ' ' . $model->name . '</h3>'], 'labelColOptions' => ['style' => 'width: 30%'], 'attributes' => ['name', 'description', ['attribute' => 'parent_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => $model->getParentCandidates(), 'value' => $model->parent ? $model->parent->name : '', 'visible' => $model->competition_type != Competition::TYPE_SEASON], ['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 ? $model->course->name : ''], ['attribute' => 'holes', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => array(18 => '18', 9 => '9')], ['attribute' => 'rule_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(['' => ''] + Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name'), 'value' => $model->rule_id ? $model->rule->name : ''], ['attribute' => 'start_date', 'format' => 'date', 'type' => DetailView::INPUT_DATE, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]]], ['attribute' => 'registration_begin', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_begin ? new DateTime($model->registration_begin) : ''], ['attribute' => 'registration_end', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_end ? new DateTime($model->registration_end) : ''], 'handicap_min', 'handicap_max', 'age_min', 'age_max', ['attribute' => 'gender', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ['' => ''] + Competition::getLocalizedConstants('GENDER_')], ['attribute' => 'status', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Competition::getLocalizedConstants('STATUS_')]]]); ?> <?php if (in_array($model->competition_type, [Competition::TYPE_SEASON, Competition::TYPE_TOURNAMENT])) { switch ($model->competition_type) { case Competition::TYPE_SEASON: $searchModel = new TournamentSearch(); $dataProvider = $searchModel->search(['TournamentSearch' => ['parent_id' => $model->id]]); $type = Competition::TYPE_TOURNAMENT; break; case Competition::TYPE_TOURNAMENT: $searchModel = new MatchSearch(); $dataProvider = $searchModel->search(['MatchSearch' => ['parent_id' => $model->id]]); $type = Competition::TYPE_MATCH; break;