I'm not sure if this feature should go with this module in the first place, but as Forum Access can add moderators on a per-forum basis, I figured I give it a shot. At the end of each forum description, I type the name of the moderator(s) that are assigned to that forum, like this:

Forum title
Here goes the description of the forum.
Moderators: jdevries, some_other_user

If I am going to add or remove a user from his moderating position, I need to manually edit this entry in the forum description. Would it be possible to automatically append a list of moderators (for each forum) to the end of the forum description?

Comments

merlinofchaos’s picture

At the moment, it can't be automatic as the module has no way to hook into that; you'll need to theme it.

I can, however, add a function in forum_access to at least make it easier to get the list of moderators for the current forum so that in your theme you can add this information. That's the best I'll be able to do.

jdevries’s picture

Such a function would be a very highly appreciated addition to an already great module. So if you would, please.

robotjox’s picture

hi, could you please give a hint on how to list the moderators? I've been trying to for a long time, but I can't really figure out how to read the acl and forum_access tables... Just a few pointers would be extremely welcome.

thanks!
Morten

robotjox’s picture

here's a function I wrote that does the job for me. I.e. a comma-separated list of moderators with links to each moderator's profile.

function _forum_access_get_moderators($forumid) {
$acl_id = db_result(db_query("SELECT acl_id from {acl} WHERE name = '$forumid'"));
$result = db_query_range("SELECT uid from {acl_user} WHERE acl_id = '$acl_id'", 0, 8);
$items = array();
while ($row = db_fetch_object($result)) {
$account = user_load(array('uid' => $row->uid));
$items[] = l($account->name, "user/" . $account->name);
}
return implode(', ', $items);
}

this is really the first function I wrote, so I dunno if it's complete crap - any feedback/corrections are really welcome.

Morten

merlinofchaos’s picture

You want the destination of l() to be 'user/' . $account->uid -- I assume you have some aliasing so that $account->name works. That's fine, and l() is smart enough to detect those aliases and translate, so you're guaranteed that l() will go to the right place.

robotjox’s picture

yes, of course - thanks for pointing that out.
should we close this topic now or how does this work?

merlinofchaos’s picture

Certainly not; we need to get something like this actually *into* the module as an API so that it can be used, along with suggestions for how to implement it in theming.

denney’s picture

I'm having trouble figuring out how to theme the list of forums to use the function provided by robotjox. Can anyone help point me in the right direction?

I've added the function to my template.php, I just need to know how to add a call to that function for the forums list.

denney’s picture

Nevermind my last comment. Found the book page on modifying the forum list.

jaydub’s picture

Version: 5.x-1.6 » 5.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.14 KB

attached is my patch to the current -dev with my take on a function and theming function to return the list of moderators for a given forum

salvis’s picture

And how would you use forum_access_moderator_list()?

jaydub’s picture

I use it in my forum theme function where the list of forums is drawn. As each forum (or container) is being read from the array of tids and rendered I call forum_access_moderator_list($tid) which if there are moderators will give me a formatted list of moderator usernames as in forums like phpbb.

salvis’s picture

Thank you for the explanation and the patch.

It looks good, but I don't know enough about theming to try it out. Do I have to copy and adapt the theme_forum_list() function? And where do I put it?

Is there no simpler way to get the moderators list onto the screen?

jaydub’s picture

hmmm...it's hard to tell you what you should do if you don't know how Drupal theming (and theme overrides) work.

Do you know how to override a theme function in your theme's template.php?

salvis’s picture

Status: Needs review » Needs work

Right. I've tried it out by patching forum.module.

When used that way, the bold "Moderators" string turns out to be among the heaviest text on the page.

Why do you move the colon outside of t()? Are you sure that it applies universally to all languages? (I know that the French like having a space preceding the colon.)

Hard-coding plural on such an important page as the forum listing indicates a lack of attention to details.

Finally, shouldn't the theme function define classes to enable css theming?

All this brings me to something like this:

    $output  = '<span class="moderator-list-title">'. format_plural(count($moderators_links), 'Moderator:', 'Moderators:') .'</span> ';
    $output .= implode(', ', $moderators_links);
    $output  = '<div class="moderator-list">'. $output .'</div>';
    return $output;
salvis’s picture

What do you think, jaydub?

jaydub’s picture

first off I should mention that I am not the forum_access maintainer. I just posted a suggested patch to implement the feature from this issue...

regarding your point salvis I have to ask a few things...

- why do you think you need to patch forum.module?

There is no need to do that for this issue in fact it doesn't really make any sense since forum.module has no connection to forum_access and a core module should never have any dependency on a contrib module.

All that I provided was a function to return the moderator list as an array and a _default_ theming function for the moderator list. I did not include any code to place this within the context of the forum list output (whether the theming functions in forum.module or your own overrides).

If you want to format the moderator list differently, that is what the concept of theme overrides is all about.

I suggest you collect your ideas on the ideal output and see if the forum_access maintainer can add to his/her next release.

salvis’s picture

first off I should mention that I am not the forum_access maintainer.

I know, I'm the maintainer... and I'm trying to discuss your patch with you...

Since I couldn't get theming to work, I temporarily patched forum.module to see your code in action.

#15 is the result of my review.

jaydub’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

how about this attempt at incorporating your suggestions?

salvis’s picture

Status: Needs review » Needs work

Yes, we're getting close. Does it work for you that way?

I see only one remaining issue:

http://api.drupal.org/api/function/format_plural/5:

Since t() is called by this function, make sure not to pass already-localized strings to it.

Please supply a brief description for the README.txt file — just the information that you'd expect to find there in order to use the moderators list (doesn't need to be in patch format).

Will this also work for Drupal 6, i.e. Forum Access 6.x-1.x-dev?

Thanks!

michelle’s picture

I don't know about the specific forum access code for D6, but the theme function will need to be registered and it would be be better to provide a .tpl file for it.

Once this gets added, I'll add the function call to advforum.

Thanks,

Michelle

salvis’s picture

@Michelle: Seems like we lost jaydub. Do you have experience with theming? Will themers look inside the module code to find what they need to know, or do we need some information in the README.txt?

/**
 * Return a themed list of moderators for a given forum.
 */
function forum_access_moderator_list($tid) {
  $acl_id = db_result(db_query("SELECT acl_id from {acl} WHERE name = '%s'", $tid));
  $result = db_query("SELECT uid from {acl_user} WHERE acl_id = '%s'", $acl_id);
  $moderators = array();
  while ($row = db_fetch_object($result)) {
    $moderators[] = $row->uid;
  }
  return theme('forum_access_moderator_list', $moderators);
}

should work pretty much the same for D6, except for the theming part. Do you know how this .tpl stuff works?

michelle’s picture

Sorry to take so long on this. I've been pretty much ignoring anything forum related for the last week or so and spending what little time I have working on my own site and a client site.

Anyway... I don't know if themers look in the modules... I do, when I'm theming, but I'm a coder so that could be why. :) Would be nice to have themable functions in the readme to make it easier for them.

I'm a little sketchy on the .tpls in D6 and when you do and don't need to register them. I _think_ if you have the .tpl in the theme it picks it up automatically but not sure on the module. It's been a while since I did the D6 port and it's a bit fuzzy. In general, though, this looks like a good way to do it. I could just put a call to forum_access_moderator_list($tid) in advanced forum, then.

Thanks,

Michelle

nunoveloso’s picture

hi!

Drupal 5.x-1.x-dev doesn't work for me. As soon as I go to example.com/forum, there is a white screen.
Anyway, I tried to apply the patch to the stable version and I do not have my moderators names below the title of the forum.

Does this happens with you? I'm a coder and currently studying how to develop modules for Drupal so I could not help with my fresh knowledge on this stuff.

This will be a such important patch because all the common fora have this feature.

greetings!

salvis’s picture

Drupal 5.x-1.x-dev doesn't work for me.

nunoveloso18: Do not hijack issues. Open a new issue, state what you did in chronological order, what works and what doesn't.

Do not reply here!

salvis’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.79 KB

Committed to 5.x-1.x-dev — it can't hurt, but I still don't know how to use it and I wish someone would try whether it actually works.

Here's a stab in the dark at providing a moderator list for Drupal 6. I've looked at some modules and most of them come without .tpl files. Is there a textbook sample module anywhere?

nunoveloso’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Status: Needs review » Needs work

I am sorry, it was my first post over here. I intended to talk about the patch. How is it going?

cheers!

michelle’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Needs work » Needs review

Changing the settings back to how salvis had them.

Salvis - Thanks for this. I haven't had any time to work on advforum lately. I will add support for this as soon as I can.

Michelle

salvis’s picture

Thanks, Michelle :-)

Please let me know whether it works — I'm on thin ice here...

@nunoveloso18: your post #24 doesn't have enough focus to fit into this thread. Try the new 5.x-1.x-dev, and if there's a problem then please open a new issue, state what you did in chronological order, what works and what doesn't. BTW, I installed 5.x-1.x-dev on some production sites and it works fine here.

salvis’s picture

Status: Active » Fixed

I've implemented a forum_access_preprocess_forum_list(&$variables) function for D6. This adds forum_access_maintainers forum_access_moderators (corrected as per #37) to each $forum in the $forums variable, containing an uid-indexed array of user objects. forum-list.tpl.php can then use the user objects to assemble a moderators list.

However, this function can be very expensive on a site with many moderators. It's not used by the default forum theming, and there seems to be no way to tell whether a custom theme will use it or not, so it's turned off by default. You need to...

variable_set('forum_access_provide_moderators_template_variable', TRUE);

... to enable it, and provide suitable theming.

For the benefit of Advanced Forum I've added a forum_access_get_moderator_uids($tid) function to both versions. This returns an array of UIDs for one forum and the caller can do with it whatever it pleases.

This has been committed to both -dev snapshots, give it up to 12 hours to be packaged. Note: You must update to the new -dev snapshots of ACL as well!

Status: Needs review » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

__Sander__’s picture

Hmm... I am trying to theme it into the advanced forum, but it is not working for me.
I have set that variable to true.
But the function keeps returning me empty lists.
I tried both 1.x.5 and the dev version.

I am running
$variables["forums"]=$forums;
forum_access_preprocess_forum_list($variables);
in the beginning

and

$moderator_links=$forum->forum_access_maintainers;
// echo(sizeof($moderator_links));
if (sizeof($moderator_links)>0) {
echo(''. format_plural(count($moderators_links), 'Moderator:', 'Moderators:') .' an> ');
//$output .= implode(', ', $moderators_links);
echo('

'. $output .'

');

echo('

');
}

when a forum is listed

salvis’s picture

Hmm, I thought Advanced Forum was already doing this for you...

michelle’s picture

No, it's going to get rolled into the moderation submodule but that's been postponed so it's in limbo at the moment.

Michelle

__Sander__’s picture

I could provide a theme with this option, but for the moment I am stuck with getting empty lists.
Probably there is something wrong with my syntax.
But there are no warnings, just empty lists!
Don't mind if we reopen this issue?

salvis’s picture

Status: Closed (fixed) » Active

No problem.

As I wrote above, I can't really help because I don't know how this is supposed to work, but reasonable patches are welcome, especially if you can get a second person to test and review.

__Sander__’s picture

I've implemented a forum_access_preprocess_forum_list(&$variables) function for D6. This adds forum_access_maintainers to each $forum in the $forums variable, containing an uid-indexed array of user objects. forum-list.tpl.php can then use the user objects to assemble a moderators list.

In fact, it adds forum_access_moderators!

Now I am ready to make a theme using this trick (when I have time).
What would be the best way to share it?

michelle’s picture

When you folks are finished with this issue here in FA, toss it over to AF version 2.x. No promises I'll get to it any time soon but at least then I won't forget about it.

Michelle

__Sander__’s picture

Moving here: http://drupal.org/node/891978#comment-3759286
It seems to be not an issue of Forum Access anymore.
Just don't forget to say in the API description that you provide $forum->forum_access_moderators, not $forum->forum_access_maintainers after preprocessing

salvis’s picture

I've corrected #30 — thanks!

Please let me know if this error appears in any other places.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.