/**
  * Test team for schedule availability
  * Different rules may apply:
  *  1. within each timeslot a team may play one or more times each day
  *  2. if timeslot allows more games each day then a rest period must be allowed between each match
  *  3. if timeslot allows more games each day and penalty for different sites is selected only one site is allowed for these matches
  *  4. No two matches can be played at the same time
  * @param Team $team the team to be verified
  * @param DateTime $slotschedule the schedule to test for availablity
  * @param Playground $playground the planned playground for the scheduled match
  * @param Timeslot $timeslot the planned timeslot for the scheduled match
  * @return bool true if schedule is available for the planned playground and timeslot
  */
 private function isTeamCapacity(Team $team, DateTime $slotschedule, Playground $playground, Timeslot $timeslot)
 {
     $date = Date::getDate($slotschedule);
     $time = Date::getTime($slotschedule);
     $key = $this->makeKey($team, $date, $timeslot);
     if (isset($this->teams[$key])) {
         if (count($this->teams[$key]) < $timeslot->getCapacity() && !isset($this->teams[$key][$time])) {
             /* @var $match MatchPlan */
             foreach ($this->teams[$key] as $match) {
                 /* @var $diff DateInterval */
                 $diff = $match->getSchedule()->diff($slotschedule);
                 if ($diff->h * 60 + $diff->i < $team->getCategory()->getMatchtime() + $timeslot->getRestperiod()) {
                     return false;
                 }
                 if ($timeslot->getPenalty() && $match->getPlayground()->getSite()->getId() != $playground->getSite()->getId()) {
                     return false;
                 }
             }
             return true;
         }
         return false;
     }
     $this->teams[$key] = array();
     return $timeslot->getCapacity() > 0;
 }