Skip to content

Commit

Permalink
Removed limit of one open event per class. Fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryA committed Aug 28, 2015
1 parent 3cf0ce5 commit 813465b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
16 changes: 0 additions & 16 deletions models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function rules()
[['eventDate'], 'date', 'format' => 'yyyy-mm-dd'],
[['state'], 'string'],
['state', 'default', 'value' => 'Registration'],
['state', 'validateState'],
[['name'], 'string', 'max' => 100]
];
}
Expand Down Expand Up @@ -285,21 +284,6 @@ public function isOKToDelete($id)
])->count() > 0 ? false : true;
}

/**
* function to ensure only one event per weight class can be open at a time
*/
public function validateState($attribute, $params)
{
if (Event::find()->andWhere(['classId' => $this->classId])
->andWhere(['not', ['state' => 'Complete']])
->andWhere(['not', ['state' => 'Future']])
->andWhere(['not', ['id' => $this->id]])
->count() > 0)
{
$this->addError($attribute, 'There can be only one open event per weight class');
}
}

public static function getPosition($finalFight, $eventId)
{
$event = Event::findOne($eventId);
Expand Down
33 changes: 25 additions & 8 deletions models/Robot.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,40 @@ public static function dropdown($active = NULL, $eventId = NULL, $teamId = NULL)
}

/**
* Return checked if robot is entrant to any event which is not complete
* Return checked if robot is entrant to any event which is not complete (or selected event)
* Return value is checked attribute of checkbox
* @param integer $target
* @param integer $eventId (optional)
* @return string
*/
public static function isSignedUp($target)
public static function isSignedUp($target, $eventId = NULL)
{
if ($event = Event::find()->andWhere(['not',['state' => 'Complete']])->one())
if ($eventId == NULL)
{
if ($events = Event::find()->andWhere(['not',['state' => 'Complete']])->all())
{
$robots = 0;
foreach ($events as $event)
{
$robots += static::find()
->joinWith('entrants')
->andWhere(['{{%entrant}}.`robotId`' => $target])
->andWhere(['{{%entrant}}.`eventId`' => $event->id])
->count();
}
return ($robots > 0) ? 'checked' : '';
}
return '';
}
else
{
$robots = static::find()
->joinWith('entrants')
->andWhere(['{{%entrant}}.`robotId`' => $target])
->andWhere(['{{%entrant}}.`eventId`' => $event->id])
->count();
->joinWith('entrants')
->andWhere(['{{%entrant}}.`robotId`' => $target])
->andWhere(['{{%entrant}}.`eventId`' => $eventId])
->count();
return ($robots > 0) ? 'checked' : '';
}
return '';
}

/**
Expand Down
9 changes: 0 additions & 9 deletions views/robot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@
return $classDropdown[$model->classId];
},
],
[
'format' => 'raw',
'label' => 'Signed Up',
'value' => function($model, $index, $dataColumn) {
/* figure out if robot is signed up */
$checked = Robot::isSignedUp($model->id);
return '<div><input type="checkbox" name="signup" value="true" disabled ' . $checked . '></div>';
},
],
],
]);

Expand Down

0 comments on commit 813465b

Please sign in to comment.