diff --git a/011-Component-Scripts.md b/011-Component-Scripts.md index e98229f..6aadaac 100644 --- a/011-Component-Scripts.md +++ b/011-Component-Scripts.md @@ -8,43 +8,46 @@ The 'user helper method' is simply code. If you don't know how to write PHP this ### Example Helper Method(Create User) -Ideally you would connect that company to a user in the system. (It can happen that you are not going to add that company to a user because a user can have multiple companies). If you click on this tab'select user', you could select the user. But if you haven't selected a user and you've entered an email address and a name [00:01:49](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m49s) and the needed information, then once you click save, close or save, the system will actually create a user for you - and will automatically email the user details to that user. That is because of that specific helper class that I added. Clicking 'helper class', [00:02:14](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m14s) it doesn't do it on its own, you need to write the code for it. Let me show you where I did it in the controller(See video). There is an area if we open up company, called: 'PostsaveHook'. [00:02:38](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m38s) +Ideally you would connect that company to a user in the system. (It might be that you won't add that company to a user because a user can have multiple companies.) If you click on 'select user', you could select the user. [00:01:49](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m49s) But if you haven't selected a user, and have entered an email address, a name, and the needed information, then when you close or save the system will create a user for you and will automatically email the user details to that user. This is because of that specific helper class that I added. [00:02:14](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m14s) It doesn't do it on its own; you need to write the code for it. Let me show you where I did it in the controller. (See video.) If we open up company there is an area called: 'PostsaveHook'. [00:02:38](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m38s) When we looked at the admin views we could target this area. That is what I did. -Remember when we looked at the admin views we could target this area. That's exactly what I did. This is how we go about: I'm in the 'admin view' for 'company'. If I go to PHP you would see that I have some Ajax there and I have an area which is the 'postsavehook method'. [00:03:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m03s) In the postsavehook method, I'm basically checking some things, some values. If the user does not exist, A check is done (See video). Then the 'create user' is used. [00:03:41](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m41s) This placeholder convention has been mentioned before. Here you are using the brackets convention not the # one.'[[[Component]]]Helper' and this will be replaced with the components code name. It gets the helper class: create_user. In the helper class of this component, [00:04:13](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m13s) if this is closed, go to the helper and open the 'helper class'. That is the name 'costbenefitprojection'. It is the components name and then it's called helper. In helper class there is a feature called 'create_user'. [00:04:39](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m39s) It gets an array in it, and that array has some values which we will be using, like password 1, password 2. and it will set the password. I'm not going to explain this code. Basically it just shows you where the function is. The function was added to the components helper class and in that script, I'm simply calling that function after having build the user. I set the array as; 'name' and the email as 'validData'. The function, if there is no password set, will set a random password and again use another method which is also part of the helper class we've exported with all helper classes, this 'random [00:05:28](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m28s) method' where you can get a random string. That is creating a user and then it sets up the password and then it gets the array ready. It gets a model. The model, I got it from there, 'getmodel'. Again we are using a component builder custom method which gets the specific model from the system and then fires the register method upon this dataset and then updates [00:06:11](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m11s) the parameters for the system regarding this new user. Sends the email and then returns the ID. We need the ID. [00:06:41](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m41s) If you don't have the ID, it will send a message to the user and if we have the ID, it will store it into that database to connect that item to that user automatically and then click 'save'. That is custom scripting. [00:06:59](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m59s) +This is how we go about it: Go in the 'admin view' for 'company'. If you go to PHP you'd see some Ajax there and an area which is the 'postsavehook method'. [00:03:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m03s) In the postsavehook method, I'm checking some values. If the user does not exist, A check is done, then the 'create user' used. (See video.) [00:03:41](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m41s) This placeholder convention had been mentioned before. Here you use the brackets convention, not the # one.'[[[Component]]]Helper.' This will be replaced with the component's code name. It gets the helper class, create_user. If this is closed in the helper class of this component, go to the helper and open the 'helper class'. [00:04:13](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m13s) The component's name is 'costbenefitprojection' and is called helper. In helper class there is a feature called 'create_user'. [00:04:39](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m39s) It gets an array in it, and that array has values which we will be using, like password 1, password 2. It will set the password. This shows you where the function is. The function was added to the components helper class and in that script, I'm calling that function after having build the user. I set the array as 'name' and the email as 'validData'. The function, if there is no password set, will set a random password and use another method. This 'random method' where you can get a random string is part of the helper class we've exported with all helper classes. [00:05:28](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m28s) It creates a user, sets up the password, and then gets the array ready. It gets a model. I got the model from there, 'getmodel'. Once more we are using a component builder custom method. It gets the specific model from the system then fires the register method upon this dataset and updates the parameters for the system regarding this new user. [00:06:11](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m11s) It sends the email and returns the ID. [00:06:41](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m41s) We need the ID. If you don't have the ID, it will send a message to the user; if we have the ID, it will store it into that database to connect that item to that user automatically. Save. [00:06:59](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m59s) ### Add UiKit -All that this switch does is that it adds that method to your helper class. Whereas this switch adds the Uikit library to your media folder, as well as integrates it dynamically wherever you use [00:07:19](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m19s) the Uikit class names. You won't need to write that in any custom way, it automatically adds it. The same goes with FooTable. +This switch adds the method to your helper class. (See video.) Whereas this switch adds the Uikit library to your media folder as well as integrates it dynamically wherever you use the Uikit class names. [00:07:19](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m19s) You won't need to write it in any custom way; it automatically adds it. The same goes with FooTable. ### Add Global CSS To Admin Back End -This CSS is global CSS for all the back end views. If you want to add CSS that would target the entire back end, then you do it here. +This CSS is global CSS for all the back end views. If you want to add CSS that would target the entire back end, you do it here. ### Add Custom PHP Helper Admin Class -This is a place for you to add your own custom scripting to the helper_admin Class. [00:07:47](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m47s) As you can see ,here is a whole custom scripting here for Sermon distributor. For the admin area, as well as an event. +This is a place for you to add your own custom scripting to the helper_admin Class. (See video.) [00:07:47](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m47s) Here is a whole custom scripting for Sermon distributor and the admin area, as well as an event. ### Add Global Admin Event -This event concept has been briefly mentioned before, but what we want to achieve with the event is basically: Let me explain. [00:08:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m09s) If you look at the back end part of 'sermon distributor', it has a file which is the in main file which Joomla calls 'first', and in that file it basically triggers that global admin event. The global admin event is nothing else than a function inside of your helper function. So it always triggers it, [00:08:40](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m40s) if you add that switch. Then it passes the document object. The document object is being built up here. I'm just passing it over to the global event. There is no need to clear it. If I was to open the helper class, which we have here(See video), and scroll to the top, it says here [00:09:08](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m08s) 'loaddropboxajax'. This again is just another function. I wrote that function that you can add whatever functions you want to run globally every time a page opens. That is a way to run it like a chronicle task on the front and the back end of the component. If you have things that you want to be done chronically, this feature is targeted at doing that. [00:09:35](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m35s) In this instance we are loading the 'LoadDropboxAjax'. If we go back to the component, you see that I am just adding that script. First I just clicked global admin event 'yes' and added that script. That's all they added. That script was taken and placed inside of the global event. The trigger'globalevent' is set by component builder you don't need to write that. [00:10:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m03s) It will insert this'globalevent' trigger itself just because you clicked 'yes'. You need to then just add the script that must run inside of the global event. Which I decided to be another function and then this function which I want to run, I added to the admin view, you see here(See video) at the admin helper class. [00:10:29](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m29s) I added that function . So I basically just used that'loadDropboxAjax' name, and called it 'self', because we are inside of that class. That's how you call 'static class method' and pass same information. In my method I'm adding JavaScript to the document object. I want that document and then I set 'addScriptDeclaration'. [00:10:59](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m59s) That means on every page of this component in the back end, it adds this little script which then calls by Ajax which I explained previously and it starts checking the Dropbox listing automatically. This automatic feature has been added to the component so that you can do the same in other components. That's the purpose of the event switch. The same is applicable to the site area. [00:11:37](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m37s) I also added that same class. +This event concept has been mentioned before, but this is what we want to achieve with the event. [00:08:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m09s) In the back end part of 'sermon distributor' there is a file. It is the in main file which Joomla calls 'first', and in that file it triggers that global admin event. The global admin event is nothing but a function inside of your helper function. It always triggers it if you add that switch and passes the document object. [00:08:40](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m40s) The document object is being built up here. I'm passing it over to the global event. There is no need to clear it. If you open the helper class and scroll to the top, it says loaddropboxajax'. [00:09:08](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m08s) This is just another function. I wrote it so that you can add whatever functions you want to run globally every time a page opens. It can run like a chronicle task on the front and the back end of the component. If you have things that you want to be done chronically, this feature is targeted to do that. [00:09:35](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m35s) For instance, we are loading the 'LoadDropboxAjax'. If we go back to the component, you'd see that I am adding that script. First I clicked global admin event 'yes' and added the script. That's all they added. The script was taken and placed inside the global event. The trigger'globalevent' is set by component builder; you don't need to write it. [00:10:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m03s) It will insert this 'globalevent' trigger because you clicked 'yes'. Then you need to add the script that must run inside of the global event. This function, which I want to run, I added to the admin view at the admin helper class. [00:10:29](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m29s) I used the 'loadDropboxAjax' name, and called it 'self', because we are inside of the class. That's how you call 'static class method' and pass same information. In my method I'm adding JavaScript to the document object. I want that document and then I set 'addScriptDeclaration'. [00:10:59](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m59s) It means that on every page of this component in the back end, this little script is added which then calls by Ajax and checks the Dropbox listing automatically. This automatic feature had been added to the component so that you can do the same in other components. That's the purpose of the event switch. The same is applicable to the site area. [00:11:37](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m37s) ### Add Custom PHP Helper Site View -Why is there different helper classes for the front and the back? Well, it's about security, and permissions. - - There are things that I wanted to do in the back end, where not many questions are asked. Where on the front I might be more protective. So for that reason the implementation is also often different in the front than in the back. That's why we have two different files: Helpers site class, [00:12:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m09s) and the Helper admin class , custom scripting can be added. I added that same script to the front and also added a site event which also triggers that same script. What if everybody triggers the script? Is it not going to run multiple times? Well, [00:12:32](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m32s) that's exactly part of what has been done. I actually added a feature in the Ajax call. That logs whether it's already active. If it is active, it just ignores that call. So basically it has a controller over whether it should run or not. It has a timer you can set [00:12:56](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m56s) for the sermon distributor. You can set how often you want Dropbox links to be updated. Every day, every 2 days, and so this script(See video). If it wants to update and it's not time it just dies. Since it's Ajax the user himself don't even notice a delay in his page. The page opens as fast as it always do and then fire that Ajax call to the server. Which will starts this whole process on the server. This is all possible inside of component builder, simply through these custom areas. +Why are there different helper classes for the front and the back? It's about security and permissions. For example, there are things that I want to do in the back end where many questions aren't asked; on the front I might be more protective. Hence the implementation is often different in the front than in the back. That's why we have two different files: the Helpers site class and the Helper admin class where custom scripting can be added. [00:12:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m09s) I added the same script to the front and added a site event which triggers it. What if everybody could trigger the script? Is it going to run multiple times? [00:12:32](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m32s) The answer is that it is exactly part of what has been done. I added a feature in the Ajax call that logs whether it's active or not. If it is active, it ignores that call. It has a controller determining whether it should run or not and a timer that you can set for the sermon distributor. [00:12:56](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m56s) You can set how often you want Dropbox links to be updated, or whether it wants to update or not. Since it's Ajax the user himself don't even notice a delay in his page. The page opens as fast as it always do and fires that Ajax call to the server which will start the whole process on the server. This is all possible inside of component builder through these custom areas. ### Add MySQL Dump -You can also add a SQL dump. [00:13:50](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m50s) Instead of adding it to the actual views. You can export all the views and add them here'MySQL'. It will be actually added to the same file. So don't do it twice. This is another area to add a SQL dump file. +You can also add a SQL dump. [00:13:50](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m50s) Instead of adding it to the actual views you can export all the views and add them here. (See video.) It will be added to the same file, so don't do it twice. This is another area to add a SQL dump file. -### Dashboard Methods(with example) +### Dashboard Methods (with example) -Then we have this nice feature called dashboard methods. Let me show you what I've done with it. All this data that I'm showing you is dummy. [00:14:23](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m23s) It is not related to this application but it is just me testing it. I wanted to add this usage statistics to the component, so you could see which country has done what, when in what area. I needed to take a lot of different database tables and calculate, by using certain ways. I wanted to have that on the dashboard. The dashboard already have all these icons. I didn't want it [00:14:53](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m53s) to add another custom view, which I could have done, custom admin view. I wanted it simply right there at the moment of the page load. So we added that feature to Component Builder and we called it dashboard methods. Now let me go to one where I actually had it implemented. +Let me show you what I've done with dashboard methods. All this data that I'm showing you is dummy. (See video.) [00:14:23](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m23s) It is not related to the application but I'm just testing it. I wanted to add this usage statistics to the component, so you can see which country has done what, when, and in what area. I took a lot of different database tables and calculated by using certain ways. I wanted to have that on the dashboard. The dashboard have all these icons already. I didn't want it to add another custom view. [00:14:53](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h14m53s) I wanted it right there at the moment of the page load. So we added this feature to Component Builder and called it dashboard methods. -I could spend more time in explaining and less on typing. I created a [00:15:26](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m26s) method called 'getusagedata'. It's a public function method and inside it I added my script. Inside of this script I'm calling other methods which I made it protected. the script that must be called from the dashboard tab. You set that up here'Dashboar Tab -Add'. Here is the tab, and it's HTML. We called the tab 'Usage Statistics' and the header we made 'Table', [00:16:01](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m01s) and here(see video) is the 'HTML'. Which we are using. and in the HTML you see PHP and the way we do that is with that convention of '?' and checks whether the usage data is there. +I created a method called 'getusagedata'. [00:15:26](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h15m26s) It's a public function method inside which I added my script. Inside this script I'm calling other methods which I made to protect the script that must be called from the dashboard tab. You set that up here. ('Dashboar Tab -Add'.) Here is the tab and it's HTML. We called the tab 'Usage Statistics' and the header 'Table.' (See video.) [00:16:01](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m01s) Here is the 'HTML' which we are using. In the HTML you see PHP. We do it with that convention of '?' and checking whether the usage data is there. -How do I know that I should target 'this usage data' and then 'items'? Well, this area 'usagedata' is a convention area. The way that, that convention works, is [00:16:46](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m46s) by that one there. (see video). So'Usage data' relates to 'usage data'.The moment you add the word 'get', in front of a function, it will be added to a 'global', the result of that 'get' will be added to '$this->' and without the 'get' name, so that is the convention. [00:17:15](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m15s) The convention is you could have called that 'get', the "manonthemoon". Then this would be 'manonthemoon', obviously all in lowercase. That'get' will be dropped and this 'UsageData' is going to be used lowercase, just as the 'this'. [00:17:37](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m37s) That's the convention. I know it might not be that obvious but it works. So your other functions, if they are protected should not have the word 'get' in it. At the moment it is set, to 'set'. That one is 'set', this one is 'visitcheck'. This one is set 'companies' and set 'countries'. [00:18:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m03s) +How do I know that I should target 'this usage data' and the 'items'? This area 'usagedata' is a convention area. The convention works by this one here. (See video.) [00:16:46](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h16m46s) 'Usage data' relates to 'usage data'. The moment you add the word 'get' in front of a function it will be added to a 'global.' The result of that 'get' will be added to '$this->' without the 'get' name. [00:17:15](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m15s) The convention is that you could have called that 'get', the "manonthemoon". Then this would be 'manonthemoon', all in lowercase. The 'get' will be dropped and this 'UsageData' will be used lowercase like the 'this'. [00:17:37](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h17m37s) I know the convention might not be that obvious, but it works. If your other functions are protected they should not have the word 'get' in them. (See video.) [00:18:03](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m03s) -A lot of PHP can be added in here and all these PHP together gets the data that is needed on the page. When all the data is collected it is placed in what is seen as the 'item'. A field or a method value is returned. [00:18:43](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m43s) This method value is being populated in this sub functions and in one of them is added the name, 'items' as a pointer and it is a object. [00:19:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m09s) The code itself will not be explained right now, but this'usagedata' is getting returned, because it's an object. If you look here you are able to target 'items' as an object and if it exist, if it is set, you can start looping through items and certain places you are using totals and different values. That is just adding some of that data to the page. [00:19:45](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m45s) This could have been a simple class, in fact you could have left this out completely and could only put a comment. You could have done this(see video). You can set it 'not needed' and then in here 'Dashboard Tab - Add' you can do HTML. If you just want to give information to the user concerning the person who made the component, maybe some would like to run a RSS feed here(See video), you could have done it right here. [00:20:34](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m34s) I'm just showing you that you can reach into PHP here, and that the PHP that you reached in, has the convention of dropping the get and then using that front area, 'usage data', to place information in which you can parse in your HTML as you would do in any other component view. This has been just a quick overview of the script area of a component. It's something that might become very useful if you are a developer, to inable you to add custom scripting to a component through this methods. In the next tutorial we will look at 'ReadMe' and maybe their FTP server concepts. [00:21:27](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m27s) +### Adding Data to a Page + +A lot of PHP can be added here, all of which together gets the data that is needed on the page. When all the data is collected it is placed in the 'item'. A field or a method value is returned. [00:18:43](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h18m43s) This method value is being populated in these sub functions. The name, 'items' is added in one of them as a pointer; it is a object. [00:19:09](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m09s) The code itself will not be explained right now, but this 'usagedata' is getting returned because it's an object. Here you are able to target 'items' as an object; if it exist and is set you can start looping through items and certain places in which you are using totals and different values. [00:19:45](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h19m45s) + +This could have been simple. You could have left this out completely and only placed a comment. You could have done this. (See video.) You can set it 'not needed' and in here ('Dashboard Tab - Add') you can do HTML. If you just want to give information to the user concerning the person who made the component, you might like to run a RSS feed here. (See video.) [00:20:34](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h20m34s) You can reach into PHP here, and the PHP that you reached in has the convention of dropping the get and using the front area, 'usage data', to place information in which you can parse your HTML as you would do in any other component view. + +This has been a quick overview of the script area of a component. It might come in very useful if you are a developer enabling you to add custom scripting to a component through these methods. [00:21:27](https://www.youtube.com/watch?v=xY9TWQrF8AQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h21m27s)