public function update_equipment_location($equipment_type, $equipment_id, $location_id) { $DB_data = $this->load->database('default', TRUE); $table = "locations"; $success = false; $locatable_types = $this->get_equipment_types($this->site_id); $locatable_identifier = make_equipment_identifier($equipment_type, $equipment_id); $new_info = array('location_id' => $location_id); $new_info['updater_id'] = $this->user_id; $new_info['locatable_type_id'] = $locatable_types[$equipment_type]['id']; $new_info['locatable_id'] = $equipment_id; $new_info['locatable_identifier'] = $locatable_identifier; $test_query = $DB_data->get_where($table, array('locatable_identifier' => $locatable_identifier), 1); if ($test_query && $test_query->num_rows() > 0) { //already exists, update $id = $test_query->row()->id; $DB_data->where('id', $id)->update($table, $new_info); if ($DB_data->affected_rows() > 0) { $success = true; } } else { //doesn't exist, make it $new_info['created_at'] = date('Y-m-d H:i:s'); $new_info['creator_id'] = $this->user_id; $DB_data->insert($table, $new_info); if ($DB_data->affected_rows() > 0) { $success = true; } } trigger_solr_update(); return $success; }
public function get_ticket_listing_by_equipment($equipment_type, $equipment_id) { $equipment_identifier = make_equipment_identifier($equipment_type, $equipment_id); $entries = array(); $DB_data = $this->load->database('default', TRUE); $ticket_listing = array(); //get tickets with this piece of equipment $DB_data->select('ticket_id')->distinct(); $ticket_query = $DB_data->get_where(TICKET_EQUIPMENT_TABLE, array("equipment_identifier" => $equipment_identifier)); if ($ticket_query && $ticket_query->num_rows() > 0) { foreach ($ticket_query->result() as $row) { $ticket_listing[$row->ticket_id] = array(); } } if (!empty($ticket_listing)) { $details_query = $DB_data->where_in('id', array_keys($ticket_listing))->get(TICKET_DETAILS_TABLE); if ($details_query && $details_query->num_rows() > 0) { foreach ($details_query->result_array() as $row) { $ticket_id = $row['id']; unset($row['id']); $entries[$ticket_id] = $row; } } $equipment_list = array(); $DB_data->select(array("equipment_identifier", "ticket_id")); $assoc_equipment_query = $DB_data->where_in('ticket_id', array_keys($ticket_listing))->where('ISNULL(`deleted_at`)')->get(TICKET_EQUIPMENT_TABLE); if ($assoc_equipment_query && $assoc_equipment_query->num_rows() > 0) { foreach ($assoc_equipment_query->result() as $row) { extract(split_equipment_identifier($row->equipment_identifier)); $entries[$row->ticket_id]['equipment'][$equipment_type][$equipment_id] = array('identifier' => $row->equipment_identifier, 'id' => $equipment_id, 'name' => $this->get_equipment_name($row->equipment_identifier)); } } } $my_equipment_name = $this->get_equipment_name(make_equipment_identifier($equipment_type, $equipment_id)); $results = array('entries' => $entries, 'section_name' => "{$equipment_type}_{$my_equipment_name}", 'section_description' => ucwords($equipment_type) . ": {$my_equipment_name} Tickets"); return $results; }
function _change_associated_equipment($values, $action) { extract($values); $child_identifier = $new_equipment_item; $parent_identifier = is_numeric($parent_equipment_id) ? make_equipment_identifier($parent_equipment_type, $parent_equipment_id) : $parent_equipment_id; $ret_object = $this->inv_model->change_equipment_associations($parent_identifier, $child_identifier, $action); transmit_array_with_json_header($ret_object, "field {$action}ed successfully", true); }