/**
  * Retrieve pending appointments for current terms for given tutorId.
  * Pending appointments start time will be at least 30 minutes away from it's starting time
  * @param $tutorId
  * @return array
  * @throws Exception
  */
 public static function retrievePendingForCurrentTerms($tutorId)
 {
     $query = "SELECT `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_ID . "` , `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_START_TIME . "` , `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_END_TIME . "`,\n\t\t\t`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TERM_ID . "`,\n\t\t\t`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_COURSE_ID . "`, `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TUTOR_USER_ID . "`,  `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TUTOR_USER_ID . "`,\n\t\t\t`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_MESSAGE . "`\n\t\t\tFROM `" . App::getDbName() . "`.`" . self::DB_TABLE . "`\n\t\t\tLEFT JOIN  `" . App::getDbName() . "`.`" . TermFetcher::DB_TABLE . "`\n\t\t\tON `" . App::getDbName() . "`.`" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TERM_ID . "`=`" . TermFetcher::DB_TABLE . "`.`" . TermFetcher::DB_COLUMN_ID . "`\n\t\t\tWHERE `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_TUTOR_USER_ID . "` = :tutor_id\n\t\t\tAND `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_LABEL_MESSAGE . "` ='" . Appointment::LABEL_MESSAGE_PENDING . "'\n\t\t\tAND :now BETWEEN `" . TermFetcher::DB_COLUMN_START_DATE . "` AND `" . TermFetcher::DB_COLUMN_END_DATE . "`\n\t\t\tORDER BY `" . self::DB_TABLE . "`.`" . self::DB_COLUMN_START_TIME . "` DESC";
     try {
         $now = App::getCurrentTime();
         $dbConnection = DatabaseManager::getConnection();
         $query = $dbConnection->prepare($query);
         $query->bindParam(':now', $now, PDO::PARAM_STR);
         $query->bindParam(':tutor_id', $tutorId, PDO::PARAM_INT);
         $query->execute();
         return $query->fetchAll(PDO::FETCH_ASSOC);
     } catch (PDOException $e) {
         App::storeError($e->getMessage());
         throw new Exception("Could not retrieve data from database.");
     }
 }
Exemple #2
0
 /**
  * Write the contents to the file, using the FILE_APPEND flag to append the content to the end of the file
  * and the LOCK_EX flag to prevent anyone else writing to the file at the same time
  * @param $messsage
  * @internal param $e
  */
 public static function storeError($messsage)
 {
     $file = ROOT_PATH . '../../app_errors.log';
     $messsage = App::getCurrentTime() . $messsage;
     file_put_contents($file, $messsage, FILE_APPEND | LOCK_EX);
 }