Skip to content

Commit

Permalink
Merge pull request #75 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
Release version 3.1.1
  • Loading branch information
nguyenanhung authored Feb 7, 2023
2 parents 9823d63 + 5af6f77 commit a593920
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 210 deletions.
2 changes: 1 addition & 1 deletion src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
interface Environment
{
public const PROJECT_NAME = 'My Database by HungNG';
public const VERSION = '3.1.0.2';
public const VERSION = '3.1.1';
public const LAST_MODIFIED = '2023-02-07';
public const AUTHOR_NAME = 'Hung Nguyen';
public const AUTHOR_EMAIL = 'dev@nguyenanhung.com';
Expand Down
185 changes: 19 additions & 166 deletions src/Model/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,30 +687,8 @@ public function getInfo($wheres = '', $fields = 'id', $format = null, $select =
}
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $fields);
$this->logger->debug(__FUNCTION__, 'SQL Queries: ' . $query->toSql());
if ($format === 'result') {
$result = $query->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
} else {
$result = $query->first();
// $this->logger->debug(__FUNCTION__, 'Format is get first Result => ' . json_encode($result));
}
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}
if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}
if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}
if (($format === 'result') && ($result->count() <= 0)) {
return null;
}

return $result;
return $this->formatReturnRowsResult($query, $format);
}

/**
Expand Down Expand Up @@ -901,22 +879,9 @@ public function getResult($wheres = array(), $select = array('*'), $options = nu
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $this->table . '.' . $this->primaryKey, $options);
$this->logger->debug(__FUNCTION__, 'SQL Queries: ' . $query->toSql());
$result = $query->get($select);
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));

if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}
if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}
if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1050,23 +1015,9 @@ public function getResultWithSimpleInnerJoin(array $joins = array(), $select = a
}
$select = $this->prepareFormatSelectField($select);
$result = $db->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1106,23 +1057,9 @@ public function getResultWithInnerJoinAndWheres(array $joins = array(), $wheres
}
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $this->table . '.' . $this->primaryKey, $options);
$result = $query->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1160,23 +1097,9 @@ public function getResultWithSimpleCrossJoin(array $joins = array(), $select = a
}

$result = $db->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1215,23 +1138,9 @@ public function getResultWithCrossJoinAndWheres(array $joins = array(), $wheres
}
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $this->table . '.' . $this->primaryKey, $options);
$result = $query->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1268,23 +1177,9 @@ public function getResultWithSimpleLeftJoin(array $joins = array(), $select = ar
$db->leftJoin($join['table'], $join['first'], $join['operator'], $join['second']);
}
$result = $db->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1323,23 +1218,9 @@ public function getResultWithLeftJoinAndWheres(array $joins = array(), $wheres =
}
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $this->table . '.' . $this->primaryKey, $options);
$result = $query->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1376,23 +1257,9 @@ public function getResultWithSimpleRightJoin(array $joins = array(), $select = a
$db->rightJoin($join['table'], $join['first'], $join['operator'], $join['second']);
}
$result = $db->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down Expand Up @@ -1431,23 +1298,9 @@ public function getResultWithRightJoinAndWheres(array $joins = array(), $wheres
}
$query = $this->prepareWhereAndFieldStatement($db, $wheres, $this->table . '.' . $this->primaryKey, $options);
$result = $query->select($select)->get();
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
if ($format === 'json') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Json');
return $result->toJson();
}

if ($format === 'array') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Array');
return $result->toArray();
}

if ($format === 'base') {
// $this->logger->debug(__FUNCTION__, 'Output Result is Base');
return $result->toBase();
}

return $result;
// $this->logger->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
return $this->formatReturnResult($result, $format, false);
}

/**
Expand Down
Loading

0 comments on commit a593920

Please sign in to comment.