Skip to content

028 How to change exported values and setup custom import options

Amigo edited this page Jul 6, 2019 · 23 revisions

HOW TO CHANGE EXPORT VALUES AND SETUP CUSTOM IMPORT OPTIONS

  • Example Components

A short explanation of how to change the values that are being exported and to have a Custom Import option with an import of the data. Component Builder allows you to have import and export function by default in all the List Views of the components. 00:00:35 The component called IP Data is used to take a IP address and translate it to determine from which country it came and then a costing update is performed on your website based on that IP Data.

  • Example IP Tables

Select IP Tables which is on the IP Table Dashboard. 00:01:07 The 'CNTRY' value may be seen, that is the country, and the 'REGISTRY', which indicates to who the IP table belongs and the range,'IP from'/'IP to' is being reflected.

Export Feature

If 'Export Data' has been clicked without selecting any values, it will give this warning: 'Please first make a selection from the list'. 00:01:35 Only export values that had been selected. If all needs to be exported, change this value to 'all'. In some instances, if the table is too long, it is not possible to export all the values at once.

Exporting the data in large quantities is not advisable in Joomla. If quantities exceeds 3000 items, Rather go to MySQL and get a dump file. 00:02:16 Although it is often seen that the Listview is being used for up to 10000 items and quite complex inheritance in structure is involved. But in this instance having the import and export in mind, makes it quite different. If for this purpose this need to be exported but for some reason this zzz or AUS value should be replaced by the country name. 00:02:51

<<<<<<<<<<<<<<<<

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 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 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 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 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 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 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 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 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 _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 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 that. So after all was done you want to change the values 00:09:18 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.

Import Features Explained

Now if you want to have a different import type as usual. Usually to import values you just 00:09:40 update these. If you leave the id in it updates, if you take the id out it creates. Now let's say I don't want to use the ids I want to use these values instead. And then you need to create a custom import concept. We have tried to make that easy as possible and yet it's still quite complex. 00:10:13

Custom Import Tab(default import code)

You basically go to custom import. There is a little warning, because it is quite daunting. You add there yes, and it will load into these areas, the actual script that are used by default in these various concepts. 00:10:38 If you do not understand what you seeing here, I suppose you should rather not be trying to do this or you should seek some classes from lynda.com or elsewhere. Udome it's also a good place sharpen up some of your PHP skills. Then you could make changes to this, for example take out that chunk, 00:11:09 then do a search, put something in you can find like your name or whatever. Save and compile it. Go and search where does this come up? Where does this come out? What is happening? You'd realize that 00:11:31 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 what you are doing in 00:11:59 this HTML and PHP view area. So it depends on what you do in the view. Currently this is set up to do your normal import as you would usually do. Changing this will also change your normal import concept. That is how you would Change your custom import concept. Please read through the code. Maybe compile it. 00:12:33 Go look at what it's done. Look around see how the default import and concepts work. 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 a 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 Well in that case this area is definitely what you looking for. You'll be able to 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 back end of your component. So literally changing how that button behaves and how that one behaves is what I have just shown you.

Clone this wiki locally