Пример #1
0
 /**
  * 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());
     }
 }
Пример #2
0
 /**
  * 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');
     }
 }