update stream count by 1 seem impossible
Jamroom Developers
OK thanks for attaching the module. So there's a couple things in the view I'll go over:
jrCore_validate_location_url();
You don't want this at the top of your view function UNLESS the view is being called by an XHR/Ajax request that has had the URL prepared with jrCore_set_csrf_cookie(). Your JS functions are not using that function so you do not want that at the top of your view function.
Here is your view function working for me:
/**
* @param $_post
* @param $_user
* @param $_conf
* @return bool|void
*/
function view_jrShoutcastPlayer_update($_post, $_user, $_conf)
{
if (!isset($_post['song']) || strlen($_post['song']) == 0) {
return jrCore_json_response(array('error' => 'invalid song title'));
}
if (!isset($_post['profile_name'])) {
return jrCore_json_response(array('error' => 'invalid profile name'));
}
// Get all audio files that are part of this album
$_sp = array(
'search' => array(
"audio_title = {$_post['song']}",
"profile_name = {$_post['profile_name']}",
"audio_artist = {$_post['profile_name']}"
// "_item_id = 3" - use by brian for testing
),
'return_item_id_only' => true,
'exclude_jrUser_keys' => true,
'exclude_jrProfile_quota_keys' => true,
'order_by' => false,
'limit' => 1
);
$_rt = jrCore_db_search_items('jrAudio', $_sp);
if (isset($_rt) && is_array($_rt)) {
jrCore_db_increment_key('jrAudio', reset($_rt), 'audio_file_stream_count', 1, true);
return jrCore_json_response(array('success' => 1));
}
return jrCore_json_response(array('error' => 'update failed'));
}
Note a couple changes I made:
'return_item_id_only' => true,
In your case you are only interested in the _item_id - by using the "return_item_id_only" $_rt will just be a simple array with the matching ID if found - i.e.
0 => 3
This is much more efficient since it saves a second query that gets the actual keys for the item.
I also set "order_by" to FALSE - there's no reason to request an order when you're getting one result.
Attached is the update - let me know how that works for you.
updated by @brian: 06/17/23 07:26:24AM