From ae9798634ba62aa1e4ee9897460a32b7ca26047f Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Mon, 3 Jun 2019 09:50:13 +0200 Subject: [PATCH] Updated 007 Admin Views (markdown) --- 007-Admin-Views.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/007-Admin-Views.md b/007-Admin-Views.md index c15367c..c829841 100644 --- a/007-Admin-Views.md +++ b/007-Admin-Views.md @@ -130,30 +130,28 @@ In sermondistributor, which is the component to which that view belongs, there i This is where this php script is going to be used. (See video.) I added the Ajax controller concepts here, but the actual JavaScript that fires off all this is set to the global event which means that every time a back end area is opened in this component, it loads that JavaScript to the view. [01:10:00](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h10m00s) JavaScript then executes an Ajax request which starts updating the Dropbox listing. Sermondistributor is able to link to media inside of a shared Dropbox folder. This whole method here that we looking at passes that Dropbox folder every so often to make sure that it's up to date. [01:10:28](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h10m28s) That's what it's all about. - - **Get Item - Items Joomla API Method** -Here you can see that if you know the Joomla API, you know that it has a (getitem method) [01:10:45](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h10m45s), it has a (getitems method) in the model. In the model there's a (getitem method) in the editing model. In the list model there is a (getitems method). Then there's a (getlistquery) in the (jmodellist). And there is a (safe method), there's a (postsavehook method) in the controller. There is (allowedit method). +Here you can see that if you know the Joomla API, you know that it has a 'getitem method'. [01:10:45](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h10m45s), it has a 'getitems method' in the model. In the model there's a 'getitem method' in the editing model. In the list model there is a 'getitems method'. Then there's a 'getlistquery' in the 'jmodellist'. And there is a 'safe method', there's a 'postsavehook method' in the controller. There is 'allowedit method'. [01:11:10](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h11m10s) -There's a (batchcopy method). There's a (batchmove method). There's a (script before delete) method. There's a (script after delete). These are all PHP places in which you can dump custom scripting. +There's a 'batchcopy method'. There's a 'batchmove method'. There's a 'script before delete method'. There's a 'script after delete'. These are all PHP places in which you can dump custom scripting. **Save Method** -If you want the save method, [01:11:32](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h11m32s) you need to know where the save method is, so if I would open sermon here, scroll down to get item. So you can add custom scripting to the get item method. [01:12:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m06s) -There is save method and so if we go back here and we click on the save method, it says here, that should run PHP here, that should run in the save method. And then you have the data, it's a array and it's called [01:12:27](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m27s) data. So If you look here it means you're able to target that value. It gets placed into save. And I am sure that your custom [01:12:47](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m47s) value code will be placed in before the parent saved. But if you do not know in any of those custom scripts where that code will be set. What you can do is just type: it is [01:13:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h13m06s) loaded here. Save it and compile the component and then go look at the code. And you will see where it is showing up. And then you can add and say I've got all these values already in the script, because all that component builder is going to do it's just going to dump, let's say, (it is loaded here) [01:13:37](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h13m37s) That is how it will look. It'll just add the string. So when the component itself runs it will treated as code. This is a comment but I mean if it was code. It will just execute. So it is the way for you to add custom scripting right into your component almost anywhere. You are able to target through these switches. +If you want the 'save method', [01:11:32](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h11m32s) you need to know where the 'save method' is, so if I would open 'sermon' here, scroll down to 'get item'. So you can add custom scripting to the 'get item method'. [01:12:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m06s) +There is 'save method' and if we go back and we click on the 'save method', it says; "PHP Here that should run in the 'save method'(array). And then you have the $data, it's a array and it's called [01:12:27](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m27s) $data. So If you look here it means you're able to target that value. It gets placed into 'save method'. Most likely your custom [01:12:47](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h12m47s) value code will be placed in before the '(parent::saved($data))'. But if you do not know in which of those custom scripts that code will be set. Just type: it is [01:13:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h13m06s) loaded here. Save it and compile the component and then go and look at the code. And you will see where it is showing up. And then you can add and say I've got all these values already in the script, because all that component builder is going to do it's just going to dump, let's say, (it is loaded here) [01:13:37](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h13m37s)(See video) That is how it will look. It'll just add the string. So when the component itself runs it will treat it as code. This is a comment but if it was code it will just execute. It is the way to add custom scripting right into your component almost anywhere you are able to target through these switches. **Post Save Hook** -The post save hook [01:14:05](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m05s) is actually in the controller not in the model. So You go to the controller sermon. Scroll to the bottom and you see there is a (postsavehook). It basically gives you the model and it gives you the valid data and you can actually can perform extra features on it. [01:14:27](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m27s) But in all these things you should just read the description. It says "PHP here that should run in the postSavehook Method and there is the (object)$model is the data model object and (array) validated data". So if you just read our little note here, then you can start coding for it. That is adding custom scripting to the view. [01:14:55](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m55s) Basically the list view as well as each view and then the MySQL dump area which we looked at earlier. +The 'postSaveHook' [01:14:05](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m05s) is actually in the controller not in the model. Go to the controller 'sermon'. Scroll to the bottom, there is 'postSaveHook'. It basically gives you the model and it gives you the valid data and you can actually perform extra features on it. [01:14:27](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m27s) But in all these things you should just read the description. It says "PHP here that should run in the 'postSavehook' Method and there is the (object)$model,the data model, object and (array) validated data". So if you just read our little note here, then you can start coding for it. That is adding custom scripting to the view. [01:14:55](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h14m55s) Basically the list view as well as each view and then the 'MySQL' dump area which we looked at earlier. **MySQL Dumps Test Data**(insert into table) -You can do two kinds of dumps. What is this used mostly for? Well what I found while I was busy developing that I would be busy setting up a component [01:15:15](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h15m15s) and install it and then add dummy data to it to see if it works. And then every time I make a change and I uninstall that component and install the new one because whatever change it made to the database won't be added to the database via an update. You need to uninstall the component and install it again to get the database back to where you want it. And so the only way I could save myself [01:15:43](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h15m43s) time, is to actually say listen I'm going to re-install this component and the dummy data for sermons. I would like to retain. So I would go to table and I open the tables. It will show me a list of all the tables that are in the database at that moment. And then I would scroll to sermon table. Click on it [01:16:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m06s) and it will load the table and what it should be called in the data set. Here(Source Map) is some explanation if you want to do other tables. Let's say you want to have it mapped to multiple tables, then this(Source Map) is the explanation on how to do that. I would not recommend doing this because possibly you will not get [01:16:29](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m29s) what you expect. And just going with the values that he populates for you, will possibly your best call, unless those values change and if you are making changes adding new fields. You must realize that you need to come and reset this by clicking on something else. And then clicking on it again and that it loads the new [01:16:57](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m57s) list of fields that are related to this table to this back end view table. And that way when you compile the component then component builder will actually grab the data from the database and build a dump file for you. +You can do two kinds of dumps. What is this used mostly for? Well what I found while I was busy developing that I would be busy setting up a component [01:15:15](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h15m15s) and install it and then add dummy data to it to see if it works. And then every time I make a change and I uninstall that component and install the new one because whatever change it made to the database won't be added to the database via an update. You need to uninstall the component and install it again to get the database back to where you want it. And so the only way I could save myself [01:15:43](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h15m43s) time, is to actually to re-install this component and the dummy data for sermons I would like to retain. So I would go to table and open the tables. It will show a list of all the tables that are in the database at that moment. And then scroll to sermon table. Click on it [01:16:06](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m06s) and it will load the table and what it should be called in the data set. Here 'Source Map' is some explanation if you want to do other tables. Let's say you want to have it mapped to multiple tables, then this'Source Map' is the explanation on how to do that. I would not recommend doing this because possibly you will not get [01:16:29](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m29s) what you expect and just going with the values that he populates for you, will possibly be the best, unless those values change and if you are making changes adding new fields. You must realize that you need to come and reset this by clicking on something else. And then clicking on it again and that it loads the new [01:16:57](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h16m57s) list of fields that are related to this table to this back end view table. In that way you compile the component, then component builder will actually grab the data from the database and build a dump file for you. **Dump File Itself** -Now that is one way of doing it. [01:17:18](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h17m18s) It might be a little bit complex but it saved me tons of hours. The other way would be to just do a dump file itself. So you'd go to your MySQL, you would open the specific, let's use smaller field types. [01:17:40](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h17m40s) Click on export and then you would select SQL format and click 'go'. And this will create a dump file of all the data in the table. And you can basically paste that dump file in here. [01:18:17](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h18m17s) So you click 'export', click 'quick' then SQL and then 'Go'. And then save it. Then go to that file(cb componentbuilder_fieldtpye.sql) open it and having it open. [01:18:41](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h18m41s) You just replace this string(cd) with (#_). Click 'Replace All'. And you will not use the table structure because that is already in component builder. You just use [01:19:03](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h19m03s) this(selected in blue) area here. Basically you would copy this area(selected in blue) like that, cut, come here(MySQL) paste and click save. And that will mean that you have the dump file. And it will always be added [01:19:36](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h19m36s) to your new install. If a dump file is way too big, you will see it by just after your clicked save, come and look at the end and see if it cut it off somewhere. So let's say it cut it off there, then I would know my dumb file is to big for use. [01:20:04](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m04s) Let's just make sure, (componentbuilder.admin.view) (structure) For your dump file I used medium text. There it is 'sql'. I've used medium text. [01:20:39](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m39s) So that means It's quite big you can really put a lot of text inside of it. If you want to know exactly how much, just Google it, and you will see I'm going to remove this because It's not related to sermons at all. [01:20:57](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m57s) In fact I'm not even go to use the dump here, save and close. +[01:17:18](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h17m18s)(See video) It might be a little bit complex but it saves time. The other way would be to just do a dump file itself. So you'd go to your 'MySQL', you would open the specific 'Fieldtypes', [01:17:40](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h17m40s) click on export and then select SQL format and click 'go'. And this will create a dump file of all the data in the table. And you can basically paste that dump file in here. [01:18:17](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h18m17s) So you click 'export', click 'quick' then SQL and then 'Go'. And then save it. Then go to that file(cb componentbuilder_fieldtpye.sql) open it and having it open. [01:18:41](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h18m41s) You just replace this string(cd) with (#_). Click 'Replace All'. And you will not use the table structure because that is already in component builder. You just use [01:19:03](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h19m03s) this(selected in blue) area here. Basically you would copy this area(selected in blue) like that, cut, come here(MySQL) paste and click save. And that will mean that you have the dump file. And it will always be added [01:19:36](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h19m36s) to your new install. If a dump file is way too big, you will see it by just after your clicked save, come and look at the end and see if it cut it off somewhere. So let's say it cut it off there, then I would know my dumb file is to big for use. [01:20:04](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m04s) Let's just make sure, (componentbuilder.admin.view) (structure) For your dump file I used medium text. There it is 'sql'. I've used medium text. [01:20:39](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m39s) So that means it's quite big, you can really put a lot of text inside of it. If you want to know exactly how much, just Google it, and you will see I'm going to remove this because it's not related to sermons at all. [01:20:57](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h20m57s) In fact I'm not even go to use the dump here, save and close. That is basically setting up an admin view. I know I've run around and it seemed quite hectic and I possibly will redo this video at a certain stage. Try to be structured but I think it is informative enough. [01:21:20](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h21m20s) If you have any questions please email me and I will try to communicate with you. If I see that a certain question comes up often enough I will add it to the Video possibly redoing this specific area. [01:21:35](https://www.youtube.com/watch?v=CdSKSCTzmRA&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=01h21m35s) Admin views is quite intense and we will possibly revisit many of the concepts that we have looked at today.