public function getTemplateParameters()
 {
     $teamId = $this->_websoccer->getUser()->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     $sponsor = SponsorsDataService::getSponsorinfoByTeamId($this->_websoccer, $this->_db, $teamId);
     $sponsors = array();
     $teamMatchday = 0;
     if (!$sponsor) {
         $teamMatchday = MatchesDataService::getMatchdayNumberOfTeam($this->_websoccer, $this->_db, $teamId);
         if ($teamMatchday >= $this->_websoccer->getConfig("sponsor_earliest_matchday")) {
             $sponsors = SponsorsDataService::getSponsorOffers($this->_websoccer, $this->_db, $teamId);
         }
     }
     return array("sponsor" => $sponsor, "sponsors" => $sponsors, "teamMatchday" => $teamMatchday);
 }
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         return null;
     }
     $sponsor = SponsorsDataService::getSponsorinfoByTeamId($this->_websoccer, $this->_db, $teamId);
     if ($sponsor) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_stillcontract"));
     }
     // check min matchday
     $teamMatchday = MatchesDataService::getMatchdayNumberOfTeam($this->_websoccer, $this->_db, $teamId);
     if ($teamMatchday < $this->_websoccer->getConfig("sponsor_earliest_matchday")) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_tooearly", $this->_websoccer->getConfig("sponsor_earliest_matchday")));
     }
     // check if selected sponsor is in list of available sponsors
     // (sponsor might be selected by other teams in meanwhile)
     $sponsors = SponsorsDataService::getSponsorOffers($this->_websoccer, $this->_db, $teamId);
     $found = FALSE;
     foreach ($sponsors as $availableSponsor) {
         if ($availableSponsor["sponsor_id"] == $parameters["id"]) {
             $found = TRUE;
             break;
         }
     }
     if (!$found) {
         throw new Exception($this->_i18n->getMessage("sponsor_choose_novalidsponsor"));
     }
     // update team
     $columns["sponsor_id"] = $parameters["id"];
     $columns["sponsor_spiele"] = $this->_websoccer->getConfig("sponsor_matches");
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_verein";
     $whereCondition = "id = %d";
     $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $teamId);
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("sponsor_choose_success"), ""));
     return null;
 }