diff --git a/src/Charcoal/Model/AbstractModel.php b/src/Charcoal/Model/AbstractModel.php index e8157255..ba2e1ff4 100644 --- a/src/Charcoal/Model/AbstractModel.php +++ b/src/Charcoal/Model/AbstractModel.php @@ -301,30 +301,19 @@ public function saveProperties(array $properties = null) public function loadFromL10n($key, $value, array $langs) { $switch = []; - $where = []; + $where = []; foreach ($langs as $lang) { - $switch[] = 'when `'.$key.'_'.$lang.'` = :ident then \''.$lang.'\''; - $where[] = '`'.$key.'_'.$lang.'` = :ident'; + $switch[] = 'WHEN `'.$key.'_'.$lang.'` = :ident THEN \''.$lang.'\''; + $where[] = '`'.$key.'_'.$lang.'` = :ident'; } - $q = ' - SELECT - *, - (case - '.implode("\n", $switch).' - end) as _lang - FROM - `'.$this->source()->table().'` - WHERE - ('.implode(' OR ', $where).') - LIMIT - 1'; - - $binds = [ - 'ident' => $value - ]; - - $sth = $this->source()->dbQuery($q, $binds); + $source = $this->source(); + + $sql = 'SELECT *, (CASE '.implode("\n", $switch).' END) AS _lang '; + $sql .= 'FROM `'.$source->table().'` '; + $sql .= 'WHERE ('.implode(' OR ', $where).') LIMIT 1'; + + $sth = $source->dbQuery($sql, $binds); if ($sth === false) { throw new PDOException('Could not load item.'); } diff --git a/src/Charcoal/Source/DatabaseSource.php b/src/Charcoal/Source/DatabaseSource.php index 740dc292..9be42ff3 100644 --- a/src/Charcoal/Source/DatabaseSource.php +++ b/src/Charcoal/Source/DatabaseSource.php @@ -424,15 +424,11 @@ public function loadItemFromKey($key, $ident, StorableInterface $item = null) } $table = $this->table(); - $query = sprintf(' - SELECT - * - FROM - `%s` - WHERE - `%s` = :ident - LIMIT - 1', $table, $key); + $query = sprintf( + 'SELECT * FROM `%s` WHERE `%s` = :ident LIMIT 1', + $table, + $key + ); $binds = [ 'ident' => $ident