Skip to content

Commit

Permalink
Merge pull request #134 from kivudesign/version_boss
Browse files Browse the repository at this point in the history
[ENH] add missing count method for entity model
  • Loading branch information
bim-g authored Sep 17, 2023
2 parents e5fc13c + 0e38de1 commit 654d5d5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Core/Orm/EntityModel/Provider/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ abstract class Entity implements EntityInterface
* @var array
*/
private array $include_entity;
/**
* @var array|mixed
*/
private array $param;
use EntityReflexion;

/**
Expand All @@ -31,6 +35,7 @@ public function __construct()
{
$this->db = DB::getInstance();
$this->include_entity = [];
$this->param = [];
}

/**
Expand Down Expand Up @@ -200,7 +205,28 @@ public function findOne(): array
return ['exception' => $ex->getMessage()];
}
}
/**
* @return array
*/
public function count(): array
{
try {

$query = $this->db->count($this->getTableName());
if (isset($this->param['where'])) {
$query->where($this->param['where']);
}

$result = $query->result();
$this->param = [];
if ($this->db->error()) {
throw new \Exception($this->db->error());
}
return $result;
} catch (\Exception $ex) {
return ['exception' => $ex->getMessage()];
}
}
/**
* @param array $fields
* @return $this
Expand Down

0 comments on commit 654d5d5

Please sign in to comment.