Ejemplo n.º 1
0
 /**
  * get
  *
  * @param int $pk
  *
  * @return  \Windwalker\Data\Data
  */
 public static function get($pk = null)
 {
     if (!$pk) {
         return User::get();
     }
     $cache = CacheFactory::getCache('user');
     $key = 'user.' . $pk;
     if ($cache->exists($key)) {
         return $cache->get($key);
     }
     $user = User::get($pk);
     $cache->set($key, $user);
     return $user;
 }
Ejemplo n.º 2
0
 /**
  * get
  *
  * @param int $id
  *
  * @return  mixed|Data
  */
 public static function getPostAuthor($id)
 {
     $cache = CacheFactory::getCache('authors');
     if ($cache->exists('author.' . $id)) {
         return $cache->get('author.' . $id);
     }
     $author = (new DataMapper('authors'))->findOne($id);
     if ($author->user) {
         $user = User::get($author->user);
         $author->name = $user->fullname;
         $author->description = $user->description;
         $author->image = $user->image;
         $author->website = $user->website;
         $author->image = $author->image ?: UserHelper::getGavatar($user->email, 200);
     }
     $cache->set('author.' . $id, $author);
     $cache->set('author.' . $author->user . '.' . $author->blog, $author);
     return $author;
 }