| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/sipapbd_2020_perubahan/application/modules/pilih/models/ |
Upload File : |
<?php
class Pilih_lokasi_model extends Pilih_Model {
function __construct()
{
parent::__construct();
}
function getLokasi($param, $isCount=FALSE)
{
$fieldmap = array(
'id' => 'ID_LOKASI',
'idp' => 'ID_PARENT_LOKASI',
'lokasi' => 'LOKASI',
'lvl' => 'LEVEL_LOKASI'
);
$wh = $this->checkSearch($param['q'], $fieldmap);
// if ($wh) $this->db->or_where($wh);
//($param['sort_by'] != null && !$isCount) ? $this->db->order_by( $fieldmap[$param['sort_by']], $param['sort_direction']) :'';
/* $this->db->select('
a.id_lokasi,
a.id_parent_lokasi,
a.lokasi,
a.level_lokasi');
$this->db->from('lokasi a');
$this->db->where('a.id_lokasi <>', 0);
$this->db->group_by('
a.id_lokasi,
a.id_parent_lokasi,
a.lokasi,
a.level_lokasi'); */
if($param['q']){
$query = $this->db->query("
with recursive t as (
select id_lokasi, lokasi, level_lokasi, id_parent_lokasi from lokasi where id_parent_lokasi is null
union all
select t1.id_lokasi, t1.lokasi, t1.level_lokasi, t1.id_parent_lokasi from t join lokasi t1 on (t1.id_parent_lokasi = t.id_lokasi)
)
select * from t where upper(lokasi) like upper('%".$param['q']."%')
");
}
else{
$query = $this->db->query("
with recursive t as (
select id_lokasi, lokasi, level_lokasi, id_parent_lokasi from lokasi where id_parent_lokasi is null
union all
select t1.id_lokasi, t1.lokasi, t1.level_lokasi, t1.id_parent_lokasi from t join lokasi t1 on (t1.id_parent_lokasi = t.id_lokasi)
)
select * from t
");
//return $query->result_array();
}
if ($isCount) {
$this->db->select('
a.id_lokasi,
a.id_parent_lokasi,
a.lokasi,
a.level_lokasi');
$this->db->from('lokasi a');
$this->db->where('a.id_lokasi <>', 0);
$this->db->group_by('
a.id_lokasi,
a.id_parent_lokasi,
a.lokasi,
a.level_lokasi');
$result = $this->db->count_all_results();
return $result;
}
else {
$result = $query->result_array();
return $result;
}
}
}