Dzień dobry,
Mam problem, mianowicie nie wiem jak dodać warunek aby został sprawdzany. Mam kod odnośnie meczów piłkarskich, pierwszy kod pozwala na wysłanie zaproszenia na mecz. Drugi kod odpowiada za akceptacje lub odrzucenie zaproszenia. Oba kody działają ale brakuje mi w drugim kodzie sprawdzania czy użytkownik, który nadesłał zaproszenie już rozgrywa mecz tego dnia. Reasumując, chce osiągnąć aby każdy użytkownik mógł zagrać jeden mecz dziennie.
Kod do wysyłania zaproszenia
//verify number of friendlies available
$possibleFS = $this->_websoccer->getConfig("friendlies_per_day");
$ownFS = FriendliesDataService::countFriendlyMatches($this->_websoccer, $this->_db, $teamId, $day, $month, $year);
$ownTmpFS = FriendliesDataService::countTmpFriendlyMatches($this->_websoccer, $this->_db, $teamId);
$opponentFS = FriendliesDataService::countFriendlyMatches($this->_websoccer, $this->_db, $opponentId, $day, $month, $year);
$opponentTmpFS = FriendliesDataService::countTmpFriendlyMatches($this->_websoccer, $this->_db, $opponentId);
$opponentType = FriendliesDataService::checkIfNationalteam($this->_websoccer, $this->_db, $opponent);
$myFS = $ownFS;
$rivalFS = $opponentFS;
if($myFS >= $possibleFS) {
throw new Exception($this->_i18n->getMessage("friendly_schedule_err_own_fs", $this->_websoccer->getConfig("friendlies_per_day")));
}
if($rivalFS >= $possibleFS) {
throw new Exception($this->_i18n->getMessage("friendly_schedule_err_opponent_fs", $this->_websoccer->getConfig("friendlies_per_day")));
}
Kod akceptujący zaproszenia
public function executeAction($parameters) {
// check if feature is enabled
if (!$this->_websoccer->getConfig("friendlies_on_off")) {
return;
}
$user = $this->_websoccer->getUser();
$teamId = $user->getClubId($this->_websoccer, $this->_db);
$myTeam = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $teamId);
$myNationalTeamId = NationalteamsDataService::getNationalTeamManagedByCurrentUser($this->_websoccer, $this->_db);
$myNationalTeam = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $myNationalTeamId);
//get necessary params
$matchId = $parameters["id"];
$action = $parameters["action"];
$matches = array();
//check for selected match
$count = FriendliesDataService::getFriendlyMatchById($this->_websoccer, $this->_db, $matchId, $user);
if ($count) {
$matches = FriendliesDataService::getFriendlyMatchById($this->_websoccer, $this->_db, $matchId, $user);
$matchInfo = call_user_func_array('array_merge', $matches);
//if action is accepting the match
if($action=="accept") {
//insert accepted game in _spiel table
$this->insertIntoMatchTable($matchInfo);
//delete match from temporary table after insertion
$this->deleteFromFriendlyTmpTable($matchId);
// success message
if ($myTeam['team_id'] == $matchInfo['home_id'] || $myNationalTeam['team_id'] == $matchInfo['home_id']) {
$opponentTeam = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $matchInfo['guest_id']);
if($myTeam['team_id'] == $matchInfo['home_id']) {
$team_name = $myTeam['team_name'];
} else {
$team_name = $myNationalTeam['team_name'];
}
$str = $team_name." vs. ".$opponentTeam['team_name'];
} else {
$opponentTeam = TeamsDataService::getTeamById($this->_websoccer, $this->_db, $matchInfo['home_id']);
if($myTeam['team_id'] == $matchInfo['guest_id']) {
$team_name = $myTeam['team_name'];
} else {
$team_name = $myNationalTeam['team_name'];
}
$str = $opponentTeam['team_name']." vs. ".$team_name;
}
Wydaje mi się, że potrzeba warunku w if($action="accept") ale nawet jak dodaje warunek to i tak go omija i akceptuje mecz.
czyli
if($action=="accept") {
if($meczprzeciwnik >= 1){
break;
}
}