/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Scorecard::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'competition_id' => $this->competition_id, 'golfer_id' => $this->golfer_id, 'tees' => $this->tees]); $query->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * @inheritdoc */ public function afterFind() { parent::afterFind(); if ($this->registration) { if (!($this->tees = $this->registration->tees)) { if ($competition = $this->registration->competition) { if ($competition->course) { $this->tees = $competition->course->getFirstTees(); } } } if ($competition = $this->registration->competition) { $this->player = $this->registration->competition->isTeamCompetition() ? $this->registration->team : $this->registration->golfer; } else { // @todo ? $this->player = $this->registration->golfer; } } }
public function apply($competition) { $params = $this->getParameters(); $this->bestOf = isset($params['bestOf']) ? intval($params['bestOf']) : null; $children_competitions = $competition->getCompetitions()->andWhere(['status' => Competition::STATUS_CLOSED])->select('id'); Yii::trace('children comp=' . print_r($children_competitions->asArray()->all(), true)); foreach ($competition->getScorecards()->andWhere(['status' => Scorecard::STATUS_OPEN])->each() as $scorecard) { Yii::trace('scorecard=' . $scorecard->id); $registrations = Registration::find()->andWhere(['competition_id' => $children_competitions])->andWhere(['golfer_id' => $scorecard->registration->golfer_id]); $children_scorecards = Scorecard::find()->andWhere(['registration_id' => $registrations->select('id')])->andWhere(['status' => Scorecard::STATUS_RETURNED]); if (intval($this->bestOf) > 0) { $children_scorecards->orderBy([$this->source_type => $this->source_direction])->limit($this->bestOf); } $count_children = clone $children_scorecards; $sum_children = $children_scorecards->sum($this->source_type); $scorecard->{$this->destination_type} = $sum_children; $scorecard->rounds = $count_children->count(); $scorecard->save(); } Yii::trace('bestOf=' . $this->bestOf); }
/** * @return \yii\db\ActiveQuery */ public function getScorecards() { return $this->hasMany(Scorecard::className(), ['practice_id' => 'id']); }
/** * @inheritdoc */ public function afterFind() { parent::afterFind(); $this->tees = $this->practice->tees; $this->player = $this->practice->golfer; }
/** * Returns scorecards for this competition. Ignore registered non-participant. * * @return \yii\db\ActiveQuery */ public function getScorecards() { return $this->hasMany(Scorecard::className(), ['registration_id' => 'id'])->viaTable('registration', ['competition_id' => 'id']); //return Scorecard::find()->where(['registration_id' => $this->getRegistrations()->select('id')]); }
use kartik\widgets\ActiveForm; use yii\helpers\Html; use yii\helpers\Url; Icon::map($this, Icon::WHHG); /* @var $this yii\web\View */ /* @var $searchModel app\models\RegistrationSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('igolf', 'Scorecards for competition «{0}»', $competition->name); $this->params['breadcrumbs'][] = ['label' => Yii::t('igolf', 'Competitions'), 'url' => ['competition/index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="scorecard-index"> <?php echo GridView::widget(['options' => ['id' => 'registration'], 'dataProvider' => $dataProvider, 'panel' => ['heading' => '<h4>' . $this->title . '</h4>', 'footer' => Html::a(Yii::t('igolf', 'Publish'), Url::to(['scorecard/publish', 'id' => $competition->id]), ['class' => 'btn btn-success'])], 'export' => false, 'columns' => [['attribute' => 'golfer_name', 'label' => Yii::t('igolf', 'Player'), 'value' => function ($model, $key, $index, $widget) { return $model->player->name; }], ['attribute' => 'status', 'label' => Yii::t('igolf', 'Scorecard Status'), 'value' => function ($model, $key, $index, $widget) { return Yii::t('igolf', $model->status); }, 'filter' => Scorecard::getLocalizedConstants('STATUS_')], ['attribute' => 'status', 'label' => Yii::t('igolf', 'Registration Status'), 'value' => function ($model, $key, $index, $widget) { return $model->registration ? Yii::t('igolf', $model->registration->status) : ''; }, 'filter' => Registration::getLocalizedPostCompetitionStatuses()], ['class' => 'kartik\\grid\\ActionColumn', 'template' => '{view} {update} {reset}', 'buttons' => ['reset' => function ($url, $model) { if ($model->hasDetails()) { $url = Url::to(['delete', 'id' => $model->id]); return Html::a('<i class="glyphicon glyphicon-remove"></i>', $url, ['title' => Yii::t('igolf', 'Delete score details'), 'data-confirm' => Yii::t('igolf', 'Delete score details for this golfer?')]); } else { return '<i class="glyphicon glyphicon-remove disabled"></i>'; } }]]]]); ?> </div>
/* @var $searchModel app\models\RegistrationSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = $competition->getFullName(); $this->params['breadcrumbs'][] = ['label' => Yii::t('igolf', 'Competitions'), 'url' => ['competition/index']]; $this->params['breadcrumbs'][] = $this->title; $input_decimal = ['type' => function ($model, $key, $index, $widget) { return $model->hasDetails() ? TabularForm::INPUT_STATIC : TabularForm::INPUT_TEXT; }, 'columnOptions' => ['width' => '100px']]; $apply_rule = in_array($competition->competition_type, [Competition::TYPE_TOURNAMENT, Competition::TYPE_SEASON]) ? Html::a(Yii::t('igolf', 'Compute'), Url::to(['competition/apply', 'id' => $competition->id]), ['class' => 'btn btn-primary']) : ''; ?> <div class="scorecard-index"> <?php $form = ActiveForm::begin(); ?> <?php echo TabularForm::widget(['form' => $form, 'dataProvider' => $dataProvider, 'gridSettings' => ['panel' => ['heading' => '<h4>' . $this->title . '</h4>', 'footer' => Html::submitButton('Save', ['class' => 'btn btn-primary']) . ' ' . $apply_rule . ' ' . Html::a(Yii::t('igolf', 'Scorecard Status'), Url::to(['status', 'id' => $competition->id]), ['class' => 'btn btn-primary']) . ' ' . Html::a(Yii::t('igolf', 'Publish'), Url::to(['publish', 'id' => $competition->id]), ['class' => 'btn btn-success'])]], 'serialColumn' => false, 'actionColumn' => false, 'checkboxColumn' => false, 'attributes' => ['id' => ['type' => TabularForm::INPUT_HIDDEN, 'columnOptions' => ['visible' => false]], 'golfer_name' => ['type' => TabularForm::INPUT_STATIC, 'value' => function ($model, $key, $index, $widget) { return $model->registration->golfer->name; }, 'noWrap' => true], 'tee_time' => ['type' => TabularForm::INPUT_STATIC, 'value' => function ($model, $key, $index, $widget) { return $model->registration->flight ? $model->registration->flight->start_time : ''; }, 'noWrap' => true], 'golfer_hdcp' => ['type' => TabularForm::INPUT_STATIC, 'label' => Yii::t('igolf', 'Handicap'), 'value' => function ($model, $key, $index, $widget) { return $model->registration->golfer->handicap; }, 'noWrap' => true], 'thru' => $input_decimal, 'score' => $input_decimal, 'score_net' => $input_decimal, 'stableford' => $input_decimal, 'stableford_net' => $input_decimal, 'points' => $input_decimal, 'rounds' => $input_decimal, 'status' => ['type' => TabularForm::INPUT_DROPDOWN_LIST, 'items' => Scorecard::getLocalizedConstants('STATUS_')]]]); ?> <?php ActiveForm::end(); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getScorecards() { return $this->hasMany(Scorecard::className(), ['id' => 'scorecard_id'])->viaTable('score', ['hole_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getScorecard() { return $this->hasOne(Scorecard::className(), ['id' => 'scorecard_id']); }
/** * @return \yii\db\ActiveQuery */ public function getScorecards() { return $this->hasMany(Scorecard::className(), ['registration_id' => 'id']); }
<?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>
/** * Finds the Scorecard model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Scorecard the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findScorecard($id) { if (($model = Scorecard::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> <?php echo $form->field($model, 'competition_type')->dropDownList(Competition::getLocalizedConstants('TYPE_'))->hint(Yii::t('igolf', 'Rule applies to this type of competition')); ?> <?php echo $form->field($model, 'source_type')->dropDownList(Scorecard::getConstants('SCORE_'))->hint(Yii::t('igolf', 'Source column for score')); ?> <?php echo $form->field($model, 'source_direction')->dropDownList(Scorecard::getConstants('DIRECTION_'))->hint(Yii::t('igolf', 'Source column for score ordering. ASC is smallest wins to largest looses. DESC is opposite.')); ?> <?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
}, 'visible' => $competition === null], ['attribute' => 'competition_type', 'label' => Yii::t('igolf', 'Competition Type'), 'value' => function ($model, $key, $index, $widget) { return Yii::t('igolf', $model->registration->competition->competition_type); }, 'filter' => Competition::getLocalizedConstants('TYPE_'), 'visible' => $competition === null], ['attribute' => 'golfer_name', 'label' => Yii::t('igolf', 'Golfer'), 'value' => function ($model, $key, $index, $widget) { return $model->registration->golfer->name; }], ['label' => Yii::t('igolf', 'Created At'), 'attribute' => 'created_at', 'format' => 'datetime', 'value' => function ($model, $key, $index, $widget) { return new DateTime($model->created_at); }], ['label' => Yii::t('igolf', 'Last Update'), 'attribute' => 'updated_at', 'format' => 'datetime', 'value' => function ($model, $key, $index, $widget) { return new DateTime($model->updated_at); }], ['attribute' => 'status', 'value' => function ($model, $key, $index, $widget) { return Yii::t('igolf', $model->status); }, 'filter' => Scorecard::getLocalizedConstants('STATUS_')], ['class' => 'kartik\\grid\\CheckboxColumn']]]); ?> <?php $statuses = '<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">' . Yii::t('igolf', 'Change Status of Selected Scorecards to ') . ' <span class="caret"></span></button><ul class="dropdown-menu" role="menu">'; foreach (Scorecard::getLocalizedConstants('STATUS_') as $key => $value) { $statuses .= '<li>' . Html::a(Yii::t('igolf', 'Change to {0}', $value), null, ['class' => 'igolf-bulk-action', 'data-status' => $key]) . '</li>'; } $statuses .= '</ul></div>'; $buttons = $competition ? Html::a(Yii::t('igolf', 'Scores'), Url::to(['competition', 'id' => $competition->id]), ['class' => 'btn btn-primary']) : ''; $buttons .= ' ' . $statuses; echo $buttons; ?> </div> <script type="text/javascript"> <?php $this->beginBlock('JS_PJAXREG'); ?> $("a.igolf-bulk-action").click(function(e) { collected = $('#scorecard').yiiGridView('getSelectedRows');
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['source_direction'], 'in', 'range' => array_keys(Scorecard::getConstants('DIRECTION_'))], [['source_type', 'destination_type'], 'in', 'range' => array_keys(Scorecard::getConstants('SCORE_'))], [['status'], 'in', 'range' => array_keys(self::getConstants('STATUS_'))]]); }