public function validateStudent(Student $student) { $errors = []; $errors['firstName'] = $this->validateName($student->getFirstName()); $errors['lastName'] = $this->validateName($student->getLastName()); $errors['gender'] = $this->validateGender($student->getGender()); $errors['group'] = $this->validateGroup($student->getGroup()); $errors['email'] = $this->confirmEmail($student->getEmail(), $student->getToken()); $errors['birthYear'] = $this->validateBirthYear($student->getBirthYear()); $errors['status'] = $this->validateStatus($student->getStatus()); $errors['rating'] = $this->validateRating($student->getRating()); return array_filter($errors, [$this, 'filterErrors']); }
/** * Updates given Student entity in the database. * * @param Student $student Student entity to update. */ public function updateStudent(Student $student) { $query = $this->pdo->prepare("UPDATE students SET name = :name_bind, surname = :surname_bind, " . "gender = :gender_bind, sgroup = :sgroup_bind, email = :email_bind, byear = :byear_bind, status = :status_bind, " . "rating = :rating_bind WHERE token = :token_bind"); $query->bindValue(':token_bind', $student->getToken(), \PDO::PARAM_STR); $query->bindValue(':name_bind', $student->getFirstName(), \PDO::PARAM_STR); $query->bindValue(':surname_bind', $student->getLastName(), \PDO::PARAM_STR); $query->bindValue(':gender_bind', $student->getGender(), \PDO::PARAM_STR); $query->bindValue(':sgroup_bind', $student->getGroup(), \PDO::PARAM_STR); $query->bindValue(':email_bind', $student->getEmail(), \PDO::PARAM_STR); $query->bindValue(':byear_bind', $student->getBirthYear(), \PDO::PARAM_INT); $query->bindValue(':status_bind', $student->getStatus(), \PDO::PARAM_STR); $query->bindValue(':rating_bind', $student->getRating(), \PDO::PARAM_INT); $query->execute(); }
/** * Authorizes given Student entity. * * This method authorizes user using cookies. In details, it adds an * authorization cookie to the given response instance. Authorization * cookie contains an authorization token, which is unique for every student * entity. * * This method throws an InvalidArgumentException if given student entity does * not have an authorization token. You can use createAuthToken() method to generate * an auth token for a student entity. * * @param Student $student Student to authorize * @param ResponseInterface $response Response instance for authorization cookie. * * @throws \InvalidArgumentException If given Student instance does not have an * authorization token. * * @return \Psr\Http\Message\ResponseInterface Response instance with authorization cookie. */ public function authorizeUser(Student $student, ResponseInterface $response) { if (empty($student->getToken())) { throw new \InvalidArgumentException('Student must have an authorization' . ' token in order to complete authorization.'); } $dateTime = new \DateTime("now"); $dateTime->add(new \DateInterval("P90D")); return FigResponseCookies::set($response, SetCookie::create('authorization')->withValue($student->getToken())->withExpires($dateTime->format(\DateTime::COOKIE))->withPath('/')); }