Skip to content

Commit

Permalink
Merge pull request #92 from nguyenanhung/v4.x
Browse files Browse the repository at this point in the history
Release version 4.0.6
  • Loading branch information
nguyenanhung authored Sep 12, 2024
2 parents fe2a22c + 90e8134 commit 67913eb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 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
{
public const PROJECT_NAME = 'My Database Packages by HungNG';
public const VERSION = '4.0.5';
public const LAST_MODIFIED = '2024-09-11';
public const VERSION = '4.0.6';
public const LAST_MODIFIED = '2024-09-12';
public const AUTHOR_NAME = 'Hung Nguyen';
public const AUTHOR_EMAIL = '[email protected]';
public const AUTHOR_URL = 'https://nguyenanhung.com';
Expand Down
61 changes: 50 additions & 11 deletions src/Model/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,27 +777,51 @@ public function buildOperatorSpaceShipTo(Builder $db, $id, string $field = 'id',
*
* @param \Illuminate\Database\Query\Builder $db
* @param $orderByField
* @param string $defaultField
* @param mixed $table
* @param $defaultField
* @param $table
* @param $tmpTable
* @param $tmpField
*
* @return \Illuminate\Database\Query\Builder
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 07/02/2023 28:46
*/
public function bindOrderBy(Builder $db, $orderByField, string $defaultField = 'updated_at', $table = null): Builder
{
public function bindOrderBy(
Builder $db,
$orderByField,
$defaultField = 'updated_at',
$table = null,
$tmpTable = null,
$tmpField = null
) {
if (empty($table)) {
$table = $this->table;
}
if (isset($orderByField) && is_array($orderByField) && count($orderByField) > 0) {
foreach ($orderByField as $field) {
$db->orderBy($table . '.' . $field['field_name'], $field['order_value']);
if (
($tmpTable !== null && $tmpField !== null) &&
$field['field_name'] === $tmpField &&
$this->getSchema()->hasColumn($tmpTable, $tmpField)
) {
$db->orderBy($tmpTable . '.' . $tmpField, $field['order_value']);
} else {
$db->orderBy($table . '.' . $field['field_name'], $field['order_value']);
}
}
} elseif (mb_strtolower($defaultField) === 'random') {
} elseif (strtolower($defaultField) === 'random') {
$db->inRandomOrder();
} else {
$db->orderByDesc($table . '.' . $defaultField);
if (
($tmpTable !== null && $tmpField !== null) &&
$defaultField === $tmpField &&
$this->getSchema()->hasColumn($tmpTable, $tmpField)
) {
$db->orderByDesc($tmpTable . '.' . $tmpField);
} else {
$db->orderByDesc($table . '.' . $defaultField);
}
}

return $db;
Expand All @@ -808,21 +832,36 @@ public function bindOrderBy(Builder $db, $orderByField, string $defaultField = '
*
* @param \Illuminate\Database\Query\Builder $db
* @param $orderByField
* @param mixed $table
* @param $table
* @param $tmpTable
* @param $tmpField
*
* @return \Illuminate\Database\Query\Builder
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 07/02/2023 28:41
*/
public function bindOrderByNoDefault(Builder $db, $orderByField, $table = null): Builder
{
public function bindOrderByNoDefault(
Builder $db,
$orderByField,
$table = null,
$tmpTable = null,
$tmpField = null
) {
if (empty($table)) {
$table = $this->table;
}
if (isset($orderByField) && is_array($orderByField) && count($orderByField) > 0) {
foreach ($orderByField as $field) {
$db->orderBy($table . '.' . $field['field_name'], $field['order_value']);
if (
($tmpTable !== null && $tmpField !== null) &&
$field['field_name'] === $tmpField &&
$this->getSchema()->hasColumn($tmpTable, $tmpField)
) {
$db->orderBy($tmpTable . '.' . $tmpField, $field['order_value']);
} else {
$db->orderBy($table . '.' . $field['field_name'], $field['order_value']);
}
}
}

Expand Down

0 comments on commit 67913eb

Please sign in to comment.