function jrCore_counter

SteveX
SteveX
@ultrajam
12 years ago
2,589 posts
Looking at the jrCore_counter function in jrCore/lib/misc.php I see that it has $unique as a parameter, but that parameter isn't used within the function.

Is support for counting every view (ie not unique to the ip address) going to be added into the function or should I create my own function to do this?

Thanks

/**
 * Count a hit for a module item with user tracking
 *
 * @param string $module Module to check unique hit for
 * @param string $iid Unique Item ID
 * @param string $name Type of count to store
 * @param int $amount Amount to increment counter by
 * @param bool $unique Check IP Address if true
 * @return bool
 */
function jrCore_counter($module, $iid, $name, $amount = 1, $unique = true){
    // Our steps:
    // - check IP status of hitting user
    // - if user passes IP check, increment daily count
    $iid = intval($iid);
    if (jrCore_counter_is_unique_viewer($module, $iid, $name)) {
        return jrCore_db_increment_key($module, $iid, "{$name}_count", intval($amount));
    }
    return true;
}



--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 12/09/13 04:52:58PM
brian
@brian
12 years ago
10,149 posts
I'll check out that function and see where the $unique comes in to play.

If all you need is a simple counter for each time something happens (regardless of uniqueness of the event), and your module is using a DataStore, you can do:

jrCore_db_increment_key('ujModuleName', #, 'my_counter', 1);

Where "#" is the _item_id of the DS item you want to increment that key for. If the key does not exist, it will be created and set to "1". The last param can be set to your increment value.

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 10/17/13 11:01:50AM
SteveX
SteveX
@ultrajam
12 years ago
2,589 posts
OK thanks Brian.

I just got an error when leaving this forum page. When clicking the >> Forum >> link in the breadcrumbs above I saw a white page with the error
Quote: CRI: Query Error: Duplicate entry '6-0-using-jamroom' for key 'view_unique'



--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
brian
@brian
12 years ago
10,149 posts
Yeah I saw that in the debug log too - I'll check it out.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags