solved Atypical Site Builder Widget

TiG
TiG
@tig
7 years ago
184 posts
Looking to build a Site Builder template widget for the home page that will provide a unique list of authors with a few of their most recent blogs or discussions listed below them. No concerns with the presentation or algorithmic logic. The question is more how to approach the problem.

This widget requires blending data from jrDiscussion_item_key, jrBlog_item_key and jrProfile_item_key. So this takes jrCore_list out of the equation (or so it would appear). If we had one table I would simply insert a template widget with:

jrCore_list module="jr..." search1= ... , template="mytemplate.tpl"

What is a sensible (recommended) way to initiate a Site Builder template widget that must combine several tables and then feed a custom template?


--
TiG

updated by @tig: 01/16/18 05:16:38PM
michael
@michael
7 years ago
7,692 posts
You COULD build it AS a widget, but since you're not planning on releasing the thing as a module, what I would do would be to use the TEMPLATE CODE widget along with a custom smarty function from your module and put all the logic into the function.

So in the TEMPLATE CODE widget would go:
{xxSomeModule_foo}

and in your module xxSomeModule build the custom smarty function:

Docs: "Defining your own SMARTY function"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1569/defining-your-own-smarty-function
paul
@paul
7 years ago
4,325 posts
Would the Seamless module be an alternaive to the jrCore_list in the case? - https://www.jamroom.net/the-jamroom-network/documentation/modules/289/seamless
This module is also supported in SiteBuilder as the 'Item List (Combined)' widget.


--
Paul Asher - JR Developer and System Import Specialist
TiG
TiG
@tig
7 years ago
184 posts
@michael - Thanks, that is a tip that will no doubt come in handy down the road (if not immediately) since it offers full flexibility.


--
TiG
TiG
TiG
@tig
7 years ago
184 posts
@paul - I would like to see jrSeamless work for this application since the module seems to be built for exactly this situation. So naturally I am trying this first. The basics are working, but I cannot seem to get search to work for me.

Here is my initiating code (incomplete, just focused on discussion_type for the moment):

{jrSeamless_list modules="jrBlog,jrDiscussion" order_by="_updated desc" limit="15" 
search="discussion_type != 'cat'" 
template="columnists_item_list.tpl"} 

For performance reasons, I would like to exclude all cat discussion_types rather than skip them in the presentation template. However, the search above does not seem to work. The discussion_type cat items are included in the items list.

Also, is there any way to introduce an OR into the search? The documentation seems to indicate using comma-separated conditions in the order of the modules. That does not seem to work but I suspect it is because I am using an improper search syntax.

I will keep poking around, but I wanted to get my question enqueued in the meantime. Thanks.


--
TiG

updated by @tig: 10/17/17 11:04:58AM
TiG
TiG
@tig
7 years ago
184 posts
@paul - Found the problem; it was the single quotes around the string 'cat'.


--
TiG
paul
@paul
7 years ago
4,325 posts
Yeah, the literal single quotes are not needed within the search.
Keep in mind when using the Seamless module that it is a 'heavy hitter' on the server in that every module specified would perform its own 'jrCore_list' call and then all the results are processed/filtered/sorted etc. so on a busy site you may start to see performance issues.


--
Paul Asher - JR Developer and System Import Specialist
TiG
TiG
@tig
7 years ago
184 posts
@paul - looks like the limit is not applied until after the db query. Seems to me that means every record in the data store that matches the search criteria will be returned before the limit-imposed slicing (and other functionality). I do not see how I can override this using a listener. If I am reading this correctly I will have to go another route. In my case I only want to return about 15 items (the most recently updated 15 items) so this would be a very long route to get there given the number of discussions and blogs in the data store. Let me know if I am reading this incorrectly. Thanks.


--
TiG
michael
@michael
7 years ago
7,692 posts
In your custom smarty function 3 search calls for the last 15 items ordered by updated
        $_sp = array(
            'skip_triggers' => true,
            'order_by' => array('_updated' => 'desc'),
        );
        $_rt = jrCore_db_search_items('jrBlog', $_sp);

// repeat for the other wanted modules, 
// merge by the updated time to filter to the latest 15
// spit it out to the templates

    $out = jrCore_parse_template('your-formatting-template.tpl', $_rep, 'xxSomeModule');
return $out;
TiG
TiG
@tig
7 years ago
184 posts
@michael - My first approach was to try the jrSeamless functionality since that seems to be designed for the kind of task I am facing. The only concern I have is performance. I do not want to process a huge result set only to get the most recent 15 items. And in Perrie's case the Blog and Discussion tables are very large. Ergo my question to paul.

On your point, I am indeed considering my own smarty function per your suggestion. Happily I could use much of what exists in jrSeamless to make a custom module for this. Given I do not want to bring back a large result set only to strip off the top 15 items, I would likely pursue a custom SQL query that enables the optimizer to return a much smaller result set. That is, I would have no concern processing the most recent 15 selected blogs and the most recent 15 selected discussions to deliver the most recent 15 [blog | discussion].

Thanks for the advice.


--
TiG
paul
@paul
7 years ago
4,325 posts
Not entirely clear on what the issue is @tig
How is the 'limit' parameter not working as you expected?


--
Paul Asher - JR Developer and System Import Specialist
TiG
TiG
@tig
7 years ago
184 posts
@paul - the limit is not passed to the DBMS (best I can tell). So the query returns more records than the limit. The limit is applied by the smarty function after the results have been returned during consolidation.


--
TiG
TiG
TiG
@tig
7 years ago
184 posts
@paul - I was able to get around this by passing a sort_limit argument with the same number as the limit argument. So I should be able to put jrSeamless into production. :)


--
TiG
paul
@paul
7 years ago
4,325 posts
Glad you're sorted.
Yes, the 'limit' parameter in Seamless is a bit of a compromise because basically it needs to work with the overall 'order_by' so just getting the first 10 (say) of each module may not yield accurate results. So 'over-sampling' is needed and then the use of the 'sort_limit' instead. This is why this module can be a 'heavy-hitter' as suggested above.
hth


--
Paul Asher - JR Developer and System Import Specialist

updated by @paul: 10/18/17 03:03:34AM

Tags