Updated 011 Component Scripts (markdown)

Amigo 2019-07-16 13:38:06 +02:00
parent da0c4ba1e2
commit 4489798cd1

@ -16,7 +16,7 @@ The 'user helper method' is simply code. If you don't know how to write PHP this
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. 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.
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) 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.
### Add UIKit ### Add UIKit
@ -62,7 +62,7 @@ Let me show you what I've done with dashboard methods. All this data that I'm sh
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 '<?php echo,' then closing it there '>?' and checking 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 '<?php echo,' then closing it there '>?' and checking whether the usage data is there.
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) 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.)
### Adding Data to a Page ### Adding Data to a Page