Skip to content

Commit

Permalink
Merge pull request #13 from drosanda/feature/enrich_search_result
Browse files Browse the repository at this point in the history
FEAT: #12 enrich search result
  • Loading branch information
drosanda authored Sep 3, 2024
2 parents fbf904d + ebb7251 commit fbafbc9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PHP Lint Check

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: PHP lint
run: |
lint_errors=$(find app -type f -name "*.php" -exec php -l {} \; 2>&1)
echo "$lint_errors"
if grep -q "Parse error" <<< "$lint_errors"; then
exit 1
fi
17 changes: 15 additions & 2 deletions app/model/api/d_provinsi_model.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class D_Provinsi_Model extends SENE_Model
class D_Provinsi_Model extends \SENE_Model
{
public $tbl = 'd_provinsi';
public $tbl_as = 'dp';
Expand Down Expand Up @@ -112,30 +112,43 @@ public function getSearch($nation_code, $negara_nama, $keyword="")
$this->db->order_by("$this->tbl_as.nama", "asc");
return $this->db->get('', 0);
}
private function join_zipcode()
{
$composites = [
$this->db->composite_create("$this->tbl3_as.id", "=", "$this->tbl6_as.d_kabkota_id", "AND", 1, 0),
$this->db->composite_create("$this->tbl4_as.id", "=", "$this->tbl6_as.d_kecamatan_id", "AND", 0, 1)
];

return $composites;
}
public function cari($keyword)
{
$this->db->select_as("$this->tbl2_as.nama", "negara", 0);
$this->db->select_as("$this->tbl_as.nama", "provinsi", 0);
$this->db->select_as("$this->tbl3_as.nama", "kabkota", 0);
$this->db->select_as("$this->tbl4_as.nama", "kecamatan", 0);
$this->db->select_as("$this->tbl5_as.nama", "desakel", 0);
$this->db->select_as("$this->tbl6_as.kodepos", "kodepos", 0);

$this->db->from($this->tbl, $this->tbl_as);
$this->db->join($this->tbl2, $this->tbl2_as, 'nation_code', $this->tbl_as, 'd_negara_nation_code', '');
$this->db->join($this->tbl3, $this->tbl3_as, 'd_provinsi_id', $this->tbl_as, 'id', '');
$this->db->join($this->tbl4, $this->tbl4_as, 'd_kabkota_id', $this->tbl3_as, 'id', '');
$this->db->join($this->tbl5, $this->tbl5_as, 'd_kecamatan_id', $this->tbl4_as, 'id', '');
$this->db->join_composite($this->tbl6, $this->tbl6_as, $this->join_zipcode(), '');
if (strlen($keyword)>0) {
$this->db->where_as("$this->tbl_as.nama", $keyword, 'OR', 'like%%', 1, 0);
$this->db->where_as("$this->tbl2_as.nama", $keyword, 'OR', 'like%%', 0, 0);
$this->db->where_as("$this->tbl3_as.nama", $keyword, 'OR', 'like%%', 0, 0);
$this->db->where_as("$this->tbl4_as.nama", $keyword, 'OR', 'like%%', 0, 0);
$this->db->where_as("$this->tbl5_as.nama", $keyword, 'OR', 'like%%', 0, 1);
$this->db->where_as("$this->tbl5_as.nama", $keyword, 'OR', 'like%%', 0, 0);
$this->db->where_as("$this->tbl6_as.kodepos", $keyword, 'OR', 'like%%', 0, 1);
}
$this->db->order_by("$this->tbl_as.nama", "asc");
$this->db->order_by("$this->tbl3_as.nama", "asc");
$this->db->order_by("$this->tbl4_as.nama", "asc");
$this->db->order_by("$this->tbl5_as.nama", "asc");
$this->db->order_by("$this->tbl6_as.kodepos", "asc");
return $this->db->get('', 0);
}
}

0 comments on commit fbafbc9

Please sign in to comment.