コード例 #1
0
ファイル: IsUnique.php プロジェクト: Clanify/Clanify
 /**
  * Method to check if the Team satisfies the Specification.
  * @param IEntity $team The Team which will be checked.
  * @return bool The state if the Team satisfies the Specification.
  * @since 1.0.0
  */
 public function isSatisfiedBy(IEntity $team)
 {
     //check if a Team Entity is available.
     if (!$team instanceof Team) {
         return false;
     }
     //find all Team Entities with the same tag and name (unique properties).
     $teams = $this->repository->findUnique($team->tag, $team->name);
     //check if the Team Entity is unique on database.
     if ($team->id === 0 && count($teams) > 0) {
         return false;
     } else {
         //filter all Team Entities with another id.
         $teams = array_filter($teams, function (Team $item) use($team) {
             return $team->id != $item->id;
         });
         //return the state if a Team Entity is available after filter.
         return count($teams) === 0;
     }
 }
コード例 #2
0
ファイル: TeamController.php プロジェクト: Clanify/Clanify
 public function memberAdd()
 {
     $teamID = filter_input(INPUT_POST, 'team_id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
     //check if the team id is available.
     if ($teamID !== false && $teamID !== null && is_numeric($teamID) && $teamID > 0) {
         //get the members which will be assigned.
         $options = ['flags' => FILTER_REQUIRE_ARRAY | FILTER_NULL_ON_FAILURE];
         $members = filter_input(INPUT_POST, 'members', FILTER_DEFAULT, $options);
         //check if a member was found.
         if ($members !== false && count($members) > 0) {
             $teams = TeamRepository::build()->findByID($teamID);
             if (count($teams) === 1) {
                 $users = UserRepository::build()->findByID($members);
                 $teamUserTableMapper = TeamUserTableMapper::build();
                 foreach ($users as $user) {
                     $teamUserTableMapper->create($teams[0], $user);
                 }
                 $this->redirect(URL . 'team/edit/' . $teams[0]->id);
                 return;
             }
         }
     }
     $this->redirect(URL . 'team');
     return;
 }
コード例 #3
0
ファイル: ClanController.php プロジェクト: Clanify/Clanify
 /**
  * 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');
 }