[FEATURE] insert id

Status
Not open for further replies.

cheesegrits

Support Gopher
Code:
If I've missed something obvious and there is already a way of doing this, my apologies.

I needed to be able to provide the last insert id as part of the submit feedback. Specifically, as the 'ticket id' I hand the customer when they submit feedback. No point maintaining my own unique, indexed, auto incrementing, numeric ID for a record when it already has one. :)

I couldn't find any way of doing this as-is, so I did this.

In fabrik.class.php, around line 1030 in processForm(), I added one line:

[code]                $insertId = $oTable->_lastInsertId;
                # $$$ hugh
                $this->insertId = $insertId;


In fabrik_parent.class.php, around line 268, in _replaceWithGlobals(), I added one line:

function _replaceWithGlobals( $msg ){
global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_offset, $Itemid, $mosConfig_sitename, $my;
# $$$ hugh
$msg = str_replace('{fabrik_internal_id}',$this->insertId, $msg)
[/code]

So I can now use {fabrik_internal_id} in my feedback forms and (I'm assuming, I haven't tested it yet) emails.

I tried just global'ing $insertId into _replaceWithGlobals() rather than copying it to $this in processForm() 'cos it'd be one less file edit, but it always showed up as NULL and I was too tired to work out why. Probably a Class Thang.

Anyway, I'd be Ever So Grateful if you could include this little patch into the svn head, so I don't have to keep patching my version. Unless of course I've spaced and there is already some way of doing this!

-- hugh
 
Hi Hugh

I've fixed this as of revision 132, although in a slightly different manner:

In fabrik.class.php I was already attempting to put back in the insert id with this code:

Code:
//add the key value back into the aData array
				$tmpKey 	= str_replace(".", "___", $oTable->db_primary_key);
				
				$this->_data[$tmpKey] 		= $oTable->_lastInsertId;
				$_REQUEST[$tmpKey] 			= $oTable->_lastInsertId;
				$_POST[$tmpKey] 			= $oTable->_lastInsertId;
				
				if( $oTable->db_primary_key != '' ){
					$this->_data[$oTable->db_primary_key] 						 = $insertId;
					$_POST[$oTable->db_table_name . "___" . $oTable->db_primary_key] = $insertId;
					$this->_data[$oTable->db_primary_key] = $insertId;
					$this->_data[$tmpKey] = $insertId;
					$_POST['fabrik_internal_id'] = $insertId;
					$_REQUEST['fabrik_internal_id'] = $insertId;
					$_REQUEST[$oTable->db_table_name . "___" . 'fabrik_internal_id'] = $insertId;
				}else{
					$this->_data['fabrik_internal_id'] = $insertId;
					$this->_data[$oTable->db_table_name . '___fabrik_internal_id'] = $insertId;
					$_POST[$oTable->db_table_name . '___fabrik_internal_id'] = $insertId;
					$_POST['fabrik_internal_id'] = $insertId;
					$_REQUEST['fabrik_internal_id'] = $insertId;
					$_REQUEST[$oTable->db_table_name . "___" . 'fabrik_internal_id'] = $insertId;
				}


This wasnt quiet working for colelcting this value in the emails or thanks message, so I changed it to :

Code:
//add the key value back into the aData array
				$tmpKey 	= str_replace(".", "___", $oTable->db_primary_key);
				$shortKey 	= $oTable->_shortKey( $oTable->db_primary_key );
				
				$this->_data[$tmpKey] 		= $oTable->_lastInsertId;
				$_REQUEST[$tmpKey] 			= $oTable->_lastInsertId;
				$_POST[$tmpKey] 			= $oTable->_lastInsertId;
				
				if( $oTable->db_primary_key != '' ){
					$this->_data[$oTable->db_primary_key] 						 = $insertId;
					$_POST[$oTable->db_table_name . "___" . $oTable->db_primary_key] = $insertId;
					$this->_data[$oTable->db_primary_key] = $insertId;
					$this->_data[$tmpKey] = $insertId;
					$this->_data[$shortKey] = $insertId;
					$_POST['fabrik_internal_id'] = $insertId;
					$_REQUEST['fabrik_internal_id'] = $insertId;
					$_REQUEST[$oTable->db_table_name . "___" . 'fabrik_internal_id'] = $insertId;
				}else{
					$this->_data['fabrik_internal_id'] = $insertId;
					$this->_data[$oTable->db_table_name . '___fabrik_internal_id'] = $insertId;
					$_POST[$oTable->db_table_name . '___fabrik_internal_id'] = $insertId;
					$_POST['fabrik_internal_id'] = $insertId;
					$_REQUEST['fabrik_internal_id'] = $insertId;
					$_REQUEST[$oTable->db_table_name . "___" . 'fabrik_internal_id'] = $insertId;
				}

The is ensured that the insert id is inserted back in the forms _data array, and can be accesible from parent.class.php:

parseMessageForPlaceHolder()
-> _replaceWithFormData()

Cheers
Rob
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top