Example #1
0
 public static function create_new_ticket($args)
 {
     $table = static::$table;
     $possible_keys = static::$possible_keys;
     // Get the date and the time
     if (null == $args['call_date'] && null == $args['call_time']) {
         $args['call_time'] = date("H:i:00");
         $args['call_date'] = date("Y-m-d");
     }
     // When a ticket is created defaults to open
     if (null == $args['call_status']) {
         $args['call_status'] = 'open';
     }
     // Initialize all the query construction variables
     $insert_string = "INSERT INTO {$table} (";
     $values_string = 'VALUES (';
     $values_array = array();
     $cnt = 0;
     // Get all fields that were updated
     foreach ($args as $key => $value) {
         // Check to make sure it is a valid field, if not throw it away
         if (in_array($key, $possible_keys, true)) {
             // Only add a comma if there is a value before it
             if ($cnt++ != 0) {
                 $insert_string .= ", ";
                 $values_string .= ", ";
             }
             $insert_string .= "{$key}";
             $values_string .= "?";
             $values_array[] = $value;
         }
     }
     $updateSQL = "{$insert_string}) {$values_string})";
     $result = \PSU::db('calllog')->Execute($updateSQL, $values_array);
     $call_id = \PSU::db('calllog')->Insert_ID();
     // If success create a new update as well
     if ($result) {
         $args['date_assigned'] = $args['call_date'];
         $args['time_assigned'] = $args['call_time'];
         $args['datetime_assigned'] = $args['call_date'] . ' ' . $args['call_time'];
         $args['call_id'] = $call_id;
         $origin_update = Update::create_new_update($args);
     }
     // Create a new Ticket object
     $ticket = new Ticket($call_id);
     return $ticket;
 }