Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version 4.0.6 #92

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading