original_string: public function buildDataRequestQuery(DataRequest $dataRequest, QueryBuilder $queryBuilder, $entity, $tableCode)
      {
          $queryBuilder->select($tableCode)
                       ->from($entity, $tableCode);
          
          $hasWhere = false;
          $i = 1;
          foreach ($dataRequest->getFilters() as $filter) {
              $whereQuery = $tableCode . '.' . $filter->getFieldName() . ' ' . $filter->getMode() . ' :p' . $i;
              if ($hasWhere) {
                  $queryBuilder->andWhere($whereQuery);
              } else {
                  $queryBuilder->where($whereQuery);
                  $hasWhere = true;
              }
              
              $queryBuilder->setParameter('p' . $i, $this->prepareValue($filter->getNeededValue(), $filter->getMode()));
              $i++;
          }
          
          // Sorting
          if ($dataRequest->hasSorting()) {
              $mode = 'ASC';
              if (in_array($dataRequest->getSortByDirection(), array('ASC', 'DESC'))) {
                  $mode = $dataRequest->getSortByDirection();
              }
              
              $queryBuilder->orderBy($tableCode . '.' . $dataRequest->getSortBy(), $mode);
          }
          
          // Offset
          if ($dataRequest->hasRange()) {
              $queryBuilder->setFirstResult($dataRequest->getOffset());
              $queryBuilder->setMaxResults($dataRequest->getNumberOfEntries());
          }
      }
code: public function buildDataRequestQuery(DataRequest $dataRequest, QueryBuilder $queryBuilder, $entity, $tableCode)
      {
          $queryBuilder->select($tableCode)
                       ->from($entity, $tableCode);
          
          $hasWhere = false;
          $i = 1;
          foreach ($dataRequest->getFilters() as $filter) {
              $whereQuery = $tableCode . '.' . $filter->getFieldName() . ' ' . $filter->getMode() . ' :p' . $i;
              if ($hasWhere) {
                  $queryBuilder->andWhere($whereQuery);
              } else {
                  $queryBuilder->where($whereQuery);
                  $hasWhere = true;
              }
              
              $queryBuilder->setParameter('p' . $i, $this->prepareValue($filter->getNeededValue(), $filter->getMode()));
              $i++;
          }
          
          // Sorting
          if ($dataRequest->hasSorting()) {
              $mode = 'ASC';
              if (in_array($dataRequest->getSortByDirection(), array('ASC', 'DESC'))) {
                  $mode = $dataRequest->getSortByDirection();
              }
              
              $queryBuilder->orderBy($tableCode . '.' . $dataRequest->getSortBy(), $mode);
          }
          
          // Offset
          if ($dataRequest->hasRange()) {
              $queryBuilder->setFirstResult($dataRequest->getOffset());
              $queryBuilder->setMaxResults($dataRequest->getNumberOfEntries());
          }
      }
code_tokens: public function buildDataRequestQuery ( DataRequest $ dataRequest , QueryBuilder $ queryBuilder , $ entity , $ tableCode ) { $ queryBuilder -> select ( $ tableCode ) -> from ( $ entity , $ tableCode ) ; $ hasWhere = false ; $ i = 1 ; foreach ( $ dataRequest -> getFilters ( ) as $ filter ) { $ whereQuery = $ tableCode . '.' . $ filter -> getFieldName ( ) . ' ' . $ filter -> getMode ( ) . ' :p' . $ i ; if ( $ hasWhere ) { $ queryBuilder -> andWhere ( $ whereQuery ) ; } else { $ queryBuilder -> where ( $ whereQuery ) ; $ hasWhere = true ; } $ queryBuilder -> setParameter ( 'p' . $ i , $ this -> prepareValue ( $ filter -> getNeededValue ( ) , $ filter -> getMode ( ) ) ) ; $ i ++ ; } // Sorting if ( $ dataRequest -> hasSorting ( ) ) { $ mode = 'ASC' ; if ( in_array ( $ dataRequest -> getSortByDirection ( ) , array ( 'ASC' , 'DESC' ) ) ) { $ mode = $ dataRequest -> getSortByDirection ( ) ; } $ queryBuilder -> orderBy ( $ tableCode . '.' . $ dataRequest -> getSortBy ( ) , $ mode ) ; } // Offset if ( $ dataRequest -> hasRange ( ) ) { $ queryBuilder -> setFirstResult ( $ dataRequest -> getOffset ( ) ) ; $ queryBuilder -> setMaxResults ( $ dataRequest -> getNumberOfEntries ( ) ) ; } }
docstring: Builds the query for the given data request object
  
  @access public
  @param \Zepi\DataSource\Core\Entity\DataRequest $dataRequest
  @param \Doctrine\ORM\QueryBuilder $queryBuilder
  @param string $entity
  @param string $tableCode
docstring_tokens: Builds the query for the given data request object