[eluser]Andy UK[/eluser]
Hi,
I'm developing a ticket system where tickets are assigned to relationships with clients. If a relationship exists, then the ticket is given that relationship id. If no current relationship exists then a new one is added and the new id is assigned to the ticket that triggered its creation. The problem i have is that when i get the last insert id of the new relationship and add it to the recently created ticket, i'm always getting the value of 1. Here is the controller code...
Code:
//Insert new ticket into system
$ticket_data = array(
'contact_name' => $name,
'contact_email' => $email,
'contact_number' => $contact_number,
'ticket_body' => $notes,
'property_id' => $property_id,
'ticket_type' => 'Viewing Request',
'ticket_source' => 'Website',
'assigned_to' => $broker_id,
'ticket_creation_date' => date("Y-m-d H:i:s")
);
// Add new ticket to database and get its ID
$ticket_id = $this->property->addNewTicket($ticket_data);
// Check for existing open relationship with client via email address or phone number
$relationship_id_via_email = $this->property->relationshipCheckEmail($email);
$relationship_id_via_phone = $this->property->relationshipCheckPhone($contact_number);
if($relationship_id_via_email)
{
$this->property->assignTicketRelationship($ticket_id, $relationship_id_via_email);
}
else
// Else if no relationship exists, add a new one
{
$relationship_data = array(
'name' => $name,
'email' => $email,
'tel' => $contact_number,
'status_id' => 1,
'client_source_id' => 1,
'added_on' => date("Y-m-d H:i:s")
);
$new_relationship_id = $this->property->openNewRelationship($relationship_data);
// Assign the new relationship ID to the previously added ticket
$this->property->assignTicketRelationship($ticket_id, $new_relationship_id);
}
And here is the relevant model code...
Code:
function addNewTicket($data)
{
$this->db->insert('tickets', $data);
return $this->db->insert_id();
}
Code:
function openNewRelationship($data)
{
$this->db->insert('client_relationship_instances', $data);
return $this->db->insert_id();
}
$new_relationship_id is the variable that holds the last inserted client relationship and that's the one that is coming back as 1 every time a new client relationship is created.
Any ideas?