Skip to content

Commit 7ab590b

Browse files
committed
Upgrade Custom_Base_model
1 parent 5a483f2 commit 7ab590b

File tree

1 file changed

+53
-31
lines changed

1 file changed

+53
-31
lines changed

hungng/HungNG_Custom_Based_model.php

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -678,27 +678,29 @@ public function delete($id = '')
678678
* Function request_builder
679679
*
680680
* @param $search
681+
* @param $table
681682
*
682683
* @author : 713uk13m <dev@nguyenanhung.com>
683684
* @copyright: 713uk13m <dev@nguyenanhung.com>
684685
* @time : 08/16/2021 29:37
685686
*/
686-
public function request_builder($search)
687+
public function request_builder($search, $table = '')
687688
{
689+
$tableName = !empty($table) ? trim($table) : $this->tableName;
688690
if (!empty($search)) {
689691
foreach ($search as $field => $value) {
690-
if (!empty($value) && $this->db->field_exists($field, $this->tableName)) {
692+
if (!empty($value) && $this->db->field_exists($field, $tableName)) {
691693
if (is_array($value)) {
692-
$this->db->where_in($this->tableName . '.' . $field, $value);
694+
$this->db->where_in($tableName . '.' . $field, $value);
693695
} else {
694-
$this->db->like($this->tableName . '.' . $field, $value);
696+
$this->db->like($tableName . '.' . $field, $value);
695697
}
696698
}
697699
if ($field === 'sort') {
698700
$sort = (strpos($value, '-') === false) ? 'DESC' : 'ASC';
699701
$column = (strpos($value, '-') === false) ? $value : substr($value, 1);
700-
if ($this->db->field_exists($column, $this->tableName)) {
701-
$this->db->order_by($this->tableName . '.' . $column, $sort);
702+
if ($this->db->field_exists($column, $tableName)) {
703+
$this->db->order_by($tableName . '.' . $column, $sort);
702704
}
703705
}
704706
}
@@ -742,19 +744,21 @@ public function build_list_id_with_parent_id($allSubId, $parentId)
742744
*
743745
* @param $value
744746
* @param $field
747+
* @param $table
745748
*
746749
* @return bool|\CI_DB_query_builder|object
747750
* @author : 713uk13m <dev@nguyenanhung.com>
748751
* @copyright: 713uk13m <dev@nguyenanhung.com>
749752
* @time : 08/02/2023 31:03
750753
*/
751-
public function prepare_simple_wheres_not_statement($value, $field = 'id')
754+
public function prepare_simple_wheres_not_statement($value, $field = 'id', $table = '')
752755
{
756+
$tableName = !empty($table) ? trim($table) : $this->tableName;
753757
if ($value !== null) {
754758
if (is_array($value)) {
755-
$this->db->where_not_in($this->tableName . '.' . $field, $value);
759+
$this->db->where_not_in($tableName . '.' . $field, $value);
756760
} else {
757-
$this->db->where($this->tableName . '.' . $field . $this->is_not, $value);
761+
$this->db->where($tableName . '.' . $field . $this->is_not, $value);
758762
}
759763
}
760764

@@ -766,19 +770,21 @@ public function prepare_simple_wheres_not_statement($value, $field = 'id')
766770
*
767771
* @param $value
768772
* @param $field
773+
* @param $table
769774
*
770775
* @return bool|\CI_DB_query_builder|object
771776
* @author : 713uk13m <dev@nguyenanhung.com>
772777
* @copyright: 713uk13m <dev@nguyenanhung.com>
773778
* @time : 08/02/2023 31:11
774779
*/
775-
public function prepare_simple_wheres_statement($value, $field = 'id')
780+
public function prepare_simple_wheres_statement($value, $field = 'id', $table = '')
776781
{
782+
$tableName = !empty($table) ? trim($table) : $this->tableName;
777783
if ($value !== null) {
778784
if (is_array($value)) {
779-
$this->db->where_in($this->tableName . '.' . $field, $value);
785+
$this->db->where_in($tableName . '.' . $field, $value);
780786
} else {
781-
$this->db->where($this->tableName . '.' . $field, $value);
787+
$this->db->where($tableName . '.' . $field, $value);
782788
}
783789
}
784790

@@ -940,19 +946,21 @@ public function bind_recursive_from_category($allSubId, $parentId, $field = 'cat
940946
*
941947
* @param $id
942948
* @param $field
949+
* @param $table
943950
*
944951
* @return bool|\CI_DB_query_builder|object
945952
* @author : 713uk13m <dev@nguyenanhung.com>
946953
* @copyright: 713uk13m <dev@nguyenanhung.com>
947954
* @time : 08/02/2023 03:06
948955
*/
949-
public function filter_by_primary_id($id, $field = 'id')
956+
public function filter_by_primary_id($id, $field = 'id', $table = '')
950957
{
958+
$tableName = !empty($table) ? trim($table) : $this->tableName;
951959
if ($id !== null) {
952960
if (is_array($id)) {
953-
$this->db->where_in($this->tableName . '.' . $field, $id);
961+
$this->db->where_in($tableName . '.' . $field, $id);
954962
} else {
955-
$this->db->where($this->tableName . '.' . $field, $id);
963+
$this->db->where($tableName . '.' . $field, $id);
956964
}
957965
}
958966

@@ -964,19 +972,21 @@ public function filter_by_primary_id($id, $field = 'id')
964972
*
965973
* @param $id
966974
* @param $field
975+
* @param $table
967976
*
968977
* @return bool|\CI_DB_query_builder|object
969978
* @author : 713uk13m <dev@nguyenanhung.com>
970979
* @copyright: 713uk13m <dev@nguyenanhung.com>
971980
* @time : 08/02/2023 03:02
972981
*/
973-
public function build_operator_equal_to($id, $field = 'id')
982+
public function build_operator_equal_to($id, $field = 'id', $table = '')
974983
{
984+
$tableName = !empty($table) ? trim($table) : $this->tableName;
975985
if ($id !== null) {
976986
if (is_array($id)) {
977-
$this->db->where_in($this->tableName . '.' . $field, $id);
987+
$this->db->where_in($tableName . '.' . $field, $id);
978988
} else {
979-
$this->db->where($this->tableName . '.' . $field, $id);
989+
$this->db->where($tableName . '.' . $field, $id);
980990
}
981991
}
982992

@@ -988,19 +998,21 @@ public function build_operator_equal_to($id, $field = 'id')
988998
*
989999
* @param $id
9901000
* @param $field
1001+
* @param $table
9911002
*
9921003
* @return bool|\CI_DB_query_builder|object
9931004
* @author : 713uk13m <dev@nguyenanhung.com>
9941005
* @copyright: 713uk13m <dev@nguyenanhung.com>
9951006
* @time : 08/02/2023 02:59
9961007
*/
997-
public function build_operator_not_equal_to($id, $field = 'id')
1008+
public function build_operator_not_equal_to($id, $field = 'id', $table = '')
9981009
{
1010+
$tableName = !empty($table) ? trim($table) : $this->tableName;
9991011
if ($id !== null) {
10001012
if (is_array($id)) {
1001-
$this->db->where_not_in($this->tableName . '.' . $field, $id);
1013+
$this->db->where_not_in($tableName . '.' . $field, $id);
10021014
} else {
1003-
$this->db->where($this->tableName . '.' . $field . $this->is_not, $id);
1015+
$this->db->where($tableName . '.' . $field . $this->is_not, $id);
10041016
}
10051017
}
10061018

@@ -1012,15 +1024,17 @@ public function build_operator_not_equal_to($id, $field = 'id')
10121024
*
10131025
* @param $id
10141026
* @param $field
1027+
* @param $table
10151028
*
10161029
* @return bool|\CI_DB_query_builder|object
10171030
* @author : 713uk13m <dev@nguyenanhung.com>
10181031
* @copyright: 713uk13m <dev@nguyenanhung.com>
10191032
* @time : 08/02/2023 02:56
10201033
*/
1021-
public function build_operator_less_than_to($id, $field = 'id')
1034+
public function build_operator_less_than_to($id, $field = 'id', $table = '')
10221035
{
1023-
$this->db->where($this->tableName . '.' . $field . ' ' . self::OPERATOR_LESS_THAN, $id);
1036+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1037+
$this->db->where($tableName . '.' . $field . ' ' . self::OPERATOR_LESS_THAN, $id);
10241038

10251039
return $this->db;
10261040
}
@@ -1030,15 +1044,17 @@ public function build_operator_less_than_to($id, $field = 'id')
10301044
*
10311045
* @param $id
10321046
* @param $field
1047+
* @param $table
10331048
*
10341049
* @return bool|\CI_DB_query_builder|object
10351050
* @author : 713uk13m <dev@nguyenanhung.com>
10361051
* @copyright: 713uk13m <dev@nguyenanhung.com>
10371052
* @time : 08/02/2023 02:53
10381053
*/
1039-
public function build_operator_greater_than_to($id, $field = 'id')
1054+
public function build_operator_greater_than_to($id, $field = 'id', $table = '')
10401055
{
1041-
$this->db->where($this->tableName . '.' . $field . ' ' . self::OPERATOR_GREATER_THAN, $id);
1056+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1057+
$this->db->where($tableName . '.' . $field . ' ' . self::OPERATOR_GREATER_THAN, $id);
10421058

10431059
return $this->db;
10441060
}
@@ -1048,15 +1064,17 @@ public function build_operator_greater_than_to($id, $field = 'id')
10481064
*
10491065
* @param $id
10501066
* @param $field
1067+
* @param $table
10511068
*
10521069
* @return bool|\CI_DB_query_builder|object
10531070
* @author : 713uk13m <dev@nguyenanhung.com>
10541071
* @copyright: 713uk13m <dev@nguyenanhung.com>
10551072
* @time : 08/02/2023 02:50
10561073
*/
1057-
public function build_operator_less_than_or_equal_to($id, $field = 'id')
1074+
public function build_operator_less_than_or_equal_to($id, $field = 'id', $table = '')
10581075
{
1059-
$this->db->where($this->tableName . '.' . $field . ' ' . self::OPERATOR_LESS_THAN_OR_EQUAL_TO, $id);
1076+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1077+
$this->db->where($tableName . '.' . $field . ' ' . self::OPERATOR_LESS_THAN_OR_EQUAL_TO, $id);
10601078

10611079
return $this->db;
10621080
}
@@ -1066,15 +1084,17 @@ public function build_operator_less_than_or_equal_to($id, $field = 'id')
10661084
*
10671085
* @param $id
10681086
* @param $field
1087+
* @param $table
10691088
*
10701089
* @return bool|\CI_DB_query_builder|object
10711090
* @author : 713uk13m <dev@nguyenanhung.com>
10721091
* @copyright: 713uk13m <dev@nguyenanhung.com>
10731092
* @time : 08/02/2023 02:46
10741093
*/
1075-
public function build_operator_greater_than_or_equal_to($id, $field = 'id')
1094+
public function build_operator_greater_than_or_equal_to($id, $field = 'id', $table = '')
10761095
{
1077-
$this->db->where($this->tableName . '.' . $field . ' ' . self::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $id);
1096+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1097+
$this->db->where($tableName . '.' . $field . ' ' . self::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $id);
10781098

10791099
return $this->db;
10801100
}
@@ -1084,15 +1104,17 @@ public function build_operator_greater_than_or_equal_to($id, $field = 'id')
10841104
*
10851105
* @param $id
10861106
* @param $field
1107+
* @param $table
10871108
*
10881109
* @return bool|\CI_DB_query_builder|object
10891110
* @author : 713uk13m <dev@nguyenanhung.com>
10901111
* @copyright: 713uk13m <dev@nguyenanhung.com>
10911112
* @time : 08/02/2023 02:41
10921113
*/
1093-
public function build_operator_space_ship_to($id, $field = 'id')
1114+
public function build_operator_space_ship_to($id, $field = 'id', $table = '')
10941115
{
1095-
$this->db->where($this->tableName . '.' . $field . ' ' . self::OPERATOR_IS_SPACESHIP, $id);
1116+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1117+
$this->db->where($tableName . '.' . $field . ' ' . self::OPERATOR_IS_SPACESHIP, $id);
10961118

10971119
return $this->db;
10981120
}

0 commit comments

Comments
 (0)