From 5c1fe7d40f7485a0995f5d5979c5deacc9cb2070 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 6 Mar 2017 20:11:23 +0100 Subject: [PATCH] Fixing language request --- DataStorage/Database/DataMapperAbstract.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 91744d591..337af075b 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1492,15 +1492,16 @@ class DataMapperAbstract implements DataMapperInterface * Get object. * * @param int $relations Load relations + * @param string $lang Language * * @return array * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getAll(int $relations = RelationType::ALL) + public static function getAll(int $relations = RelationType::ALL, string $lang = '') { - $obj = self::populateIterable(self::getAllRaw()); + $obj = self::populateIterable(self::getAllRaw($lang)); self::fillRelations($obj, $relations); self::clear(); @@ -1533,13 +1534,14 @@ class DataMapperAbstract implements DataMapperInterface * @param int $limit Newest limit * @param Builder $query Pre-defined query * @param int $relations Load relations + * @param string $lang Language * * @return mixed * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL) + public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, string $lang = '') { self::extend(__CLASS__); @@ -1553,6 +1555,10 @@ class DataMapperAbstract implements DataMapperInterface $query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC'); } + if (!empty(self::$language_field) && !empty($lang)) { + $query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); + } + $sth = self::$db->con->prepare($query->toSql()); $sth->execute(); @@ -1686,14 +1692,21 @@ class DataMapperAbstract implements DataMapperInterface /** * Get all in raw output. * + * @param string $lang Language + * * @return array * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getAllRaw() : array + public static function getAllRaw(string $lang = '') : array { $query = self::getQuery(); + + if (!empty(self::$language_field) && !empty($lang)) { + $query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); + } + $sth = self::$db->con->prepare($query->toSql()); $sth->execute();