Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Models;
- use CodeIgniter\Model;
- class ListMobilModel extends Model
- {
- protected $table = 'mobil';
- // protected $returnType = 'object';
- // protected $useTimestamps = true;
- protected $allowedFields = ['mbid', 'mobil_pabrikan', 'mobil_nama', 'mobil_thumbnail', 'mobil_slug', 'mobil_status'];
- public function getDetailMobil($slug)
- {
- return $this->db->table('mobil')->where('mobil_slug', $slug)->get()->getRow();
- }
- public function getListSpek($mbid)
- {
- return $this->db->table('mobilspek')->select('spkid,spek_tipe')->where('spek_mobil', $mbid)->get()->getResultArray();
- }
- public function getDetailSpek($id)
- {
- return $this->db->table('mobilspek')->select('spek_tabel')->where('spkid', $id);
- }
- public function getDetailDefaultSpek($id)
- {
- return $this->db->table('mobilspek')->where('spek_mobil', $id);
- }
- public function getDetailHargaMobil($slug, $kota)
- {
- $query = $this->db->query("SELECT * FROM halaman as hl JOIN mobil as car ON hl.halaman_pabrikan = car.mobil_pabrikan WHERE hl.halaman_kota = '$kota' AND car.mobil_slug = '$slug'")->getRow();
- if ($query == null) {
- return false;
- }
- $result = array();
- foreach ($query as $key => $value) {
- $result[$key] = $value;
- }
- $imgQ = $this->getImglMobil($result['hlid'], $result['mobil_nama']);
- for ($i = 0; $i < count($imgQ); $i++) {
- $result['img'][$i]['url'] = $imgQ[$i]['im_url'];
- $result['img'][$i]['alt'] = $imgQ[$i]['im_alt'];
- }
- $result['img'][$i]['url'] = $result['mobil_thumbnail'];
- $result['img'][$i]['alt'] = "Harga " . $result['mobil_judul'];
- $kreditQ = $this->getListKreditMobil($result['halaman_sales'], $result['hlid'], $result['mobil_nama']);
- if ($kreditQ != null) {
- foreach ($kreditQ as $key => $value) {
- $result[$key] = $value;
- }
- }
- return $result;
- // $query = $this->db->query("SELECT * FROM mobil as car JOIN harga as hg ON hg.hg_mobil = car.mobil_nama JOIN halaman as hl ON hl.hlid = sl.said JOIN harga as hg ON hg.hg_mobil = car.mobil_nama JOIN kredit as kr ON hl.halaman_sales = kr.kr_sales WHERE hl.halaman_kota = '$kota' AND car.mobil_slug = '$slug'")->getRow();
- if ($query != null) {
- return $query;
- } else {
- return $this->db->query("SELECT * FROM harga as hg JOIN halaman as hl ON hl.hlid = hg.hg_dealer JOIN sales as sl ON hl.halaman_sales = sl.said JOIN mobil as car ON hg.hg_mobil = car.mobil_nama WHERE hl.halaman_kota = '$kota' AND car.mobil_slug = '$slug'")->getRow();
- }
- }
- public function getListDetailHargaMobil($slug, $kota)
- {
- return $this->db->query("SELECT * FROM harga as hg JOIN halaman as hl ON hl.hlid = hg.hg_dealer JOIN sales as sl ON hl.halaman_sales = sl.said JOIN mobil as car ON hg.hg_mobil = car.mobil_nama JOIN kredit as kr ON hl.halaman_sales = kr.kr_sales WHERE hl.halaman_kota = '$kota' AND car.mobil_slug = '$slug'")->getResultArray();
- }
- private function getImglMobil($id, $nama)
- {
- return $this->db->table('img_mobil')->where('im_dealer', $id)->like('im_nama', $nama)->where('img_tipe', 0)->get()->getResultArray();
- }
- private function getListKreditMobil($said, $id, $nama)
- {
- if ($said == 1) {
- return $this->db->query("SELECT kr_dp, kr_cicilan, kr_tenor,kr_bunga FROM kredit WHERE kr_dealer = $id AND kr_nama LIKE '$nama'")->getRow();
- }
- return $this->db->query("SELECT kr_dp, kr_cicilan, kr_tenor,kr_bunga FROM kredit WHERE kr_sales = $said AND kr_dealer = $id AND kr_nama LIKE '$nama'")->getRow();
- }
- private function getListHarga($id, $pid)
- {
- return $this->db->table("harga as hg")->select("car.mobil_judul, car.mobil_thumbnail, hg.hg_mobil, hg.hg_dealer, hg.hg_tipe, hg.hg_mt, hg.hg_at")->join("mobil as car", "car.mobil_nama = hg.hg_mobil")->where("hg.hg_dealer", $id)->where("hg.hg_mobil", $pid)->get()->getResultArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment