/**
  * Test loading a list of unplayed matches
  */
 public function test_list_open_matches()
 {
     $this->get_tournament_with_open_matches();
     $matches = $this->object->open_matches();
     $this->assertTrue(is_array($matches), 'BBTournament::open_matches() did not return an array)');
     foreach ($matches as $match) {
         $this->assertInstanceOf('BBMatch', $match);
     }
 }
Beispiel #2
0
 /**
  * Overrides BBModel::save() so we can return false if trying to save an orphaned team
  * {@inheritdoc}
  */
 public function save($return_result = false, $child_args = null)
 {
     //Tournament must be saved first
     if (is_null($this->tournament->id)) {
         return $this->set_error('Tournament must be saved before adding teams');
     }
     //Remember whether or not we need to clear cache after the save is successful
     $reset_opponents = false;
     foreach (array_keys($this->new_data) as $key) {
         $key = strtolower($key);
         if ($key == 'wins' || $key == 'lb_wins' || $key == 'bronze_wins') {
             $reset_opponents = true;
             break;
         }
     }
     //If the race was changed, flag a reload
     $flag_reload = isset($this->new_data['race']);
     //json notes
     $notes = null;
     if (array_key_exists('notes', $this->new_data)) {
         $notes = $this->new_data['notes'];
         if (is_object($notes) || is_array($notes)) {
             $this->new_data['notes'] = json_encode($notes);
         }
     }
     //Let BBModel handle the rest
     if (!($save_result = parent::save($return_result, array('tourney_id' => $this->tournament->id)))) {
         return false;
     }
     //If bracket position was adjusted manually, reset opponents / cache etc
     if ($reset_opponents) {
         $this->tournament->clear_id_cache();
         $this->reset_opponents();
         $this->tournament->open_matches(true);
     }
     //If the race changed, flag a reload so that we download the race name, id, and icon values
     if ($flag_reload) {
         $this->flag_reload();
     }
     //Success!
     return $save_result;
 }