DIR : /home/kozerus/public_html/dgs/tournaments/include/tournament_template_ladder.php

/home/kozerus/public_html/dgs/tournaments/include

<?php
/*
Dragon Go Server
Copyright (C) 2001-  Erik Ouchterlony, Jens-Uwe Gaspar

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

 /* Author: Jens-Uwe Gaspar */

//$TranslateGroups[] = "Tournament";

require_once 'tournaments/include/tournament_globals.php';
require_once 'tournaments/include/tournament_template.php';
require_once 'tournaments/include/tournament_log_helper.php';

require_once 'tournaments/include/tournament_cache.php';
require_once 'tournaments/include/tournament_extension.php';
require_once 'tournaments/include/tournament_ladder.php';
require_once 'tournaments/include/tournament_ladder_props.php';

 /*!
  * \file tournament_template_ladder.php
  *
  * \brief Base Classe and functions to handle Ladder-typed tournaments
  */


 /*!
  * \class TournamentTemplateLadder
  *
  * \brief Template-pattern for general Ladder-tournaments
  */
abstract class TournamentTemplateLadder extends TournamentTemplate
{
   protected function __construct( $wizard_type, $title_main, $title_extras )
   {
      parent::__construct( $wizard_type, $title_main, $title_extras );

      // overwrite tournament-type-specific properties
      $this->allow_register_tourney_status = array( TOURNEY_STATUS_REGISTER, TOURNEY_STATUS_PLAY );
      $this->allow_edit_tourney_status_td_adm_edit = array( TOURNEY_STATUS_NEW, TOURNEY_STATUS_REGISTER, TOURNEY_STATUS_PLAY );
      $this->allow_game_annul = true;
      $this->showcount_tournament_standings = 5;
      $this->limits->setLimits( TLIMITS_TRD_MAX_ROUNDS, false, 1, 1 );
      $this->limits->setLimits( TLIMITS_TL_MAX_DF, false, 0, TLADDER_MAX_DEFENSES );
      $this->limits->setLimits( TLIMITS_TL_MAX_CH, false, 1, TLADDER_MAX_CHALLENGES );
   }

   /*!
    * \brief Function to persist create tournament-tables for ladder-tournament.
    * \internal
    */
   protected function _createTournament( Tournament $tourney, TournamentProperties $tprops, TournamentRules $t_rules,
                                         TournamentLadderProps $tl_props )
   {
      global $NOW;

      ta_begin();
      {//HOT-section to create various tables for new tournament
         // insert tournament-related tables
         if ( !$tourney->persist() )
            $this->create_error("TournamentTemplateLadder._createTournament.tourney.insert(%s)");
         $tid = $tourney->ID;

         $tprops->tid = $tid;
         if ( !$tprops->insert() )
            $this->create_error("TournamentTemplateLadder._createTournament.tprops.insert(%s,$tid)");

         $t_rules->tid = $tid;
         if ( !$t_rules->insert() )
            $this->create_error("TournamentTemplateLadder._createTournament.t_rules.insert(%s,$tid)");

         $tl_props->tid = $tid;
         if ( !$tl_props->insert() )
            $this->create_error("TournamentTemplateLadder._createTournament.tl_props.insert(%s,$tid)");

         $t_ext = new TournamentExtension( $tid, TE_PROP_TLADDER_RANK_PERIOD_UPDATE, 0,
               TournamentUtils::get_month_start_time($NOW, 1) ); // start with next month
         if ( !$t_ext->persist() )
            $this->create_error("TournamentTemplateLadder._createTournament.t_ext.insert(%s,$tid)");

         $this->create_default_tournament_director( $tid );

         TournamentLogHelper::log_create_tournament( $tid, $tourney );
      }
      ta_end();

      return $tid;
   }//_createTournament


   public function copyTournament( $tlog_type, $src_tid )
   {
      error('not_implemented', "TournamentTemplateLadder.copyTournament($tlog_type,$src_tid)");
   }//copyTournament

   public function getDefaultPoolNamesFormat()
   {
      return '';
   }

   public function checkProperties( Tournament $tourney, $t_status )
   {
      $tid = $tourney->ID;
      $errors = array();

      if ( $t_status == TOURNEY_STATUS_REGISTER )
      {
         $tl_props = TournamentCache::load_cache_tournament_ladder_props( "TournamentTemplateLadder.checkProperties({$this->uid})", $tid );
         $errors = $tl_props->check_ladder_properties();
      }

      // IMPORTANT NOTE for $t_status == PAIR: TPs on APPLY/INVITE-status are allowed!

      return $errors;
   }//checkProperties

   public function checkPooling( Tournament $tourney, $round )
   {
      return array(); // no check for ladder
   }

   public function checkParticipantRegistrations( $tid, array $arr_TPs )
   {
      return TournamentLadder::check_participant_registrations( $tid, $arr_TPs );
   }

   public function checkGamesStarted( $tid )
   {
      return array(); // games need not be started
   }

   public function checkPoolsFinish( Tournament $tourney, TournamentRound $tround )
   {
      return array( array(), array() ); // no pools or rounds (only one) for ladders
   }

   public function joinTournament( Tournament $tourney, TournamentParticipant $tp, $tlog_type )
   {
      ta_begin();
      {//HOT-section to save TournamentParticipant and add user in ladder
         $result = $tp->persist();
         if ( $tourney->Status == TOURNEY_STATUS_PLAY && $tp->Status == TP_STATUS_REGISTER )
            $result = TournamentLadder::add_user_to_ladder( $tp->tid, $tp->uid, $tlog_type );
      }
      ta_end();
      return $result;
   }

   public function checkClosingTournament( Tournament $tourney )
   {
      return array( array(), array() );
   }

} // end of 'TournamentTemplateLadder'

?>
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer