Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
521 views
in Q2A Core by

I would like to display avatar list of other users who are putting me into favorite.

qa_db_user_favorite_users_selectspec() in qa-db-selects.php.

How can I make function qa_db_user_favorited_users_selectspec() / qa_db_user_followup_users_selectspec() ?

Q2A version: 1.5.1

1 Answer

+1 vote
by
edited by

Below code is not taking into consideration error handling and EXTERNAL USER. This code does not guarantee processing under all environment. Avatar needs to set up default picture. Please adjust CSS by yourself. 

 
Sample core code: qa-db-selects.php
 
// Add [start]
function qa_db_user_favorited_users_selectspec($userid) {
require_once QA_INCLUDE_DIR.'qa-app-updates.php';
return array(
'columns' => array('^users.userid', 'handle', 'points', 'flags', '^users.email', 'avatarblobid', 'avatarwidth', 'avatarheight'),
'source' => "^users JOIN ^userpoints ON ^users.userid=^userpoints.userid JOIN ^userfavorites ON ^users.userid=^userfavorites.userid WHERE ^userfavorites.entityid=$ AND ^userfavorites.entitytype=$",
'arguments' => array($userid, QA_ENTITY_USER),
'sortasc' => 'handle',
);
}
// Add [end]
 
 
Sample plugin [definition]: qa-plugin/followed-user-widget/qa-plugin.php
 
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
qa_register_plugin_module('widget', 'qa-followed-user.php', 'qa_followed_user', 'Followed User');
 
 
Sample plugin [process]: qa-plugin/followed-user-widget/qa-followed-user.php
 
class qa_followed_user {
function option_default($option) {
if ($option=='followed_user_count_users') return 8;
if ($option=='followed_user_avatat_size') return 50;
}
function admin_form() {
$saved=false;
if (qa_clicked('followed_user_save_button')) {
qa_opt('followed_user_count_users', (int)qa_post_text('followed_user_count_users_field'));
qa_opt('followed_user_avatat_size', (int)qa_post_text('followed_user_avatat_size_field'));
$saved=true;
}
return array(
'ok' => $saved ? 'Followed User settings saved' : null,
'fields' => array(
array(
'label' => 'Maximum users to show:',
'type' => 'number',
'value' => (int)qa_opt('followed_user_count_users'),
'suffix' => 'users',
'tags' => 'NAME="followed_user_count_users_field"',
),
array(
'label' => 'Avatar size to show:',
'type' => 'number',
'value' => (int)qa_opt('followed_user_avatat_size'),
'suffix' => 'px',
'tags' => 'NAME="followed_user_avatat_size_field"',
),
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'NAME="followed_user_save_button"',
),
),
);
}
function allow_template($template) {
return ($template!='admin');
}
function allow_region($region) {
return ($region=='side');
}
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) {
$userid=qa_get_logged_in_userid();
if (!isset($userid)) return;
$users=qa_db_single_select(qa_db_user_favorited_users_selectspec($userid));
$themeobject->output('<H2>', qa_lang_html('addon/followed_user'), '</H2>');
$themeobject->output('<P class="qa-follow-users-message">', qa_lang_html_sub('addon/followed_user_count', count($users)), '</P>');
$output = null;
if (count($users) >= 1) {
$output = $output.'<UL CLASS="qa-follow-users qa-followed-users-widget">'."\n";
foreach (array_slice($users,0,(int)qa_opt('followed_user_count_users')) as $user){
$output = $output.'<LI>'."\n";
$output = $output.qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], (int)qa_opt('followed_user_avatat_size'), true)."\n";
$output = $output.'<DIV style="width:'.(int)qa_opt('followed_user_avatat_size').'px;overflow:hidden;white-space:nowrap;">'.qa_get_one_user_html($user['handle'], false).'</DIV>'."\n";
$output = $output.'</LI>'."\n";
}
$output = $output.'</UL>'."\n";
$output = $output.'<DIV STYLE="clear:both;"></DIV>'."\n";
}
$themeobject->output($output);
}
};
 
Sample lang [addon]: qa-lang/custom/qa-lang-addon.php
 
return array(
'followed_user' => 'Users followed up',
'followed_user_count' => 'followed up by ^ users.',
);
by
OOOOOOOOOOOOH

GREAT THANKS !!!!

Will work with this during the next hours. I am splitting up the user page into tabs using GET and the missing tab was FOLLOWERS !!!

Thank You very much, that is really great help !!!
by
Hi sama, thanks again it works now!

Showing my progress to the kids they asked me to add a "followers" count to the user profile page, as it seems to be very important criteria how many followers a user has.

Did You implement that as well ? Or do You think this number could be retrieved from Your excellent function ?

Anyway, having the followers list is a huge advantage...
by
edited by
To be sure, I want followers count, too. I added two-line code.

$themeobject->output('<P class="qa-follow-users-message">', qa_lang_html_sub('addon/followed_user_count', count($users)), '</P>');

'followed_user_count' => 'followed up by ^ users.',

+Plus+ : I changed process in case count is 0.
by
Hello sama,

thats great news. Will include it as well,

thank You again

monk333
...