-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e2f53d
commit 1e48fdb
Showing
2 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ | |
interface Environment | ||
{ | ||
const PROJECT_NAME = 'My Database Packages by HungNG'; | ||
const VERSION = '2.2.2'; | ||
const LAST_MODIFIED = '2023-09-26'; | ||
const VERSION = '2.2.3'; | ||
const LAST_MODIFIED = '2024-09-11'; | ||
const AUTHOR_NAME = 'Hung Nguyen'; | ||
const AUTHOR_EMAIL = '[email protected]'; | ||
const AUTHOR_URL = 'https://nguyenanhung.com'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,10 @@ trait Helper | |
* @param int $pageIndex | ||
* @param int $pageSize | ||
* | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @return array | ||
* @see https://laravel.com/docs/6.x/queries#ordering-grouping-limit-and-offset | ||
* | ||
* @return array | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/21/2021 23:24 | ||
|
@@ -74,17 +74,17 @@ public function prepareOffset($page = 1, $size = 10) | |
$start = $page; | ||
} | ||
|
||
return (int) $start; | ||
return (int)$start; | ||
} | ||
|
||
/** | ||
* Function prepareOptionFormat | ||
* | ||
* @param mixed $options | ||
* | ||
* @return string|null | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* | ||
* @return string|null | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 09/22/2021 22:22 | ||
|
@@ -107,10 +107,10 @@ public function prepareOptionFormat($options = array()) | |
* | ||
* @param string $selectField String danh sác các cột cần lấy ra | ||
* | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @return array|string|string[] | ||
* @see https://laravel.com/docs/6.x/queries#selects | ||
* | ||
* @return array|string|string[] | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 09/21/2021 10:57 | ||
|
@@ -144,10 +144,10 @@ public function formatSelectFieldStringToArray($selectField = '') | |
* | ||
* @param array|string|null $selectField Mảng hoặc string danh sác các cột cần lấy ra | ||
* | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @return array|string|string[] | ||
* @see https://laravel.com/docs/6.x/queries#selects | ||
* | ||
* @return array|string|string[] | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 09/21/2021 12:12 | ||
|
@@ -212,7 +212,9 @@ public function prepareQueryStatementOptions(Builder $builder, $options = null) | |
} | ||
|
||
// Sắp xếp dữ liệu đổ ra ngẫu nhiên nếu như Option Order By ghi nhận giá trị random | ||
if (isset($options['orderBy']) && is_string($options['orderBy']) && strtolower($options['orderBy']) === 'random') { | ||
if (isset($options['orderBy']) && is_string($options['orderBy']) && strtolower( | ||
$options['orderBy'] | ||
) === 'random') { | ||
$builder->inRandomOrder(); | ||
} | ||
|
||
|
@@ -229,20 +231,20 @@ public function prepareQueryStatementOptions(Builder $builder, $options = null) | |
* Function prepareWhereAndFieldStatement | ||
* | ||
* @param \Illuminate\Database\Query\Builder $builder Class Query Builder | ||
* @param string|array $wheres Mảng hoặc giá trị dữ liệu cần so sánh | ||
* @param mixed $fields Column cần so sánh | ||
* @param mixed $options Mảng dữ liệu các cấu hình tùy chọn | ||
* @param string|array $wheres Mảng hoặc giá trị dữ liệu cần so sánh | ||
* @param mixed $fields Column cần so sánh | ||
* @param mixed $options Mảng dữ liệu các cấu hình tùy chọn | ||
* example $options = [ | ||
* 'format' => null, | ||
* 'orderBy => [ | ||
* 'id' => 'desc' | ||
* ] | ||
* ]; | ||
* | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @return \Illuminate\Database\Query\Builder | ||
* @see https://laravel.com/docs/6.x/queries | ||
* | ||
* @return \Illuminate\Database\Query\Builder | ||
* @see https://github.com/nguyenanhung/database/blob/master/src/Model/Helper.php | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 09/22/2021 02:38 | ||
|
@@ -392,7 +394,13 @@ public function prepareJoinStatement(Builder $builder) | |
if (isset($join['table'], $join['first'], $join['operator'], $join['second'])) { | ||
// Tiến hành join vào các bảng để lấy CSDL | ||
if (isset($join['type'])) { | ||
$builder->join($join['table'], $join['first'], $join['operator'], $join['second'], $join['type']); | ||
$builder->join( | ||
$join['table'], | ||
$join['first'], | ||
$join['operator'], | ||
$join['second'], | ||
$join['type'] | ||
); | ||
} else { | ||
$builder->join($join['table'], $join['first'], $join['operator'], $join['second']); | ||
} | ||
|
@@ -513,7 +521,7 @@ public function bindRecursiveFromCategory(Builder $db, $recursive, $parentId, $f | |
$listCategory[] = $parentId; // Push category cha | ||
foreach ($recursive as $item) { | ||
$itemId = is_array($item) ? $item['id'] : $item->id; | ||
$listCategory[] = (int) $itemId; // Push các category con vào mảng dữ liệu | ||
$listCategory[] = (int)$itemId; // Push các category con vào mảng dữ liệu | ||
} | ||
$db->whereIn($table . '.' . $field, $listCategory); // Lấy theo where in | ||
} else { | ||
|
@@ -547,7 +555,16 @@ public function filterByPrimaryId(Builder $db, $id, $field = 'id', $table = null | |
} | ||
if ($id !== null) { | ||
if (is_array($id)) { | ||
$db->whereIn($table . '.' . $field, $id); | ||
$countId = count($id); | ||
if ($countId > 1) { | ||
$db->whereIn($table . '.' . $field, $id); | ||
} else { | ||
if (isset($id[0])) { | ||
$db->where($table . '.' . $field, self::OPERATOR_EQUAL_TO, $id[0]); | ||
} else { | ||
$db->whereIn($table . '.' . $field, $id); | ||
} | ||
} | ||
} else { | ||
$db->where($table . '.' . $field, self::OPERATOR_EQUAL_TO, $id); | ||
} | ||
|
@@ -576,7 +593,16 @@ public function buildOperatorEqualTo(Builder $db, $id, $field = 'id', $table = n | |
} | ||
if ($id !== null) { | ||
if (is_array($id)) { | ||
$db->whereIn($table . '.' . $field, $id); | ||
$countId = count($id); | ||
if ($countId > 1) { | ||
$db->whereIn($table . '.' . $field, $id); | ||
} else { | ||
if (isset($id[0])) { | ||
$db->where($table . '.' . $field, self::OPERATOR_EQUAL_TO, $id[0]); | ||
} else { | ||
$db->whereIn($table . '.' . $field, $id); | ||
} | ||
} | ||
} else { | ||
$db->where($table . '.' . $field, self::OPERATOR_EQUAL_TO, $id); | ||
} | ||
|
@@ -605,7 +631,16 @@ public function buildOperatorNotEqualTo(Builder $db, $id, $field = 'id', $table | |
} | ||
if ($id !== null) { | ||
if (is_array($id)) { | ||
$db->whereNotIn($table . '.' . $field, $id); | ||
$countId = count($id); | ||
if ($countId > 1) { | ||
$db->whereNotIn($table . '.' . $field, $id); | ||
} else { | ||
if (isset($id[0])) { | ||
$db->where($table . '.' . $field, self::OPERATOR_NOT_EQUAL_TO, $id[0]); | ||
} else { | ||
$db->whereNotIn($table . '.' . $field, $id); | ||
} | ||
} | ||
} else { | ||
$db->where($table . '.' . $field, self::OPERATOR_NOT_EQUAL_TO, $id); | ||
} | ||
|