/** * Create a new Student object, given the set of initial attribute values. * @param firstName the first name * @param lastName the last name * @param userName the user (login) name * @param password the password * @param emailAddress the email address * @param studentId the student identifier * @param major the student's major * @param address the student's address * @return Entity\StudentImpl a new Student object instance with the given attribute values * @throws RDException in case either firstName, lastName, userName, or studentId is null */ public function createStudent($firstName = null, $lastName = null, $userName = null, $password = null, $emailAddress = null, $studentId = null, $major = null, $address = null) { $aStudent = new Entity\StudentImpl(); // if ($firstName != null && $lastName != null && $userName != null && $password != null && // $emailAddress != null && $studentId != null && $major != null && $address != null) { $aStudent->setFirstName($firstName); $aStudent->setLastName($lastName); $aStudent->setUserName($userName); $aStudent->setPassword($password); $aStudent->setEmailAddress($emailAddress); $aStudent->setStudentId($studentId); $aStudent->setMajor($major); $aStudent->setAddress($address); // } return $aStudent; }
/** * 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); }
/** * Restores student in database. * * @param Entity\StudentImpl $modelStudent * @return StudentIteratorc * @throws RDException */ public function restoreStudent($modelStudent) { $q = 'SELECT * from team10.user WHERE user.user_type = 0 '; if ($modelStudent != null) { if ($modelStudent->getFirstName() != NULL) { $q .= ' AND first_name = ' . $this->wrap($modelStudent->getFirstName()); } if ($modelStudent->getLastName() != NULL) { $q .= ' AND last_name = ' . $this->wrap($modelStudent->getLastName()); } if ($modelStudent->getUserName() != NULL) { $q .= ' AND user_name = ' . $this->wrap($modelStudent->getUserName()); } if ($modelStudent->getPassword() != NULL) { $q .= ' AND password = '******' AND email_address = ' . $this->wrap($modelStudent->getEmailAddress()); } if ($modelStudent->getMajor() != NULL) { $q .= ' AND major = ' . $this->wrap($modelStudent->getMajor()); } if ($modelStudent->getAddress() != NULL) { $q .= ' AND address = ' . $this->wrap($modelStudent->getMajor()); } if ($modelStudent->getStudentId() != NULL) { $q .= ' AND student_id = ' . $modelStudent->getStudentId(); } if ($modelStudent->getId() != -1) { $q .= ' AND user_id = ' . $modelStudent->getId(); } } //echo $q; $stmt = $this->dbConnection->prepare($q . ';'); if ($stmt->execute()) { //get results from Query $resultSet = $stmt->fetchAll(\PDO::FETCH_ASSOC); // return iterator return new StudentIterator($resultSet, $this->objLayer); } else { throw new RDException('Error restoring student model'); } }
/** * Stores link between captain and team. * * @param Entity\StudentImpl $student * @param Entity\TeamImpl $team * @throws RDException */ public function storeStudentCaptainOf($student, $team) { $q = 'UPDATE team10.team SET captain_id = ? WHERE team_id = ?;'; $stmt = $this->dbConnection->prepare($q); $studentID = $student->getId(); $teamID = $team->getId(); $stmt->bindParam(1, $studentID, \PDO::PARAM_INT); $stmt->bindParam(2, $teamID, \PDO::PARAM_INT); if ($stmt->execute()) { echo "\n {$student->getFirstName()} {$student->getLastName()} successfully added as team captain of: " . $team->getName(); } else { throw new RDException($student->getUserName() . ' unsuccessfully added as team captain of: ' . $team->getName()); } }
<?php require_once "autoload.php"; use edu\uga\cs\recdawgs\logic\impl\LogicLayerImpl; use edu\uga\cs\recdawgs\entity\impl as Entity; $logicLayer = new LogicLayerImpl(); $userName = trim($_POST['userName']); try { // find admin or student $adminModel = new Entity\AdministratorImpl(); $adminModel->setUserName($userName); $admin = $logicLayer->findAdmin($adminModel, -1)->current(); $studentModel = new Entity\StudentImpl(); $studentModel->setUserName($userName); $student = $logicLayer->findStudent($studentModel, -1)->current(); // reset password $logicLayer->resetPassword($student, $admin); $successMsg = urlencode("Password successfully reset!"); header("Location: ../login.php?status={$successMsg}"); } catch (\edu\uga\cs\recdawgs\RDException $rde) { $error_msg = urlencode($rde->string); header("Location: ../login.php?status={$error_msg}"); } catch (Exception $e) { $errorMsg = urlencode("Unexpected error"); header("Location: ../login.php?status={$errorMsg}"); } exit;