44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Tourist_attraction_model extends CI_Model
|
|
{
|
|
public function __constructor()
|
|
{
|
|
parent::__constructor();
|
|
}
|
|
|
|
public function create($data) {
|
|
$sql = $this->db->insert_string('tourist_attraction', $data) .
|
|
' ON CONFLICT (attraction, address_id) DO NOTHING RETURNING id';
|
|
$query = $this->db->query($sql);
|
|
}
|
|
|
|
public function create_multiple($data) {
|
|
// Prepare SQL query for multiple values with ignore conflict
|
|
$insert_query = 'INSERT INTO tourist_attraction (active, address_id, attraction, city_id, description, feature_image) VALUES ';
|
|
$values = array_map(function($poi) {
|
|
$result = '('
|
|
. $this->db->escape($poi['active']) . ','
|
|
. $poi['address_id'] . ','
|
|
. $this->db->escape($poi['attraction']) . ','
|
|
. $poi['city_id'] . ','
|
|
. $this->db->escape($poi['description']) . ','
|
|
. $this->db->escape($poi['feature_image']) . ')';
|
|
|
|
return $result;
|
|
}, $data);
|
|
$str_values = implode(',', $values);
|
|
$insert_query .= $str_values . ' ON CONFLICT (attraction, address_id) DO UPDATE ';
|
|
$insert_query .= 'SET description = EXCLUDED.description, feature_image = EXCLUDED.feature_image, active = EXCLUDED.active WHERE tourist_attraction.active != true';
|
|
|
|
// Excute query
|
|
return $this->db->query($insert_query);
|
|
}
|
|
|
|
public function update_by_id($id, $data) {
|
|
$this->db->where('id', $id);
|
|
return $this->db->update('tourist_attraction', $data);
|
|
}
|
|
} |