Let's assume that there's some kind of posts' like/dislike mod installed in a phpbb 3.0.x forum. In any existing topic, the posts would look something like this (with a pair of positive/negative buttons per post):
In this example, let's assume that depicted topic contains 3 posts which ids are 13, 14 and 15.
When any user likes (or dislikes) a certain post, that user can click on the respective button, so the author of that post will gain a positive (or negative) point (this part is not interesting for my question).
The mod has this associated table named phpbb_likes:
The table shows what post (post id) in the whole forum have been liked or disliked, what kind of action (like or dislike) was made and who (what username) made the action.
Now, I want to improve this like/dislike mod, adding a new feature (non existing previously). That feature is to show who liked/disliked the posts. Following the example, and according to the table, I need to get something like this:
My code to get this goal is the next:
In viewtopic.php, before the line
// End signature parsing, only if needed
I'm adding:Code: Select all
// My block
$sql= 'SELECT user
FROM phpbb_likes
WHERE action="like"
AND post= '. (int) $post_id;
$result= $db-> sql_query( $sql );
$aMyblock= array();
while( $row2= $db-> sql_fetchrow( $result ) ) {
$aMyblock[]= array( 'TPL_VAR' => $row2['user'] );
}
$db-> sql_freeresult( $result );
$prev_post_id = $row['post_id'];
I'm adding:Code: Select all
foreach( $aMyblock as $aBlock ) {
$template-> assign_block_vars( 'postrow.myblock', $aBlock );
}
<!-- IF postrow.S_POST_UNAPPROVED or postrow.S_POST_REPORTED -->
I'm adding:Code: Select all
<p>Liked by: <!-- BEGIN myblock --> {postrow.myblock.TPL_VAR} <!-- END myblock --></p>
Any suggestion?