Skip to content

Commit

Permalink
IBX-2292: Changed API to use identifiers instead of numeric IDs (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaK authored Jul 27, 2022
1 parent 2a4373a commit aeee20a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions code_samples/api/public_php_api/src/Command/SegmentCommand.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
<?php declare(strict_types=1);

namespace App\Command;

use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Segmentation\Service\SegmentationService;
use Ibexa\Segmentation\Value\SegmentCreateStruct;
use Ibexa\Segmentation\Value\SegmentGroupCreateStruct;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Ibexa\Segmentation\Service\SegmentationService;

class SegmentCommand extends Command
{
Expand All @@ -28,7 +28,8 @@ public function __construct(SegmentationService $segmentationService, UserServic
}

protected function configure()
{}
{
}

protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -51,21 +52,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

$newSegment = $this->segmentationService->createSegment($segmentCreateStruct);

$segmentGroup = $this->segmentationService->loadSegmentGroup(1);
$segmentGroup = $this->segmentationService->loadSegmentGroupByIdentifier('custom_group');

$segments = $this->segmentationService->loadSegmentsAssignedToGroup($segmentGroup);

foreach ($segments as $segment) {
$output->writeln('Segment ID: ' . $segment->id . ', name: ' . $segment->name);
}

$segment = $this->segmentationService->loadSegment(1);
$segment = $this->segmentationService->loadSegmentByIdentifier('segment_1');

$this->segmentationService->assignUserToSegment($user, $segment);

$output->writeln(($this->segmentationService->isUserAssignedToSegment($user, $segment)
? "The user is assigned to the segment."
: "The user is not assigned to the segment."
$output->writeln((
$this->segmentationService->isUserAssignedToSegment($user, $segment)
? 'The user is assigned to the segment.'
: 'The user is not assigned to the segment.'
));

return self::SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions docs/api/public_php_api_managing_users.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ To manage Segments, use the `SegmentationService`.

### Getting Segment information

To load a Segment Group, use `SegmentationService::loadSegmentGroup()`.
To load a Segment Group, use `SegmentationService::loadSegmentGroupByIdentifier()`.
Get all Segments assigned to the group with `SegmentationService::loadSegmentsAssignedToGroup()`:

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 53, 60) =]]
```

Similarly, you can load a Segment in a group by using `SegmentationService::loadSegmentGroup()`:
Similarly, you can load a Segment in a group by using `SegmentationService::loadSegmentIdentifier()`:

``` php
[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 61, 62) =]]
Expand Down

0 comments on commit aeee20a

Please sign in to comment.