HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Badges - an add-on...

Login / Search

 [ Join | More ]
 Add topic 
Posted
Item has a rating of 5 (Liked by Jean)  
Rating:
#90927 (In Topic #18342)
Avatar

Community saint

As I mentioned in some other thread of mine, I want something somewhat like 'awards', but a bit different.  I want users to be able to earn and/or be given certain 'awards', based on any number of things.  Could be post count, could be number of 'likes' received, number of years on the site, etc.    I will call them badges… they should display under a users name by each post they make (see examples below.. the 1k are for 1000 posts, the round one is number of years on the site).    Perhaps on their publicly available profile page as well.    

I think I have delayed it via questioning my ability to do it long enough, and it's time to at least start getting some logic behind the idea and start coding.

My first thought was I didn't want to add many extra DB calls for every single post when displaying them, as that might bog things down.    So how do I do that?   Another table in the site DB that holds pointers to user number and badge number's that they 'earn'.  Of course a table for badges as well.    The thing is, do I have it check the conditions each badge has for earning it against the user each time it needs to display badges?  Have the site just update it whenever a user logs on, or have an administration task where you run a routine to do the checks and update the user->badge table?    That could be set up as a cron job as well.   Not sure which path to go down.

But in the event of a badge for # of posts, or # of years on the system, I wonder if each badge needs a field in the table that identifies it as similar to other ones, ie, all # of post badges have a type field that is 'postno' so in the code it is easy to group and pick the highest one for that user.   

I have attached examples from a different site, that uses different software, showing some of what I am calling badges, as an example of what I am going for…

So I guess right now I'm looking for thoughts on this, as I work to sort of lay it all out before I start coding anything.

Paul
Back to the top
 
Posted
Rating:
#90928
Avatar

If you don't want to go with the usergroup hooks thing I mentioned, another idea might be to extend the non-bundled ocGiftGiver addon. It has overlap.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#90929
Avatar

Community saint

I might take some ideas from both, but because I want to show the badges on the users profile and by each post, it seems an actual 'add-on' might not be the right path, as the base code is going to need some modification as well.

I'll look at the giftgiver one and see what it does and how close it comes.

Paul
Back to the top
 
Posted
Rating:
#90941
Avatar

Community saint

Is there any solid documentation for building a complex add-on, that has user side and backend stuff?

I was going through the giftgiver one, and looking at the admin code, and some is a bit confusing as to purpose and what is needed.    I see how it creates the tables and such, but I cant find anything about 'packaging' addon's together…

Also, is there any information about the 'hooks' system and what you can 'hook' into??


Paul
Back to the top
 
Posted
Rating:
#90942
Avatar

Have you read through the Code Book?

Actually packaging an addon is trivial - done through the Admin Zone - but the coding should all be described in the Code Book.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#90943
Avatar

Community saint

Ah, just found the part deep in on this stuff, thanks.

ocPortal Code Book - ocPortal.com

This is gonna take a lot longer than I thought, because it's a heck of a lot to ingest. ;)

Paul
Back to the top
 
Posted
Rating:
#90949
Avatar

Community saint

Arbo said

As I mentioned in some other thread of mine, I want something somewhat like 'awards', but a bit different.  I want users to be able to earn and/or be given certain 'awards', based on any number of things.  Could be post count, could be number of 'likes' received, number of years on the site, etc.    I will call them badges… they should display under a users name by each post they make (see examples below.. the 1k are for 1000 posts, the round one is number of years on the site).    Perhaps on their publicly available profile page as well.    

I think I have delayed it via questioning my ability to do it long enough, and it's time to at least start getting some logic behind the idea and start coding.

My first thought was I didn't want to add many extra DB calls for every single post when displaying them, as that might bog things down.    So how do I do that?   Another table in the site DB that holds pointers to user number and badge number's that they 'earn'.  Of course a table for badges as well.    The thing is, do I have it check the conditions each badge has for earning it against the user each time it needs to display badges?  Have the site just update it whenever a user logs on, or have an administration task where you run a routine to do the checks and update the user->badge table?    That could be set up as a cron job as well.   Not sure which path to go down.

But in the event of a badge for # of posts, or # of years on the system, I wonder if each badge needs a field in the table that identifies it as similar to other ones, ie, all # of post badges have a type field that is 'postno' so in the code it is easy to group and pick the highest one for that user.   

I have attached examples from a different site, that uses different software, showing some of what I am calling badges, as an example of what I am going for…

So I guess right now I'm looking for thoughts on this, as I work to sort of lay it all out before I start coding anything.


This is a wonderful idea, Paul.

I've been actively giving badges to my students through a partly automatic and manual system based on Points Earned, moving up the usergroup ladder and through the non-bundled ocThanks with its own usergroup badges. Usergroup already include the option of showing earned badges on each posts. My badges icons are huge, but they get the student's attention and becomes a source of pride during their learning and long after the courses are over as they also were part of the graduation qualification process. However, I wouldn't mind getting them to the size you are proposing once the classes are over.

Here is an example of a post with earned badges:
Back to the top
 
Posted
Rating:
#90951
Avatar

Community saint

Perhaps I will take a look at that one as well.  Right now I'm struggling with the addon_registry php file, just working on a basic piece for the admin side.

Paul
Back to the top
 
Posted
Rating:
#90952
Avatar

Community saint

Jean,

You sure it's ocThanks?   I looked at that, and it didn't have anything about badges or icons.

Paul
Back to the top
 
Posted
Rating:
#90953
Avatar

Community saint

Chris, I messed around with another addon and modified it to get started.   When I upload the .tar file, it get's an error saying 'this file is not an addon for this software'.    A stack dump:

Code


Critical error - bailing out

This is an error that has been elevated to critical error status because it occurred during the primary error mechanism reporting system itself (possibly due to it occuring within the standard output framework). It may be masking a secondary error that occurred before this, but was never output - if so, it is likely strongly related to this one, thus fixing this will fix the other.
This file is not an addon for the website software (version: 9.0.1, PHP version: 5.2.17, URL: /adminzone/pg/admin_addons/multi_action/index.php?keep_fatalistic=1&install_0=2badges.tar&redirected=1)
Stack trace...

File -> '/home1/paulsfly/public_html/pfm/sources/failure.php'
Line -> 693
Function -> 'die_html_trace'
Args -> array ( 0 => 'This file is not an addon for the website software (version: 9.0.1, PHP version: 5.2.17, URL: /adminzone/pg/admin_addons/multi_action/index.php?keep_fatalistic=1&install_0=2badges.tar&redirected=1)', )
File -> '/home1/paulsfly/public_html/pfm/sources/global2.php'
Line -> 1009
Function -> '_fatal_exit'
Args -> array
File -> '/home1/paulsfly/public_html/pfm/sources/failure.php'
Line -> 240
Function -> 'fatal_exit'
Args -> array
File -> '/home1/paulsfly/public_html/pfm/sources/global2.php'
Line -> 969
Function -> '_generic_exit'
Args -> array
File -> '/home1/paulsfly/public_html/pfm/sources/addons.php'
Line -> 758
Function -> 'warn_exit'
Args -> array
File -> '/home1/paulsfly/public_html/pfm/adminzone/pages/modules/admin_addons.php'
Line -> 328
Function -> 'inform_about_addon_install'
Args -> array ( 0 => '2badges.tar', 1 => array ( ), 2 => array ( 0 => '2badges.tar', ), )
File -> '/home1/paulsfly/public_html/pfm/adminzone/pages/modules/admin_addons.php'
Line -> 125
Function -> 'multi_action'
Class -> 'Module_admin_addons'
Type -> '->'
Object -> Module_admin_addons::__set_state(array( ))
Args -> array ( )
File -> '/home1/paulsfly/public_html/pfm/sources/zones.php'
Line -> 425
Function -> 'run'
Class -> 'Module_admin_addons'
Type -> '->'
Object -> Module_admin_addons::__set_state(array( ))
Args -> array ( )
File -> '/home1/paulsfly/public_html/pfm/sources/site.php'
Line -> 838
Function -> 'load_module_page'
Args -> array ( 0 => 'adminzone/pages/modules/admin_addons.php', 1 => 'admin_addons', )
File -> '/home1/paulsfly/public_html/pfm/sources/site.php'
Line -> 629
Function -> 'request_page'
Args -> array ( 0 => 'admin_addons', 1 => true, )
File -> '/home1/paulsfly/public_html/pfm/adminzone/index.php'
Line -> 39
Function -> 'do_site'
Args -> array ( )

If I manually upload the three files to the right place, it shows up in the addon's configuration page, and you can install and deinstall it.   But no menu option for it shows up from the admin menu….

I'm kinda confused about how this works, since it seems it should be working…   hmm.

Paul
Back to the top
 
Posted
Rating:
#91027
Avatar

Community saint

Arbo said

Jean,

You sure it's ocThanks?   I looked at that, and it didn't have anything about badges or icons.


​You are right Paul, ocThanks has normally nothing to do with badges or icons, but on my site it has everything to do with it. I've created 14 usergroups with badge icons, added  14 reasons to give points to the POINTS_GIVE  template and matched them with the usergroups  in a Hall of Fame page with the ocThanks side_recent_block. The manual part is for me to add the qualifying members to the correct usergroup when they achieve a fixed point goal.  I like the ocThanks addon because it makes it possible for all members to participate in the badge earning process, not just admins. When I know more about PHP and the ocPortal codebook, I will  work on an automatic mod to do that. You are leading the way in sharing your modding process thoughts with all of us. It is a kind of tutorial which I find very useful and thank you for it.:):thumbs:
Back to the top
 
Posted
Rating:
#91031
Avatar

Community saint

Ah, I see what you mean for how yours works.  

And I still have a long way to go on this one, but will keep putting out my progress and thoughts and questions and confusions along the way.

The first thing I need is to figure out the basic 'addon' stuff I mentioned in the post above yours.. for if I can't get a basic thing like that down, no matter how much I code, It will never be an installable addon.


Paul
Back to the top
 
Posted
Rating:
#91039
Avatar

Community saint

Chris, or anyone.   I traced through that stack trace, it appears to exist out at the warn_exit in sources/addons.php … whatever line it says, 75x or something, Looking in that code, it appears to be exiting because it can't find a mod.inf or there is a problem with it.   I have one in the file though.   

I 'tar'ed the file up in the console on my mac, and am guessing it should be compatible.   Any ideas?  Or guidance?

I attached the latest tar file to this post.   The addon won't work, but if I can't get past this step, there's no point in continuing.
Attachment
» Download: badges.tar (222 Kb, 264 downloads so far)

Paul
Back to the top
 
Posted
Rating:
#91041
Avatar

Community saint

Nevermind on the questions about an addon tar.

I had created an badges folder and had everything in it, and was tar'ing the file from outside it.    I re-created it from inside it and for some reason that makes all the difference in the world.

There are still some strange things, like a lot of DS_Store files and copies of files with . on the front of them… but I can work around that for now.

Paul
Back to the top
 
Posted
Rating:
#91043
Avatar

Community saint

Ok, to start, you need a mod.inf file… this is mine:

Code

name=ocBadges
author=Paul Arbogast
organisation=none
version=1
incompatibilities=
dependencies=OCF
description=Allows administrators to add 'badges' to the system that users earn, based on different criteria (# of posts, # of likes, etc.)

Paul
Back to the top
 
Posted
Rating:
#91044
Avatar

Community saint

I need a language file, so have lang_custom/EN/ocbadges.ini:

Code

[strings]
BADGES_TITLE=Badges
DOC_OCGIFTS=Badges - add/edit/delete badges to be earned by users or given by administrators.
MANAGE_BADGES=Manage Badges

For now that's all I need, it will get a lot longer.

Paul
Back to the top
 
Posted
Rating:
#91045
Avatar

Community saint

In order to have a 'manage badges' option in the administration zone, you need a file in sources_custom/hooks/systems/do_next_menus.  This is my ocbadges.php for that spot:

Code

<?php

class Hook_do_next_menus_ocbadges
{

   /**
    * Standard modular run function for do_next_menu hooks. They find links to put on standard navigation menus of the system.
    *
    * @return array         Array of links and where to show
    */
   function run()
   {
      require_lang('ocbadges');
      //if (!addon_installed('ocgifts')) return array();

      return array(
         array('setup','ocbadges',array('admin_ocbadges',array(),get_page_zone('admin_ocbadges')),do_lang_tempcode('MANAGE_BADGES'),('DOC_OCBADGES'))
      );
   }

}

This loads the language file, puts the menu item in the 'setup' menu, tells it that option will run adminzone/admin_ocbadges.php when that menu item is clicked.

Paul
Back to the top
 
Posted
Rating:
#91047
Avatar

Community saint

Now I need the admin side file… so adminzone/pages/modules gets admin_ocbadges.php….

Code (php)

<?php

/**
  * admin_badges.php
  *
 */


require_code('aed_module');

/**
 * Module page class.
 */

class Module_admin_ocbadges extends standard_aed_module
{

This starts out the module.  Since this is going to be a simple add/edit/delete module, OCP has a class for that, the aed_module class.  So you need to do the above to 'extend' that class for your new class.

Paul
Back to the top
 
Posted
Rating:
#91048
Avatar

Community saint

for the admin class, you'll need a function that creates needed tables upon install and removes them upon uninstall of the module:

Code (php)

        function install($upgrade_from=NULL)
        {
                if (is_null($upgrade_from))
                {
                        $GLOBALS['SITE_DB']->create_table('ocp_badges',array(
                                'id'=>'*AUTO',
                                'descrip'=>'SHORT_TEXT',
                                'image'=>'SHORT_TEXT',
                                'earned'=>'BINARY',
                                'earneval'=>'LONG_TEXT',
                                'enabled'=>'BINARY',
                        ));

                        $default_gifts=array();
                        $default_gifts[]=array('descrip'=>'1000 Posts','image'=>'','earned'=>1,'earneval'=>'#posts>1000','enabled'=>1);
                        foreach ($default_gifts as $dg)
                        {
                                $GLOBALS['SITE_DB']->query_insert('ocp_badges',$dg);
                        }

                        $GLOBALS['SITE_DB']->create_table('ocp_badges_members',array(
                                'id'=>'*AUTO',
                                'user_id'=>'USER',
                                'badge_id'=>'AUTO_LINK',

                        ));
                }
    }

Paul
Back to the top
 
Posted
Rating:
#91049
Avatar

Community saint

I reference an image that is used in the hooks - do_next_menus (the file in that folder, mentioned above)…

So i need to include that image in themes/default/images_custom/bigicons




Last edit: by Arbo

Paul
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Expand