Skip to content

Commit

Permalink
[Update] Add tags and supertags (groups/super_groups)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo committed Aug 4, 2022
1 parent 1137ffa commit 5f3193e
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Controller/Api/RoutingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Oveleon\ContaoPropstackApiBundle\Controller\Note\NoteController;
use Oveleon\ContaoPropstackApiBundle\Controller\SearchInquiry\SearchInquiryController;
use Oveleon\ContaoPropstackApiBundle\Controller\Hook\HookController;
use Oveleon\ContaoPropstackApiBundle\Controller\Tag\TagController;
use Oveleon\ContaoPropstackApiBundle\Controller\Tag\SuperTagController;
use Oveleon\ContaoPropstackApiBundle\Controller\Task\TaskController;
use Oveleon\ContaoPropstackApiBundle\Controller\Team\TeamController;
use Oveleon\ContaoPropstackApiBundle\Controller\Unit\UnitController;
Expand Down Expand Up @@ -278,6 +280,56 @@ public function activityTypes(): JsonResponse
throw new ApiMethodDeniedException('The method used is not supported');
}

/**
* Tags
*
* @Route("/tags", name="tags")
*/
public function tags(): JsonResponse
{
$request = $this->requestStack->getCurrentRequest();
$parameters = $request->query->all();

$objTags = new TagController();
$objTags->setFormat(PropstackController::FORMAT_JSON);

switch($request->getMethod())
{
case PropstackController::METHOD_READ:
// Read
return $objTags->read($parameters);

case PropstackController::METHOD_CREATE:
// Create
return $objTags->create($parameters);
}

throw new ApiMethodDeniedException('The method used is not supported');
}

/**
* Super tags
*
* @Route("/super_tags", name="super_tags")
*/
public function superTags(): JsonResponse
{
$request = $this->requestStack->getCurrentRequest();
$parameters = $request->query->all();

$objTags = new SuperTagController();
$objTags->setFormat(PropstackController::FORMAT_JSON);

switch($request->getMethod())
{
case PropstackController::METHOD_READ:
// Read
return $objTags->read($parameters);
}

throw new ApiMethodDeniedException('The method used is not supported');
}

/**
* Tasks
*
Expand Down
14 changes: 14 additions & 0 deletions src/Controller/Options/SuperTagOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Oveleon\ContaoPropstackApiBundle\Controller\Options;

final class SuperTagOptions extends Options
{
protected function configure(): void
{
$this->set(Options::MODE_READ, [
'entity',
'include'
]);
}
}
20 changes: 20 additions & 0 deletions src/Controller/Options/TagOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Oveleon\ContaoPropstackApiBundle\Controller\Options;

final class TagOptions extends Options
{
protected function configure(): void
{
$this->set(Options::MODE_READ, [
'super_group',
'entity'
]);

$this->set(Options::MODE_CREATE, [
'super_group_id',
'entity',
'name',
]);
}
}
33 changes: 33 additions & 0 deletions src/Controller/Tag/SuperTagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Oveleon\ContaoPropstackApiBundle\Controller\Tag;

use Oveleon\ContaoPropstackApiBundle\Controller\Options\Options;
use Oveleon\ContaoPropstackApiBundle\Controller\Options\SuperTagOptions;
use Oveleon\ContaoPropstackApiBundle\Controller\PropstackController;

/**
* Handle super tag calls
*
* @link https://docs.propstack.de/reference/merkmale
*
* @author Sebastian Zoglowek <https://github.com/zoglo>
*/
class SuperTagController extends PropstackController
{
protected string $route = 'super_groups';

/**
* Read super tags
*/
public function read(array $parameters)
{
$this->call(
(new SuperTagOptions(Options::MODE_READ))
->validate($parameters),
self::METHOD_READ
);

return $this->getResponse();
}
}
47 changes: 47 additions & 0 deletions src/Controller/Tag/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Oveleon\ContaoPropstackApiBundle\Controller\Tag;

use Oveleon\ContaoPropstackApiBundle\Controller\Options\Options;
use Oveleon\ContaoPropstackApiBundle\Controller\Options\TagOptions;
use Oveleon\ContaoPropstackApiBundle\Controller\PropstackController;

/**
* Handle tag calls
*
* @link https://docs.propstack.de/reference/merkmale
*
* @author Sebastian Zoglowek <https://github.com/zoglo>
*/
class TagController extends PropstackController
{
protected string $route = 'groups';

/**
* Read tags
*/
public function read(array $parameters)
{
$this->call(
(new TagOptions(Options::MODE_READ))
->validate($parameters),
self::METHOD_READ
);

return $this->getResponse();
}

/**
* Create tags
*/
public function create(array $parameters)
{
$this->call(
(new TagOptions(Options::MODE_CREATE))
->validate($parameters),
self::METHOD_CREATE
);

return $this->getResponse();
}
}

0 comments on commit 5f3193e

Please sign in to comment.