Quick way to customize the yourtablename.fieldname.csv file

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Quick way to customize the yourtablename.fieldname.csv file

Post by shasta59 » 2013-06-22 04:31

Okay everyone.

Even though Calgary AB has been hit with massive flooding my area of town is ok. While out helping a few friends in the stricken area I had a bit of a brainstorm on how to give a quick way to create a csv file used with lookup values as found in the hooks folder. This method means you do not need to update the csv file then upload it. It is all handled for you in a separate table to which only admin or whomever you want has access.

This is based upon this example on the AppGini site but taken further.

http://www.bigprof.com/appgini/help/adv ... agic-files

Step 1:

Create a new table and call it what you wish but I call mine csvfiles
Fields are: (for example)

id
csv_file_contents_yourtablename
csv_file_contents_yourtablename2

Create as many fields as you need csv files created.

Then in the hook file for the table for which you need the csv file created put in the following code under both after insert and after update

Code: Select all

$csvFile='tablename.fieldname.csv';

	$fp=@fopen("$csvFile", "w");
	fwrite($fp, $data['your_field_name']);
	fclose($fp);
		return '';
The above code assumes only one field and therefore only one csv file to create. If you have many csv files to create then just setup a loop to enter all the correct filenames etc.

Or you could write one of the above for each filename.

This way you no longer have to edit the csv file and then upload it. You just enter the table, make your changes and it will overwrite the file for you. Only caution, the 'w' flag in the fopen command will overwrite the file each time.

Enjoy

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Quick way to customize the yourtablename.fieldname.csv f

Post by KSan » 2013-06-22 05:53

Great to hear you are not affected by the floods. Wishing all the best. Thanks for the shared code. As always, superb!!!

fbrano
Veteran Member
Posts: 31
Joined: 2018-03-19 10:39

Re: Quick way to customize the yourtablename.fieldname.csv file

Post by fbrano » 2019-03-04 14:16

Where is problem in my code, when I want conditionally modify content of choices in field:

When existing record is open for modification in DV, list of options does not change according value in `Stav_pristupu`
When new record is added also I have to set value of list options to one choice = "ziadany"
Should it be somewhere else e.g. Pristupy_before_insert or Pristupy_dv?

function Pristupy_before_update(&$data, $memberInfo, &$args){

$csvFile='./hooks/Pristupy.stav_pristupu.csv';
$fp=@fopen("$csvFile", "w");
$aktualny_stav_pristupu = $data['Stav_pristupu'];
switch ($aktualny_stav_pristupu) {
case "ziadany":
fwrite($fp, "ziadany;;schvaleny;;zamietnuty");
break;
case "schvaleny":
fwrite($fp, "schvaleny;;aktivny");
break;
case "aktivny":
fwrite($fp, "aktivny;;zamknuty;;odoberany;;zruseny");
break;
case "zamknuty":
fwrite($fp, "aktivny;;zamknuty;;odoberany;;zruseny");
break;
case "odoberany":
fwrite($fp, "odoberany;;zruseny");
break;
case "zruseny":
fwrite($fp, "zruseny");
break;
default:
fwrite($fp, "ziadany");
}
fclose($fp);

return TRUE;
}

Post Reply