How would you link it?
I want to add to existing array of mentioned extension listener. (at least that makes the most sense to me, but I am open to other suggestions) Here is the array from ext listiner:
Code: Select all
//Last active topics
$sql = 'SELECT forum_id, topic_id, topic_title, topic_time, topic_views, topic_poster, topic_posts_approved, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time, topic_last_view_time, topic_last_poster_id
FROM ' . TOPICS_TABLE . '
WHERE ' . $this->db->sql_in_set('forum_id', $flast) . '
AND ' . $this->content_visibility->get_visibility_sql('topic', 'topic') . '
ORDER BY topic_last_post_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['last_total']);
while ($row = $this->db->sql_fetchrow($result))
{
$this->template->assign_block_vars('last_topic', array(
'LAST_LINK' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'U_LAST_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']),
'LAST_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']),
'USERNAME_LAST' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']),
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_REPLIES' => $row['topic_posts_approved'],
'TOPIC_LAST_POSTER_NAME' => $row['topic_last_poster_name'],
'TOPIC_LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'],
'TOPIC_LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']),
'TOPIC_LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']),
));
}
$this->db->sql_freeresult($result);
Code: Select all
'U_AVATAR => $this->user_loader->get_avatar($row['topic_last_poster_id']),
Code: Select all
$user_helper = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
Code: Select all
'U_AVATAR => $user_loader->get_avatar($row['topic_last_poster_id']),
unset($user_loader);
after freeresult.Wow, this makes so much more sense. I was already researching maybe using JOIN tables option ;DGanstaZ wrote: ↑Sat Oct 13, 2018 4:00 pm You can inject user_helper class to service .yml file and constructor and just add this line to template_assign_blocks:Or add before/after $sqlCode: Select all
'U_AVATAR => $this->user_loader->get_avatar($row['topic_last_poster_id']),
to template_assign_blocks:Code: Select all
$user_helper = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
AndCode: Select all
'U_AVATAR => $user_loader->get_avatar($row['topic_last_poster_id']),
unset($user_loader);
after freeresult.
Code: Select all
$user_helper = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
Code: Select all
$user_loader = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
Code: Select all
// $array of user ids
$user_loader->load_users($array);
Code: Select all
'U_AVATAR' => $this->user_loader->get_avatar($row['topic_last_poster_id'], true, false),
$user_loader->load_users($array);
?Code: Select all
//Last active topics JOIN ' . USERS_TABLE . ' ON user_id = topic_last_poster_id
$user_loader = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
$user_loader->load_users($array);
$sql = 'SELECT forum_id, topic_id, topic_title, topic_time, topic_views, topic_poster, topic_posts_approved, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time, topic_last_view_time, topic_last_poster_id
FROM ' . TOPICS_TABLE . '
WHERE ' . $this->db->sql_in_set('forum_id', $flast) . '
AND ' . $this->content_visibility->get_visibility_sql('topic', 'topic') . '
ORDER BY topic_last_post_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['last_total']);
while ($row = $this->db->sql_fetchrow($result))
{
$this->template->assign_block_vars('last_topic', array(
'LAST_LINK' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'U_LAST_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']),
'LAST_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']),
'USERNAME_LAST' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']),
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_REPLIES' => $row['topic_posts_approved'],
'TOPIC_LAST_POSTER_NAME' => $row['topic_last_poster_name'],
'TOPIC_LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'],
'TOPIC_LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']),
'TOPIC_LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']),
'USERNAME_AV' => $this->user_loader->get_avatar($row['topic_last_poster_id'], true, false),
));
}
$this->db->sql_freeresult($result);
unset($user_loader);
Code: Select all
$user_loader = new \phpbb\user_loader($this->db, $this->phpbb_root_path, $this->phpEx, USERS_TABLE);
$sql = 'SELECT forum_id, topic_id, topic_title, topic_time, topic_views, topic_poster, topic_posts_approved, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time, topic_last_view_time, topic_last_poster_id
FROM ' . TOPICS_TABLE . '
WHERE ' . $this->db->sql_in_set('forum_id', $flast) . '
AND ' . $this->content_visibility->get_visibility_sql('topic', 'topic') . '
ORDER BY topic_last_post_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['last_total']);
$array = [];
$user_loader->load_users($array);
while ($row = $this->db->sql_fetchrow($result))
{
$array[] = $row['topic_last_poster_id'];
$this->template->assign_block_vars('last_topic', array(
'LAST_LINK' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'U_LAST_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']),
'LAST_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']),
'USERNAME_LAST' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']),
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_REPLIES' => $row['topic_posts_approved'],
'TOPIC_LAST_POSTER_NAME' => $row['topic_last_poster_name'],
'TOPIC_LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'],
'TOPIC_LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']),
'TOPIC_LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']),
'USERNAME_AV' => $user_loader->get_avatar($row['topic_last_poster_id']),
));
}
$this->db->sql_freeresult($result);
unset($user_loader);
Code: Select all
//Last active topics
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_time, t.topic_views, t.topic_poster, t.topic_posts_approved, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time, t.topic_last_view_time, t.topic_last_poster_id, u.user_id, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height
FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
WHERE u.user_id = t.topic_last_poster_id
AND ' . $this->db->sql_in_set('forum_id', $flast) . '
AND ' . $this->content_visibility->get_visibility_sql('topic', 'topic') . '
ORDER BY t.topic_last_post_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['last_total']);
while ($row = $this->db->sql_fetchrow($result))
{
/* Map arguments for phpbb_get_avatar() */
$row_avatar = array(
'avatar' => $row['user_avatar'],
'avatar_type' => $row['user_avatar_type'],
'avatar_height' => 20,
'avatar_width' => 20,
);
$topic_last_poster_av = (!empty($row['user_avatar'])) ? phpbb_get_avatar($row_avatar, '') : '';
$this->template->assign_block_vars('last_topic', array(
'LAST_LINK' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'U_LAST_TOPIC' => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']),
'LAST_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']),
'USERNAME_LAST' => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']),
'TOPIC_TITLE' => $row['topic_title'],
'TOPIC_VIEWS' => $row['topic_views'],
'TOPIC_REPLIES' => $row['topic_posts_approved'],
'TOPIC_LAST_POSTER_NAME' => $row['topic_last_poster_name'],
'TOPIC_LAST_POSTER_COLOUR' => $row['topic_last_poster_colour'],
'TOPIC_LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']),
'TOPIC_LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']),
'TOPIC_LAST_POSTER_AV' => $topic_last_poster_av,
));
}
$this->db->sql_freeresult($result);
Code: Select all
<img src="{BOARD_URL}ext/galandas/lasttopics/styles/all/theme/images/icon_profile.png" height="20" width="20" title="{last_topic.TOPIC_LAST_POSTER_NAME}" alt="" />
Code: Select all
{% if last_topic.TOPIC_LAST_POSTER_AV is not empty %}{{ last_topic.TOPIC_LAST_POSTER_AV }}{% else %}<img src="{BOARD_URL}ext/galandas/lasttopics/styles/all/theme/images/icon_profile.png" height="20" width="20" title="{last_topic.TOPIC_LAST_POSTER_NAME}" alt="" />{% endif %}