Skip to content

Commit a6a82f8

Browse files
authored
Update Model.php
1 parent a96e0b6 commit a6a82f8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/Model.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,22 @@ public static function instance($arg1, $arg2 = null) {
6767
$table = $model['table'];
6868

6969
if (isset($arg2)) {
70-
$fields = "`$arg1` = :value";
71-
$bind = [':value' => $arg2];
70+
$filter_str = "`$arg1` = :value";
71+
$binds = [':value' => $arg2];
7272
} else {
7373
if (is_array($arg1)) {
74-
$filters = [];
75-
$bind = [];
76-
foreach ($arg1 as $key => $value) {
77-
$filters[] = "`$key` = :$key";
78-
$bind[$key] = $value;
79-
}
80-
81-
$fields = implode(' AND ', $filters);
74+
$filter_str = self::create_filter($arg1, $binds, null);
8275
} else {
83-
$fields = "`id` = :value";
84-
$bind = [':value' => $arg1];
76+
$filter_str = "`id` = :value";
77+
$binds = [':value' => $arg1];
8578
}
8679
}
8780

88-
$active_field = self::get_field('active') ? "AND active = 1" : "";
81+
if (self::get_field('active')) {
82+
$filter_str = 'active = 1 AND '.$filter_str;
83+
}
8984

90-
return self::query_row("SELECT * FROM `$table` WHERE $fields $active_field", $bind);
85+
return self::query_row("SELECT * FROM `$table` WHERE $filter_str", $binds);
9186
}
9287

9388
public static function connect($host, $database, $username, $password) {

0 commit comments

Comments
 (0)