Ticket SQL Class

Description



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
Location: /gateway-api/database-handlers/mysql/ticket.sql.class.php

Provides functions to retrieve information regarding the tickets. Can retrieve the ticket itself, whose watching it, the headers, request a ticket, change the priority, and other functions to handle the functionality of a ticket.

Variables Summary



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
var $db

Function Summary



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
ticket_sql(&$db)
basic_view($params)
get_headers($params)
requester_list($params)
requester_list_by_tickets($params)
watcher_list($params)
watcher_list_by_tickets($params)
flag_list_by_tickets($params)
tag_list_by_tickets($params)
spotlight_list_by_tickets($params)
add_tag($params)
remove_tag($params)
set_ticket_priority($params)
set_ticket_due($params)
add_task($params)
flag_tickets($params)
get_primary_contact_by_tickets($params)
get_ticket_steps($params)
get_ticket_conflict_data($params)
set_status_awaiting_reply($params)
get_ticket_requesters($params)
add_requesters($params)
delete_requesters($params)
update_ticket_subject($params)
get_thread_data($params)

Method Summary



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
CerWorkstationTickets::addTagsToTicketId(array($tag_id), $ticket_id)
CerWorkstationTickets::removeTagsToTicketId(array($tag_id), $ticket_id)
CerWorkstationTickets::addFlagToTicket($agent_id, $ticket_id)
CerWorkstationTickets::setTicketWaitingonCustomer($ticket_id,1)

Variable Details



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
var $db - line 32 is a scalar representation of the @db variable that houses the database connection information.

Function Details



Description | Variables (details) | Functions (details) | Methods (details) | Required Files

Name: ticket_sql - line 39

Parameters:

&$db - a reference to the database handler

Description

Assigns the incoming parameter to the variable $db as a reference.

Name: basic_view - line 53

Parameters:

$params - A scalar representation of the array of variables that the function needs($field, $direction, $page, $limit)

Return

return $this->db->GetAll(sprintf($sql, $field, $direction, $page, $limit)) - Returns all the data that is selected from the execution of the sql statement represented by $sql

Description

The $page variable will be initialized with the result of the $page variable paramater multipled with the value of $limit variable parameter.

Assigns a sql statement to the variable $sql to select the fields listed in the table below along with how the tables are joined:

 Tables Used
 ticketthread(two references)address(two references)queue_addressesqueuepublic_gui_userscompany
Joined by:queue_addresses_id  queue_addresses_id   
Joined by:ticket_queue_id   queue_id  
Joined by:  public_user_id  public_user_id 
Joined by:     company_idid
Fields selected:ticket_id
ticket_subject
ticket_priority
ticket_spam_trained
last_reply_by_agent
ticket_spam_probability
is_closed
is_deleted
is_waiting_on_customer
min_thread_id
ticket_mask
ticket_time_worked
ticket_date
min_thread_id
max_thread_id
thread_date(reference 1)
thread_receieved(reference 2)
thread_address_id(reference 1)
thread_address_id(reference 2)
thread_date(reference 1)
address_address(reference 1)
address_address(reference 2)
address_banned(reference 2)
queue_address
queue_domain
queue_addressed_id
queue_id
queue_name
 name
id
The fields will be selected where:
  1. the max_thread_id field of the ticket table equals the thread_id field of the first reference to the thread table
  2. the min_thread_id field of the ticket table equals the thread_id field of the second reference to the thread table
  3. the address_id field of the first reference to the address table equals the thread_address_id field of the first reference to the thread table
  4. the address_id field of the second reference to the address table equals the thread_address_id of the second reference to the thread table
The table will be ordered using the values of the vairables $field and $direction, and the table will have a limit set by the value of the $page, and $limit variables.

Name: get_headers - line 84

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, $tickets)) - Returns all the data that is selected as result of executing the sql statement represented by $sql.

Description

Assigns a sql statement to the variable $sql to select the fields listed in the table below along with how the tables are joined:

 Tables Used
 ticketthread(referenced twice)address(referenced twice)queue_addressesqueuepublic_gui_userscompanysla
Joined by:queue_addresses_id  queue_addresses_id    
Joined by:ticket_queue_id   queue_id   
Joined by:  public_user_id  public_user_id  
Joined by:     company_idid 
Joined by:      sla_idid
Fields selected:ticket_id
ticket_subject
ticket_priority
ticket_spam_trained
last_reply_by_agent
ticket_spam_probability
min_thread_id
is_closed
is_deleted
is_waiting_on_customer
ticket_mask
ticket_time_worked
ticket_date
min_thread_id
max_thread_id
skill_count
ticket_due
thread_date(reference 1)
thread_received(reference 2)
thread_address_id(reference 1)
thread_address_id(reference 2)
thread_type(reference 1)
address_address(reference 1)
address_address(reference 2)
address_banned(reference 2)
queue_address
queue_domain
queue_address_id
queue_name
queue_id
 name
id
sla_expire_date
name
id
The fields will be selected on the following conditions:
  1. the max_thread_id field of the ticket table equals the thread_id field of the first reference of the thread table
  2. the min_thread_id field of the ticket table equals the thread_id field of the second reference to the thread table
  3. the address_id field of the first reference to the address table equals the thread_address_id field of the first reference to the thread table
  4. the address_id field of the second reference to the address table equals the thread_address_id field of the second reference to the thread table
  5. the ticket_id field of the ticket tables contains one of the values in the variable $tickets

Name: requester_list - line 116

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id)

Return

return $this->db->GetAll(sprintf($sql, $ticket_id)) - Returns all the data that is selected as a result of executing the sql statement represented by $sql

Description

Assigns a statement to the variable $sql to select the suppress field from the requestor table, and the address_id and address_id fields from the address table. The address_id field will be used to join both the requestor and address tables. The data will be selected where the ticket_id field of the requestor table equals the value of the $ticket_id variable.

Name: requester_list_by_tickets - line 123

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$tickets))) - Returns all the data that is found upon the execution of the sql statement represented by $sql

Description

Assigns a sql statement to the variable $sql to select the ticket_id and supress fields from the requestor table and the address_id and address_address fields from the address table. The addres_id field will be used to join both the requestor and address table. The fields will be selected where the ticket_id field of the requestor tables contains one of the values of the $tickets variable after it has been converted to a comman deliminated list.

Name: watcher_list - line 137

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$ticket_id))) - Returns all the data that is found upon the execution of the sql statement represented by $sql

Description

Assigns a space to the variable $sql.

Name: watcher_list_by_tickets - line 143

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

returns $this->db->GetAll(sprintf($sql, implode(', ',$tickets))) - Returns all the data that is selected as a result of executing the sql statement represented by $sql

Description

Assigns a space to the variable $sql.

Name: flag_list_by_tickets - line 153

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$tickets))) - Returns all the data that is selected by the execution of the sql statement represented by $sql

Description

Assigns a sql statement to the variable $sql to select the agent_it and ticket_id fields from the ticket_flags_to_agents table where the ticket_id field contains one of the values in the variables $tickets after it has been converted into a comma deliminated list.

Name: tag_list_by_tickets - line 169

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$tickets)) - Returns all the data that is selected by the execution of the sql statement by the variable $sql.

Description

Assigns a sql statement to the variable $sql to select the ticket_id, and tag_id fields from the workstation_tags_to_tickets table, the tag_name and tag_set_id fields from the workstation_tags table and the name field from the workstation_tag_sets table. The tag_id is used to join both the workstation_tags and workstation_tags_to_tickets tables, and the tag_set_id field of the workstation_tags table will be joined to the id field of the workstation_tag_sets table. The data will be selected where the ticket_id field of the workstation_tags_to_tickets table contains one of the values in the $tickets variable after it has been converted to a comma deliminated list.

Name: spotlight_list_by_tickets - line 179

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$tickets)) - Returns all the results that are selected by executing the sql statement represented by $sql.

Description

Assigns a sql statement to the variable $sql to select the ticket_id and agent_id fields from the ticket_spotlights_to_agents table and the user_name field of the user table. The tables are joined where the agent_id field of the ticket_spotlights_to_agents table equals the user_id field of the user table and the ticket_id field of the ticket_spotlights_to_agents tables contains one in the values in the $tickets variable after it has been converted to a comma deliminated list.

Name: add_tag - line 188

Parameters:

$params - A scalar representation of the array of variables that the function needs($tag_id, $ticket_id)

Return

return TURE - returns the boolean value of TRUE

Description

Executes an include statement to inclue the CerWorkstationTickets.class.php class. The addTagsFromTicketId(array(4tag_id),$ticket_id) method call by passing in the array represented by $tag_id and the $ticket_id variable.

Name: remove_tag - line 197

Parameters:

$params - A scalar representation of the array of variables that the function needs($tag_id, $ticket_id)

Return

return TURE - returns the boolean value of TRUE

Description

Executes an include statement to inclue the CerWorkstationTickets.class.php class. The removeTagsFromTicketId(array(4tag_id),$ticket_id) method call by passing in the array represented by $tag_id and the $ticket_id variable.

Name: set_ticket_priority - line 206

Parameters:

$params - A scalar representation of the array of variables that the function needs($priority, $ticket_id)

Return

return $this->db->Execute(sprintf($sql, $priority, $ticket_id)) - Returns the value that is generated upon the execution of the sql statement represented by $sql.

Description

Assigns a sql statement to the variable $sql to update the ticket_priority field with the value of the $priority variable in the ticket table where the ticket_id field equals the value of the $ticket_id variable.

Name: set_ticket_due - line 212

Parameters:

$params - A scalar representation of the array of variables that the function needs($due, $ticket_id)

Return

return $this->db->Execute($sql) - Returns the value that is generated upon the execution of the sql statement represented by $sql.

Description

Assigns a sql statment to the variable $sql to update the ticket table by setting the ticket_due field equal to the variable $due formatted as a date showing year-month-day hour:minute:seconds where the ticket_id fields equals the variable $ticket_id.

Name: add_task - line 220

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id, $estimate, $title)

Return

return $this->db->Execute(sprintf($sql, $ticket_id, $estimate, $this->db->qstr($title))) - Returns the value that is generated upon the execution of the sql statement represented by $sql

Description

Assigns a sql statement to the variable $sql to insert into the ticket_tasks table the values of $ticket_id, $estimate, UNIX_TIMESTAMP(), the number zero, and $title into the ticket_id, estimate, date_added, completed, and title fields.

Name: flag_tickets - line 230

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets, $agent_id, $overrid)

Return

return $flagged_by_others_only - Returns an array of tickets that are not associated with agents id represented by the variable $agent_id

Description

Assigns a sql statement to the variable $sql and then assigns the results of its execution to the variable $res. The sql statement will select from the ticket_id, and agent_id fields of the ticket_flags_to_agents table where the ticket_id contains one of the values in the $tickets array after it has been converted into a comma deliminated list.

The $flagged_by_others, $flagged_by_others_only, and the $flagged_by_me variables are all initialized as a blank array. As long as the $res variable is an array a loop is executed where the following steps occur upon each iteration:

  1. The variable $ticket_id is assigned the value of the current loops iteration ticket_id subscript of the $res variable.
  2. If the agent_id subscript of the $row variable is equal to the value of the agent_id variable then the next available subscript of the $flagged_by_me variables is assigned the value of the $ticket_id variable subscript of the $tickets variable. Otherwise the next available subscript of the $flagged_by others variable will assigned the values of the $ticket_id variable subscript of the $tickets variable.
Both the $flagged_by_me and $flagged_by_thers arrays will be converted to contain only unique values.

If the $override variable contains either the number one or the boolean value of TRUE then the $tickets_to_insert variable will be assigned an array containing all the values of the $ticket array that are not in the $flagged_by_me variable. This array will contain all the tickets that have not been flagged, and because the override variable is true all the tickets that were assigned to others. Otherwist the $tickets_to_insert array will be assigned all the values in the $tickets array that are not in the $flagged_by_me, and $flagged_by_others arrays. This will leave only tickets that have been not been flagged by anyone yet. Then the $flagged_by_others_only variable is assigned all the values in the $flagged_by_others array thatr is not in the $flagged_by_me array. This will generate an array of flagged tickets that do not belong to the agent.

An include statement is executed to include the CerWorkstationTickets.class.php file. As long as the $tickets_to_insert variable is an array then for each value in that array the cerWorkstationTickets::addFlagToTicket($agent_id,$ticket_id) metho call will be executed with the values of the $agent_id parameter, and the current iterations subscript containing the ticket information represented by $ticket_id.

Name: get_primary_contact_by_tickets - line 286

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets)

Return

return $this->db->GetAll(sprintf($sql, implode(', ',$tickets)) - Returns all the data is selected by the sql statement represented by the variable $sql

Description

Assigns a sql statement to the variable $sql to select the ticket_id field from the ticket table, and the name_first and name_last field combined into one string, and the public_user_id field all from the public_gui_user table. The fields are selected where the min_thread_id field of the ticket table equals the thread_id field of the thread table, th thread_address_id field of the thread table equals the address_id of the address table and the public_user_id field of both the ticket and the public_user_id tables is equal. The data will be selected where the ticket_id field of the ticket table contains one of the values in the $tickets array after it has been converted into a comma deliminated list.

Name: get_ticket_steps - 293

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id)

Return

return $this->db->GetAll(sprintf($sql, $ticket_id)) - Returns all the data that is selected as a result of executing the sql statement represented by $sql

Description

Assigns a sql statement to the variable $sql to select the ticket_id, id, date_created, note, and created_by_agent_id fields from the next_stap table and the user_name from the user table where the user_id field of the user tale equals the created_by_agent_id field of the next step table and the ticket_id of the next_step equals the value of the $ticket_id variable. The results will be ordered by the date_created field of the next_step table.

Name: get_ticket_conflict_data - line 305

Parameters:

$params - A scalar representation of the array of variables that the function needs($tickets, $agent_id)

Return

return $res - Returns a value representing the data that is returned from the execution of the sql statement
return array() - A blank array is returned only if the incoming parameter $tickets is blank

Description

As long as the $tickets variable is not blank thene the $ticket_str variable would be assigned the value of $tickets converted into a comma deliminated list. A sql statement is assigned to $sql to select the ticket_id and ticket_subject fields from the ticket table, and the user_id and user_name fields from the user table. Tables will be joined where the ticket_id field of the ticket_flags_to agents table equals the ticket_id field of the ticket table, and the agent_id field of the ticket_flags_to_agents table equals the user_id field of the user table. The fields will be selected where the user_id field of the user table equals the value of the $agent_id variable, and the ticket_id field of the ticket_flags_to_agents table contains a value in the $ticket_str variable. The results will be ordered by the ticket_id field of the ticket table.

Name: set_status_awaiting_reply - line 328

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id)

Return

return TRUE - returns the boolean value of TRUE

Description

Executes the statement to include the CerWorkstationTickets.class.php file. Calls the CerWorkstationTickets::setTicketWaitingOnCustomer($ticket_id) method call to set a flag indicating the ticket in question is awaiting information from the customer.

Name: get_ticket_requesters - linw 337

Parameters:

$params - A scalar representation of the array of variables that the function needs($ticket_id)

Return

return $requesters - Returns the array where each subscript contains an array of values representing one row of data selected by the execution of a sql statement.

Description

Assigns a sql statement to the variable $sql to select the following fields from the following tables where they are joined in the table listed below:

 Tables
 addresspublic_gui_userscompanyticketthreadrequestor
INNER JOIN by:address_id    address_id
LEFT JOIN by:public_user_idpublic_user_id    
LEFT JOIN by: company_idid   
INNER JOIN by:   ticket_id ticket_id
INNER JOIN by:   min_thread_idthread_id 
IF conditionial - returns 1 on TRUE, 0 on FALSE    thread_address_idaddress_id
Fields selected:address_address
address_id
name_first
name_last
public_user_id
id
name
   
This will be selected where the ticket_id field of the requestor table equals the value of the $ticket_id variable.

The variable $result will be assigned the result returned from the execution of the sql statement represented by $sql, and the variable $requesters will be initialized as a blank array.

Name: add_requesters - line 361

Parameters:

$params - A scalar representation of the array of variables that the function needs($address_list, $ticket_id)

Return

return ($error_flag !== TRUE) - Returns a boolean value of FALSE if the value of $error_flag is TRUE, or TRUE if the value of $error_flag is the boolean value FALSE

Description

Assigns the $addresses variable with a comma deliminated list of the values of the $address_list variable where each value is preceeded and succeded by a single quote. A sql statement is assigned to the variable $sql and executed to assign the variable $res all values of the address_id field of the address table where the adddress_address field contains one of the values in the $addresses_list variable.

The variable $error_flag is initialized with the boolean value of false. If the variable $res is an array then for each value a sql statement will be assigned to the variable $sql2 to insert into the requestor table the value of the $ticket_id variable, and the current array value of the variable $res as long as a key in the table is not duplicated. In the event the execution of the sql statement represented by $sql fails the $error_flag variable will be set to the boolean value of true.

Name: delete_requesters - line 381

Parameters:

$params - A scalar representation of the array of variables that the function needs($adress_list, $ticket_id)

Return

return ($error_flag !== TRUE) - Returns a boolean value of FALSE if the value of $error_flag is TRUE, or TRUE if the value of $error_flag is the boolean value FALSE

Description

Assigns the $addresses variable with a comma deliminated list of the values of the $address_list variable where each value is preceeded and succeded with a single quote. A sql statement is assigned to the variable $sql and executed to return all the values in the address_id field of the address table where the address_adress field contains a value in the $addresses variable to the variable $res.

The following three variables are then initialized, $address_id_list with an empty string, $first_time with the boolean value TRUE, and $error_flag with the boolean value FALSE. As long as the variable $res is not blank then each value will have single quotes prepended and appended to it and assigned to the variabe $address_id_list with a comma seperating each value.

As long as the $address_id_list is not blank the a sql statement will be assigned to the variable $sql to delete from the requestor table where the ticket_id field is equal to tha $ticket_id variable, and the address_id field contains one of the values in the $address_id_list variable. The variable $error_flag will be set to the value of true if the exeuction of the sql statement represented by $sql is not succesful.

Name: update_ticket_subject - line 410

Parameters:

$params - A scalar representation of the array of variables that the function needs($subject, $ticket_id, $status)

Return

return TRUE - Returns the boolean value of TRUE.

Description

Assigns and executes the sql statement assigned to the variable $sql to update the ticket table with the values of the $subject array where the ticket_id field equals the value of the $ticket_id variable.

A second sql statement is executed if it was assigned to $sql by one of the following conditions based on the variable $status.

  1. If the value is open a sql statement will be assigned to $sql to update the ticket by setting the is_closed, and is_deleted fields equal to zero where the ticket_id field equals that $ticket_id variable.
  2. If the value is closed a sql statement will be assigned to $sql to update the ticket table by setting the is_closed field equal to one and the is_deleted field equal to zero where the ticket_field equals the variable $ticket_id.
  3. If the value is deleted the sql statement assigned to $sql will assign the number one to both the is_closed, and is_deleted tables where the ticket_id field equals the value of $ticket_id.

Method Details



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
CerWorkstationTickets::addTagsToTicketId - Line 192 Calls the addTagsToTicketId function of the CerWorkstationTickets class and passes the $tag_id variable as an array and the $ticket_id variable as parameters

CerWorkstationTickets::removeTagsToTicketId - Line 201 Calls the removeTagsToTicketId function of the CerWorkstationTickets class and passes the $tag_id variable as an array and the $ticket_id variable as parameters

CerWorkstationTickets::addFlagToTicket - Line 272 Calls the addFlagToTicket function of the CerWorkstationTickets class and passes the $agent_id, and the $ticket_id variables as parameters

CerWorkstationTickets::setTicketWaitingonCustomer - Line 332 Calls the setTicketWaitingonCustomer function of the CerWorkstationTickets class and passes the $ticket_id variable, and the number one as parameters

Required Files



Description | Variables (details) | Functions (details) | Methods (details) | Required Files
File NameLine Number Called OnLocation
CerEntityObject.class.phpLine 21cerberus-api/entity/CerEntityObject.class.php
CerNextStep.class.phpLine 22cerberus-api/entity/CerNextStep.class.php
CerWorkstationTickets.class.phpLines 191, 200, and 331cerberus-api/workstation/CerWorkstationTickets.class.php