Skip to content

Commit

Permalink
Release version 2.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenanhung committed Sep 11, 2024
1 parent 7e2f53d commit 1e48fdb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
73 changes: 54 additions & 19 deletions src/Model/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand All @@ -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
Expand Down Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1e48fdb

Please sign in to comment.