Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+22 votes
11.6k views
in Plugins by
edited by
Just wondering whether someone else has already made headway on a badges plugin.  I've created a working prototype with a single badge that creates two databases, one for badge types, one for user-earned badges, checks for whether a badge is warranted on an event, awards the badge, and stores a notify flag, giving a notice when the recipient loads a page.  It also implements a table on the user profile page to show which badges have been earned, and number of each.
by
Badge widget not displaying correctly at two places

Plugin Options:
1- Show badge widget beside points in user meta
(does not show up)
2- Show badge widget beside points in question list
gives an error something like Undefined index:  .......qa-include/qa-app-format.php(1466) : eval()'d code - at user profile in recent activity questions.
Also page for badges is not displaying correctly.

I am using latest version of this plugin with Q2A 1.5.4.

Great great plugin but needs fixes.

Thanks
by
same here in 1.5.4

27 Answers

+1 vote
by
At the moment there is no official plugin for badges. As the Q2A community isn't very big yet, it probabily doesn't exists any. If you want to share yours, don't be afraid. :)
+16 votes
by
Okay, here's the plugin:

https://github.com/NoahY/q2a-badges

It now has 6 badges, a basic admin interface (on/off), and a notification system with jquery closing effects.  Place all of the files in the git repository into qa-plugins/badges and navigate to the site.  

This is definitely alpha code!  Not for production sites, yet.
by
Thanks very much for sharing the plugin.

I'm sorry but I can't get read.rst opened, so can you please tell me how it works? If you installed it on your site, can you give me the url to see some examples.
by
You're welcome... hopefully it will really take off.  The rst file is just a text file.  try "cat README.rst".  If you've put it in the right place, go to the admin-> plugins page to see the badges that are installed.  also, verify that the database tables have been created.  It creates two tables right now, ^badges and ^userbadges (where ^ is the table prefix for q2a).
by
Here's the updated info from the github:

-----------
Translation
-----------
The translation file is qa-lang-badges.php.  Copy this file to the qa-lang/<your-language>/ directory.  Edit the right-hand side strings in this file with notepad++ (don't ever use Window's Notepad. For anything. Ever.), for example, changing:

'good_question'=>'Nice Question',

to

'good_question'=>'Swali nzuri',

for Swahili.  Don't edit the string on the left-hand side or bad things will happen.

Once you've completed the translation, don't forget to set the site language in the admin control panel... to Swahili.
+2 votes
by

Okay, the plugin now has 22 badges, but they are pretty simple ones.  Here's the list:

Nice Question - Question received +2 upvote
Good Question - Question received +3 upvote
Great Question - Question received +5 upvote
Nice Answer - Answer received +2 upvote
Good Answer - Answer received +3 upvote
Great Answer - Answer received +5 upvote
Verified Human - Successfully verified email address
Voter - Voted 10 times
Avid Voter - Voted 25 times
Devoted Voter - Voted 50 times
Asker - Asked 10 questions
Questioner - Asked 25 questions
Inquisitor - Asked 50 questions
Answerer - Posted 10 answers
Lecturer - Posted 25 answers
Preacher - Posted 50 answers
Commenter - Posted 10 comments
Commentator - Posted 25 comments
Annotator - Posted 50 comments
Learner - Accepted answers to 1 questions
Student - Accepted answers to 5 questions
Scholar - Accepted answers to 15 questions

also, there is now a Badges page for visitors to see the badge list and descriptions, and the badges now have types (e.g. gold, silver, bronze), with corresponding css coloring.

by
Can you please tell me where I can find the texts for Badges? I would like to translate them.
by
Great!  They are in the qa-plugin.php file.  Each one is in the following format:

$badges['nice_question'] = array('name'=>'Nice Question','desc'=>'Question received +# upvote', 'var'=>2, 'type'=>0);

I don't quite grock the q2a translation format yet, if someone wants to edit the code to allow it to use the q2a translator, feel free.

Oh, and another thing, I haven't tested all the badges yet, so I don't really know if they work :)  Maybe they just look pretty.  I have tested the nice answer and questions, though... they work.
by
Oops... yep.  It's broken... give me a sec.
+1 vote
by

It would perfect if you can set badges and for what you can get them at admin section.

by
it's a bit complicated for that... it really takes programming code to work out the logistics of a badge, I think.  What you can do is choose the variables, e.g. how many votes before a question/answer is "nice", etc.
+1 vote
by
Okay, I tested out all the badge functions, and they were mostly broken :)  Fixed now.  I am able to trigger all of the 22 badge awarding functions by setting each of the values to 1 in the admin and then carrying out the action.  Try it yourself and let me know.  There is a list of awarded badges in the user profile as well.
by
edited by
Thanks, but after activating plugin i get error: "Notice: Undefined index: var in /home/xxxxxx/xxxxxx/xxxxxx/nezinau.net/public_html/Q2A/qa-plugin/badges/qa-badge-admin.php on line 23

Notice: Undefined index: var in /home/xxxxxx/xxxxxx/xxxxxx/nezinau.net/public_html/Q2A/qa-plugin/badges/qa-badge-admin.php on line 52"

And then in all pages (exept admin page): "Notice: Undefined variable: notice in /home/xxxxxx/xxxxxx/xxxxxx/site.com/public_html/Q2A/qa-include/qa-app-format.php(1264) : eval()'d code on line 128"

However functionality works, and plugin looks really great ! Cant't wait for stable release.
by
Ha :) as long as it works... those errors are because I was asking it whether something existed in the wrong way.  Should be fixed now.  I'm getting some strange warnings as well, but it's working.  Also, I've figured out the translation scheme, and have a translation file made now.
by
Nice, thanks again :) Is it possible to manage (delete, add, rename) badges not necessarily at admin section maybe in future... ?
by
What I was thinking of was allowing a disable checkbox in the admin for each badge.  As for add/delete, I think it's difficult.  Easier to just add/subtract them in the php code... unless someone wants to expand the project beyond my basic intention.
+2 votes
by
Just an update, there is now a translation file, which I assume can be overriden by a language file, but I'm not so sure about that.  The file is qa_lang_badge.php

It is now also possible to disable individual badges and to change the badge names via the admin screen by clicking on the badge's icon.  Descriptions are not editable.

Also, the notification now has a timer, so it fades away automatically after a set (but configurable) time.
+2 votes
by
Okay, I think it's almost there.  Let's call this a pre-beta release.  There are now 40 badges in total, what a fairly simple feature set.  Most of the quirky badges will take some time, but I managed to implement a consecutive days visiting badge, so you can keep people coming back :)

The readme is on the github site, again:

https://github.com/NoahY/q2a-badges

and there is a download available there, either in .tar.gz format:

https://github.com/NoahY/q2a-badges/tarball/master

or .zip format:

https://github.com/NoahY/q2a-badges/zipball/master

let me know what you think - I've already contacted Gideon and once the plugin is considered reasonably stable, it may be added to the site.
+1 vote
by
edited by
Another update:

There is now a button that (hopefully) allows you to retroactively award badges - it basically runs through all checks for all posts and all users to see if anyone should have been awarded a badge.  I imported 176 questions, 400+ answers and 1000+ comments from askbot, and successfully awarded 600+ badges this way to ~100 users.  The button is on the plugins page badges box.

Also, if anyone has this up and running on a production site, maybe they could share a link so people could see how it works?  I've received a demo request and don't have a demo site to share.
by
And there is same information of badges on all user profiles.
by
Maybe you have the plugin installed twice?  Very strange.  I don't get that here.
by
No. Now i'm reinstaled plugin to newest version and after rechecking i get error:
"Fatal error: Call to undefined method DateTime::diff() in /xxx/xxx/xxx/xxx/xxxl/xxx/qa-plugin/NoahY-q2a-badges-283c17e/qa-badge-admin.php on line 287"

By the way i don't know how for you but for me new order of badges is not comfortable
by
edited by
demo from production site: http://www.gute-mathe-fragen.de/badges

However, still using v2.2 of your plugin. Will check your changes now to determine if necessary to update it...

Edit: As far as I see the main change from v2.2 to recent v3.6 is "upgrade lang files to 1.5 way". From checking here: https://github.com/NoahY/q2a-badges/commits/master/
0 votes
by

Database query error 1048

Column 'object_id' cannot be null

INSERT INTO qa_userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) VALUES (NOW(), 1, NULL, 1, _utf8 'old_timer', 0)

 

by
can you update to the latest code and try again?  sorry, it's still under heavy development, but the latest code should fix that error... hopefully :)
0 votes
by

I had this error message:

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

Notice: Undefined variable: userid in /home/olimpiad/public_html/ask/qa-plugin/NoahY-q2a-badges-73edc42/qa-plugin.php on line 328

 


Also after I checked to activate the badge, all posting (but one) disappear from the front page.

by
Yeah, sorry, I broke it last night :) please update to the latest code and confirm that it is working now.
by
I am literally in LOVE with you for making this plugin.
I found a few errors and I know you're still developing it, so;

http://ilysfm.com/user/Lindsay

As you can see if a user has LOADS of badges the alignment (at least in Chrome) gets messed up. Also on the login page there are a few errors listed at the top of the page.
by
Also when viewing other profiles you seem to only see YOUR achievements rather than theirs.
by
Glad it's working, sort of :)  Are you using the latest version of the code?  It's 0.7 right now, and the errors you mention don't seem to crop up any more, except the alignment.  I can't see badges on the page you link to, are they still there?
by
Oh wait, I see.. I broke it again... just a sec :)
by
Yes, I upgraded to 0.7 and alas the errors still remain.
And you can't see the badges because you're not logged in. As mentioned you only seem to be able to see YOUR badges on other people's profiles. So if you're not logged in, you have no badges, so even if you go to a profile WITH badges, you don't see any.

Login page:
Warning: Invalid argument supplied for foreach() in /home/bennyboy/public_html/qa-include/qa-page.php on line 397

Warning: Invalid argument supplied for foreach() in /home/bennyboy/public_html/qa-include/qa-page.php on line 482

Warning: Invalid argument supplied for foreach() in /home/bennyboy/public_html/qa-include/qa-page.php on line 499



Profile page:
Notice: Undefined index: loggedin in /home/bennyboy/public_html/qa-include/qa-app-format.php(1264) : eval()'d code on line 396
by
Gotcha.  Okay, I've fixed that.  It was just a mistake in trying to get the user's handle.  The three warnings on the login page are a persistent problem.  They are only warnings, though, so you can just turn off PHP error showing (which should be off anyway on a production site!).  Just set:

display_errors = Off

in php.ini

and they should not affect the site.  I'll probably fix them soon, anyway.
by
Okay I'll do just that. The only error I see now is the alignment but that shouldn't be a huge problem to fix I hope! Thaks again and keep up the good work!
by
Nice.  Okay, I think I've fixed the alignment problem.  Bizarre, it wasn't happening on other sites, just yours.  Now it should work better hopefully.
by
I upgraded but still the alignment issues. Could it be the sheer amount of badges some people have? For example I have 79 'Nice Comment' badges and upon clicking the 'x79' a huge list of questions fills the page.

I also changed the CSS style to see if that was a problem but no difference.
by
Better to figure this out using private messages...
by
Looks like your last update of qa-badge-layer.php fixed this issue!

Thank you!
+1 vote
by
Two updates, I figured out what was causing the mysterious qa-page.php errors; Gideon told me not to do something and I kept doing it.  Today I took that code out and the errors finally went away. :)

Also, based on this post:

http://www.question2answer.org/qa/8389/chance-update-will-send-emails-users-they-earned-badge-title#a8431

there is now the option to notify users of new badges via email.
0 votes
by
Notice: Use of undefined constant QA_FINAL_EXTERNAL_USERS - assumed 'QA_FINAL_EXTERNAL_USERS' in /home/olimpiad/public_html/ask/qa-include/qa-app-format.php(1227) : eval()'d code on line 610 Fatal error: Call to undefined function qa_get_userids_from_public() in /home/olimpiad/public_html/ask/qa-include/qa-app-format.php(1227) : eval()'d code on line 611
by
It seems, from conversations with Gideon, that QA_FINAL_EXTERNAL_USERS only came into existence in 1.4 (or was it 1.4.1?).  Can you confirm that you are using the latest version of q2a?  If you are, there seems no way you could receive this error, since it is defined in qa-base.php.

I'll update the plugin to specify that it only works with 1.4 and beyond.
...