ilhambch

List Mobil Model

Mar 3rd, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.10 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Models;
  4.  
  5. use CodeIgniter\Model;
  6.  
  7. class ListMobilModel extends Model
  8. {
  9.     protected $table      = 'mobil';
  10.     // protected $returnType = 'object';
  11.     // protected $useTimestamps = true;
  12.     protected $allowedFields = ['mbid', 'mobil_pabrikan', 'mobil_nama', 'mobil_thumbnail', 'mobil_slug', 'mobil_status'];
  13.  
  14.     public function getDetailMobil($slug)
  15.     {
  16.         return $this->db->table('mobil')->where('mobil_slug', $slug)->get()->getRow();
  17.     }
  18.     public function getListSpek($mbid)
  19.     {
  20.         return $this->db->table('mobilspek')->select('spkid,spek_tipe')->where('spek_mobil', $mbid)->get()->getResultArray();
  21.     }
  22.     public function getDetailSpek($id)
  23.     {
  24.         return $this->db->table('mobilspek')->select('spek_tabel')->where('spkid', $id);
  25.     }
  26.     public function getDetailDefaultSpek($id)
  27.     {
  28.         return $this->db->table('mobilspek')->where('spek_mobil', $id);
  29.     }
  30.     public function getDetailHargaMobil($slug, $kota)
  31.     {
  32.         $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();
  33.         if ($query == null) {
  34.             return false;
  35.         }
  36.         $result = array();
  37.         foreach ($query as $key => $value) {
  38.             $result[$key] = $value;
  39.         }
  40.         $imgQ = $this->getImglMobil($result['hlid'], $result['mobil_nama']);
  41.         for ($i = 0; $i < count($imgQ); $i++) {
  42.             $result['img'][$i]['url'] = $imgQ[$i]['im_url'];
  43.             $result['img'][$i]['alt'] = $imgQ[$i]['im_alt'];
  44.         }
  45.         $result['img'][$i]['url'] = $result['mobil_thumbnail'];
  46.         $result['img'][$i]['alt'] = "Harga " . $result['mobil_judul'];
  47.         $kreditQ = $this->getListKreditMobil($result['halaman_sales'], $result['hlid'], $result['mobil_nama']);
  48.         if ($kreditQ != null) {
  49.             foreach ($kreditQ as $key => $value) {
  50.                 $result[$key] = $value;
  51.             }
  52.         }
  53.         return $result;
  54.         // $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();
  55.         if ($query != null) {
  56.             return $query;
  57.         } else {
  58.             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();
  59.         }
  60.     }
  61.     public function getListDetailHargaMobil($slug, $kota)
  62.     {
  63.         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();
  64.     }
  65.     private function getImglMobil($id, $nama)
  66.     {
  67.         return $this->db->table('img_mobil')->where('im_dealer', $id)->like('im_nama', $nama)->where('img_tipe', 0)->get()->getResultArray();
  68.     }
  69.     private function getListKreditMobil($said, $id, $nama)
  70.     {
  71.         if ($said == 1) {
  72.             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();
  73.         }
  74.         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();
  75.     }
  76.     private function getListHarga($id, $pid)
  77.     {
  78.         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();
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment