solved Module Relationships and Question about counting number entries in multiple fields.

alt=
@makuta
11 years ago
38 posts
I am in the process of developing a Music Chart Reporting system and I would like to know how to create a relationship between the audio module and a custom review module so I can associate an audio record to the review entry entry. Is the comment function a module and if it is, can I modify it to put additional fields and options for a review system?

Also, if i were to entry numbers in a three fields and I would like to use a fourth to total the amount and save it, can I do it using form designer?
updated by @makuta: 01/18/15 02:38:38AM
brian
@brian
11 years ago
10,149 posts
Yes - I would recommend checking out the User Comments module (jrComment) - it does this. Basically it stored a "comment_module" and "comment_item_id" key for each comment that is made that contains the module and item that the comment was made for.

As for doing math on some fields and storing it to a 4th field, no - the form designer is not going to help with that. Instead, in your custom module what you want to do is simply compute it on access via "db_get_item" and "db_search_items" event listeners - again check out the following function:

jrComment_db_get_item_listener()

in the jrComment/include.php file to see how it "listens" for the DataStore access on a comment and adds in the info about the item. You would want to run your computation on your fields and add in the key for the 4th field right in the listener.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@makuta
11 years ago
38 posts
The fields I want to calculate is in the audio module. They are

audio_chart1_points_count
audio_chart2_points_count
previous_chart_point_count

This will give me the sum of all three fields that will be automatically calculated and then stored once submitted in:

overall_chart_points_count

Can you tell me how I can write that out and make it work in the audio module?
alt=
@makuta
11 years ago
38 posts
Got another question regarding the youtube module import function. How do I get it to import the views from youtube?
paul
@paul
11 years ago
4,335 posts
When creating YouTube videos with module requests meta data from YouTube about the video, and the current 'viewCount' is part of the returned data. However, it is not saved as it most users would want to see views the item has had on their site.

To get the data, you could utilise the module function that gets the meta data - jrYouTube_get_feed_data('YouTubeVideoID') - in your templates or a custom module.
hth
Pa


--
Paul Asher - JR Developer and System Import Specialist
alt=
@makuta
11 years ago
38 posts
That answered the question but not really provide any steps to do it. Are there any files I have to modify to do it? What about the arrays in the jrYoutube module, does the get_feed_data function exists in that file?
paul
@paul
11 years ago
4,335 posts
Sorry. To use this in a youtube list or detail template, do something like this -
{assign var="_ytdata" value=jrYouTube_get_feed_data(`$item['youtube_id']`)}
Video Streams: {$_ytdata.viewCount}
If you include a {debug} after the assign, you can checkout all of the YT video variables that you can now use.
Pa


--
Paul Asher - JR Developer and System Import Specialist

updated by @paul: 11/11/14 03:00:14AM
alt=
@makuta
11 years ago
38 posts
I actually would like to store the youtube views that way I can use it in the advanced charts.
paul
@paul
11 years ago
4,335 posts
In that case, you'll need a custom module to listen for youtube creations and add that field (plus any others you might need) onto the YouTube DataStore. See https://www.jamroom.net/the-jamroom-network/documentation/development


--
Paul Asher - JR Developer and System Import Specialist
alt=
@makuta
11 years ago
38 posts
I changed the domain name for my website and now I cannot login. Could I get some assistance? this is the error I receive:

a system level error was encountered trying to validate the form values: error:
michael
@michael
11 years ago
7,791 posts
I've added a couple of sections to this docs page:

"Somethings wrong, what do i do?"
https://www.jamroom.net/the-jamroom-network/documentation/problems/114/somethings-wrong-what-do-i-do

Try the repair.php method followed by the FTP cache clearing. That should get you going again.
alt=
@makuta
11 years ago
38 posts
Your suggestion works. But you should advise administrators that they should only delete the files from the jrCore, jr(Skin Folder) and jrImage. If they delete the folders the site will go blank. I add to recreate the folders I mentioned in order for the site to work after I deleted the folders.
alt=
@makuta
11 years ago
38 posts
I would like to make a booking module and I would want to use the private notes module as the basis for it. How can I use Form Designer to redesign the private notes module to add fiields I need for booking?
michael
@michael
11 years ago
7,791 posts
makuta:...you should advise administrators that they should only delete the files from the jrCore, jr(Skin Folder) and jrImage. If they delete the folders the site will go blank. I add to recreate the folders I mentioned in order for the site to work after I deleted the folders.

You shouldn't need to do that, if the cached files aren't there they will be created.

Glad to hear you got it working.

Not sure the Private Notes is the best one to use as a base for a "booking module". The Form Designer is not activated in it. Have you looked at the:

"simple custom forms"
http://www.jamroom.net/the-jamroom-network/networkmarket/88/simple-custom-forms

module? It has the option of Form Designer fields
Quote: description: Create simple forms that send results as a private note or email to admin users

You could add the fields you want and send them to the private notes (or store them in the datastore).
alt=
@makuta
11 years ago
38 posts
how can I store data in a field then automatically add it to another field from a cronjob?
michael
@michael
11 years ago
7,791 posts
makuta:
how can I store data in a field then automatically add it to another field from a cronjob?

I don't understand the purpose of the question sorry. Why would you want to do it via a cronjob?

If your going to build another module to have a datastore to move it to, then you might as well use that module from the beginning rather than move data over later on.

I suspect im not understanding.
michael
@michael
11 years ago
7,791 posts
makuta:....I would like to know how to create a relationship between the audio module and a custom review module....
ah, that might be the purpose.

You can add save the _item id in the datastore. so if underneath the audio item you add a review template, when you save the info to the review_ data store, add in a field for review_audio_item_id that corresponds to the '_item_id' of the audio file in the audio files datastore.

Then when you search on your datastore, you can retrieve all the associated reviews.

either in code in a module:
        // get reviews for audio item 15
        $_sp = array(
            'search'        => array(
                "review_audio_item_id = 15"
            ),
            'skip_triggers' => true,
            'limit'         => 1000000
        );
        $_rt = jrCore_db_search_items('xxReviews', $_sp);

or in the templates
{jrCore_list module="xxReviews" search="review_audio_item_id = 15" .......}

in the example above the module is called xxReviews and i chose audio item id 15, you'd probably use a variable there.
alt=
@makuta
11 years ago
38 posts
This is what I want to do:

- Submit points in 2 fields (i.e. F1 (NYC Points) = 98 , F2 (SF Points) = 100 so F1 + F2 = F3 (Weekly Total)

- I want to save the sum of F1 and F2 automatically instead of manually doing the sum and inputting it in F3. I don't want the field to be editable.

- I want to be able to add the saved numbers to F4 which will take the overall count when every point is submitted.

(i.e. Week 1 - 98 + 100 = 198
F4 Total = 198

Week 2 - 100 + 100 = 200
F4 Total = 398

Since there is already a Audio Stream Count field, I want to be able to add the new numbers like when a song is played.

Is there a way to trigger the add function to sum the total from each field and add them to the audio stream count?
michael
@michael
11 years ago
7,791 posts
You could use the 'daily_maintenance' event. That fires once a day. When it fires, if your module is listening for it:

eg: In the this module
https://www.jamroom.net/the-jamroom-network/networkmarket/22/db-and-system-backup

In the _init() function include file:
/modules/jrBackup/includes.php
jrCore_register_event_listener('jrCore', 'daily_maintenance', 'jrBackup_daily_maintenance_listener');

That code listens for the 'daily_maintenance' and when that runs it fires its own function:
jrBackup_daily_maintenance_listener()

Take a look at that to see how the code is applied.

In your code you would use the search function to return the audio data you want, then use the update function to update the datastore.

Take a look in modules/jrAudio/index.php to see the update functions.
alt=
@makuta
11 years ago
38 posts
I looked at your suggestion but couldn't figure out how to actually implement it especially using the audio support module.

jrCore_register_event_listener('jrCore', 'weekly_stream', 'jrAudio_weekly_stream_listener');

// Event Listeners
jrCore_register_event_listener('jrCore', 'system_check', 'jrAudio_system_check_listener');
jrCore_register_event_listener('jrCore', 'stream_file', 'jrAudio_stream_file_listener');
jrCore_register_event_listener('jrCore', 'get_save_data', 'jrAudio_get_save_data_listener');
jrCore_register_event_listener('jrCore', 'db_search_params', 'jrAudio_db_search_params_listener');

jrCore_register_module_feature('jrSearch', 'search_fields', 'jrAudio', 'audio_title', 52);

jrCore_register_module_feature('jrProfile', 'profile_stats', 'jrAudio', 'profile_jrAudio_item_count', 52);
michael
@michael
11 years ago
7,791 posts
There is no event called 'weekly_stream' provided by the jrCore module. and if there was, the function jrAudio_weekly_stream_listener doesn't exist in the jrAudio module.

Take a read of this page, it should help understand the concept:

"Events and Listeners"
https://www.jamroom.net/the-jamroom-network/documentation/development/1011/events-and-listeners

You don't want to alter the audio module, you need to make your own. Then listen for existing events and run your own modules functions. so if your module is called xxReviews then in xxReviews_init() you would have:

function xxReviews_init(){
 jrCore_register_event_listener('jrCore', 'daily_maintenance', 'xxReviews_daily_maintenance_listener');
return true;
}

/**
 * Daily maintenance
 * @param $_data array incoming data array
 * @param $_user array current user info
 * @param $_conf array Global config
 * @param $_args array additional info about the module
 * @param $event string Event Trigger name
 * @return array
 */
function xxReviews_daily_maintenance_listener($_data, $_user, $_conf, $_args, $event)
{ // do whatever you want to do here, then return $_data // this function will run once a day. return $_data; }

--edit--
This could be useful to you too:
"Developers guide to customizing Jamroom"
https://www.udemy.com/developers-guide-to-customizing-jamroom
updated by @michael: 11/27/14 12:15:11AM
michael
@michael
11 years ago
7,791 posts
Here's the basic module structure to get you going.

It listens for the daily maintenence, then searches all the audio files and adds 10 points to the 'audio_overall_chart_points_count' for each audio item in the system.

it needs tweaking to do whatever you want it to actually do.
zip
xxReviews.zip  •  3KB


updated by @michael: 11/27/14 12:31:53AM
alt=
@makuta
11 years ago
38 posts
First thing I want to do is display the stream count and do the sum of two fields that display in a template.
alt=
@makuta
11 years ago
38 posts
Thank you michael. I think this is a great start.
michael
@michael
11 years ago
7,791 posts
makuta:
First thing I want to do is display the stream count and do the sum of two fields that display in a template.

You're going to have to start thinking in much more specific terms. "I want to do is display the stream count" is very ambiguous. There are many ways to display something and many locations to display it.

Where you want to display it will make a big difference in the method you use to get the info out there.

and take it one step at a time. first get the data you want into the database, then think about getting it out.

Or the other way around, first think about getting what you want out of the database, then think about manipulating then storing it.
alt=
@makuta
11 years ago
38 posts
Michael thanks for the xxReviews module it explains exactly what I was trying to do. I created a new module and added the variables to it. I do have a question though, if i want to have the data updated immediately instead of being triggered by the daily maintenance, how would I do that?
alt=
@makuta
11 years ago
38 posts
I made some adjustment to the array by doing the below, is that an appropriate way to use the function:

$new_total = $item['audio_chart1_point_count'] + $item['audio_chart2_point_count'] + $item['audio_chart3_point_count'] + $item['audio_chart4_point_count'] + $item['audio_file_stream_count'];
alt=
@makuta
11 years ago
38 posts
I get this message: [admin]: jrCore_trigger_event: defined event listener function does not exist: jdReviews_daily_maintenance_listener
alt=
@makuta
11 years ago
38 posts
Michael I want to thank you for your assistance. I figured out the issue with the module and fixed it. I had to change the event listener from

xxReviews_view_results_listener to xxReviews_daily_maintenance_listener

now it does the calculations I want. But I would only want it to do the update weekly. how would I have it do that?
paul
@paul
11 years ago
4,335 posts
Quote: But I would only want it to do the update weekly. how would I have it do that?
Try wrapping your listener code in the following if statement -
{
    if (date("D") == 'Mon') { // Or 'Tue', 'Wed' . . .
        // Your Code Here
    }
    return $_data;
}
hth
Pa


--
Paul Asher - JR Developer and System Import Specialist
alt=
@makuta
11 years ago
38 posts
How about a specific time?
michael
@michael
11 years ago
7,791 posts
makuta:.... if i want to have the data updated immediately instead of being triggered by the daily maintenance, how would I do that?...

If you want a function to fire based off of a URL, eg: someone visits:
your-site.com/reviews/some_location

Then that corresponds to the 'some_location' function for your module. (because you chose 'reviews' as the module base URL, so anything that goes to '/reviews/' gets sent to xxReviews)

That url is defined in your _meta() function in your includes file.

/**
 * meta
 */
function xxReviews_meta(){
    $_tmp = array(
        'name'        => 'Reviews',
        'url'         => 'reviews',
        'version'     => '1.0.0',
        'developer'   => 'a Reviews module, ©' . strftime('%Y'),
        'description' => 'a module related to reviews,
        'category'    => 'site',
        'license'     => 'mpl'
    );
    return $_tmp;
}

Think yours should look like that ^^

What is looked for by the system is a function in the index.php file with a certain name.
so your index.php file needs a function called view_xxReviews_some_location()

This is what your index.php file should look like:
<?php
/**
 * @copyright YOUR NAME
 * @author your name <you [at] yoursite [dot] com>
 */

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

//------------------------------
// some_location
//------------------------------
function view_xxReviews_some_location($_post, $_user, $_conf)
{ return 'hello world'; }
There is a Jamroom5 "Hello World" repo here:
https://github.com/PMaynard/JR5-Hello-World

With a bunch of 'Hello World' examples in it. It might be useful to you.

updated by @michael: 11/28/14 01:44:41AM
michael
@michael
11 years ago
7,791 posts
makuta:
How about a specific time?

If you need it to fire at a specific time I suggest cron from your server to call a url.
alt=
@makuta
11 years ago
38 posts
I want to be able to create an option for users who are profile admin to click on a Record Label that is created in the system. So this is the situation:

- Record Label sign up under quota 2
- Have permission to create profile for Artist under Quota 1
- When adding song under Artist profile, I want to have a dropdown or browse list that loads record labels from quota 2.

The reason I would like that is because in Reggae music there are several production companies that produce music for Artists and when they add them to my site, they are doing it under their profile making them the artists and they are adding the artist name and the song time to identify who actually sing the song. I want to link the song to the production company so record label would be list will be linked back to the record label profile.
SteveX
SteveX
@ultrajam
11 years ago
2,584 posts
It won't get you all of the way there, but have you seen this docs page?
https://www.jamroom.net/ultrajam/documentation/code/1322/power-users-creating-a-record-label-quota


--
¯\_(ツ)_/¯ 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 :)
alt=
@makuta
11 years ago
38 posts
Thank you all for your assistance. It helped alot in my project. Now I have a very simple question in regards to the MediaProLight Template:

- I want to create horizontal display of content such as news, youtube videos and music. Basically I want to have it where it would be listed like this:

Content Type (News, Video, Music etc)
Column 1 | Column 2 | Column 3 | Column 4

Each Column would have the following structure
Image
title
artist

How would I do it?
michael
@michael
11 years ago
7,791 posts
Better to ask a new question in a new thread @makuta. It helps people who are searching for the answer know where to look.

Perhaps a title of "How do I create a 4 column layout in a template?".

The answer is to use 4 columns. Jamroom is made up of a 12 column grid, so using 4 columns 3 wide would get you the structure you need.
 
<div class="row">
 <div class="col3">Column 1</div>
 <div class="col3">Column 2</div>
 <div class="col3">Column 3</div>
 <div class="col3">Column 4</div>
</div>

Tags