Esempio n. 1
0
 /**
  * @param int $sectionId
  * @param int $categoryId
  * @return bool
  */
 public function canRead($sectionId, $categoryId = null)
 {
     if ($this->isSiteAdmin() || $this->isSiteModerator()) {
         return true;
     }
     if ($this->isBanned($sectionId)) {
         return false;
         // can't read if it's banned
     }
     if (isset($this->user2Sections[$sectionId])) {
         $groupId = $this->user2Sections[$sectionId]['group_id'];
         if (is_null($categoryId)) {
             return (bool) $this->user2Sections[$sectionId]['groupRights']['canread'];
         }
     } else {
         if (!isset($this->sections[$sectionId])) {
             $this->sections[$sectionId] = ForumSection::findByPk($sectionId);
         }
         if (!isset($this->sections[$sectionId])) {
             return false;
             // section doesn't exists
         }
         $groupId = $this->sections[$sectionId]->default_visitors_group_id;
     }
     if (is_null($categoryId)) {
         return (bool) ForumUserGroup::findByPk($groupId)->canread;
     }
     $categoryRights = ForumUserGroup::getDb()->table('forum_groups2categories')->where("group_id = :id AND category_id = :cat")->setParams([':id' => $groupId, ':cat' => $categoryId])->first();
     if (!$categoryRights) {
         return (bool) ForumUserGroup::findByPk($groupId)->canread;
     }
     return (bool) $categoryRights['canread'];
 }