34 013 dynamicGet
Amigo edited this page 2019-08-08 17:03:33 +02:00


Sermon - Preacher Get Example

00:00:00 (Click on these time links to see Youtube video)

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.

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 run 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 the 'Preacher' view. Load it and place this as 'asset_id'. (See video.) It is suggested that you don't change that. 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.

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 'Global configuration' where there is a 'Default list limit'. This will be used as the amount limiting the data being returned to the page. It will only return twenty items. 00:07:26 If I set the 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'd 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, the 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 this, 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 its 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; Joomla's own applications, like Article Manager, does it. Your component is going to do it the same way Joomla article manager is bringing categories into the articles. 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 other views that are part of your component. You can select it to return a single row or a list of rows. If single row is chosen it will join it to the other data set you have as your main data or main source. It will be another item in the array. For example, that is why 'Name' cannot be used in this instance. (See video.) 00:10:51 It needs to have the series_ in front of it so that it doesn't clash with the other data set that might have a value called 'Name'. So, 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 a single return. It will 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 edited as it may malfunction. Further development still needs to be done in this area, making it possible to change the name to anything you like. At the moment you can change it but it will still write it this way in the code, dropping the fields you don't select. 00:13:54 If you say that you don't want these, it won't get those fields and only this data will be returned. Again, you can have equal, not equal, equal or not. We also have 'IN' function. 00:14:22 If this 'On field' is an array, you can use the 'IN' function to make sure that it checks whether the ID is in the array.

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' and we'll look at the 'filters' and the 'where'. 00:15:06 Refresh the page, then go to the code. Since 'get' is used in the front of the component, go to the front end of 'sermon distributor', not the admin area. The dynamic get is used in the model to get the data. 00:15:33 It's getting a list query and using pagination getting all this. (See video.) 00:16:02 In the code the main method which has this id(a.name) or the data set may be seen. (See video.) 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. It writes it here, showing you where in the compiler it has been done. It sets up the second one; 'series' saying 'series = c.id''. (See video.) 00:16:50 It also tells you what it wants from 'c': the 'name', the 'alias', and a series name changing it to 'series' since this is in the select query. 00:17:12 This 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 'quotename', which you can pass to arrays, the first array being the name of the value, which in this case is 'name' and 'alias'. 00:17:35 The second array is what is needed once the query is completed. It links this into the the query one-by-one. (See video.) All of those, even the category one, is linked in here. 00:17:59 It checks for 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 but a number, it adds it directly. That is where the query is done. Return false if there is no id. 00:18:23 This is done through 'filtering' and 'where'.

An example on how it adds the preacher as well as series to the query: In the back open 'Join View Tables - Add', to find series, preacher, and statistics. 00:18:41 Multiple statistics are selected because there can be multiple files for one sermon. (There will be a number per file.) 00:19:02 It does the query and in 'getitem' adds a new function called 'getidSermonstatistics' with a random key, 'Fcff_E', to ensure it doesn't conflict with any other method on the page. The 'Fcff_E' random key places it into this variable. 00:19:27

When we look at the site layout area and the templates I'll talk about this transition again and the fact that you need to know that it is in this variable. I'm trying, inside of your layouts and your site views, etc, to give you the correct name, but it isn't watertight. 00:19:51 You might need to check this if it doesn't work. We're adding statistics into this (idsermonstatistic) variable through a method also on the page and we are passing the ID of the sermon. 00:20:19 Go to UI, 'statistics', 'multiple' and join to the left. You can select any of these. (See video.) Use the main table 'a.id'; it must be equal to 'e.sermon'. These are the only values that needs to return from the 'e.sermon'. The 'e.sermon' is this value here, and 'a.id' must equal with e.sermon. (See video.) 00:20:48 In the code this function 'idsermonstatisticFcff_E' takes the 'id' and places it next to 'e.sermon'. The two arrays are what it is in the database and what it should be now. It checks whether it has any arrays or any values, then returns it as an object list which gets placed in this space. (See video.) 00:21:17

Dynamic Get Custom Script


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

Dynamic Get Join DB Tables


Coming back to the 'Join View Tables' area. Let's 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' to be equal to 'b.id' which is the ID of the category. Only a title and alias is needed. That is how this is set up. 00:23:44 Only the title and the alias are necessary and has been returned. It links it in there which is part of what is seen here when viewing the query option, the sixth section. (See video.)

Dynamic Get Filters - Where - Ordering - Globals


Here is a 'filter', a'where', an 'ordering' and a 'setting' of globals. The 'setting' of globals: if you have a value in this query that you want to use in a custom query (which isn't 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. It could be tested here. (See video.) There is an option to use 'This' and 'State'. 00:24:38 It is the different set types. You can set the value to 'State' or the value to 'This'.

It is necessary to know the key. For example in this case, if 'name' is used it won't work because there are more than one name. Usually this global function only function well when you return a single item. 00:25:01 When 'getitem', not 'getlistquery', is done you can give it a name because it makes sense. It won't add it to the global scope of the model that you can access through other model methods which are custom methods. 00:25:24

There is a list of possible filtering. Depending on what needs to be done any of these may be selected. (See video.) 00:25:45 Some of them aren't formulated yet. 'Date', for example, doesn't work well yet. These do: 'Categories', 'user', 'group', 'access level', 'user' 'id', the function 'variable', array', 'value', 'repeatable value'. (See video.) You can use and implement them. 00:26:15 To know how it works some knowledge of PHP is needed. You need to compile it and look in the code what it has done and where it placed what. That is why this is all set in the model. For example, we wanted to do a 'JRequest::getint by id'. 00:26:39 This is the get area that has been added. In the code you will see 'State Key' and 'JRequest::getint by id'. It is a function variable; it does not change or adapt this at all. It indicates that it must be equal to 'preacher'. Since Component Builder doesn't know if this variable is going to be a string or integer, this function has to check if it is a string or a number and then build up the query respectively. It is the only way to implement it at this stage. 00:27:08

Dynamic Get Access (Default added)


We have a bunch of values that fire every time in a custom dynamic get model. You might need these values. (See video.) Instead of doing custom scripting to get these values on the page, these values gets dynamically added every time. The 'userid', the 'group', the 'authorised group', the 'access level', the 'app', and the 'input values' are on the page by either URL or post; it indicates that it has been initiated, and set it to true. 00:28:08 If you have custom methods, like 'getpreacher', it checks whether it had been set. If it had, it does not set it again; it is ready to be used. But if it hasn't been set, it sets it, and again sets it to true. 00:28:32 These global variables can be used inside the code like the global variable we spoke of earlier. Out of that global variable we access the 'levels', which has the get authorized view levels of the specific user that has now accessed this model or the view this model belongs to. If it is in the access levels. 00:29:00 'Public' is another access level. If the user isn't signed in, he is 'public'. This will validate true in the query. Set it up by adding access level in 'a.access'. 00:29:28 Check in the main source table for 'a.access' if the user is there. So you don't need to add a 'state key' because the code is done for you.

Dynamic Get "Where"


You can add any table key equal to a certain value.The value could be another table like "b.field" or it even a global variable, like we said we can set up. It can also be an 'userid' which is already on the table. It could be done as in this case, only an integer, '1'. It is important to make sure that all the sermons returned are published. 00:30:18 If you have an unpublished sermon it won't be returned at all.

Dynamic Get Ordering


To set up a 'getlistquery' with pagination through this ordering method use the 'a.ordering' and send. You can order all the items. Add many as you like. Be sure the table that you ordering could use a name. It could be a 'name', as in an ordering table key. You can do descending or ascending which would be added to the query. 00:31:03 It also added ordering to the data set from your dynamic get method. With the joint view tables you can do dependency calls from other tables in the back end, bringing the data together into one items array. 00:31:25 That's what dynamic get is for. There is a main source on the model.

'Getpreacher' is another dynamic get function we looked at. 00:31:45 If it is opened, it is a 'getcustom'. Its custom name is 'getpreacher'. These are its relationships; in this instance it does not have any relationships or links to other tables. (See video.) 00:32:04 It gets the preachers details right here, but has a filter which uses the same integer and access levels as the filters. (See video.) It uses a 'where'; it can be seen that it is published and that it does not need ordering, because it is one preacher. 00:32:41 It doesn't have any global settings. From these settings, Component Builder writes all this code. We use this function called 'UIkitComp' and a global static method, 'getuikitcomp'. It's a method that VDM built. To get more acquainted with Uikit, google 'getUIkit'. It's a CSS JavaScript library, which makes the modeling of your views easy. It has components that you can use, like tool tip andall, etc. 00:33:45 Guardian is another component. But not all of its components are loaded every time.

We wrote a method in PHP that looks at text fields and editor fields. This is an editor field, so we send it to 'getuikitComp' method. View this method in helper class 'sermondistributor'. It has the classes already identified which is what this initial model field value holds. 00:34:56 It holds any component names that has already been identified. This also get passed here with the content. Check in the content whether there is a class='uk'; if it's not 'false', start looping to check which components there are. A list of the components that are available can be seen. It is determined on-the-fly whether these components should load by looking at the content placed in the description field. It is then added back to this array. (See video.) This is updated and eventually you have an array of the items. 00:36:00 In the view, go to the 'view', in this case, 'Preacher', and open 'view.html.php'. When Component Builder compiled the application these are the components that look inside the content of your site view, as well as your custom admin view, and identify that these components must be loaded for Uikit. It is placed here dynamically but since you could have added some components inside the script that is stored in the description area, it has 'getuikitcomponent' which reaches back into the model and gets the variables' value through a method at the bottom of this page,'getuikitComp'. (See video.) 00:37:04 Through this method it reaches in to get the array. Once it has the array, check if it is set and an array. If it is an array, set it to the array already on the page. Here loop through the array and load these components, CSS and JavaScript, as required. (See video.)

The Uikit's needed components will be loaded on the page by 'user' adding some of the components to its description as style. While Uikit works like Bootstrap, the class name can be added to the specific DIF or HTML tag and activate the needed scripting around it. 00:38:08

You can do this through JavaScript, but I do most of it in the HTML to leave the load on the server. That's why this feature has been added, although it is perhaps beyond the scope of the dynamic get. It fits partly because it is placed in the query developed by dynamic get. Once you've dynamic get set up, these dynamic gets may be added to either site views or custom admin views. These 'dynamic gets' are what gets the data for you. It's where you model the data that you want to work with. 00:39:12 You can then use them in site views and custom admin views.