1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting users permissions/checking if a user can view a forum.

Discussion in 'XenForo Development Discussions' started by Renari, Sep 21, 2012.

  1. Renari

    Renari Member

    I don't see this being done anywhere, I made a page and dumped all the variables available to it however outside of the session data having the user id I've found nothing.
  2. Carlos

    Carlos Well-Known Member

    It can be done, but the permission system is a little confusing to make this a reality.
  3. arcaneex

    arcaneex Active Member

    Well you can use a conditional to check if a user in the usergroup which can view a forum.
    <xen:if is="{xen:helper ismemberof, $visitor, x}">
    Replace X with the User group ID.
  4. Renari

    Renari Member

    Can you do this in PHP?
  5. arcaneex

    arcaneex Active Member

    No idea, sorry.
    EDIT: It may be possible using the database, using the same if condition. But to be honest, not sure how.
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Code example from the forum controller:


    		if ($forumIds)
    			/* @var $forumModel XenForo_Model_Forum */
    			$forumModel = XenForo_Model::create('XenForo_Model_Forum');
    			$visitor = XenForo_Visitor::getInstance();
    			$permissionCombinationId = $visitor['permission_combination_id'];
    			$forums = $forumModel->getForumsByIds($forumIds, array(
    				'permissionCombinationId' => $permissionCombinationId
    			foreach ($forums AS $forum)
    				$visitor->setNodePermissions($forum['node_id'], $forum['node_permission_cache']);
    				if ($forumModel->canViewForum($forum))
    					$forumData[$forum['node_id']] = array(
    						'title' => $forum['title'],
    						'url' => XenForo_Link::buildPublicLink('forums', $forum)
    borbole likes this.

Share This Page