/** * @see AbstractJob::execute() */ function execute() { // only consider highscore users since we assume that they are actually playing and not waiting for a team assignment or something. $users = UsersDataService::getActiveUsersWithHighscore($this->_websoccer, $this->_db, 0, 1000); foreach ($users as $user) { UserInactivityDataService::computeUserInactivity($this->_websoccer, $this->_db, $user['id']); } }
public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // check if it is own player $player = PlayersDataService::getPlayerById($this->_websoccer, $this->_db, $parameters["id"]); if ($clubId != $player["team_id"]) { throw new Exception("nice try"); } // if player is not happy at club, he does not want to extend at all $satisfaction = $player["player_strength_satisfaction"]; if ($satisfaction < MINIMUM_SATISFACTION_FOR_EXTENSION) { throw new Exception($this->_i18n->getMessage("extend-contract_player_is_unhappy")); } // check if player is already on market if ($player["player_transfermarket"]) { throw new Exception($this->_i18n->getMessage("sell_player_already_on_list")); } // no salary decrease if ($parameters["salary"] < $player["player_contract_salary"]) { throw new Exception($this->_i18n->getMessage("extend-contract_lower_than_current_salary")); } $averageSalary = $this->getAverageSalary($player["player_strength"]); // if salary is already higher than average, then just expect 10% more if ($player["player_contract_salary"] > $averageSalary) { $salaryFactor = 1.1; } else { // make minimum salary dependent on happiness $salaryFactor = (200 - $satisfaction) / 100; } $salaryFactor = max(1.1, $salaryFactor); $minSalary = round($player["player_contract_salary"] * $salaryFactor); // the salary should be at least 90% of the average, except if this would douple the salary if ($averageSalary < $parameters["salary"] * 2) { $minSalaryOfAverage = round(0.9 * $averageSalary); $minSalary = max($minSalary, $minSalaryOfAverage); } if ($parameters["salary"] < $minSalary) { // decrease satisfaction $this->decreaseSatisfaction($player["player_id"], $player["player_strength_satisfaction"]); throw new Exception($this->_i18n->getMessage("extend-contract_salary_too_low")); } // check if club can pay this salary TeamsDataService::validateWhetherTeamHasEnoughBudgetForSalaryBid($this->_websoccer, $this->_db, $this->_i18n, $clubId, $parameters["salary"]); // check goal bonus $minGoalBonus = $player["player_contract_goalbonus"] * 1.3; if ($parameters["goal_bonus"] < $minGoalBonus) { throw new Exception($this->_i18n->getMessage("extend-contract_goalbonus_too_low")); } $this->updatePlayer($player["player_id"], $player["player_strength_satisfaction"], $parameters["salary"], $parameters["goal_bonus"], $parameters["matches"]); // reset inactivity UserInactivityDataService::resetContractExtensionField($this->_websoccer, $this->_db, $user->id); // success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("extend-contract_success"), "")); return null; }
public static function movePlayersWithoutTeamToTransfermarket(WebSoccer $websoccer, DbConnection $db) { $columns['unsellable'] = 0; $columns['lending_fee'] = 0; $columns['lending_owner_id'] = 0; $columns['lending_matches'] = 0; $fromTable = $websoccer->getConfig('db_prefix') . '_spieler'; // select players: // 1) any player who has no contract any more and are not on the market yet // 2) any player who has no contract any more, but still on the team list // 3) any player who had been added to the list before his contract ended. $whereCondition = 'status = 1 AND (transfermarkt != \'1\' AND (verein_id = 0 OR verein_id IS NULL) OR transfermarkt != \'1\' AND verein_id > 0 AND vertrag_spiele < 1 OR transfermarkt = \'1\' AND verein_id > 0 AND vertrag_spiele < 1)'; // update each player, since we might also update user's inactivity $result = $db->querySelect('id, verein_id', $fromTable, $whereCondition); while ($player = $result->fetch_array()) { $team = TeamsDataService::getTeamSummaryById($websoccer, $db, $player['verein_id']); if ($team == NULL || $team['user_id']) { if ($team['user_id']) { UserInactivityDataService::increaseContractExtensionField($websoccer, $db, $team['user_id']); } $columns['transfermarkt'] = '1'; $columns['transfer_start'] = $websoccer->getNowAsTimestamp(); $columns['transfer_ende'] = $columns['transfer_start'] + 24 * 3600 * $websoccer->getConfig('transfermarket_duration_days'); $columns['transfer_mindestgebot'] = 0; $columns['verein_id'] = ''; // do not move player out of team if team has no manager // (prevents shrinking of teams) } else { $columns['transfermarkt'] = '0'; $columns['transfer_start'] = '0'; $columns['transfer_ende'] = '0'; $columns['vertrag_spiele'] = '5'; $columns['verein_id'] = $player['verein_id']; } $db->queryUpdate($columns, $fromTable, 'id = %d', $player['id']); } $result->free(); }