1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Adding "Forum Moderators" to forum_view...

Discussion in 'Development Tutorials [Archive]' started by Jaxel, Jun 14, 2011.

  1. Jaxel

    Jaxel Well-Known Member

    If you have a forum, with a lot of moderators, chances are moderators are designated to individual forums. Unfortunately, right now XenForo has no way to show the moderators for a specific forum, on that forum... So I have done it using hooks on my forum...

    I do all customization on my forum to a product called "EWRcustom", its basically an Add-On that I don't release to the public, which contains all my custom settings and changes. This add-on has things like my sub forum grid listing, advert placements, thread sticky separations, user ribbons, etc. There are many hooks, custom models, listeners etc in this custom add-on of mine, but I will not be releasing the most of them to the public.

    Today I just added "forum moderators" to this product and now I will show you how...

    Below is my listener class: (I have removed other modifications from this class for this tutorial)
    class EWRcustom_Listener_Template
        public static function template_create($templateName, array &$params, XenForo_Template_Abstract $template)
            switch ($templateName)
                case 'forum_view':
        public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
            switch ($hookName)
                case 'forum_view_pagenav_before':
                    $modModel = XenForo_Model::create('XenForo_Model_Moderator');
                    $conditions = array('content' => array('node', $hookParams['forum']['node_id']));
                    $hookParams['moderators'] = $modModel->getContentModerators($conditions);
                    $hookParams['modCount'] = count($hookParams['moderators']);
                    $contents .= $template->create('EWRcustom_forum_view_pagenav_before', $hookParams);
    This is pretty simple... first it precaches a custom template called "EWRcustom_forum_view_pagenav_before". Then it looks for the hook 'forum_view_pagenav_before' which is inside the master template "forum_view". When it finds that template, it instantiates that moderator model, sends the node_id as a condition and fetches all the mdoerators for that forum. Then it builds the custom template and appends it to the hook.

    Next I create that custom template "EWRcustom_forum_view_pagenav_before".
    <xen:if is="{$modCount}">
        <style type="text/css">.pageContent { position: relative; }</style>
        <div class="sectionMain" style="position: absolute; top: 45px; right: 20px;">
            <b>{xen:phrase moderators}:</b>
            <xen:foreach loop="$moderators" value="$moderator" i="$i">
                <a href="{xen:link members, $moderator}" class="username">{$moderator.username}</a><xen:if is="{$i} < {$modCount}">,</xen:if>
    Then, simply create the two code event listeners in your AdminCP (I will not write a tutorial on how to do this as there are already several on this forum) and your moderators will be listed!

    Example: http://www.8wayrun.com/forums/new-player-arena.92/
  2. ragtek

    ragtek Guest

    $modModel = new XenForo_Model_Moderator;

    why, why why, do you use new and not XenForo_Model::create ?

    It's the same with your other add-ons, sometimes you use the create method and sometimes new so it's not possible to use the xenforo proxy classes to override / extend the add-ons
    James and Forsaken like this.
  3. Jaxel

    Jaxel Well-Known Member

    Because I didn't know there was a difference... I've said many times that Object Orientation is new to me (I'm primarily a procedural programmer), and nobody told me I was doing anything wrong... Also, it looks like in the past there WASN'T a difference, the difference was added in one of the betas.

    Thanks for your advice... I will look into fixing my other mods.

Share This Page