/**
  * Called to join a player to a team
  *
  * When this method is called only set a values for $teamObj and $student OR $teamName and $studentId
  * Only those two combinations can be used:
  * e.g. joinTeam($teamObj=$myTeam, $user=$myUser); or joinTeam($teamName="Team Rocket", $userId=$myUserId);
  *
  * This is used to simulate overloading methods in PHP since this feature is unique to Java.
  *
  * @param Entity\TeamImpl $teamObj The team the player is joining
  * @param String $teamName The string name of the team to join
  * @param Entity\StudentImpl $studentObj The Student persistence object of the user joining the team
  * @param int $studentId The MySQL id of the student joining the team
  * @throws RDException if any parameter is null or if the max number of team members has been reached
  * @return int ID of the team joined
  */
 public function joinTeam($teamObj = null, $teamName = null, $studentObj = null, $studentId = -1)
 {
     if ($teamName != null) {
         //create iter to find team with given team name
         $modelTeam = new Entity\TeamImpl();
         $modelTeam->setName($teamName);
         $teamIter = $this->objectLayer->findTeam($modelTeam);
         $teamObj = $teamIter->current();
     }
     if ($studentId > -1) {
         //create iter to find student with given id
         $modelStudent = new Entity\StudentImpl();
         $modelStudent->setId($studentId);
         $studentIter = $this->objectLayer->findStudent($modelStudent);
         $studentObj = $studentIter->current();
     }
     //check for maximum number of players in the team
     $teamMemberIter = $this->objectLayer->restoreStudentMemberOfTeam($teamObj);
     $leagueIter = $this->objectLayer->restoreTeamParticipatesInLeague($teamObj);
     $league = $leagueIter->current();
     if ($teamMemberIter->size() >= $league->getMaxMembers()) {
         throw new RDException("Maximum number of members has been reached.");
     }
     $this->objectLayer->createStudentMemberOfTeam($studentObj, $teamObj);
 }
Beispiel #2
0
 /**
  * Saves student in database.
  *
  * @param Entity\StudentImpl $student
  * @throws RDException
  */
 public function saveStudent($student)
 {
     //die(var_dump($student));
     if ($student->isPersistent()) {
         //update
         $q = "UPDATE " . DB_NAME . ".user " . "set first_name = ?,\n              last_name = ?,\n              user_name = ?,\n              password = ?,\n              email_address = ?,\n              student_id = ?,\n              address = ?,\n              major = ?\n              WHERE user_id = ?;";
         //create prepared statement from query
         $stmt = $this->dbConnection->prepare($q);
         //bind parameters to prepared statement
         //bind parameters to prepared statement
         $firstName = $student->getFirstName();
         $lastName = $student->getLastName();
         $userName = $student->getUserName();
         $password = $student->getPassword();
         $emailAddress = $student->getEmailAddress();
         $address = $student->getAddress();
         $major = $student->getMajor();
         $studentId = $student->getStudentId();
         $persistenceId = $student->getId();
         $stmt->bindParam(1, $firstName, \PDO::PARAM_STR);
         $stmt->bindParam(2, $lastName, \PDO::PARAM_STR);
         $stmt->bindParam(3, $userName, \PDO::PARAM_STR);
         $stmt->bindParam(4, $password, \PDO::PARAM_STR);
         $stmt->bindParam(5, $emailAddress, \PDO::PARAM_STR);
         $stmt->bindParam(6, $studentId, \PDO::PARAM_STR);
         $stmt->bindParam(7, $address, \PDO::PARAM_STR);
         $stmt->bindParam(8, $major, \PDO::PARAM_STR);
         $stmt->bindParam(9, $persistenceId, \PDO::PARAM_STR);
         if ($stmt->execute()) {
             echo 'student updated successfully';
         } else {
             throw new RDException('Error updating student');
         }
     } else {
         //create Query
         $q = "INSERT INTO team10.user (first_name, last_name, user_name, password, email_address, student_id, address, major, user_type)\n              VALUES(?, ?, ?, ?, ?, ?, ?, ?, 0);";
         //create prepared statement from query
         $stmt = $this->dbConnection->prepare($q);
         //bind parameters to prepared statement
         $firstName = $student->getFirstName();
         $lastName = $student->getLastName();
         $userName = $student->getUserName();
         $password = $student->getPassword();
         $emailAddress = $student->getEmailAddress();
         $address = $student->getAddress();
         $major = $student->getMajor();
         $studentId = $student->getStudentId();
         $stmt->bindParam(1, $firstName, \PDO::PARAM_STR);
         $stmt->bindParam(2, $lastName, \PDO::PARAM_STR);
         $stmt->bindParam(3, $userName, \PDO::PARAM_STR);
         $stmt->bindParam(4, $password, \PDO::PARAM_STR);
         $stmt->bindParam(5, $emailAddress, \PDO::PARAM_STR);
         $stmt->bindParam(6, $studentId, \PDO::PARAM_STR);
         $stmt->bindParam(7, $address, \PDO::PARAM_STR);
         $stmt->bindParam(8, $major, \PDO::PARAM_STR);
         if ($stmt->execute()) {
             $student->setId($this->dbConnection->lastInsertId());
             echo 'student created successfully';
         } else {
             throw new RDException('Error creating or updating Student ' . print_r($stmt->errorInfo()));
         }
     }
 }