Пример #1
0
 public static function createUser($first_name, $last_name, $email, $user_type, $majorId, $coursesIds, $termId)
 {
     self::validateName($first_name);
     self::validateName($last_name);
     self::validateNewEmail($email, self::DB_TABLE);
     self::validateUserType($user_type);
     //$this->validate_teaching_course($teaching_courses);
     try {
         $queryInsertUser = "******" . App::getDbName() . "`.`" . User::DB_TABLE . "` (`" . User::DB_COLUMN_EMAIL . "`,\n\t\t\t`" . User::DB_COLUMN_FIRST_NAME . "`, `" . User::DB_COLUMN_LAST_NAME . "`, `" . User::DB_COLUMN_USER_TYPES_ID . "`)\n\t\t\t\tVALUES(\n\t\t\t\t\t:email,\n\t\t\t\t\t:first_name,\n\t\t\t\t\t:last_name,\n\t\t\t\t\t(SELECT `" . UserTypesFetcher::DB_COLUMN_ID . "` FROM `" . UserTypesFetcher::DB_TABLE . "` WHERE `" . UserTypesFetcher::DB_COLUMN_TYPE . "`=:user_type )\n\t\t\t\t)";
         $dbConnection = DatabaseManager::getConnection();
         $dbConnection->beginTransaction();
         $queryInsertUser = $dbConnection->prepare($queryInsertUser);
         $queryInsertUser->bindParam(':email', $email, PDO::PARAM_STR);
         $queryInsertUser->bindParam(':first_name', $first_name, PDO::PARAM_STR);
         $queryInsertUser->bindParam(':last_name', $last_name, PDO::PARAM_STR);
         $queryInsertUser->bindParam(':user_type', $user_type, PDO::PARAM_STR);
         $queryInsertUser->execute();
         // last inserted if of THIS connection
         $userId = $dbConnection->lastInsertId();
         if (strcmp($user_type, User::TUTOR) === 0) {
             Major::validateId($majorId);
             Tutor::insertMajor($userId, $majorId);
             if ($coursesIds !== NULL) {
                 Tutor_has_course_has_schedule::addCourses($userId, $coursesIds, $termId);
             }
         }
         $dbConnection->commit();
         return $userId;
     } catch (Exception $e) {
         $dbConnection->rollback();
         throw new Exception("Could not insert user into database.");
     }
 }
Пример #2
0
 public static function addCourse($tutorId, $teachingCoursesId, $termId)
 {
     foreach ($teachingCoursesId as $courseId) {
         Course::validateId($courseId);
         if (Tutor::teachesCourseWithIdOnTerm($courseId, $tutorId, $termId)) {
             throw new Exception("Tutor already teaches a course with id {$courseId}");
         }
     }
     Term::validateId($termId);
     Tutor_has_course_has_schedule::addCourses($tutorId, $teachingCoursesId, $termId);
 }