summaryrefslogtreecommitdiffstats
path: root/src/Psecio/Gatekeeper/DataSource/Mysql.php
diff options
context:
space:
mode:
authorBruno Skvorc <bruno@skvorc.me>2016-02-07 13:33:07 +0000
committerBruno Skvorc <bruno@skvorc.me>2016-02-07 13:33:07 +0000
commitb78dd603e327a625f4b70bc13ce3998b8c4d8a02 (patch)
tree06c911ee390436565d39785a72ffe21318936274 /src/Psecio/Gatekeeper/DataSource/Mysql.php
parent0f782126134f87499534d3690b893b829151cfd1 (diff)
downloadgatekeeper-b78dd603e327a625f4b70bc13ce3998b8c4d8a02.zip
gatekeeper-b78dd603e327a625f4b70bc13ce3998b8c4d8a02.tar.gz
gatekeeper-b78dd603e327a625f4b70bc13ce3998b8c4d8a02.tar.bz2
Count feature in progress
Diffstat (limited to 'src/Psecio/Gatekeeper/DataSource/Mysql.php')
-rw-r--r--src/Psecio/Gatekeeper/DataSource/Mysql.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Psecio/Gatekeeper/DataSource/Mysql.php b/src/Psecio/Gatekeeper/DataSource/Mysql.php
index 5a1403a..a254f67 100644
--- a/src/Psecio/Gatekeeper/DataSource/Mysql.php
+++ b/src/Psecio/Gatekeeper/DataSource/Mysql.php
@@ -228,6 +228,37 @@ class Mysql extends \Psecio\Gatekeeper\DataSource
}
/**
+ * Find count of entities by where conditions.
+ * All where conditions applied with AND
+ *
+ * @param \Modler\Model $model Model instance
+ * @param array $where Data to use in "where" statement
+ * @return array Fetched data
+ */
+ public function count(\Modler\Model $model, array $where = array())
+ {
+ $properties = $model->getProperties();
+ list($columns, $bind) = $this->setup($where);
+
+ $update = array();
+ foreach ($bind as $column => $name) {
+ // See if we keep to transfer it over to a column name
+ if (array_key_exists($column, $properties)) {
+ $column = $properties[$column]['column'];
+ }
+ $update[] = $column.' = '.$name;
+ }
+
+ $sql = 'select * from '.$model->getTableName();
+ if (!empty($update)) {
+ $sql .= ' where '.implode(' and ', $update);
+ }
+
+ $result = $this->fetch($sql, $where, true);
+ return $result;
+ }
+
+ /**
* Execute the request (not a fetch)
*
* @param string $sql SQL statement to execute