Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
Decode json list field for ids in search params listener
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/26/13 08:05 
I have a module which links to items in another module using a json array (similar to how playlist works).

I also need to check dates on the linked items when listing the main module, which I am doing using a search params listener (at least one of the linked items needs to fall into the date range in order for the main item to show in the list). It seems that in the search params I need a comma list field to provide the ids, so I've duplicated my json field as a comma list field.

Is there a way of doing this (decoding the json) without having a comma list field in the db alongside the json array field (and always keeping the lists in the two fields in sync)?

That's probably clear as mud unless you've tried something similar, but worth asking in case somebody has.

Thanks (over optimistically) Very Happy


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/26/13 19:47 
don't know. (didn't really understand)

You could listen for when the item is added and add a separate date field to the modules datastore via your module.

That way you'd have the format you want when you want to search for it.

And to keep it clean, listen for the integrity check and rebuild those dates on the items during this phase. (if rebuilding is possible)


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/27/13 00:33 
Thanks Michael, but there are possibly many linked items for each main module item.

I need to show the main module item if at least one linked item falls into the date range.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/27/13 01:05 
at time of main module item creation check the date range of each item, then store the earliest and latest dates with the main module item.

So you don't need to search the items dates, just the earliest and latest on the main module item.

would that work?

-- edit --
or store the item dates with the json stuff. json is just an array in a weird layout. store nested arrays.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/27/13 03:37 
I don't think that would work, I'd end up duplicating too much info from the linked items in the nested json. Much easier to maintain a second field in the main item with a comma list of the ids of the linked items and take advantage of the search params listeners (I think...).

I do use the json arrays for storing more info in another part of this project though, works great.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/27/13 17:09 
Heres the image i have of the problem in my mind.

'main item 1' is created, then stuff is added to it 'audio1','audio2','audio3' for example.

'main item 1' now has a json array along with its standard stuff:
* main_item_1_created = xxxxxx
* main_item_1_name = xxxxxx
* main_item_1_updated = xxxxxx
* main_item_1_json = json_encoded('audio1','audio2','audio3')

then you want to search "get me all the main items, where any of the items in the json array have a _created date between 1st july and the 7th july."

------------------
thats how im understanding the problem.

If thats the problem, surely storing the min/max dates of the json items with the main item could work no?

eg:
* main_item_1_created = xxxxxx
* main_item_1_name = xxxxxx
* main_item_1_updated = xxxxxx
* main_item_1_json = json_encoded()

'audio1' is added to main item
* main_item_1_created = xxxxxx
* main_item_1_name = xxxxxx
* main_item_1_updated = xxxxxx
* main_item_1_json = json_encoded('audio1')
* main_item_earliest_date = xxxxx //(audio1's creation date)
* main_item_latest_date = xxxxx //(audio1's creation date)

'audio2' is added to main item

* main_item_1_created = xxxxxx
* main_item_1_name = xxxxxx
* main_item_1_updated = xxxxxx
* main_item_1_json = json_encoded('audio1','audio2')
* main_item_earliest_date = xxxxx //(audio1's creation date)
* main_item_latest_date = xxxxx //(audio2's creation date)

'audio3' is added to main item

* main_item_1_created = xxxxxx
* main_item_1_name = xxxxxx
* main_item_1_updated = xxxxxx
* main_item_1_json = json_encoded('audio1','audio2','audio3')
* main_item_earliest_date = xxxxx //(audio3's creation date)
* main_item_latest_date = xxxxx //(audio2's creation date)

then search on "get me main items where the earliest date is greater than 1st july"

??


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/27/13 18:35 
Its a start and end date for each linked item, not a single earliest and latest. There can be very many linked items, and there are other fields which need to be searched on as well, so the search params listener seems the best way to go at the moment.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/27/13 18:41 
So the search is more like:
get me main items which are connected to at least one linked item which has past its publish date, has not yet expired, is available in UK, CA and FR, and contains a reference to profiles 7, 15, 65 and 87.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/27/13 18:49 
then what about storing the 'main item' 's item id on those items.

"get me main items which are connected to at least one linked item which has past its publish date, has not yet expired, is available in UK, CA and FR, and contains a reference to profiles 7, 15, 65 and 87 and has a main item id like ,12,"

store the main item id's as a comma separated list in a singe row and use a LIKE search.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/28/13 01:53 
But (similar to a playlist) I already have the ids.
Surely much quicker to get the items by id?


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/28/13 02:06 
as i understand it: you have the ids for all the items whether you want them or not, so if the plan is to "go get this item, just in case I might need it, then get the next item just in case i might need it, then go ........"

Your doing a lot of calls to the database on a "might need it" premise.

I was just looking for a way to get rid of that 'might'.

-- edit --
in the end, im just throwing ideas out there. you going to choose the way that feels right for the problem. If you've decided on that way, go with it. Smile


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/28/13 02:14 
Its a single call though isn't it? That's why I'm using the search params listener.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 09/28/13 02:35 
not sure if its a single call or not. If it is, your fine.

I was imagining many calls.

--edit--
jrCore_db_get_item() is one call, i was imagining a loop with that in it to check the dates of the gotten item for every item in the json array.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/28/13 02:38 
Looking back at this listener again, it isn't doing what I thought it was doing anyway.

I'm going to have to look throughthis again.

Thanks Michael


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 09/28/13 03:57 
Unlikely to be a priority for many, but datastore and db listeners are my current "docs I'd like to read" favorites.

Do you know of any documentation for similar datastore type systems? Or if similar systems exist? Haven't found anything useful via google, but I'm not exactly sure what I'm looking for.


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.