XF 2.1 Querying parent moderators & node IDs

Luehrsen

Member
Hey,

I am trying to display the moderators of my forums at the moment. So far so straightforward, the data is all available in the $node.Moderators relationship.

But not really. Only the specifically assigned moderators for that node show up in that relationship, where content_id === node_id. What does not show up are moderators, where permissions are inherited from a parent node. Category moderators for example.

So right now I'm trying to find a not too expensive way to query all parent IDs from a node and then query XF:ModeratorContent with those.

So the question is: How would you query all parents of a specific node? Or is that even necessary? Is there a more straightforward way to the information I am trying to query?
 
To answer my own question: This is how I do it at the moment. The burden on the database seems reasonable.

PHP:
<?php

namespace GWFW\ModHelper\XF\Entity;

class Node extends XFCP_Node {
    public function getParentNodeIDs( $node = null, $parent_ids = array() ) {
        if( $node === null ) {
            $node = $this;
        }

        if( $node->parent_node_id !== 0 ) {
            // The current node has a parent, load the parent and get it's parent_id
            $parent_ids = $this->getParentNodeIDs( $node->Parent, $parent_ids );
        }

        return array_merge( array( $node->parent_node_id ), $parent_ids );
    }
}

PHP:
<?php

namespace GWFW\ModHelper\XF\Repository;

class Moderator extends XFCP_Moderator
{
    public function findContentModeratorsForListByNodesArray( array $nodeArray ) {

        $contentModerator = $this->finder('XF:ModeratorContent')
            ->with(['User', 'Moderator'])
            ->order(['User.username'])
            ->where([
                    'content_id' => $nodeArray,
            ]);

        return $contentModerator;
    }
}

Reviewing the code now, the name for the $nodeArray variable is probably not good. That array contains node_ids, not nodes.
 
Back
Top Bottom