Features ¶
- Different database platforms: MySQL, PostgreSQL, SQLite..
- Assign badges to custom user table (default is "user" but it can be changed)
- Using custom layout (default: layouts/main)
- Add your own logic how specific badge is given to user. Your conditions.
- Given default style for badges, but it's 100% customizable
- Create your own view files (it will not be overwritten on next version)
- Cache badges (listed from db)
Requirements ¶
- PHP 5
- tested with Yii 1.1.10
- MySQL, PostgreSQL, SQLite.. (used Yii functions to create tables and insert data)
Installation ¶
Copy contents into protected/modules/badger/ (so it comes as protected/modules/badger/).
OR clone it with mercurial
[sh]
$ cd protected/modules
$ hg clone https://briiC@bitbucket.org/briiC/badger.yii badger
Permissions ¶
Module creates new files so you need to give permissions (only for installing part. After that you can set to default permissions) ~~~ [sh] $ cd protected/modules/ $ sudo chmod -R 0775 badger/ $ sudo chown -R myuser:www-data badger/ ~~~
Configuration ¶
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.
- install - Created tables (two: badge and _user_badge)
- dropBeforeInstall - Tries to drop badger tables before installing
Give badge to user ¶
$Badge = new Badge;
//$Badge->onSuccess = array( $object, 'notifyUser'); // add custom event after giving badge to user
$Badge->checkAndGiveGroup( 'Login' );
Create/Add/Define custom badges ¶
To add new badge into module you have to do 4 steps
1. Insert new badge into database table ¶
[sql]
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',
));
2. Add constant to Badge class ¶
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
//..
3. Write this badge logic into Badge class ¶
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_LOGINFIRST 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.
4. Draw image ¶
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
Resources ¶
- Project page at BitBucket
- There is no public demo, yet. But you can download and try it by your own.
Feedback ¶
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
Doh
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
@Drini, thanks for your feedback
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!
Release v1.0
No beta anymore:
If you are going to upgrade from beta version, please read
"Upgrade (bader BitBucket wiki)"
to know what expect.
Release v1.1
If you are going to upgrade from previous version please read
"Upgrade (bader BitBucket wiki)"
to know what expect.
Release v2.0
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.