Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
hknezevic committed Oct 11, 2024
2 parents 7ffb6c3 + 76bb602 commit 7706bc0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/API/Values/Content/Query/Criterion/UserEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\API\Values\Content\Query\Criterion;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator\Specifications;

class UserEnabled extends Criterion
{
public function __construct(bool $value)
{
parent::__construct(null, null, $value);
}

public function getSpecifications(): array
{
return [
new Specifications(
Operator::EQ,
Specifications::FORMAT_SINGLE,
Specifications::TYPE_BOOLEAN,
),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\Content;

use Ibexa\Contracts\Core\Persistence\Content as SPIContent;
use Ibexa\Contracts\Core\Search\Field;
use Ibexa\Contracts\Core\Search\FieldType;
use Ibexa\Contracts\Solr\FieldMapper\ContentFieldMapper;

final class UserEnabledFieldMapper extends ContentFieldMapper
{
public function accept(SPIContent $content): bool
{
return $this->getUserField($content) !== null;
}

public function mapFields(SPIContent $content): array
{
$userField = $this->getUserField($content);
if ($userField === null) {
return [];
}

$fields = [];

if (isset($userField->value->externalData['enabled'])) {
$fields[] = new Field(
'ng_user_enabled',
$userField->value->externalData['enabled'],
new FieldType\BooleanField(),
);
}

return $fields;
}

private function getUserField(SPIContent $content): ?SPIContent\Field
{
foreach ($content->fields as $field) {
if ($field->type === 'ezuser') {
return $field;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Netgen\IbexaSearchExtra\Core\Search\Solr\Query\Content\CriterionVisitor;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
use Netgen\IbexaSearchExtra\API\Values\Content\Query\Criterion\UserEnabled as UserEnabledCriterion;

class UserEnabled extends CriterionVisitor
{
public function canVisit(Criterion $criterion): bool
{
return $criterion instanceof UserEnabledCriterion;
}

public function visit(Criterion $criterion, ?CriterionVisitor $subVisitor = null): string
{
$isEnabled = $criterion->value[0];

return 'ng_user_enabled_b:' . ($isEnabled ? 'true' : 'false');
}
}
5 changes: 5 additions & 0 deletions lib/Resources/config/search/solr/criterion_visitors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,8 @@ services:
tags:
- { name: ibexa.search.solr.query.content.criterion.visitor }
- { name: ibexa.search.solr.query.location.criterion.visitor }

netgen.ibexa_search_extra.solr.query.content.criterion_visitor.user_enabled:
class: Netgen\IbexaSearchExtra\Core\Search\Solr\Query\Content\CriterionVisitor\UserEnabled
tags:
- { name: ibexa.search.solr.query.content.criterion.visitor }
5 changes: 5 additions & 0 deletions lib/Resources/config/search/solr/field_mappers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ services:
class: Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\Location\LocationIdFieldMapper
tags:
- { name: ibexa.search.solr.field.mapper.location }

netgen.ibexa_search_extra.solr.field_mapper.content.user_enabled:
class: Netgen\IbexaSearchExtra\Core\Search\Solr\FieldMapper\Content\UserEnabledFieldMapper
tags:
- { name: ibexa.search.solr.field.mapper.content }

0 comments on commit 7706bc0

Please sign in to comment.