Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Models\CMS\Application;
- use CodeIgniter\Model;
- class Investment_model extends Model {
- // -------------------------------
- // -------------------------------
- // Construct
- // -------------------------------
- // ---------------------------- //
- protected $table = "tb_investment";
- // -------------------------------
- // ----------- Selesai -----------
- // ---------------------------- //
- // -------------------------------
- // -------------------------------
- // Main Model
- // -------------------------------
- // ---------------------------- //
- public function select_table($parameter, $search, $limit, $start_limit, $order, $sort_type, $num_rows=TRUE){
- $this->select("*");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['id'] != FALSE) {
- $this->where('md5(id) =', $parameter['id']);
- }
- if ($parameter['is_deleted'] > -1) {
- $this->where('is_deleted', $parameter['is_deleted']);
- }
- }
- if ($search != FALSE) {
- $this->like('(LOWER(name)', strtolower($search));
- $this->orLike('LOWER(name_sektor_sub)', strtolower($search));
- $this->orLike('LOWER(name_kecamatan)', strtolower($search));
- $this->orLike('price', strtolower($search));
- $this->orLike('date_update', strtolower($search));
- $this->orLike('LOWER(is_deleted)', strtolower($search));
- $this->where('1 = 1 )');
- }
- $this->orderBy("id", "ASC");
- if ($limit != FALSE) {
- $this->limit($limit, $start_limit);
- }
- // Result
- if ($num_rows == FALSE) {
- $return = $this->get()->getResult();
- }
- else{
- $return = $this->countAllResults();
- }
- return $return;
- }
- public function select_table2($parameter, $limit, $num_rows=TRUE){
- $this->select("*");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['id'] != FALSE) {
- $this->where("md5(id) =", $parameter['id']);
- }
- }
- $this->where('is_deleted', 0);
- if ($limit != FALSE) {
- $this->limit($limit);
- }
- $this->orderBy('id', 'ASC');
- // Result
- if ($num_rows === FALSE) {
- $result = $this->get()->getResult();
- }
- else{
- $result = $this->countAllResults();
- }
- return $result;
- }
- public function select_table3($parameter, $limit, $num_rows=TRUE){
- $this->select("*");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['id'] != FALSE) {
- $this->where("md5(id) =", $parameter['id']);
- }
- if ($parameter['is_deleted'] > -1) {
- $this->where("is_deleted", $parameter['is_deleted']);
- }
- }
- if ($limit != FALSE) {
- $this->limit($limit);
- }
- $this->orderBy('id', 'ASC');
- // Result
- if ($num_rows === FALSE) {
- $result = $this->get()->getResult();
- }
- else{
- $result = $this->countAllResults();
- }
- return $result;
- }
- public function select_table4($parameter){
- $this->select("
- COALESCE(
- (
- SELECT
- images
- FROM
- tb_investment_images
- WHERE
- id_investment = tb_investment.id
- AND
- `tb_investment_images`.`is_deleted` = 0
- LIMIT 1
- ), NULL
- ) AS images,
- tb_investment.*
- ");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['tahun'] != FALSE) {
- $this->where("tahun", $parameter["tahun"]);
- }
- if ($parameter['id_sub_sektor'] != FALSE) {
- $this->where("md5(tb_investment.id_sektor_sub) =", $parameter["id_sub_sektor"]);
- }
- if ($parameter['id_kecamatan'] != FALSE) {
- $this->where("md5(tb_investment.id_kecamatan) =", $parameter["id_kecamatan"]);
- }
- if ($parameter['minValue'] != FALSE) {
- $this->where("tb_investment.price >=", $parameter["minValue"]);
- }
- if ($parameter['maxValue'] != FALSE) {
- $this->where("tb_investment.price <=", $parameter["maxValue"]);
- }
- if ($parameter['search'] != FALSE) {
- $this->like('(LOWER(tb_investment.name)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_sektor)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_sektor_sub)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_kecamatan)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_kelurahan)', strtolower($parameter['search']));
- $this->where('1 = 1 )');
- }
- }
- $this->where('tb_investment.is_deleted', 0);
- $this->groupBy('tb_investment.id');
- $this->orderBy('tb_investment.id', 'ASC');
- $data = array(
- 'data' => $this->paginate(8, 'investment'),
- "pager" => $this->pager,
- );
- return $data;
- }
- public function select_table5($parameter){
- $this->select("COUNT(tb_investment.id) AS count");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['tahun'] != FALSE) {
- $this->where("tahun", $parameter["tahun"]);
- }
- if ($parameter['id_sub_sektor'] != FALSE) {
- $this->where("md5(tb_investment.id_sektor_sub) =", $parameter["id_sub_sektor"]);
- }
- if ($parameter['id_kecamatan'] != FALSE) {
- $this->where("md5(tb_investment.id_kecamatan) =", $parameter["id_kecamatan"]);
- }
- if ($parameter['minValue'] != FALSE) {
- $this->where("tb_investment.price >=", $parameter["minValue"]);
- }
- if ($parameter['maxValue'] != FALSE) {
- $this->where("tb_investment.price <=", $parameter["maxValue"]);
- }
- if ($parameter['search'] != FALSE) {
- $this->like('(LOWER(tb_investment.name)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_sektor)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_sektor_sub)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_kecamatan)', strtolower($parameter['search']));
- $this->orLike('LOWER(tb_investment.name_kelurahan)', strtolower($parameter['search']));
- $this->where('1 = 1 )');
- }
- }
- $this->where('tb_investment.is_deleted', 0);
- $this->orderBy('tb_investment.id', 'ASC');
- $data = $this->get()->getResult();
- return $data;
- }
- public function select_table6($parameter, $limit, $order=FALSE, $num_rows=TRUE){
- $this->select("*");
- $this->table($this->table);
- if ($parameter != FALSE) {
- if ($parameter['id'] != FALSE) {
- $this->where("md5(id) =", $parameter['id']);
- }
- if ($parameter['tahun'] != FALSE) {
- $this->where("tahun", $parameter['tahun']);
- }
- if ($parameter['is_deleted'] > -1) {
- $this->where("is_deleted", $parameter['is_deleted']);
- }
- }
- if ($limit != FALSE) {
- $this->limit($limit);
- }
- if ($order != FALSE) {
- $this->orderBy('id', $order);
- }
- // Result
- if ($num_rows === FALSE) {
- $result = $this->get()->getResult();
- }
- else{
- $result = $this->countAllResults();
- }
- return $result;
- }
- // -------------------------------
- // ----------- Selesai -----------
- // ---------------------------- //
- // -------------------------------
- // -------------------------------
- // Serverside Model
- // -------------------------------
- // ---------------------------- //
- public function inserts($data = NULL){
- $process = $this->db->table($this->table)->insert($data);
- if ($process) {
- return array("status" => TRUE, "id" => $this->insertID());
- }
- else{
- return array("status" => FALSE);
- }
- }
- public function updates($id = NULL, $data = NULL){
- $process = $this->db->table($this->table)->update($data, ['md5(id)' => $id]);
- if ($process) {
- return TRUE;
- }
- else{
- return FALSE;
- }
- }
- // -------------------------------
- // ----------- Selesai -----------
- // ---------------------------- //
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement