📁 PHP Dosya Yöneticisi
/
/
home
/
demodesigncom
/
otelscripti.demodesign.com.tr
/
admin
/
models
📝
Room.php
← Geri Dön
<?php class Room extends CI_Model { public function id($id) { return $this->db ->from($this->table) ->where('id' , $id) ->where('language' , $this->language) ->get() ->row(); } public function all($limit = null, $offset = null) { $this->utils->filter(); if( $limit != null ){ $this->db->limit($limit, $offset); } return $this->db ->select("{$this->table}.*, (SELECT COUNT(images.id) FROM room_images images WHERE images.parentId = {$this->table}.id) images,") ->from($this->table) ->where('language', $this->language) ->order_by('order', 'asc') ->order_by('id', 'asc') ->get() ->result(); } public function allExtra() { return $this->db ->from('room_extra') ->where('language', $this->language) ->order_by('order', 'asc') ->order_by('id', 'asc') ->get() ->result(); } public function extraValidation($id) { return $this->db ->from('room_extra_validation') ->where('roomId', $id) ->order_by('id', 'asc') ->get() ->result(); } /** * roomManyAll * * @param $id * @return mixed */ public function roomManyAll($id) { return $this->db->from('room_many')->where('room_id', $id)->get()->result(); } /* Bağlı hotel varsa burdan hotel veritabanına bağlanıyoruz public function hotels() { return $this->db ->from('hotels') ->where('language', $this->language) ->order_by('order', 'asc') ->order_by('order', 'id') ->get() ->result(); } */ public function count($all = false) { $this->utils->filter(); return $this->db ->from($this->table) ->where('language', $this->language) ->count_all_results(); } public function insert($data = []) { $order = 1; $lastOrderRecord = $this->db ->from($this->table) ->where('language', $this->language) ->order_by('order', 'desc') ->limit(1) ->get() ->row(); if($lastOrderRecord) { $order = $lastOrderRecord->order + 1; } $this->db->insert($this->table, [ 'title' => $this->input->post('title'), 'summary' => $this->input->post('summary'), 'detail' => $this->input->post('detail'), 'slug' => $this->input->post('autoSlug') === 'true' ? makeSlug($this->input->post('title')) : makeSlug($this->input->post('slug')), 'image' => $data['image']['name'], 'metaTitle' => $this->input->post('metaTitle'), 'metaDescription' => $this->input->post('metaDescription'), 'metaKeywords' => $this->input->post('metaKeywords'), 'language' => $this->language, 'order' => $order, 'yetiskin_adet' => $this->input->post('yetiskinSayisi'), 'yetiskin_fiyat' => $this->input->post('yetiskinFiyati'), 'cocuk_adet' => $this->input->post('cocukSayisi'), 'cocuk_fiyat' => $this->input->post('cocukFiyati'), 'yatak_adet' => $this->input->post('ekYatakSayisi'), 'yatak_fiyat' => $this->input->post('ekYatakFiyati') ]); $id = $this->db->insert_id(); foreach ($this->input->post('extras') as $extra) { $this->db->insert('room_extra_validation', [ 'roomId' => $id, 'extraId' => $extra ]); } // Fiyatları kaydet foreach ($this->input->post('fiyat') ? $this->input->post('fiyat') : [] as $fiyat) { $this->db->insert('room_many', [ 'room_id' => $id, 'group_id' => $fiyat['group'], 'count' => $fiyat['count'], 'money' => $fiyat['money'], 'start' => $fiyat['start'], 'end' => $fiyat['end'] ]); } return $id; } public function update($record, $data = []) { $this->db ->where('id', $record->id) ->update($this->table, [ 'title' => $this->input->post('title'), 'summary' => $this->input->post('summary'), 'detail' => $this->input->post('detail'), 'slug' => $this->input->post('autoSlug') === 'true' ? makeSlug($this->input->post('title')) : makeSlug($this->input->post('slug')), 'image' => $data['image']['name'], 'metaTitle' => $this->input->post('metaTitle'), 'metaDescription' => $this->input->post('metaDescription'), 'metaKeywords' => $this->input->post('metaKeywords'), 'yetiskin_adet' => $this->input->post('yetiskinSayisi'), 'yetiskin_fiyat' => $this->input->post('yetiskinFiyati'), 'cocuk_adet' => $this->input->post('cocukSayisi'), 'cocuk_fiyat' => $this->input->post('cocukFiyati'), 'yatak_adet' => $this->input->post('ekYatakSayisi'), 'yatak_fiyat' => $this->input->post('ekYatakFiyati') ]); $affect = $this->db->affected_rows(); $this->db->where('roomId', $record->id)->delete('room_extra_validation'); foreach ($this->input->post('extras') as $extra) { $this->db->insert('room_extra_validation', [ 'roomId' => $record->id, 'extraId' => $extra ]); } // Oda fiyatları $this->db->where('room_id', $record->id)->delete('room_many'); // Fiyatları kaydet foreach ($this->input->post('fiyat') ? $this->input->post('fiyat') : [] as $fiyat) { $this->db->insert('room_many', [ 'room_id' => $record->id, 'group_id' => $fiyat['group'], 'count' => $fiyat['count'], 'money' => $fiyat['money'], 'start' => $fiyat['start'], 'end' => $fiyat['end'] ]); } return $affect; } public function delete($data) { if (is_array($data)) { $records = $this->db ->from($this->table) ->where_in('id', $data) ->get() ->result(); $success = $this->db ->where_in('id', $data) ->delete($this->table); if ($success) { foreach ($records as $record) { @unlink("../public/upload/room/{$record->image}"); } } return $success; } $success = $this->db ->where('id', $data->id) ->delete($this->table); @unlink("../public/upload/room/{$data->image}"); return $success; } public function order($ids = null) { if (is_array($ids)) { $records = $this->db ->from($this->table) ->where_in('id', $ids) ->where_in('language', $this->language) ->order_by('order', 'asc') ->order_by('id', 'desc') ->get() ->result(); $firstOrder = 0; $affected = 0; foreach ($records as $record) { if ($firstOrder === 0) { $firstOrder = $record->order; } $order = array_search($record->id, $ids) + $firstOrder; if ($record->order != $order) { $this->db ->where('id', $record->id) ->update($this->table, ['order' => $order]); if ($this->db->affected_rows() > 0) { $affected++; } } } return $affected; } } //Resimleri bağlı olduğu tablonun elemanının id'sine göre çekiyoruz public function image($id) { return $this->db ->from('room_images') ->where('id', $id) ->where('language', $this->language) ->get() ->row(); } //listeliyoruz public function imageAll($parents, $limit = null, $offset = null) { $this->utils->filter(); if ($limit != null) { $this->db->limit($limit, $offset); } return $this->db ->from('room_images') ->where('parentId', $parents->id) ->where('language', $this->language) ->order_by('order', 'asc') ->order_by('id', 'asc') ->get() ->result(); } //sayısını buluyoruz public function imageCount($parents) { $this->utils->filter(); return $this->db ->from('room_images') ->where('parentId', $parents->id) ->where('language', $this->language) ->count_all_results(); } //Resim ekleme işlemi public function imageInsert($parents, $data = []) { $order = 1; $lastOrderRecord = $this->db ->from('room_images') ->where('language', $this->language) ->where('parentId', $parents->id) ->order_by('order', 'desc') ->limit(1) ->get() ->row(); if ($lastOrderRecord) { $order = $lastOrderRecord->order + 1; } $this->db->insert('room_images', [ 'parentId' => $parents->id, 'image' => $data['image']['name'], 'order' => $order, 'language' => $this->language ]); return $this->db->insert_id(); } //Güncelleme public function imageUpdate($record, $data = []) { $this->db ->where('id', $record->id) ->update('room_images', [ 'image' => $data['image']['name'], ]); return $this->db->affected_rows(); } //REsim Silme public function imageDelete($data) { if (is_array($data)) { $records = $this->db ->from('room_images') ->where_in('id', $data) ->get() ->result(); $success = $this->db ->where_in('id', $data) ->delete('room_images'); if ($success) { foreach ($records as $record) { @unlink("../public/upload/room/thumb/{$record->image}"); @unlink("../public/upload/room/normal/{$record->image}"); } } return $success; } $success = $this->db ->where('id', $data->id) ->delete('room_images'); @unlink("../public/upload/room/thumb/{$data->image}"); @unlink("../public/upload/room/normal/{$data->image}"); return $success; } //Resim Sırasını düzenleme public function imageOrder($ids = null) { if (is_array($ids)) { $records = $this->db ->from('room_images') ->where_in('id', $ids) ->order_by('order', 'asc') ->order_by('id', 'desc') ->get() ->result(); $firstOrder = 0; $affected = 0; foreach ($records as $record) { if ($firstOrder === 0) { $firstOrder = $record->order; } $order = array_search($record->id, $ids) + $firstOrder; if ($record->order != $order) { $this->db ->where('id', $record->id) ->update('room_images', ['order' => $order]); if ($this->db->affected_rows() > 0) { $affected++; } } } return $affected; } } }
💾 Kaydet
İptal
📝 Yeniden Adlandır
İptal
Kaydet
🔐 Dosya İzinleri (chmod)
İzin Değeri:
Hızlı Seçim:
777
755
644
600
777
= Herkes okur/yazar/çalıştırır
755
= Sahip tam, diğerleri okur/çalıştırır
644
= Sahip okur/yazar, diğerleri okur
600
= Sadece sahip okur/yazar
İptal
Uygula