Firefox PHP

"Participation" flag in list.php

Posted by Skye N. 
"Participation" flag in list.php
September 24, 2010 01:11AM
My users are requesting an icon similar to the new flag, indicating threads they have posted in, in the list.php page

Doesn't seem to be a module for that, so I guess I'll try writing one.

Any pointers on how to do this efficiently?
I'm guessing that the list of users that have posted in each thread is not something already available in list.php so I'd have to query the db for it in the list hook.

Thanks
Skye

___
Skye Nott
Corvus Digital
Re: "Participation" flag in list.php
September 24, 2010 04:22PM
It is not available in the list data already, you're right about that. Quering for the data is one thing that you can do. That will work. Another route that you could take, could be to use the meta data of the thread starter message to store a list of user_ids for users that have participated in the thread.
Some considerations:
  • When posting messages, you could register the user_id in the meta data. This could be an array in which you store the user_id as the key and TRUE or possibly even the number of posted messages in that thread as the value. That way, you would always have the data available right away from the list script.
  • On non threaded list pages, this meta data can be used to show flags. In threaded mode, the data is not needed, since you already know the user_id for each shown message. It might still be useful though, if you want a flag at the thread starter message in threaded mode too.
  • A maintenance script would be necessary, to update the meta data list for all messages that were already posted.
  • concurrency might be an issue: when two users post about at the same time, then one post might post old data with the user_id added to it, causing the other update to be overwritten.

I hope this gives you some ideas.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: "Participation" flag in list.php
October 03, 2010 04:52AM
That's a great idea, I forgot about the meta data. Thanks for the suggestions!

___
Skye Nott
Corvus Digital
Re: "Participation" flag in list.php
April 20, 2011 10:09AM
Finally getting around to this.....

Seems to work fine, but I'm nervous about pushing this out to my production forum.
Anything look glaringly wrong?

"Storing data for messages" in the dev docs was very helpful, thanks =D

- Skye


title:  Mark My Topics
desc:   Flag topics the viewing user has posted in, so you can mark it in the list template.
author: Skye Nott
url:    [www.F4.ca]
version: 1.0
hook:   list|mod_mark_my_topics_list
hook:   before_post|mod_mark_my_topics_before_post

Language: PHP
<?php # ---------------------------------------------------------------------------- # AUTOSHRINE NETWORK - Phorum 5.2 module - mark_my_topics # (C) 2011 Skye Nott, F4 Systems <skye@F4.ca> # ---------------------------------------------------------------------------- # This module sets MESSAGE->mark_my_topics = 1 if the logged in user has # posted in this thread. Uses message meta data, so only works for posts # made with this module turned on. # # TODO: could query db if meta is empty & update thread # TODO: delete message update meta # ---------------------------------------------------------------------------- define(';MOD_MARK_MY_TOPICS_VERSION';, 1); # meta data format version define(';MOD_MARK_MY_TOPICS_DEBUG';, 0);   # ---------------------------------------------------------------------------- function mod_mark_my_topics_list($rows) { global $PHORUM;   # Only run for authenticated users if (empty($PHORUM["user"]["user_id"])) return $rows; $uid = $PHORUM["user"]["user_id"];   foreach ($rows as $key => $message) { $rows[$key][';mark_my_topics';] = 0; if ($message[';parent_id';] != 0) continue; #print "<pre>{$key} = "; print_r($message["meta"]["mod_mark_my_topics"]); print "</pre>\n"; if (!isset($message["meta"]["mod_mark_my_topics"]["version"]) || $message["meta"]["mod_mark_my_topics"]["version"] != MOD_MARK_MY_TOPICS_VERSION || !isset($message["meta"]["mod_mark_my_topics"]["users"]) || !is_array($message["meta"]["mod_mark_my_topics"]["users"])) { continue; } if (MOD_MARK_MY_TOPICS_DEBUG) { trigger_error("mark_my_topics: list {$key} | " . implode(';,';, array_keys($message["meta"]["mod_mark_my_topics"]["users"]))); } if (in_array($uid, array_keys($message["meta"]["mod_mark_my_topics"]["users"]))) { # FOUND IT $rows[$key][';mark_my_topics';] = 1; } } return $rows; }   # ---------------------------------------------------------------------------- function mod_mark_my_topics_set_meta($meta) { global $PHORUM; $uid = $PHORUM["user"]["user_id"];   if (!isset($meta["mod_mark_my_topics"]["users"]) || !is_array($meta["mod_mark_my_topics"]["users"])) { $meta["mod_mark_my_topics"] = array( "version" => MOD_MARK_MY_TOPICS_VERSION, # Use an associative array to eliminate duplicates "users" => array($uid => 1), ); } $meta["mod_mark_my_topics"]["users"][$uid] = 1;   return $meta; }   # ---------------------------------------------------------------------------- function mod_mark_my_topics_before_post($message) { global $PHORUM; $uid = $PHORUM["user"]["user_id"]; $threadid = $message["thread"];   if (MOD_MARK_MY_TOPICS_DEBUG) trigger_error("mark_my_topics: parent_id={$message[';parent_id';]} thread={$threadid} user_id={$uid}");   if ($message[';parent_id';] == 0) { # NEW TOPIC $message["meta"] = mod_mark_my_topics_set_meta($message["meta"]); if (MOD_MARK_MY_TOPICS_DEBUG) trigger_error("mark_my_topics: new thread | $uid"); } else { # TOPIC REPLY $top_parent = phorum_db_get_message($threadid); $meta = mod_mark_my_topics_set_meta($top_parent[';meta';]); phorum_db_update_message($threadid, array("meta" => $meta)); if (MOD_MARK_MY_TOPICS_DEBUG) { trigger_error("mark_my_topics: update thread {$threadid} | " . implode(';,';, array_keys($meta["mod_mark_my_topics"]["users"]))); } }   return $message; }   # ----------------------------------------------------------------------------

___
Skye Nott
Corvus Digital
Sorry, only registered users may post in this forum.

Click here to login