Esempio n. 1
0
 /**
  * Gets a user from their database row.
  * @param array $row The user's database row.
  * @return User
  */
 public static function fromRow($row)
 {
     $user = new User();
     $user->row = $row;
     ObjCache::set(OBJCACHE_TYPE_USER, $user->getUserId(), $user);
     return $user;
 }
Esempio n. 2
0
 /**
  * Gets a course given its unique row.
  * @param array $row The database row to use.
  * @return Course
  */
 public static function fromRow($row)
 {
     $course = new Course();
     $course->row = $row;
     ObjCache::set(OBJCACHE_TYPE_COURSE, $course->getCourseId(), $course);
     return $course;
 }
Esempio n. 3
0
 /**
  * Deletes this entry.
  */
 public function delete()
 {
     $query = Database::connection()->prepare('DELETE FROM entry WHERE entryid = ?');
     $query->bindValue(1, $this->getEntryId(), PDO::PARAM_INT);
     $query->execute();
     $this->changed();
     ObjCache::invalidate(OBJCACHE_TYPE_ENTRY, $this->getEntryId());
 }
Esempio n. 4
0
 /**
  * Deletes this answer.
  */
 public function delete()
 {
     // Let's see if this is the first answer
     // if it is, we should delete the question manually
     // even though the database will take care of it anyway
     // because we want to ensure "changed" fires correctly to the users
     $question = Question::fromId($this->getQuestionId());
     if ($question->getFirstAnswerId() == $this->getAnswerId()) {
         // Delete the question and this answer will go away with it
         $question->delete();
     } else {
         // We can just delete this answer and the question wil still exist
         $query = Database::connection()->prepare('DELETE FROM question_answer WHERE answerid = ?');
         $query->bindValue(1, $this->getAnswerId(), PDO::PARAM_INT);
         $query->execute();
         $this->changed();
     }
     // Make sure to invalidate this answer
     ObjCache::invalidate(OBJCACHE_TYPE_ANSWER, $this->getAnswerId());
 }
Esempio n. 5
0
 /**
  * Deletes this attachment from the system.
  * @throws Exception
  */
 public function delete()
 {
     // Delete the image from the database
     $query = Database::connection()->prepare('DELETE FROM attachment WHERE attachmentid = ?');
     $query->bindValue(1, $this->getAttachmentId(), PDO::PARAM_INT);
     if (!$query->execute()) {
         throw new Exception('Unable to delete attachment.');
     }
     // Delete the image from the disk
     $filename = self::getStoragePath($this->getAttachmentId());
     if (file_exists($filename)) {
         unlink($filename);
     }
     // Invalidate the cache version
     ObjCache::invalidate(OBJCACHE_TYPE_ATTACHMENT, $this->getAttachmentId());
 }