Skip to content
Amigo edited this page Jun 17, 2019 · 34 revisions

DynamicGet

Sermon - Preacher Get Example

We are still working with Sermon Distributor; we are going to use Preacher, a 'get' I've already set up as an illustration. Here we have 'Back-end view' selected. (See video.) 00:00:25 For example: Select nothing. This is how it will usually look when you start. Select this, (depending on which area of the back end you want to get the data from) and select back end view. That is the best way to do it. 00:00:39

Dynamic Get Source Selection

The Joomla database option gives you the access to draw data from any other component installed that moment in the Joomla Website. 00:01:01 If you select your Joomla database, you can select any database that is installed on your database at the stage. This means that you can reach out to other components through this dynamic get. 00:01:21

This is an area that I haven't tested well yet. You might try to implement it and tun into some trouble. For now it is better to use the 'Back-end view' option. 00:01:42 The other option is there is because we want the feature in the application even while we are still working to improve it. If not very complex mapping is done (for instance, if you do a simple direct database fetch like 'cb_associations') you will be able to use this and there won't be any complications. 00:02:09 These other linked or joint database structures makes it complicated. 00:02:32

There is also the 'Custom' option, using Component Builder to write your PHP for you. At 'custom Get' you can add custom PHP, that will add the methods data for you. This is a 'custom get' option where you write the code by hand whereas this 'Custom - dropdown' option writes the code for you. (See video.) 00:02:55 Select the Back-end view that you want to use; it will be the view that you connect to your component. Type your name in here, select the package, and it will load all the field names. 00:03:20

Dynamic Get Preacher View

These are the fields inside of the 'Preacher' view. Load it and place this as 'asset_id'.(See video) It is suggested that you don't change that. 00:03:50 You can remove a row if it is not needed, but what remains is the data you might want. This would be the variable name of the data when the get is used. 00:04:13

Get Types - Get Item/List Get Custom

There are four getTypes: 'getitem' which will get one item from the 'preacher' table and 'getlistquery' which will get multiple items. 00:04:41 (Depending on how many items you want to get from the database, select either 'getitem' or 'getlist'.) Then 'getcustom' and 'getcustoms', plural. The difference between these four is that you will only use the 'getitem' once per view. 00:05:04 If you are building a custom admin view, you will select a main 'get', either of a 'getitem' or either of a 'getlist'. You can add multiple 'getcustom' item or 'getcustoms' items. This can be seen as other methods that can be added to the page, but it's not the main method. 00:05:30 You have main methods:'getitem' and 'getlistquery', the exact naming of the methods that will be used. Then you have this 'getcustom' and 'getcustoms', which is almost the same as those two, except that they aren't 'main'. There will be another method in the model bringing data to the view. 00:06:00 You can add as many 'getcustom' and 'getcustoms' methods to your view as you like, but you can only add one 'getitem' and one 'getlistquery'. To determine this is to ask what the main objective of the view is. What is the main dataset that needs to be used in the view? That is what the 'getlistquery' and 'getitem' respectively are going to be used for. 00:06:27

Get List Pagination

If the main purpose of the view is to show a list of preachers, 'getlistquery' is used as the main selection. When a 'listquery' is done, there is an option of adding pagination; it decides whether the data should return a certain number. Joomla has a global number which can be set in the system administrative area under 'Global' settings. 00:07:00 Go to 'System', then to 'Global configuration', there is a 'Default list limit'. That is what will be used as the amount limiting the data being returned to the page. Here it will only return twenty items. 00:07:26 If I set that pagination to 'no', it will load all the data. 'Yes' would only load some of it, and 'no' will load all of the data, depending on what you want to do. If it to do an Ajax, be sure all the data is being loaded every time; if you rather use JavaScript to set up pagination for your view, use the 'no' switch. Most of the time just say 'yes'. 00:08:00 Component Builder will automatically add the pagination code to the page. It will also automatically add pagination code to the model at the bottom of the page; it will show a 1, 2, 3 pagination, depending on the template you are using and the styles that are on the page. If bootstrap is not on the page, that 1, 2, 3 might not look right and you might need to add styling to it. 00:08:31 Component Builder doesn't know what style is on your page so it cannot make provision for all of that. But it can load the pagination itself.

Join Data Views - Tables

In this area is data. (See video.) This data can be joined to other database tables. In this area, as with the main source, it is possible to select joint views from a table. (See video.) 00:08:57 A view table is the views of the component or any database table. One of the database tables is categories. Component Builder integrates it's application; if you add a category field to any view, it dynamically sets up a category for your component and integrates the category concept into your component. 00:09:22 It writes all the code and Joomla's own applications, like Article Manager, does it. It's uses the same conventions. If you know how Joomla article manager is bringing categories into the articles, that is the way your component is going to do it. Here at 'DB Table - cb_categories' you can select categories. (See video.) 00:09:54 In the 'Selection' area the data can be modeled. 'Model' is meant to decide what needs to be returned, as not everything needs to be returned from categories.

Joint View Tables

The Joint View Table makes it possible to select from any of the other views that are part of your component. 00:10:25 You can be selected it to return a single row or a list of rows. If single row is chosen it will join it to this other data set that you have as your main data or main source. It will be another item in the array. For example, that is why 'Name' can not be used in this instance. (See video.) 00:10:51 It needs to have that series_ in front of it so that it doesn't clash with the other data set that might have a value called 'Name'. For example, if anything is selected here it will populate this area with all the fields in that view. (See video.) 00:11:21

Concerning the 'AS' button: The same alphabetic number may not be used twice in the whole query. The whole get function can only use 'a' once, 'b' once, 'c' once, etc. 00:11:40 Provision has been made up to zz. That is the quantity of tables there may be in this area 'AS'.

Decide what type of return this 'Return Row Type' have to be. If it is set to multiple, these names will automatically update. 00:12:02 The get method will create a new method getting this data and adding it into your item list via this relationship. I'm adding the 'On Field' as the '.a' series; that is where the 'id' is for the series. 00:12:24 In the joint field, 'c.id' is used. In the main database, that is the 'a' database. There must be a field called series. It has the id of the series. It corresponds to the id in this list. If it is necessary to return a multiple, the main database, in this case 'Sermon', can be linked to multiple series's. 00:12:56

In this system a sermon can only be connected to one series; it is certainly a single return. It will then immediately add this 'series_' in front of everything to insure it doesn't clash with your 'a' table. 00:13:18 The unwanted fields can be removed but the string should not be editted as it may possibly malfunction .Some further development still needs to be done in this area. We want it to be possible for you to change this name to anything you like. We are going to try and do that eventually. You can be changing it but it will still write it this way in the code. 00:13:54 It will drop the fields you don't select. If you say that you don't want these, then it won't get those fields and you will only have this data returned. Again here you can have equal, not equal, equal or not. We also have 'IN' function. 00:14:22That means if this 'On field' is an array, then you can use the 'IN' function to make sure that it actually looks whether the ID is in this array. That's the 'IN' function. 00:14:45

Dynamic Get Preacher In Code

Where is the code is written? If we are looking into sermon 'preacher id'. We'll get to why it says 'preacher id', when we look at the 'filters' and the 'where'. 00:15:06 Let's go to the code. First refresh this page, and then go to the code. Since this 'get' is used in the front of the component, we will go to the front end and not to the admin area. Go to the front end of 'sermon distributor'. The dynamic get is used in the model to get the data. 00:15:33 It's getting a list query and it's using pagination getting all this. 00:16:02 Going into the code, the main method which has this id(a.name)or the data set may be seen. It is written here(selected area on video). Here you can see 'id', 'asset', 'name', 'alias', 'link', 'types' and 'short description'. 00:16:26

If you look at the UI it says the same things, 'alias', 'link', 'type', 'short description', 'icon', 'preacher', 'series', 'category' and 'id'. This is where it writes it. It shows you where in the compiler it has been done. Then it sets up the second one; 'series'. 00:16:50 It says; 'series = c.id''. So series, there(see video) is 'series', '=', the 'c', 'this table', 'series' and 'id'. Then it also tells you what it wants from 'c'. It wants the 'name' and the 'alias' and then it wants a series name that changes it to 'series'. 00:17:12 Since this is in the select query. This is one function there. That array 'array'(c.name)','c.alias' transposes to this array 'array'(series_name','series_alias'). That is how to use Joomla's database API. It has a thing called 'quotename', which you can pass to arrays.00:17:35The first array being the name of the value, which in this case is 'name' and 'alias'. The second array, is what is needed once the query is completed. So it links this(selected area on video) into the the query one-by-one. All of those even the category one is linked in here. Then 00:17:59 it does a check whether there's an id. If it exists, it checks whether it's a string. If it's a string, it adds a quote. If it isn't, if it is a number, it adds it directly. That is where the query is done, here return false if there is no id. We'll look at this area in a moment. 00:18:23 This is done through the 'filtering' and the 'where'.

A example of how it adds this preacher as well as series to the query: If you look at the back, open up 'Join View Tables - Add', you will see that series and preacher 00:18:41 and statistics. Multiple statistics are selected because for one sermon there can be multiple files, and there will be a number per file. 00:19:02 It is first does the query and here in 'getitem', it adds a new function called 'getidSermonstatistics' and with a random key 'Fcff_E' to ensure that it doesn't conflict with any other method on the page. We had to add this 'Fcff_E' random key. It puts it into this variable. That something that you need to 00:19:27 come and look at.

Possibly when we look at the site layout area as well as the templates, I'll be talking about this transition here again and the fact that you need to know that it is in this variable and I'm trying, inside of your layouts and your site views and these things, to give you the correct name. But it is not 00:19:51 watertight correct. Possibly you need to come and check this if it doesn't work. I'll explain that when we get there. We're adding statistics into this(idsermonstatistic) variable through a method which is also on the page and we passing the ID of the sermon. If you look at UI for instance, and go to 'statistics', 'multiple' and 00:20:19 join to the left. You can select any of these(dropdown'. Then use the main table 'a.id', it must be equal to 'e.sermon'. Then this is the only values that needs to return from the 'e.sermon'. The 'e.sermon' is this(see video) value here, and 'a.id' must equal with e.sermon. 00:20:48 If you look at the code, if we go to this function(idsermonstatisticFcff_E), it takes the 'id' and places it next to 'e.sermon'. Here's the two arrays. What it is in the database, and what it should be now. It checks whether it got any arrays or any values. 00:21:17 Then returns that as an object list, that then gets placed in this space.(See video)

Dynamic Get Custom Script

Returning to the dynamic get, it can be seen that there is a custom script area. If you click on it, you will see different switches. 00:21:54 You can select 'getlistquery' or 'before getting the items' and 'after getting the items'. If you select 'after getting the items' and you place any code there, then data gets dumped right after the initial items you have received. 00:22:14 It will add that code in there, and then return the items. That is why you can model the data right there in the dynamic get. You are going to write the code for the data after it has been 'get'. It can be checked if this code has been removed here, it will indicates if there is an array of items where all values are. 00:23:02 Make sure that those items are set and that it is there. A 'string bracket component helper function' is used to check whether the string is there. Here can some nice PHP be dumped. Even before getting the item you can add some filters or get list query,if this is model list. If this is item, you'd see that there's a different set of switches is available. It adjusts to the type of query up here. 00:23:19

Dynamic Get Join DB Tables

Coming back to this 'Join View Tables' area. Let's again look at the database table option. If category is selected and it's a single row that is returned. It is called 'b'. It is joined to the left, and set 'a.catid' that it should be equal to 'b.id', which is the 'id' of the category. Only a title and the alias is needed. That is 00:23:44 how it is set up. Only the title and the alias is nessesary and it is been returned. Then it links it in there(see video), and that's part of what is seen here when viewing the query option, it is the sixth section.

Dynamic Get Filters - Where - Ordering - Globals

Taking a look at the filters. Here is a 'filter',a'where', an 'ordering' and a 'setting' of globals. 00:24:12 The 'setting' of globals is if you have a value in this query that you possibly want to use in a custom query, which isn't even setup yet, but you want to know if this value is needed in the model. Then through this global option here, a global area can be set. Maybe it should be tested here(See video) . There is an option of using 'This' and 'State'. 00:24:38 Where it is the different set types. You can set the value to 'State' or you can set the value to 'This'.<<<<<<<<<<<<<

Here you need to know the key. I want to do the name, in this case is not going to work. Because you got more than one name. Usually this global function only functions well 00:25:01 when you are returning a single item. When you do getitem not getlistquery, but you do getitem, then this make sense and then you can give it a name. It will add it to the global scope of the model which you can access through other 00:25:24 model methods. which are custom methods. That is setting the global.

The filtering you have a a list of possible filtering. Depending on what you want to do. You might select id, or user, access, level, group, category, 00:25:45 tags or date. Some of these are not formulated yet. Like date doesn't work that well yet. Categories does, user, group, access level, user and id does well. This function variable works well. As well as array, value, repeatable value, and other all those already work very well. You can use them and implement them. The only way for you to 00:26:15 know exactly how it works you need to know a little PHP, and then you need to compile it and go look in the code what it has done and where it's placed what. That is why I showed you that this is all set in the model. Currently we are saying we wanted to do a JRequest::getint by id. 00:26:39 This is the get area that I added. I look in the code it says 'State Key' and it's this(JRequest::getint by id) here. We set it is a function variable. It doesn't change or adapt this at all. Then says it must be equal to preacher. What we are doing, since component builder doesn't know where the this variable is going to be a string or integer, that's why we have this function which first checks were that is string, 00:27:08 and then checks whether it's a number. It related and builds up the query respectively. You might feel that is too much and you're possibly right. But that is the only way I am implement it at this stage. Getting more developers involved may possibly improve this long run.

Dynamic Get Get Access( Default added)

Then you see the access. We have a bunch of values that fire every time in a custom 00:27:39 dynamic get model. It is the these(see video) values. Often times you might need these values. Instead of you having to do custom scripting to get these values on the page, we add these values dynamically every time. The userid, the group, the authorised group, the access level, the app, and then the input values, which by other URL or post is on the page, 00:28:08 and it tells you that it's been initiated, and set it to true. That is if you have custom methods, like this one getpreacher, it checks whether it's been set. If it has been set it doesn't set that again, it can just use it. But if it hasn't been set, it sets it, and also again sets it to true. 00:28:32 These global variables can be used inside of the code like the global variable we spoke of earlier. Out of that global variable we are accessing this 'levels', which has the get authorized view levels of the specific user 00:29:00 that is now accessed this model or the view that this model belongs to. If he is in these access levels. You remember that public is another access level. If the user isn't signed in, he's a public. This will validate true in the query. We set that up simply by adding access level in a.access. 00:29:28 You must check in the main source table for a.access whether the user is in that. That means you don't need to add a state key because the code is done for you. That is some of the filters.

Dynamic Get Where

Then the where. 00:29:48 You can add any table key equals to a certain value. That value could be another table like b.field or it could even be a global variable like we said we could set up. It can also be an id, a userid. The userid is already on the table. It could be like we've done it in this case just an integer which is one. We want to make sure that all the 00:30:18 sermons returned is published. If you have an unpublished sermon it shouldn't even return it at all.

Dynamic Get Ordering

That is setting up a getlistquery with pagination through this ordering method we just saying use the a.ordering 00:30:39 and send. You can order all the items. Just add many as you like. Be sure that the table that you ordering, could even use a name. It could be a name as an ordering table key. Then you could do a descending or ascending. It would be added to the query. 00:31:03 That is also added ordering to the data set from your dynamic get method. Here with the joint view tables you can do very nice dependency calls from other tables in the back end, and bring the data together into one items array. 00:31:25 That's what dynamic get is for. As you saw we have a main source on the model.

Then we have this other one called getpreacher. That is another dynamic get function which we have 00:31:45 looked at. It's called this one getpreacher. If we open it, we see it's a getcustom. We gave it a custom name called getpreacher. This is its relationships, So it basically having no 00:32:04 relationship there. Neither here. It's not linking to other tables. It's simply getting the preachers details right there(see video) simple as that. But it has a filter which is basically using the same integer and access levels as the filters. It's also using a 'where' I suppose, yes published, and it doesn't need ordering, because it's just one preacher. 00:32:41 It doesn't have any globally settings. That is getpreacher. From the this settings here, component builder writes all this code. You'd see that we have this function everywhere called UIkitComp.

Then we using a global static method, getuikitcomp. It's a method that I built if you know Uikit, if you don't know it, go to getUIkit or just google.com it. It's a JavaScript, HTML Library, CSS JavaScript library, which really makes modeling of your views very nice and easy. It has components that you can use, like tool tip, and model, 00:33:45 all these kind of models. Gordian is another component. We don't load all of it's components every time. What we've done is we've written in PHP, a method that looks at fields that are text area fields. It's not looking at every field, is only looking at the text fields and editor fields. In this component we know that this description field, is a editor field, and so we are sending it to this(getuikitComp) method.

You can go look at this method in your helper class(sermondistributor). It has the classes that already has been identified which is what this 00:34:56 initial this field name, field value model field value is actually holding. It's holding any component names that already has been identified. This gets pass also here(classes) with the content. Then we check in the content whether there is a class='uk-' and if it's not false, we start looping to check what are all the components that are in there. Here is the list of the components that are available. On-the-fly we are determining whether these components should be loaded. Just by looking at the content that was placed in the description field. Then we added back to this array(see video). It updates this, eventually you have an array of all those items. In the view, we go to the view, 00:36:00 which in this case is going to be preacher. We open the view .HTML. We get to a place where everything is going to be happening. These are of the components that when component builder compiled the application, it looks inside of the content of your site view, as well as your custom admin view and it identify that these components must be loaded for uikit. It places it here dynamically but since you could've added some components inside of the script that is stored in the description area, it now has this getuikitcomponent which reach back into the model. In the model gets this variables value through a method which is here at the bottom of the page. There it is 00:37:04 getuikitComp. Through this method it is reaching in getting that array. Once it has that array we check whether it is set. Whether it is an array and if it is an array we set it to the array that is already on this page. Then over here we loop through that array we load in those components, CSS and JavaScript as required.

You can be sure that the uikits needed components will be loaded on the page. Simply by user adding some of that components to its description as style. Because the way uikit works is you just like Bootstrap you just add the class name to the specific div or html tag. Then it activates the needed scripting around it. Which is a nice library but it's 00:38:08 quite heavy and you don't want it on the page every time. I know you could have done this through JavaScript. They have a way for you to do this through the JavaScript, but I do the most of the work in the html, to leave the load on the server, and that the browser already has much more leverage and freedom. That's why we added this feature. This is maybe beyond the scope of the dynamic get. It is all also placed in the query that is developed by dynamic get, that's partly why it fits. Once you've got your dynamic get set up, you will add these dynamic gets to either site views or to custom admin views. These dynamic gets is what gets the data for you. It's where you model the data that you want to work with. You can then 00:39:12 use them in site views and custom admin views. Next stop we will look at adding it to a site view and how all of that works.

Clone this wiki locally