Copy contents into protected/modules/badger/ (so it comes as protected/modules/badger/).
OR clone it with mercurial
$ cd protected/modules $ hg clone https://briiC@bitbucket.org/briiC/badger.yii badger
Module creates new files so you need to give permissions (only for installing part. After that you can set to default permissions)
$ cd protected/modules/ $ sudo chmod -R 0775 badger/ $ sudo chown -R myuser:www-data badger/
protected/config/main.php
//.. 'import'=>array( //.. // Badger 'application.modules.badger.models.*', //.. ), //.. 'modules'=> array( 'badger' => array( //'layout' => '//layouts/mainx', //default: "//layouts/main" //'userTable' => 'userx', // default: "user" 'cacheSec' => 3600 * 24, // cache duration. default: 3600 // Creates tables and copy necessary files 'install' => true, // remove/comment after succesful install // drop all badger tables before installing (fresh install) 'dropBeforeInstall' => false, ), //.. ), //..
There is two params that better must be removed or commented after you successfully run badge module.
$Badge = new Badge; //$Badge->onSuccess = array( $object, 'notifyUser'); // add custom event after giving badge to user $Badge->checkAndGiveGroup( 'Login' );
To add new badge into module you have to do 4 steps
insert into badge(name,slug,"desc") VALUES('Custom label','custom-slug','custom description of this badge');
OR
$cmd = Yii::app()->db->createCommand(); $cmd->insert('badge',array( 'name' => 'Custom label', 'slug' => 'custom-slug', 'desc' => 'custom description of this badge', ));
Edit modules/badger/models/Badge.php:
class Badge extends BadgeParent { // Sync manualy badge constants with database // Images must be as badge slug: // modules/badge/assets/images/login-first.png # Login const BADGE_LOGIN_FIRST = 'login-first'; # Custom const BADGE_CUSTOM_SLUG = 'custom-slug'; // <--- same as you inserted into "slug" column //..
Keep editing modules/badger/models/Badge.php and find check function. Use previously defined constant BADGE_CUSTOM_SLUG.
//.. public function check( $slug ) { switch( $slug ) { # Login # ---------------------------------------------------------- case self::BADGE_LOGIN_FIRST : # do your specific check to award or not // $canUserHaveBadge = (2 + 2) == 4; // $this->success = $canUserhaveBadge; # or just give him this badge (without checking anything) $this->success = true; break; # Custom # ---------------------------------------------------------- case self::BADGE_CUSTOM_SLUG : // Check if MyModel count is reached 1000 (or more) $this->success = MyModel::model()->my()->count() >= 1000; break; } } //..
As you see in BADGE_LOGIN_FIRST cae, there is set directly as true. It's because you must run badge check only on successful user login and there is no more to check.
Draw your own badge image. You can use template modules/badger/res/badges.svg (no copyrights). But you can draw any image (and size) as you like.
You can find more information on Badger page
Please give feedback about installation/configuration process. Which part is not so easy to understand I will try get it more clear for everybody.
Also send bugs, ideas here or at https://bitbucket.org/briiC/badger.yii/issues/new
Total 4 comments
If you are going to upgrade from previous version please read "Upgrade (bader BitBucket wiki)" to know what expect.
No beta anymore:
If you are going to upgrade from beta version, please read "Upgrade (bader BitBucket wiki)" to know what expect.
oh forgot to change user() function. I got some shortcut functions and most of them i changed. Forgot user() :) I will fix it in holidays and upload upgrade.
thanks again!
I tested this a couple days ago, and wrote a long comment which is must have forgot to submit,lol.
But I had no major problems during installation but there was a bunch of small errors, like user() instead of Yii::app()->user->id. the other errors I cant remember now.
But it seems to work for me:)
site.domain/badger is not suppossed to work,right?:p
Leave a comment
Please login to leave your comment.