/**
  * @param string                   $value
  * @param QueryOptimizationContext $context
  *
  * @return bool
  */
 protected function isTrueValue($value, QueryOptimizationContext $context)
 {
     if ($value === 'true' || $value === '1') {
         return true;
     }
     if (strpos($value, ':') === 0 || strpos($value, '?') === 0) {
         $param = $context->getOriginalQueryBuilder()->getParameter(substr($value, 1));
         if ($param instanceof Parameter) {
             $paramValue = $param->getValue();
             if ($paramValue === true || $paramValue === 1) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Gets the type of an association between the given entities
  *
  * @param string $entityClass
  * @param string $associationName
  * @param string $targetEntityClass
  *
  * @return int
  */
 protected function getAssociationType($entityClass, $associationName, $targetEntityClass)
 {
     $associations = $this->context->getClassMetadata($entityClass)->getAssociationsByTargetClass($targetEntityClass);
     if (!array_key_exists($associationName, $associations)) {
         return 0;
     }
     return $associations[$associationName]['type'];
 }
 /**
  * Get SELECT fields for optimized Query Builder.
  *
  * By default all identifier fields are added.
  * If some of them are selected as DISTINCT in original Query Builder,
  * then them also should be selected as DISTINCT in optimized Query Builder.
  *
  * @param array $originalQueryParts
  * @return array
  */
 protected function getFieldsToSelect(array $originalQueryParts)
 {
     $fieldsToSelect = [];
     foreach ($originalQueryParts['from'] as $from) {
         /** @var Expr\From $from */
         $fieldNames = $this->context->getClassMetadata($from->getFrom())->getIdentifierFieldNames();
         foreach ($fieldNames as $fieldName) {
             $selectField = $from->getAlias() . '.' . $fieldName;
             /** @var Expr\Select $originalSelect */
             foreach ($originalQueryParts['select'] as $originalSelect) {
                 foreach ($originalSelect->getParts() as $part) {
                     if (strtolower((string) $part) === 'distinct ' . $selectField) {
                         $selectField = 'DISTINCT ' . $selectField;
                         break;
                     }
                 }
             }
             $fieldsToSelect[] = $selectField;
         }
     }
     return $fieldsToSelect;
 }
 /**
  * Gets original query builder
  *
  * @return QueryBuilder
  */
 public function getOriginalQueryBuilder()
 {
     return $this->context->getOriginalQueryBuilder();
 }