From 7e8da80f1330c2334e27bc00e4d447a52f1cbe7e Mon Sep 17 00:00:00 2001 From: Amigo <49749100+aamigo@users.noreply.github.com> Date: Fri, 14 Jun 2019 15:36:02 +0200 Subject: [PATCH] Updated 028 How to change exported values and setup custom import options (markdown) --- ...-values-and-setup-custom-import-options.md | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/028-How-to-change-exported-values-and-setup-custom-import-options.md b/028-How-to-change-exported-values-and-setup-custom-import-options.md index 3211abb..5b016fe 100644 --- a/028-How-to-change-exported-values-and-setup-custom-import-options.md +++ b/028-How-to-change-exported-values-and-setup-custom-import-options.md @@ -1 +1,29 @@ -I would like to show you How to change the values that are being exported And how to then [00:00:08](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m08s) Have custom import option With an import of the data At the moment Component builder actually allows you To have Import and export by Default in all the list views Of the components you build So let's look at what I mean Here I have a component called IP data Basically used to take [00:00:35](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m35s) IP address and Translate it to what country it was from and then To update the pricing on your website based on that IP data So Obviously You might want to export or import stuff Into this component So I'm gonna have us look at for example let's say Let's take the IP tables So here we have the IP tables [00:01:07](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m07s) And as you can see We are able to see the The CNTRY value And that is basically the country and the The REGISTRY Who this IP table belongs to And The Range That is being reflected And all this values are here. Now if you click export without selecting any Values will give you this warning [00:01:35](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m35s) So Obviously you can only export the values that are selected so if you want to export them all you need Change this value to all And in some cases if the table is too big That means you might not be able to export them all at once Any anyway exporting the data that such big quantities is not really ideal I would say anything Beyond 3000 items Rather go to MySQL Get a dump file it's not ideal to use that kind of quantity with in Joomla anyway Although we have often seen the listview being used for up to [00:02:16](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m16s) 10000 registered sorry items and quite complex Inheritance in structure We're talking about the import export now and that's quite different Ok so for our purpose Let's say we wanna exporter this but let's say for some reason Instead of us Wanting to see if this zzz or AUS Value We want to instead see the country name Ok so that would be a simple implementation of what I'm trying to explain [00:02:51](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m51s) So if you would clik export now Let's do that And then let's just save this Ok so we've exported it And instead it put these AUS values here And some other values from the database all nicely exported And that's what you would expect But if you wanted this to be a different value when you export it Then you can do the following The way component builder works [00:03:26](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m26s) Is its Got this Get export data Method in the model And This Get export data method has this extra value set to True called export or _export A reason why we added this is because it is actually Using the same structure [00:03:52](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m52s) Of getting the data As you would When Let me rephrase this You're able to Target This method with custom scripting But the difficulty is that you see this part that's custom scripting And it's also been added Into the actual [00:04:21](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m21s) Get list query right there you see It's the same custom scripting So basically In our compiler we are adding the same custom script into the get list query As we are adding Into the get export data It's the same custom scripting Now the way that you would Know where is it executing is based on this value This value is not set [00:04:49](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m49s) In the list query of course It is only set In the export data So let's see where this custom scripting is done So if you got your Admin view open you go to PHP and then you scroll down Until you see the method where is it now maybe I should scroll slower is it that one yeah I think it is this one here Right Until you see the method it says get list query J model list That's the the [00:05:43](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m43s) The one and you'd said yes The the code you put in here Is added both to the Get list query As well as to the export query so if you want to change the values that are being exported But not the values that's being shown in your component you be doing it in the same area So going back here you'd see that it's that's the same code over here that is Also added over here you see that's the same code [00:06:22](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m22s) So if you were for example In here you wanted to change some value you could do that by simply Adding another lookup or something and you add this export is true Now to see where all this export = true is appearing We would go to Any Model which is obviously a list model And we would search and see there it is [00:06:55](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m55s) And there it is again So where are we now we are now in the get export data And we are in the area where is looking remember we showed you in the previous tutorial How to add some customisation to your values in the listview Some HTML well here we are asking is the export set or is it true Then Don't do this You know Don't don't add this feature here [00:07:25](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m25s) So we are avoiding adding this Customisation of coloring because we don't wanted to run when we are exporting exporting we only wanted The values so then again you can see where using the export values And Then again there So those are there The places where the export Function is coming in To play and how we can By using this [00:07:53](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m53s) Underscore export We are able to identify whether it's an export or not if it is we can make the changes to the values as we like Ok Then going back to our back end Just to show you This is the place where we did the query And this is the place Before the translation fix, decryption again We are checking whether we are doing an export And so you could literally take that [00:08:30](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m30s) And say Instead of the exclamation that if it's export is set Come on and export And export is true Then over here you know Do you think in that area there so that is if you want to change the values Before translation or before decryption or if you want to you can do it after After that So after all was done You wanna change the values [00:09:18](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m18s) On an export Then you can add it there And that is really as simple as it is Adding a Change to your exported values Now If you want to then Have a different import Type as usual Usually to import values you just [00:09:40](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m40s) Update these right and if you leave the ID in it updates if you take the ID out It creates So without an ID it will create With an ID it will update Now let's say you say we you know what I actually don't wanna use the IDs I want to use these values instead And then you need to create a custom import concept now we have tried to make that Easy as possible and yet I'm sorry to say that it's still quite complex [00:10:13](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m13s) So You basically go to custom import And then obviously there is a little warning here Because it is quite daunting You that there yes And it will load Into these areas The actual script That are used by Default In these various concepts [00:10:38](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m38s) Now if you do not understand what you seeing here Then I suppose you should rather not be trying to do this Or you should Then seek some Classes maybe from lynda.com or elsewhere I think Udome it's also a good place Sort of sharpen up some of your PHP skills And Then you could make changes to this for example maybe just take out that chunk And [00:11:09](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m09s) Then Do a search You know so put something in you can find like Your name or whatever And then save this and compile it And then go and search where does this come up Where does this come out what what is happening And then Obviously You'd realize that [00:11:31](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m31s) We don't completely remove the default Import method When you do this kind of Changes There is a way that you could make these changes And have two import methods next to each other It's not that easy but it's possible and it all depends on really What you doing and where is it now not save area But [00:11:59](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m59s) This area the HTML and PHP View area So it depends on what you do in the view so currently this is set up to do your normal Import as you would usually do So changing this will also change your normal import concept Ok so That is how you would In this area you would Change your custom import concept Please read through the code Maybe compile it [00:12:33](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m33s) Go look at what it's done Look around see how the default import and Concepts work And then make your changes accordingly I have used this area quite a lot for various applications Because sometimes you have a user that says to you or client I want to import these sets of Csv files and they are like 4000 or 40000 lines and it needs to select only specific values [00:13:06](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m06s) Well in that case this area is definitely what you looking for And you'll be able to actually adapt your import concept to accommodate those kind of complexity Well that is how to Change export values and create custom import values For any field View in the backend of your component So literally changing how that button behaves and how that one behaves is what I have just shown you. Thank you for watching. +# HOW TO CHANGE EXPORT VALUES AND SETUP CUSTOM IMPORT OPTIONS + +* ### Example Components + +I would like to show you how to change the values that are being exported. And how to have custom import option with an import of the data. At the moment component builder actually allows you to have import and export by default in all the list views of the components you build. So let's look at what I mean. Here I have a component called IP Data. Basically used to take [00:00:35](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m35s) ip address and translate it to what country it was from. Then to update the pricing on your website based on that IP Data. You might want to export or import stuff into this component. + +* ### Example IP Tables + +So I'm going to have us look at for example, the IP Tables. [00:01:07](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m07s) And as you can see we are able to see the cntry value, that is the country, and the registry, who this IP Table belongs to. The Range, that is being reflected. + +### Export Feature + +Now if you click export without selecting any values, it will give you this warning(Please first make a selection from the list). [00:01:35](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m35s) You can only export the values that are selected. If you want to export them all you need to change this value to all. In some cases, if the table is too big, that means you might not be able to export them all at once. Anyway exporting the data in such big quantities is not really ideal. I would say anything beyond 3000 items, rather go to MySQL, get a dump file. It's not ideal to use that kind of quantity with in Joomla. Although we have often seen the listview being used for up to [00:02:16](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m16s) 10000 items and quite complex inheritance in structure. We're talking about the import and export now and that's quite different. Let's say we want to export this, but let's say for some reason instead of us wanting to see this zzz or AUS value, we want to instead see the country name. That would be a simple implementation of what I'm trying to explain. [00:02:51](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m51s) + +### Exported Example In XLS Format + +So if you would click export now, save this. We've exported it, and instead it put these AUS values here, and some other values from the database, all nicely exported. That's what you would expect. But if you wanted this to be a different value when you export it, then you can do the following. + +### Export Data In Code + +The way component builder works [00:03:26](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m26s) +is, it have this getExportdata method in the model. This getExportdata method has this extra value set to true called _export. A reason why we added this is because [00:03:52](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m52s) you're able to target this method with custom scripting. But the difficulty is that you see this part, that's custom scripting. And it's also been added into the actual getlistquery. [00:04:21](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m21s) It's the same custom scripting. In our compiler we are adding the same custom script into the getlistquery as we are adding into the getExportdata. Now the way that you would know where is it executing, is based on this value. This value is not set [00:04:49](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m49s) in the listquery of course. It is only set in the export data. + +### Admin View - PHP - (GetListQuery) + +Let's see where this custom scripting is done. If you got your admin view open, you go to PHP and then you scroll down until you see the method it says getListQuery - JModellist. That's the [00:05:43](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m43s) one and you'd set yes. The code, you put in here, is added both to the getListQuery, as well as to the exportquery. If you want to change the values that are being exported, but not the values that's being shown in your component, you will be doing it in the same area. So going back here you'd see that it's that's the same code over here that is also added over here. You will see that's the same code. [00:06:22](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m22s) If you were for example in here(see video), you wanted to change some value, you could do that by simply adding another lookup or something, and you add this export is true. Now to see where all this export = true is appearing. We would go to any list model and we would search and see there it is. [00:06:55](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m55s) And there it is again. We are now in the getExportdata, we are in the area, where is looking, remember we showed you in the previous tutorial how to add some customisation to your values in the listview, some HTML, well here we are asking if the export set? or is it true? Then Don't do this. Don't add this feature here. [00:07:25](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m25s) We are avoiding adding this customisation of coloring because we don't wanted to run when we are exporting. We only wanted the values. Again you can see we're using the export values. So those are the places where the export function is coming in to play, and how we can by using this [00:07:53](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m53s) _export we are able to identify whether it's an export or not. If it is we can make the changes to the values as we like. Then going back to our back end just to show you this(PHP) is the place where we did the query. And this is the place - before the translation fix, decryption. We are checking whether we are doing an export. And so you could literally take that(see video) [00:08:30](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m30s) and say instead of the exclamation that if the export 'isset' and export is true, then over here do your thing in that area there. + + +???That is if you want to change the values before translation or before decryption or if you want to you can do it after After that So after all was done You wanna change the values [00:09:18](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m18s) On an export Then you can add it there And that is really as simple as it is Adding a Change to your exported values Now If you want to then Have a different import Type as usual Usually to import values you just [00:09:40](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m40s) Update these right and if you leave the ID in it updates if you take the ID out It creates So without an ID it will create With an ID it will update Now let's say you say we you know what I actually don't wanna use the IDs I want to use these values instead And then you need to create a custom import concept now we have tried to make that Easy as possible and yet I'm sorry to say that it's still quite complex [00:10:13](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m13s) So You basically go to custom import And then obviously there is a little warning here Because it is quite daunting You that there yes And it will load Into these areas The actual script That are used by Default In these various concepts [00:10:38](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m38s) Now if you do not understand what you seeing here Then I suppose you should rather not be trying to do this Or you should Then seek some Classes maybe from lynda.com or elsewhere I think Udome it's also a good place Sort of sharpen up some of your PHP skills And Then you could make changes to this for example maybe just take out that chunk And [00:11:09](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m09s) Then Do a search You know so put something in you can find like Your name or whatever And then save this and compile it And then go and search where does this come up Where does this come out what what is happening And then Obviously You'd realize that [00:11:31](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m31s) We don't completely remove the default Import method When you do this kind of Changes There is a way that you could make these changes And have two import methods next to each other It's not that easy but it's possible and it all depends on really What you doing and where is it now not save area But [00:11:59](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m59s) This area the HTML and PHP View area So it depends on what you do in the view so currently this is set up to do your normal Import as you would usually do So changing this will also change your normal import concept Ok so That is how you would In this area you would Change your custom import concept Please read through the code Maybe compile it [00:12:33](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h12m33s) Go look at what it's done Look around see how the default import and Concepts work And then make your changes accordingly I have used this area quite a lot for various applications Because sometimes you have a user that says to you or client I want to import these sets of Csv files and they are like 4000 or 40000 lines and it needs to select only specific values [00:13:06](https://www.youtube.com/watch?v=fau5mZ6naLc&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h13m06s) Well in that case this area is definitely what you looking for And you'll be able to actually adapt your import concept to accommodate those kind of complexity Well that is how to Change export values and create custom import values For any field View in the backend of your component So literally changing how that button behaves and how that one behaves is what I have just shown you. Thank you for watching.