/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Rule::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'rule_type', $this->rule_type])->andFilterWhere(['like', 'competition_type', $this->competition_type])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * Returns the score column corresponding to the competition's post-rule computation. * If there is no 'post-rule', there is not computed score. * * @return number Returns computed total score. */ public function getScoreFromFinalRule() { $scores = null; // echo 'yep '.$this->registration->competition->finalRule->id.', '; // @bug? if ($rule = Rule::findOne($this->registration->competition->final_rule_id)) { switch ($rule->destination_type) { case self::SCORE_GROSS: $scores = $this->score; break; case self::SCORE_NET: $scores = $this->score_net; break; case self::SCORE_STABLEFORD: $scores = $this->stableford; break; case self::SCORE_STABLEFORD_NET: $scores = $this->stableford_net; break; case self::SCORE_TOPAR: $scores = $this->lastToPar(); break; case self::SCORE_TOPAR_NET: $scores = $this->lastToPar_net(); break; case self::SCORE_POINTS: $scores = $this->points; break; } } return $scores; }
} array_pop($this->params['breadcrumbs']); $this->params['breadcrumbs'][] = $this->title; $recurrence = $model->recurrence; if ($model->recurrence) { // strips "RRULE:" at begining of string $str = strpos($model->recurrence, 'RRULE:') === 0 ? substr($model->recurrence, 6) : $model->recurrence; $rrule = new Recurr\Rule($str); $textTransformer = new Recurr\Transformer\TextTransformer(); $recurrence = ucfirst($textTransformer->transform($rrule)); } ?> <div class="competition-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(), 'label' => Yii::t('igolf', 'Parent'), 'value' => $model->parent ? $model->parent->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['view', 'id' => $model->parent_id]) : '', 'visible' => $model->competition_type != Competition::TYPE_SEASON, 'format' => 'raw'], ['attribute' => 'course_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'label' => Yii::t('igolf', 'Course'), 'items' => Course::getCourseList(true), 'value' => $model->course ? $model->course->getFullName() . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['course/view', 'id' => $model->course_id]) : '', 'format' => 'raw'], ['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->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['rule/view', 'id' => $model->rule_id]), 'format' => 'raw'], ['attribute' => 'final_rule_id', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(['' => ''] + Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name'), 'value' => $model->final_rule_id ? $model->finalRule->name . Html::a(' <span class="glyphicon glyphicon-share"></span>', ['rule/view', 'id' => $model->final_rule_id]) : '', 'format' => 'raw'], ['attribute' => 'start_date', 'format' => 'datetime', 'type' => DetailView::INPUT_DATETIME, 'widgetOptions' => ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]], 'value' => $model->registration_begin ? new DateTime($model->start_date) : ''], ['attribute' => 'recurrence', 'format' => 'raw', 'type' => DetailView::INPUT_TEXT, 'value' => $recurrence], ['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_')], 'max_players', ['attribute' => 'registration_special', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ['' => ''] + Competition::getLocalizedConstants('SPECIAL_')], 'registration_time', 'flight_size', 'flight_time', ['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;
/** * @return \yii\db\ActiveQuery */ public function getFinalRule() { return $this->hasOne(Rule::className(), ['id' => 'final_rule_id']); }
/** * Finds the Rule model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Rule the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Rule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use common\models\Competition; use common\models\Scorecard; use common\models\Rule; use kartik\detail\DetailView; use yii\helpers\Html; use yii\data\ActiveDataProvider; /* @var $this yii\web\View */ /* @var $model app\models\Rule */ $this->title = $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('igolf', 'Competition Rules'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="rule-view"> <?php echo DetailView::widget(['model' => $model, 'panel' => ['heading' => '<h3>' . $model->name . '</h3>'], 'labelColOptions' => ['style' => 'width: 30%'], 'attributes' => ['name', 'description', 'note', ['attribute' => 'competition_type', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Competition::getConstants('TYPE_')], ['attribute' => 'source_type', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Scorecard::getConstants('SCORE_')], ['attribute' => 'source_direction', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Scorecard::getConstants('DIRECTION_')], ['attribute' => 'destination_type', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => ['' => ''] + Scorecard::getConstants('SCORE_')], ['attribute' => 'handicap', 'type' => DetailView::INPUT_SWITCH, 'widgetOptions' => ['pluginOptions' => ['onText' => Yii::t('igolf', ' Use Handicap '), 'offText' => Yii::t('igolf', 'Do Not Use Handicap')]]], ['attribute' => 'team', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Rule::getTeamList()], ['attribute' => 'classname', 'type' => DetailView::INPUT_DROPDOWN_LIST, 'items' => Rule::getList()], 'parameters']]); ?> <?php $dataProvider = new ActiveDataProvider(['query' => $model->getPoints()]); echo $this->render('../point/_updates', ['dataProvider' => $dataProvider, 'rule' => $model]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getRules() { return $this->hasOne(Rule::className(), ['id' => 'rule_id']); }
?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 80]); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'rule_id')->dropDownList(['' => ''] + ArrayHelper::map(Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'final_rule_id')->dropDownList(['' => ''] + ArrayHelper::map(Rule::find()->where(['competition_type' => $model->competition_type])->asArray()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'registration_begin')->widget(DateTimePicker::classname(), ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]]); ?> <?php echo $form->field($model, 'registration_end')->widget(DateTimePicker::classname(), ['pluginOptions' => ['format' => 'yyyy-mm-dd hh:ii:ss', 'todayHighlight' => true]]); ?> <?php echo $form->field($model, 'handicap_min')->textInput(); ?> <?php
?> <?php echo $form->field($model, 'destination_type')->dropDownList(Scorecard::getConstants('SCORE_'))->hint(Yii::t('igolf', 'Destination column for result.')); ?> <?php echo $form->field($model, 'handicap')->widget(SwitchInput::className(), ['pluginOptions' => ['onText' => Yii::t('igolf', ' Use Handicap '), 'offText' => Yii::t('igolf', 'Do Not Use Handicap')]]); ?> <?php echo $form->field($model, 'team')->dropDownList(Rule::getTeamList())->hint(Yii::t('igolf', 'Camp size')); ?> <?php echo $form->field($model, 'classname')->dropDownList(Rule::getList())->hint(Yii::t('igolf', 'Rule to apply')); ?> <?php echo $form->field($model, 'parameters')->textInput(['maxlength' => 255]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('igolf', 'Create') : Yii::t('igolf', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/* @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;