summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-11-29 17:03:52 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2016-01-17 18:18:39 +0100
commitd0155e9d66665a7195194a988e16ff16623e28f0 (patch)
treed7ec1d8c369bbf57443e0b1400444aea14e0a040 /db
parent69be70eaf4be874b2414220b459179e1f0ec9a97 (diff)
first step at cleaning up integration tests
Diffstat (limited to 'db')
-rw-r--r--db/newsmapper.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/db/newsmapper.php b/db/newsmapper.php
index eea69df2a..a36956b16 100644
--- a/db/newsmapper.php
+++ b/db/newsmapper.php
@@ -29,5 +29,31 @@ abstract class NewsMapper extends Mapper {
*/
abstract public function find($id, $userId);
+ /**
+ * Performs a SELECT query with all arguments appened to the WHERE clause
+ * The SELECT will be performed on the current table and take the entity
+ * that is related for transforming the properties into column names
+ * @param array $search an assoc array from property to filter value
+ * @return array
+ */
+ public function where(array $search) {
+ $entity = new $this->entityClass;
+
+ // turn keys into sql query filter, e.g. feedId -> feed_id = :feedId
+ $filter = array_map(function ($property) use ($entity) {
+ $column = $entity->propertyToColumn($property);
+ return $column . ' = :' . $property;
+ }, array_keys($search));
+
+ $andStatement = implode(' AND ', $filter);
+
+ $sql = 'SELECT * FROM `' . $this->getTableName() . '`';
+
+ if (count($search) > 0) {
+ $sql .= 'WHERE ' . $andStatement;
+ }
+
+ return $this->findEntities($sql, $search);
+ }
} \ No newline at end of file