Exemplo n.º 1
0
 /**
  * Gets a user from their userid.
  * @param string $id The user's id.
  * @return User
  */
 public static function fromId($id)
 {
     // See if there's a cache hit
     $cached = ObjCache::get(OBJCACHE_TYPE_USER, $id);
     if ($cached != null) {
         return $cached;
     }
     // Create the user
     $user = new User();
     $user->row = self::getRowById($id);
     // Add it to the cache
     ObjCache::set(OBJCACHE_TYPE_USER, $user->getUserId(), $user);
     return $user;
 }
Exemplo n.º 2
0
 /**
  * Gets a entry given its unique id.
  * @param int $entryid The entry id.
  * @return Entry
  */
 public static function fromId($entryid)
 {
     // See if theres a cache hit
     $cached = ObjCache::get(OBJCACHE_TYPE_ENTRY, $entryid);
     if ($cached != null) {
         return $cached;
     }
     // Do the database query
     $query = Database::connection()->prepare('SELECT * FROM entry WHERE entryid = ?');
     $query->bindValue(1, $entryid, PDO::PARAM_INT);
     if (!$query->execute() || $query->rowCount() == 0) {
         throw new Exception('Entry does not exist.');
     }
     // Cache it and return
     return self::fromRow($query->fetch());
 }
Exemplo n.º 3
0
 /**
  * Gets a answer given its unique id.
  * @param int $answerid The answer id.
  * @return Answer
  */
 public static function fromId($answerid)
 {
     // See if theres a cache hit
     $cached = ObjCache::get(OBJCACHE_TYPE_ANSWER, $answerid);
     if ($cached != null) {
         return $cached;
     }
     // Do the database query
     $query = Database::connection()->prepare('SELECT * FROM question_answer WHERE answerid = ?');
     $query->bindValue(1, $answerid, PDO::PARAM_INT);
     if (!$query->execute() || $query->rowCount() == 0) {
         throw new Exception('Answer does not exist.');
     }
     return self::fromRow($query->fetch());
 }