Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+22 votes
11.4k 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
I will test with 950+ questions, 200+ users in copy of production site later today.
by
--First of all i had error at every question, at question list:

Notice: Undefined offset: 2 in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-include/qa-app-format.php(1264) : eval()'d code on line 222

Notice: Undefined offset: 1 in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-app-format.php(1264) : eval()'d code on line 222

Notice: Undefined offset: 0 in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-include/qa-app-format.php(1264) : eval()'d code on line 222

----------------------------------

---Then after checking option "Manually check all for deserved awards" i had like thousands errors at top of page temporary like:

Warning: Invalid argument supplied for foreach() in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 220

Notice: Undefined index: Q in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 197

Notice: Undefined index: Q in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 197

Notice: Undefined index: Q in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 197

Notice: Undefined index: Qvotes in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 220

Warning: Invalid argument supplied for foreach() in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 220

Notice: Undefined index: Qvotes in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 220

Warning: Invalid argument supplied for foreach() in /home/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/qa-plugin/NoahY-q2a-badges-25bf9f8/qa-badge-admin.php on line 220
by
I appreciate that, thank you.  Did id actually add the badges, though?
by
No, they didnt appear in any profile.
by
Ah, I see... when I moved it into the admin, it became part of a class.  award_badge() has to be $this->award_badge()  Fixed now.  I just tested it - delete one badge from the database, run the rebuild, and it adds one badge, as expected.  Please pull and try again.
by
edited by
I'm still getting "0 badges awarded." and bunch of nitice'ses at admin section after rechecking here is all http://pastebin.com/icKUZNGa

But error at questions seems gone. No awards are shown at profiles.

EDIT: Ooops i didnt delete badge.
EDIT: Same problem.
by
Okay, I think the warnings should be gone now... me bad syntax.

Not sure why badges aren't being awarded... you have it activated, I guess?  Try rebuilding the badge list?  And you have the badge vars set at some reasonable level that should get your users badges?
by
Can you try dropping the table qa_userbadges first?
by
Oh my bad, i didn't activate all badges (after rechecking notices are apeared). It works now but for some reason i get 2 fields for badges at every profile.
by
After dropping qa_userbadges and other badges tables  i still get 2 fields for badges at every profile.
by
I'm sorry, what do you mean "2 fields"?
by
2 same of these http://i.imgur.com/oOkA0.png in every profile, before and after "Activity by"
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
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.
...