solved The Meaning of "updated" in lists?

Zachary Moonshine
Zachary Moonshine
@zachary-moonshine
7 years ago
823 posts
when creating a list of media items if i select to display them descending by updated does that mean every time a like or comment is placed on that media item it will be boosted in that list?
updated by @zachary-moonshine: 03/23/18 07:25:48AM
paul
@paul
7 years ago
4,325 posts
As a rule, yes. Whenever a datastore item is updated, its '_updated' key value is set to the time of the update. (Its '_created' key value stays static as the time of creation).
So, if an item is 'liked'. say, or has a comment made on it, or whatever, the relative 'count' key gets incremented, hence the item's '_updated' value is set.
Hope that makes sense.


--
Paul Asher - JR Developer and System Import Specialist
Zachary Moonshine
Zachary Moonshine
@zachary-moonshine
7 years ago
823 posts
yeah thats cool, i was thinking that was what it meant so now i can just tell users to get comments and likes in order to show up on that list more often! which will force engagement
paul
@paul
7 years ago
4,325 posts
Remember that any datastore item key that ends with '_count' can be charted, so you could also force 'engagement' by showing daily/weekly charts of the number of likes or comments an item gets.


--
Paul Asher - JR Developer and System Import Specialist
Zachary Moonshine
Zachary Moonshine
@zachary-moonshine
7 years ago
823 posts
well it does not seem to work on my site for some reason, it only shows newest uploads bt no matter how many times i comment on anything old it never pops up in the list? is it because its a combined list does it have to be a single list f one module?
michael
@michael
7 years ago
7,692 posts
We're talking about datastore module keys right?
'_created'
'_updated'
???

'_updated' is the timestamp at the last time jrCore_db_update_item() was run. If you have comments on an audio file, the '_updated' for the COMMENT will change when the gear icon is used on it. the '_updated' for the audio item will not change just because someone adds a comment on it. (might for the forums, though, would have to check.)
michael
@michael
7 years ago
7,692 posts
_updated does not change on the audio item when a new comment is added.
after.jpg
after.jpg  •  110KB

initial.jpg
initial.jpg  •  107KB

michael
@michael
7 years ago
7,692 posts
If you wanted to have it change everytime a comment was added. a small module that listened for the new comments and triggered the update would force it to update when there are new comments. Its just not the default option.
Zachary Moonshine
Zachary Moonshine
@zachary-moonshine
7 years ago
823 posts
ok so i should just stick to listing by like counts i guess
michael
@michael
7 years ago
7,692 posts
A module called xxAudioOrder with just an inlcude.php file with this contents:
<?php
/**
 * @copyright noone
 */

// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function xxAudioOrder_meta(){
    $_tmp = array(
        'name'        => 'AudioOrder',
        'url'         => 'audioorder',
        'version'     => '1.0.0',
        'developer'   => 'noone, &copy;' . strftime('%Y'),
        'description' => 'Update audio files _updated key when comments are added',
        'license'     => 'mpl',
        'category'    => 'custom'
    );
    return $_tmp;
}

/**
 * init
 */
function xxAudioOrder_init(){
    jrCore_register_event_listener('jrCore', 'db_increment_key', 'xxAudioOrder_db_increment_key_listener');
    return true;
}

/**
 * Increment the _update key when a comment is added
 */
function xxAudioOrder_db_increment_key_listener($_data, $_user, $_conf, $_args, $event)
{ if (isset($_data['key']) && $_data['key'] == 'audio_comment_count' && isset($_data['update']) && $_data['update'] == false) { $_rep = array('audio_incremented' => time()); jrCore_db_update_item('jrAudio', $_data['id'][0], $_rep); } return $_data; }
would have the results you're looking for: when a comment is added the audio file's _updated timestamp would be incremented.
michael
@michael
7 years ago
7,692 posts
from jrCore 6.1.6 going forward, the listener will only need to be this:
/**
 * Increment the _update key when a comment is added
 */
function xxAudioOrder_db_increment_key_listener($_data, $_user, $_conf, $_args, $event)
{ if (isset($_data['key']) && $_data['key'] == 'audio_comment_count') { $_data['update'] = true; } return $_data; }
because the position of the listener has been moved to before the update so only 1 query now needs to be run which will be quicker.