Skip to content

Commit

Permalink
Use QueryBuilder for where() conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Nov 17, 2018
1 parent fa9ee61 commit c89fb22
Showing 1 changed file with 20 additions and 12 deletions.
Expand Up @@ -494,7 +494,7 @@ public function loadGroupData(array $groupIds)
$q
->select('created', 'creator_id', 'id', 'modified', 'modifier_id', 'name')
->from('ezcontentclassgroup')
->where('id IN (:ids)')
->where($q->expr()->in('id', ':ids'))
->setParameter('ids', $groupIds, Connection::PARAM_INT_ARRAY);

return $q->execute()->fetchAll();
Expand Down Expand Up @@ -571,8 +571,8 @@ public function loadTypesDataForGroup($groupId, $status)
{
$q = $this->getLoadTypeQueryBuilder();
$q
->where('g.group_id = :gid')
->andWhere('c.version = :version')
->where($q->expr()->eq('g.group_id', ':gid'))
->andWhere($q->expr()->eq('c.version', ':version'))
->addOrderBy('c.identifier')
->setParameter('gid', $groupId, ParameterType::INTEGER)
->setParameter('version', $status, ParameterType::INTEGER);
Expand Down Expand Up @@ -873,8 +873,9 @@ public function updateType($typeId, $status, UpdateStruct $updateStruct)
public function loadTypesListData(array $typeIds): array
{
$q = $this->getLoadTypeQueryBuilder();

$q
->where('c.id IN (:ids)')
->where($q->expr()->in('c.id', ':ids'))
->andWhere($q->expr()->eq('c.version', Type::STATUS_DEFINED))
->setParameter('ids', $typeIds, Connection::PARAM_INT_ARRAY);

Expand All @@ -893,8 +894,8 @@ public function loadTypeData($typeId, $status)
{
$q = $this->getLoadTypeQueryBuilder();
$q
->where('c.id = :id')
->andWhere('c.version = :version')
->where($q->expr()->eq('c.id', ':id'))
->andWhere($q->expr()->eq('c.version', ':version'))
->setParameter('id', $typeId, ParameterType::INTEGER)
->setParameter('version', $status, ParameterType::INTEGER);

Expand All @@ -914,8 +915,8 @@ public function loadTypeDataByIdentifier($identifier, $status)
{
$q = $this->getLoadTypeQueryBuilder();
$q
->where('c.identifier = :identifier')
->andWhere('c.version = :version')
->where($q->expr()->eq('c.identifier', ':identifier'))
->andWhere($q->expr()->eq('c.version', ':version'))
->setParameter('identifier', $identifier, ParameterType::STRING)
->setParameter('version', $status, ParameterType::INTEGER);

Expand All @@ -935,8 +936,8 @@ public function loadTypeDataByRemoteId($remoteId, $status)
{
$q = $this->getLoadTypeQueryBuilder();
$q
->where('c.remote_id = :remote')
->andWhere('c.version = :version')
->where($q->expr()->eq('c.remote_id', ':remote'))
->andWhere($q->expr()->eq('c.version', ':version'))
->setParameter('remote', $remoteId, ParameterType::STRING)
->setParameter('version', $status, ParameterType::INTEGER);

Expand All @@ -949,6 +950,7 @@ public function loadTypeDataByRemoteId($remoteId, $status)
private function getLoadTypeQueryBuilder(): QueryBuilder
{
$q = $this->connection->createQueryBuilder();
$expr = $q->expr();
$q
->select([
'c.id AS ezcontentclass_id',
Expand Down Expand Up @@ -1002,13 +1004,19 @@ private function getLoadTypeQueryBuilder(): QueryBuilder
'c',
'ezcontentclass_attribute',
'a',
'c.id = a.contentclass_id AND c.version = a.version'
$expr->andX(
$expr->eq('c.id', 'a.contentclass_id'),
$expr->eq('c.version', 'a.version')
)
)
->leftJoin(
'c',
'ezcontentclass_classgroup',
'g',
'c.id = g.contentclass_id AND c.version = g.contentclass_version'
$expr->andX(
$expr->eq('c.id', 'g.contentclass_id'),
$expr->eq('c.version', 'g.contentclass_version')
)
)
->orderBy('a.placement');

Expand Down

0 comments on commit c89fb22

Please sign in to comment.