コード例 #1
0
 /**
  * @param $userId
  * @return bool
  */
 public function canRead($userId)
 {
     if ($this->canRead !== null) {
         return $this->canRead;
     }
     if (!Loader::includeModule('socialnetwork')) {
         return false;
     }
     $cacheTtl = 2592000;
     $cacheId = 'blog_post_socnet_general_' . $this->entityId . '_' . LANGUAGE_ID;
     $timezoneOffset = \CTimeZone::getOffset();
     if ($timezoneOffset != 0) {
         $cacheId .= "_" . $timezoneOffset;
     }
     $cacheDir = '/blog/socnet_post/gen/' . intval($this->entityId / 100) . '/' . $this->entityId;
     $cache = new \CPHPCache();
     if ($cache->initCache($cacheTtl, $cacheId, $cacheDir)) {
         $post = $cache->getVars();
     } else {
         $cache->startDataCache();
         $queryPost = \CBlogPost::getList(array(), array("ID" => $this->entityId), false, false, array("ID", "BLOG_ID", "PUBLISH_STATUS", "TITLE", "AUTHOR_ID", "ENABLE_COMMENTS", "NUM_COMMENTS", "VIEWS", "CODE", "MICRO", "DETAIL_TEXT", "DATE_PUBLISH", "CATEGORY_ID", "HAS_SOCNET_ALL", "HAS_TAGS", "HAS_IMAGES", "HAS_PROPS", "HAS_COMMENT_IMAGES"));
         $post = $queryPost->fetch();
         $cache->endDataCache($post);
     }
     if (!$post) {
         $this->canRead = false;
         return false;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $this->canRead = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]) >= BLOG_PERMS_READ;
     return $this->canRead;
 }