getDirection example


        return $sorting instanceof AverageProductAmountSorting;
    }

    public function handle(SortingInterface $sorting, QueryBuilder $query)
    {
        $this->addSorting($sorting$query);
    }

    private function addSorting(AverageProductAmountSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('customer.product_avg', $sorting->getDirection());
    }
}
foreach ($parsed->getParameters() as $key => $value) {
            $query->setParameter($key$value$parsed->getType($key));
        }
    }

    /** * @param array<FieldSorting> $sortings */
    public function addSortings(EntityDefinition $definition, Criteria $criteria, array $sortings, QueryBuilder $query, Context $context): void
    {
        foreach ($sortings as $sorting) {
            $this->validateSortingDirection($sorting->getDirection());

            if ($sorting->getField() === '_score') {
                if (!$this->hasQueriesOrTerm($criteria)) {
                    continue;
                }

                // Only add manual _score sorting if the query contains a _score calculation and selection (i.e. the                 // criteria has a term or queries). Otherwise the SQL selection would fail because no _score field                 // exists in any entity.                 $query->addOrderBy('_score', $sorting->getDirection());
                $query->addState('_score');

                
$data = [
                'name' => $aggregation->getName(),
                'type' => 'histogram',
                'interval' => $aggregation->getInterval(),
                'format' => $aggregation->getFormat(),
                'field' => $aggregation->getField(),
                'timeZone' => $aggregation->getTimeZone(),
            ];

            if ($aggregation->getSorting()) {
                $data['sort'] = [
                    'order' => $aggregation->getSorting()->getDirection(),
                    'naturalSorting' => $aggregation->getSorting()->getNaturalSorting(),
                    'field' => $aggregation->getSorting()->getField(),
                ];
            }

            if ($aggregation->getAggregation()) {
                $data['aggregation'] = $this->aggregationToArray($aggregation->getAggregation());
            }

            return $data;
        }

        
->parseSorting($sorting$definition, Context::createDefaultContext());

        if ($scriptSorting) {
            static::assertTrue($fieldSort->hasParameter('script'));
            $script = $fieldSort->getParameter('script');
            static::assertSame($expectedQuery$script);

            return;
        }

        static::assertSame($sorting->getField()$fieldSort->getField());
        static::assertSame($sorting->getDirection()$fieldSort->getOrder());
        static::assertSame([]$fieldSort->getParameters());
    }

    /** * @return iterable<string, array{FieldSorting, array<mixed>, Context}> */
    public static function providerCheapestPrice(): iterable
    {
        yield 'default cheapest price' => [
            new FieldSorting('cheapestPrice', FieldSorting::ASCENDING),
            [
                
// create a wrapper query which select the root primary key and the grouped reference ids         $wrapper = $this->connection->createQueryBuilder();
        $wrapper->select(
            [
                'LOWER(HEX(' . $root . '.id)) as id',
                'LOWER(HEX(child.id)) as child_id',
            ]
        );

        foreach ($sortings as $i => $sorting) {
            $wrapper->addOrderBy(sprintf('sort_%s', $i)$sorting->getDirection());
        }

        $wrapper->from($root$root);

        // wrap query into a sub select to restrict the association count from the outer query         $wrapper->leftJoin(
            $root,
            '(' . $query->getSQL() . ')',
            'child',
            'child.' . $foreignKey . ' = ' . $root . '.id AND id_count >= :offset AND id_count <= :limit'
        );

        

    public function generateSorting(
        SortingInterface $sorting,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addSorting($sorting$query);
    }

    private function addSorting(ProductNumberSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('variant.ordernumber', $sorting->getDirection());
    }
}

class ConfigurableLanguageUnitTest extends UnitTestCase {

  /** * @covers ::getDirection */
  public function testDirection() {
    // Direction of language writing, an integer. Usually either     // ConfigurableLanguage::DIRECTION_LTR or     // ConfigurableLanguage::DIRECTION_RTL.     $configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_LTR], 'configurable_language');
    $this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());

    // Test direction again, setting direction to RTL.     $configurableLanguage = new ConfigurableLanguage(['direction' => ConfigurableLanguage::DIRECTION_RTL], 'configurable_language');
    $this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
  }

  /** * @covers ::getWeight * @covers ::setWeight */
  public function testWeight() {
    
// Add the site's default language if requested.     if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {

      // Setup a language to have the defaults with data appropriate of the       // default language only for runtime.       $defaultLanguage = $this->getDefaultLanguage();
      $default = new Language(
        [
          'id' => $defaultLanguage->getId(),
          'name' => new TranslatableMarkup("Site's default language (@lang_name)",
            ['@lang_name' => $defaultLanguage->getName()]),
          'direction' => $defaultLanguage->getDirection(),
          'weight' => $defaultLanguage->getWeight(),
        ]
      );
      $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default;
    }

    foreach ($languages as $id => $language) {
      if (($language->isLocked() && ($flags & LanguageInterface::STATE_LOCKED)) || (!$language->isLocked() && ($flags & LanguageInterface::STATE_CONFIGURABLE))) {
        $filtered_languages[$id] = $language;
      }
    }

    
public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart));
    }

    private function getSorting(ProductStockSorting $criteriaPart): FieldSort
    {
        return new FieldSort('stock', strtolower($criteriaPart->getDirection())['unmapped_type' => 'keyword']);
    }
}


    public function setCriteria(Criteria $criteria)
    {
        $this->criteria = $criteria;
    }

    private function addSorting(PriceSorting $sorting, QueryBuilder $query, ShopContextInterface $context): void
    {
        $this->listingPriceSwitcher->joinPrice($query$this->criteria, $context);

        $query->addOrderBy('listing_price.cheapest_price', $sorting->getDirection());
    }
}

  protected function assertLanguage(string $id, string $label, string $direction = ConfigurableLanguageInterface::DIRECTION_LTR, int $weight = 0): void {
    /** @var \Drupal\language\ConfigurableLanguageInterface $language */
    $language = ConfigurableLanguage::load($id);
    $this->assertInstanceOf(ConfigurableLanguageInterface::class$language);
    $this->assertSame($label$language->label());
    $this->assertSame($direction$language->getDirection());
    $this->assertSame(0, $language->getWeight());
    $this->assertFalse($language->isLocked());
  }

  /** * Tests migration of Drupal 6 languages to configurable language entities. */
  public function testLanguageMigration() {
    $this->executeMigration('language');
    $this->assertLanguage('en', 'English');
    $this->assertLanguage('fr', 'French');
  }

    public function generateSorting(
        SortingInterface $sorting,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addSorting($sorting$query);
    }

    private function addSorting(ReleaseDateSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('product.datum', $sorting->getDirection())
            ->addOrderBy('product.changetime', $sorting->getDirection());
    }
}

        return $sorting instanceof CustomerGroupSorting;
    }

    public function handle(SortingInterface $sorting, QueryBuilder $query)
    {
        $this->addSorting($sorting$query);
    }

    private function addSorting(CustomerGroupSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('customer.customer_group_name', $sorting->getDirection());
    }
}
'#type' => 'textfield',
      '#title' => $this->t('Language name'),
      '#maxlength' => 64,
      '#default_value' => $language->label(),
      '#required' => TRUE,
    ];
    $form['direction'] = [
      '#type' => 'radios',
      '#title' => $this->t('Direction'),
      '#required' => TRUE,
      '#description' => $this->t('Direction that text in this language is presented.'),
      '#default_value' => $language->getDirection(),
      '#options' => [
        LanguageInterface::DIRECTION_LTR => $this->t('Left to right'),
        LanguageInterface::DIRECTION_RTL => $this->t('Right to left'),
      ],
    ];

    return $form;
  }

  /** * Validates the language editing element. */
$this->addSorting($sorting$query);
    }

    private function addSorting(ManualSorting $sorting, QueryBuilder $query): void
    {
        $query->leftJoin(
            CategoryConditionHandler::STATE_NAME,
            's_categories_manual_sorting',
            'manual_sorting',
            'manual_sorting.product_id = product.id AND manual_sorting.category_id = ' . CategoryConditionHandler::STATE_NAME . '.categoryID'
        )
            ->orderBy('IFNULL(manual_sorting.position, 99999)', $sorting->getDirection());
    }
}
Home | Imprint | This part of the site doesn't use cookies.