public function isValid($entity) { $league = $entity->getLeague(); $user = $entity->getUser(); if (is_null($league)) { $entity->errors('League not found for registration validity.'); } # Check Player Limits if (isset($league->player_limit)) { $limits = $league->player_limit->to('array'); if (isset($limits['male']) and $user->gender == 'male') { if ($limits['male'] == 0) { $entity->regErrors('This is a women-only league.'); } else { // TODO: Change this to ::count(); $men_count = Registrations::all(array('conditions' => array('league_id' => $league->_id, 'status' => 'active', 'gender' => 'male')))->count(); if ($men_count >= $limits['male']) { $entity->regErrors('Leauge cannot accommodate any more men.'); } } } if (isset($limits['female']) and $user->gender == 'female') { if ($limits['female'] == 0) { $entity->regErrors('This is a men-only league.'); } else { $women_count = Registrations::all(array('conditions' => array('league_id' => $league->_id, 'status' => 'active', 'gender' => 'female')))->count(); if ($women_count >= $limits['female']) { $entity->regErrors('Leauge cannot accommodate any more men.'); } } } } return count($entity->regErrors(null, false)) == 0; }