Esempio n. 1
0
 /**
  * Method to check if the Clan satisfies the Specification.
  * @param IEntity $clan The Clan which will be checked.
  * @return bool The state if the Clan satisfies the Specification.
  * @since 1.0.0
  */
 public function isSatisfiedBy(IEntity $clan)
 {
     //check if a Clan Entity is available.
     if (!$clan instanceof Clan) {
         return false;
     }
     //find all Clan Entities with the same tag and name (unique properties).
     $clans = $this->repository->findUnique($clan->tag, $clan->name);
     //check whether the Clan Entity is unique on database.
     if ($clan->id === 0 && count($clans) > 0) {
         return false;
     } else {
         //filter all Clan Entities with another id.
         $clans = array_filter($clans, function (Clan $item) use($clan) {
             return $clan->id != $item->id;
         });
         //return the state if a Clan Entity is available after filter.
         return count($clans) === 0;
     }
 }
Esempio n. 2
0
 /**
  * The remove Team action of the Clan.
  * @param int $id The ID of the Clan which Teams are to be removed.
  * @since 0.0.1-dev
  */
 public function teamRemove($id)
 {
     //load the needed Session.
     $this->needSession();
     //check if the ID of the Clan is available.
     if (is_numeric($id) && $id > 0) {
         //get the Teams which are to be removed.
         $options = ['flags' => FILTER_REQUIRE_ARRAY | FILTER_NULL_ON_FAILURE];
         $teams = filter_input(INPUT_POST, 'teams', FILTER_DEFAULT, $options);
         //check if a Team was found.
         if ($teams !== false && count($teams) > 0) {
             $clans = ClanRepository::build()->findByID($id);
             //check if the Clan could be found.
             if (count($clans) === 1) {
                 $clan = $clans[0];
                 //find all Teams which should be assigend with the Clan.
                 $teams = TeamRepository::build()->findByID($teams);
                 //check if Teams are available.
                 if (count($teams) > 0) {
                     $clanTeamTableMapper = ClanTeamTableMapper::build();
                     //run through all Teams to assign with the Clan.
                     foreach ($teams as $team) {
                         $clanTeamTableMapper->delete($clan, $team);
                     }
                 }
                 //redirect to the edit view of the Clan.
                 $this->redirect(URL . 'clan/edit/' . $clan->id);
             }
         }
     }
     //redirect to the overview of the Clan.
     $this->redirect(URL . 'clan');
 }