Skip to content

Commit

Permalink
Merge pull request #161 from kivudesign/version_boss
Browse files Browse the repository at this point in the history
[FIX] error message while using asc or desc without order by.
  • Loading branch information
bim-g authored Jan 5, 2024
2 parents 7658c43 + 8e27d0e commit 19bac2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
$app_root = appDirSeparator(dirname(__DIR__));
foreach ($autoload as $src) {
$folder = $app_root . '/' . $src;
$dirs = getSubDirectories($folder);
$directories = getSubDirectories($folder);
$classFile = extractNamespace($class);
foreach ($dirs as $dir) {
foreach ($directories as $dir) {
$file = $dir . '/' . checkFileExtension($classFile);
if (is_file($file)) {
require_once "$file";
Expand Down
2 changes: 1 addition & 1 deletion config/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function serverDomain(): object
* Project autoload register
*/
require_once $ROOT_DIR . '/config/autoload.php';
require_once $ROOT_DIR . '/vendor/autoload.php';
//require_once $ROOT_DIR . '/vendor/autoload.php';
/**
* Project Utils
*/
Expand Down
37 changes: 20 additions & 17 deletions src/Core/Orm/DBSelect.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
/*
* Copyright (c) 2024. Wepesi Dev Framework
*/

namespace Wepesi\Core\Orm;

use Exception;
use PDO;
use Wepesi\Core\Escape;
use Wepesi\Core\Orm\Provider\DbProvider;
use Wepesi\Core\Orm\Traits\DBWhereCondition;
Expand Down Expand Up @@ -44,14 +49,11 @@ class DBSelect extends DbProvider
* @var string
*/
private string $_offset;

/**
* @var string
*/
private string $_dsc;
/**
* @var string
*/
private string $_asc;
private string $ascending;
/**
* @var string
*/
Expand All @@ -61,11 +63,11 @@ class DBSelect extends DbProvider

/**
*
* @param \PDO $pdo
* @param PDO $pdo
* @param string $table
* @param string|null $action
*/
public function __construct(\PDO $pdo, string $table, string $action = null)
public function __construct(PDO $pdo, string $table, string $action = null)
{
$this->table = $table;
$this->pdo = $pdo;
Expand All @@ -79,8 +81,7 @@ public function __construct(\PDO $pdo, string $table, string $action = null)
$this->_fields = ['keys' => '*'];
$this->_limit = '';
$this->_offset = '';
$this->_dsc = '';
$this->_asc = '';
$this->ascending = '';
$this->_between = '';
$this->include_object = [];
}
Expand Down Expand Up @@ -163,8 +164,7 @@ public function random(): DBSelect
*/
public function ASC(): DBSelect
{
$this->_asc = ' ASC ';
$this->_dsc = '';
$this->ascending = ' ASC ';
return $this;
}

Expand All @@ -174,8 +174,7 @@ public function ASC(): DBSelect
*/
public function DESC(): DBSelect
{
$this->_asc = '';
$this->_dsc = ' DESC ';
$this->ascending = ' DESC ';
return $this;
}

Expand Down Expand Up @@ -249,8 +248,12 @@ private function select()
}
$params = $this->where['value'] ?? [];
//
$sql = "SELECT {$fields} FROM {$this->table} " . $WHERE . $this->groupBY . $this->orderBy . $this->_asc . $this->_dsc . $this->_limit . $this->_offset;
$this->query($sql, $params);
if ($this->orderBy == '' && $this->ascending != '') {
$this->result['exception'] = 'You should provide the order by which field name to which field you to apply the `' . $this->ascending . '`.';
} else {
$sql = "SELECT {$fields} FROM {$this->table} " . $WHERE . $this->groupBY . $this->orderBy . $this->ascending . $this->_limit . $this->_offset;
$this->query($sql, $params);
}
}

/**
Expand Down Expand Up @@ -292,7 +295,7 @@ protected function formatData(array $result): array
}
return $this->buildStructure($result, $parent_entity[0], $children_entity, $other_entity);

} catch (\Exception $ex) {
} catch (Exception $ex) {
return ['exception' => $ex->getMessage()];
}
}
Expand Down Expand Up @@ -347,7 +350,7 @@ protected function buildStructure($result, string $parent_entity, array $childre
$data_result[] = (object)$parent_table;
}
return $data_result;
} catch (\Exception $ex) {
} catch (Exception $ex) {
return ['exception' => $ex->getMessage()];
}
}
Expand Down

0 comments on commit 19bac2d

Please sign in to comment.