-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
]; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
lib/Core/Search/Solr/FieldMapper/Content/UserEnabledFieldMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
lib/Core/Search/Solr/Query/Content/CriterionVisitor/UserEnabled.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters