-
-
Notifications
You must be signed in to change notification settings - Fork 178
013 dynamicGet
Sermon - Preacher Get Example
Hi we still working with sermon distributor. I'm going to use this preacher, which is a get that I already have set up here. I'll use that in our illustration. Here we can see that I have this back end 00:00:25 view selected. So let me select nothing. This is usually how it will look when you start. You'd look select this, (depending on which 00:00:39 area of the back end you want to get the data from) you'd select back end view. Which is the best way to do it.
Dynamic Get Source Selection
Then there is the Joomla database option. Would 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 actually at that stage on your database installed. That means you can reach out to other components through this dynamic get. I'm not going to do that. 00:01:21 In fact that's also an area which I haven't tested so well. You possibly might try to implement that and ran into some bugs. This stage I can't make any apologies for that since the thing you should do is, instead using back end view option. 00:01:42 You might say but why is the other option there? Well it's because that's a feature we certainly want in the application. I'm busy working in that direction, busy programming so did that feature will work without any problems. In fact for the most part if you don't do very complex mapping, if you just do a simple direct database fetch like that(cb_associations), you will be able to use this, it won't give you an issue. 00:02:09 What it really is about, is these other linked or joint database structures. That would make it complex. That might cause problems. I'm not 100% sure. Obviously it did work. I haven't tested it well enough as well as I have tested the other part and that is this back-end view. 00:02:32
There is also the custom option. Where you can just dump the whole option of using component builder to write your PHP for you. Here(custom Get) you can add custom PHP, it will add the methods data for you. This is a custom get option where you write the code 00:02:55 by hand. Where as this(Custom - dropdown) option writes the code for you. You'd select the back end view that you want to use. That back end view will be the view that you connected to your component. You need to type your name in here, and then select that package, and it will load 00:03:20 all the field names, like a.id, and a.asset, id, and a.name, and allias, and icon.
Dynamic Get Preacher View
These are all the fields inside of this(Preacher) view. I will load it and I'll put this as asset_id. I would suggest you don't change that. What you can do is you can take out a row. 00:03:50 You can remove a row like that, and you can say I don't need that row. I don't need these. Way to there, that's all the data you might want. And then you will know that this would be the variable name of the data on when these get is used. 00:04:13 That is the basic part of setting up a Get.
Get Types - Get Item/List Get Custom
I need to mention that you have getTypes as well. The getTypes have 4 of them. The getitem which will get one item from this preacher table. Then you got the getlistquery which will get multiple items. 00:04:41 Depending on how many items you want to get from the database, you would select either get item or get list. Then you get getcustom, and then you got getcustoms, that plural. The difference between these two or four is the getitem is what you will use only once per 00:05:04 view.
If you are building a custom admin view, you will select a main get either, or a getitem or a getlist. You can add multiple getcustom item or getcustoms item. You can see these as other methods that you're adding to the page, but it's not the main method. 00:05:30 You have main methods which are these getitem and getlistquery. Which by the way is the exact naming of the methods that will be used. Then you have this getcustom and getcustoms, which is almost same as these two, it's just that they are not main. There will only be another method in the model which will bring data to the view. You can add as many getcustom and getcustoms 00:06:00 methods to your view as you like, but you could only add one getitem, and one getlistquery. Usually the way we would decide on this is that we would say what is the main objective of the view? What is the main dataset that we want to use in the view? That is what we will use in the getlistquery and getitem.00:06:27
Get List Pagination
If the main purpose of the view show preachers, a list of preachers, I would use the getlistquery as the main selection here. Now you see that you have when you do a listquery, you have the option of adding pagination. That would mean whether the data should only return a certain number. Joomla has a global number. Which you set in the system administrative area under your global settings. 00:07:00 Go to system, then global configuration, then you see there is a default list limit. That is what will be use as the amount that limits the data being returned to the page. It will only return at this stage 20 items. 00:07:26 If I set that pagination to yes. If I set it to no, it will load all the data. Yes would just load some of it, and no will load all of the data. Depends on what you want to do. If you want to do an Ajax, you want to be sure that all the data is being loaded every time. You rather use JavaScript set up pagination for your view, then that is why you would 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 possibly not look right and you will need to add styling to it. 00:08:31 Component Builder doesn't know what style is on your page so they cannot make provision for all of that. But it actually can load the pagination itself. it
Join Data Views - Tables
Now here you have data and you can join this data to other database tables. Again here like with the main source you're able to select 00:08:57 joint views from a table. A view table which is the views of the component or just any database table. To one of the database tables I often connect to categories. Component builder integrates it's application. If you add a category field to any view, 00:09:22 it dynamically set up a category for your component. And integrates the category concept into your component, so it writes all that code for you and the way that Joomla's own applications like article manager does it. It's using the same conventions. If you know how Joomla article manager is bringing categories into the articles, then that is the way your component is going to do it. Here(DB Table - cb_categories) you can select categories. 00:09:54 These switches, I'll deal with them when we come and look in more detail at this area. Then you can model the data there(Selection). Model means decide what you want to return. You don't want to return everything from categories.
Join View Tables Example
But the one I want to look at first is actually this joint view table. We'll come back to the DB option. The joint view Table, let you again select from any of the other views that is part of your component. 00:10:25 Again you can select whether it should return a single row or a list of rows. When you say single row, it means it's going to join it to this other data set that you have as your main data or your main source. It will just be another item in the array. That's why you can't use the name 'Name' for example here. 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 possibly also has a value called name. So again if you select anything here(Scaling Factor - dropdown), Series, you will see that it will populate this(Selection) area with all the fields that is in that view. Then this 'AS' button here, 00:11:21 you can't use the same alphabetic number twice in the whole query. The whole get function can only use 'a' once and then 'b' once and then 'c' once and then 'd'. 00:11:40 We'd made provision up to z z. That is how many tables you can have. Only in this area here(AS).
You would first decide whether this 'Return Row Type', what type of return it will be? If you set it to multiple, these names automatically update. 00:12:02 The way that the get method will work, is it will create a new method which will get this data and add it into your item list via this relationship. I'm adding the 'On Field' as the a.series that's where the id is for the series. 00:12:24 In the joint field, I'm using the 'c.id'. 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 I wanted to return a multiple, it means that the main database which is in this case sermon, can be linked to multiple series's.
But in the system we are working with here, 00:12:56 that is not possible you can only connect a sermon to one series. That means it's certainly a single return. Then it will immediately add this series_ in front of everything to insure it doesn't clash with your a table. That's what it's doing. Again you can remove the fields you don't want but please do not edit 00:13:18 the string. It possibly would break. I want it to be possible that you can change this name to anything you like. We are going to try and do that eventually. You can be changing it will still write it this way in the code. That's part of why I'm saying you shouldn't change it not because it will break something, but because it will be ignored and you might expect something else than what it is actually doing. Still it is going to use this implementation, even if you change it. 00:13:54 It will drop the fields you don't select. If you say I 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. That means 00:14:22 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
This code if we go to the component itself, I'll show you where it writes this code. We're 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. You can actually see I'm going to 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. We go to the front end of sermon distributor. Then we are looking at the model. The dynamic get is used in the model to get the data. 00:15:33 We are looking at sermons. Let me just make sure if that. Yes, it's sermons. It's getting a list query and it's using pagination getting all this. We're looking at sermons. Sermons under the preacher id, it should be this model. 00:16:02 I could get you into the code. You can see the main method which has this id(a.name)or the data set. It is written here(selected area on video). Here you can see id, asset, name, alias, link, types, 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, id. This is where it writes it. It shows you where in the compiler it's done. Then it sets up the second one series. You can also see it says series 00:16:50 = c.id. So series, there(see video) is series, =, the c, this table, series, 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 the way that you make use of Joomla's database API. It has a thing called quotename 00:17:35 which you can pass to arrays. The first array being the name of the value, which in this case is name and alias. The second array, is what you want 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 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. This is done 00:18:23 to the filtering and the wear.
I just wanted to show how it adds this preacher as well as series to the query. If we look at the back, open up here(Join View Tables - Add), you see that series and preacher 00:18:41 and statistics. We select multiple statistics because for one sermon there can be multiple files, and per file there will be a number. So if we look at how he does that. 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 here. 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. What you need to know is that 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 type correctly. 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, this is exactly what we're saying here. We're saying, get statistics multiple, 00:20:19 join to the left. You can select any of these(dropdown). Then use the main table dot a.id, it must be equal to e.sermon. Then this is the only values I want to return from the e.sermon. The e.sermon is this(see video) value here. I'm saying 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. Puts into its place. Here's the two arrays. What it is in the database, and what it should be now. It checks whether it executes or checks whether it's got any arrays or any values. 00:21:17 Then returns that as an object list, that then gets placed inside of this space inside here.
Dynamic Get Custom Script
Now you would see this area here(see video) is custom scripting. If we go back to the dynamic get, you will see that there is a custom script area. If you click on it, you'd see that there is 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 we've received. It will add that 00:22:14 code in there, and then return the items. That is why you can model the data right there in the dynamic get. You going to write the code for the data after it's been get. You can check if I remove this code here, you'd see it tells you that there is an array of items 00:22:33 where all values are. Then I'm just saying I want to be sure that those items are set, and that they are there before I start doing it on each of them. Here I'm using the string bracket component helper functions to check whether the string is there. You can dump some nice PHP. Even before getting the item you can add some filters or get list query, 00:23:02 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. I selected category and it's a single row that's returned. I called it b. I joined it left, and I set a.catid must be equal to b.id, which is the id of the category. I only want the title and the alias. That is 00:23:44 how we set that up. Only the title in the alias and it returns that for us. Then it links it in there(see video), and that's part of what you saw here when you looked at the query option here, it's the sixth section here.
Dynamic Get Filters - Where - Ordering - Globals
Now let's look at the filters where we have a filter and an ordering and setting of globals. 00:24:12 The setting of globals is if you have a value in this query that you want to use in a custom query, which isn't even setup yet, but you want you know I'm going to need this value in the model. Then you can through this global option here, you can set a global area. Here you should maybe test it. There is an option of using 'This' and 'State'. 00:24:38 There is the different of 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 basically 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 00:31:45 Looked at it's called this one Get preacher if we Open it We see it's a It's a custom Get custom And we gave it a cluster name called get preacher and this is It's relationships So it is basically having No 00:32:04 Relationship there Neither here so it's It's not linking to other tables It's simply getting the preachers details Right there 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 but I none the less added the ordering I could actually delete this 00:32:41 And it doesn't have any globally settings okay so that is get preacher and so from the This settings here I don't think there's custom scripting nope from this settings here component builder writes all this code You'd see that we have this function everywhere called UI kit comp And then we using a global method a static method get ui comp it's a method that I built if you know uikit if you don't know it go to get UI kit or just google it It's a It's a JavaScript Library CSS JavaScript library which really makes modeling of your views very nice and easy And it has components that you can use So like tool tip and model 00:33:45 All these kind of models but Gordian is another component And we don't load all of it's components every time so what we've done is we've Written in PHP a method that looks at Fields that are text area fields And normal text Fields no mostly okay it's Not looking at every field is only looking at the text Fields and editor Fields so in in this Component we know that this description field is a Editor field and so we are sending it to this method now you can go look at this Method Method In your helper class it's over there Here's the method so So it has the classes that already has been identified which is what this 00:34:56 Initial this component area sorry Field name field value model field value is actually holding it's Holding any component names that already has been identified this gets past also here with the content then we check in the content whether there is a class UI UK underscore and if it's not false we start looping to check what What what are all the components that are in there and here is the list of the components that are available and so 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 and then we added back to this Array so it updates this eventually you have an array of All those items and in the view we go to the view 00:36:00 Which in this case is gonna be preacher We open the view dot HTML We get to a place which basically everything is gonna be happening so These are of the components that go in 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 and so it Places it here dynamically but since you could've added some components inside of the script that that is stored in the description area it now has this get uikit component which basically reach back into the model and 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 Get UI kit component basically through this method it is reaching in Into getting that array and once it has that array we basically check whether it is set Whether it is an array and if it is an array we set To the array that is already on this page then over here we loop through that array And we load in those components CSS and JavaScript as required so that You always can be sure that the UI kits 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 tag html tag and 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 now I know you could have done this through JavaScript You know it is fact they have a way for you to do this through the JavaScript but to me I felt Let me do the most work in the html so relieve the load on the on the server And that the browser already has much more Leverage and Freedom so that's why we This feature this is maybe Beyond the scope of the get the dynamic get But since we ran into I quickly mentioned it here okay so it is all Also placed in the query that is developed by Dynamic get that's partly why it Fits so once you've got your Dynamic get set up you now will add these dynamic Gets to either site views or to admin custom admin views so these Dynamic gets is what What gets the data for you and it's where you model the data that you want to work with and you can then 00:39:12 Use them in site views and custom admin views. Now next stop we will look at adding it to a site view and how all of that works. Thank you for watching.
- Home
- Beta Testing
- Custom Code
- PHP Settings
- Demo Component
-
Tutorials
- Hello World JCB
- Intro JCB Guide
- JCB Installation Steps
- Planning Components
- Field Type Overview
- Basic Fields Creation
- Admin View Management
- Advanced Field Usage
- Admin Component Integration
- Component Setting Customization
- Scripting Components
- Component FTP Options
- Dynamic Get Method
- Site View DynamicGet
- Site View Templates
- Template Setup Guide
- Layout Configuration Steps
- Custom Admin Management
- Adding Site Views
- Custom Admin Integration
- MySQL Demo Tweaking
- Global JCB Settings
- Custom Time Field
- User Helper Integration
- Email Helper Usage
- Message Store Email
- List View Unescape
- Export Import Customization
- Overwrite Custom Fields
- List Field Filtering
- Automatic Code Import
- Manual Code Implementation
- Component Export Import
- Custom Admin Buttons
- Translation Management
- Site View Permissions
- Component SQL Updates
- Site Edit Configuration
- JCB Backup System
- Helper Structure Integration
- JCB v2.5 Upgrade
- Tab Setup Guide
- JCB v2.6 Release
- Extended HelloWorld
- Field Rule Validation
- Community Snippets Intro
- Snippet Forking Tutorial
- Pull Request Snippets
- Library Manager Area
- Excel-based Translation
- Dynamic Router Details
- Database Auto Updates
- Subform Quick Demo
- VDM Package Import
- Dynamic File Inclusion
- File Field Upload
- Drag-n-Drop Upload
- Quick HelloWorld JCB
- Non-database Fields
- Dashboard Customization
- Menu Prefix Toggle
- Community JCB Packages
- Collaborative JCB Workflow
- JCB Package Install
- JCB JAB18 Event
- Convenient New Fields
- Component Language Strings
- Library Functionality Anticipation
- Join Field Relations
- License Template Change
- Code Reusability
- Local Dev Environment
- Extended Field Types
- Joomla Custom Fields
- Custom Field Expansion
- Site View Listing
- Run Expansion Method
- Form Site View
- Field URL Update
- Additional Helper Methods
- Field Validation Rules
- New Placeholder Feature
- Component Config Params
- Per-field Default Values