Exemple #1
0
 /**
  * Creates a new entry.
  * @param User $creator The creator of the entry.
  * @param type $title The title of the entry.
  * @param type $description The entry description.
  * @return Entry
  * @throws Exception
  */
 public static function create(User $creator, Course $course, $title, $description)
 {
     // Insert it into the database
     $query = Database::connection()->prepare('INSERT INTO entry (courseid, created_at, created_by, display_at, title, description)' . ' VALUES (?, ?, ?, ?, ?, ?)');
     $query->bindValue(1, $course->getCourseId(), PDO::PARAM_INT);
     $query->bindValue(2, time(), PDO::PARAM_INT);
     $query->bindValue(3, $creator->getUserId(), PDO::PARAM_INT);
     $query->bindValue(4, time(), PDO::PARAM_INT);
     $query->bindValue(5, $title, PDO::PARAM_STR);
     $query->bindValue(6, $description, PDO::PARAM_STR);
     if (!$query->execute()) {
         throw new Exception('Entry could not be created in the database.');
     }
     // Get the course from the last insert id
     $entry = self::fromId(Database::connection()->lastInsertId());
     // Sync the course
     $entry->changed();
     // Return the course
     return $entry;
 }
Exemple #2
0
 /**
  * Adds a course to the sync queue.
  * @param Course $course The course to add.
  */
 public static function course(Course $course)
 {
     self::$coursesToSync[$course->getCourseId()] = $course;
 }
 function testFind()
 {
     //arrange
     $course_name = "Chemistry";
     $course_id = 1;
     $course_number = "1000";
     $test_course = new Course($course_name, $course_number, $course_id);
     $test_course->save();
     $course_name2 = "Underwater Basketweaving";
     $course_id2 = 2;
     $course_number2 = "2531";
     $test_course2 = new Course($course_name2, $course_number2, $course_id2);
     $test_course2->save();
     //act
     $result = Course::find($test_course->getCourseId());
     //assert
     $this->assertEquals($test_course, $result);
 }