Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription entrypoints #23

Merged
merged 6 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
composer.lock
.idea
index.php
config.php
config.php
/.php-cs-fixer.php
/.php-cs-fixer.cache
/var/.php-cs-fixer.cache
34 changes: 34 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
->exclude(['var', 'tests/Support/_generated', 'tests/_output'])
->name('*.php')
->in([__DIR__.'/src', __DIR__.'/tests'])
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/var/.php-cs-fixer.cache')
->setRules([
'@Symfony' => true,
'@PER-CS2.0' => true,
'class_attributes_separation' => [
'elements' => [
'const' => 'none',
'method' => 'one',
'property' => 'one',
'trait_import' => 'none',
'case' => 'none',
],
],
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'function_declaration' => false,
'declare_strict_types' => true,
'set_type_to_cast' => true,
'no_alternative_syntax' => ['fix_non_monolithic_code' => true],
])
->setFinder($finder)
;
48 changes: 5 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Wrapper over the rest api of the Planka (https://github.com/plankanban/planka)
Tested on Planka version:
- 1.10.3
- 1.11
- 1.24.3

Implemented all entrypoints for the bar version **1.10.3** and later.

Expand Down Expand Up @@ -57,50 +58,11 @@ var_dump($result);
```


## Examples

### Example - Delete empty board

```php
<?php

use Planka\Bridge\PlankaClient;
use Planka\Bridge\TransportClients\Client;

require __DIR__ . '/vendor/autoload.php';

$config = new Config(
user: 'login',
password: '***************',
baseUri: 'http://192.168.1.101', // https://your.domain.com
port: 3000 // 443
);

$planka = new PlankaClient($config);

$planka->authenticate();

// Only projects and boards assigned to your user are available
$dto = $planka->project->list();

// dd($dto->items); // list projects

// the list will only contain boards available to your user
$boards = $dto->included->boards;

/** @var BoardItemDto $item */
foreach ($boards as $item) {
// we request each board separately
$board = $planka->board->get($item->id);

// list of board cards
$cardList = $board->included->cards;

if (empty($cardList)) {
// removing a board without cards
$planka->board->delete($item->id);
}
}
```
- [Delete empty board](docs/DELETE_EMPTY_BOARD.md)
- [Create new card on board.md](docs/ADD_NEW_CARD_ON_BOARD.md)
- [Subscribe user to card.md](docs/SUBSCRIBE_MEMBERSHIP_TO_CARD.md)

You can test this bundle for Rest API with a test script, in the folder `/tests/index.php`.
There you will find the main examples of using the script.
Expand Down
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"email": "airy@live.com"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"version": "1.2.0",
"require": {
"php": ">=8.1.0",
"symfony/http-client": "^6.2",
Expand All @@ -31,11 +34,14 @@
"dev-master": "0.1-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"version": "1.1.4",
"scripts": {
"fix-cs": [
"@php ./vendor/bin/php-cs-fixer fix --diff -v --allow-risky=yes --ansi"
]
},
"require-dev": {
"symfony/var-dumper": "^6.2",
"vimeo/psalm": "^5.11"
"vimeo/psalm": "^5.11",
"friendsofphp/php-cs-fixer": "^3.65"
}
}
}
20 changes: 20 additions & 0 deletions docs/ADD_NEW_CARD_ON_BOARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```shell
1. create card with a name.
2. edit created card, add a description, users
3. labels are added
4. files are added
```


```shell
the output of the script I expected:
1. create Card in Board with id $todo_id
2. name: $todo_name
3. descripion $todo_desc
4. tasks $todo_tasks
5. atachment $todo_atatch
6. members $todo_member
```


https://github.com/plankanban/planka/blob/v1.16.4/server/config/routes.js
46 changes: 46 additions & 0 deletions docs/DELETE_EMPTY_BOARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### Example - Delete empty board

```php
<?php

use Planka\Bridge\PlankaClient;
use Planka\Bridge\TransportClients\Client;

require __DIR__ . '/vendor/autoload.php';

$config = new Config(
user: 'login',
password: '***************',
baseUri: 'http://192.168.1.101', // https://your.domain.com
port: 3000 // 443
);

$planka = new PlankaClient($config);

$planka->authenticate();

// Only projects and boards assigned to your user are available
$dto = $planka->project->list();

// dd($dto->items); // list projects

// the list will only contain boards available to your user
$boards = $dto->included->boards;

/** @var BoardItemDto $item */
foreach ($boards as $item) {
// we request each board separately
$board = $planka->board->get($item->id);

// list of board cards
$cardList = $board->included->cards;

if (empty($cardList)) {
// removing a board without cards
$planka->board->delete($item->id);
}
}
```

https://github.com/plankanban/planka/blob/v1.16.4/server/config/routes.js

107 changes: 107 additions & 0 deletions docs/SUBSCRIBE_MEMBERSHIP_TO_CARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Example Subscribe and Unsubscribe user on cards

```php
<?php

declare(strict_types=1);

// before run `composer install`

use Planka\Bridge\Config;
use Planka\Bridge\PlankaClient;
use Planka\Bridge\Views\Dto\Card\CardMembershipDto;
use function Fp\Collection\map;

// copy config.example.php to config.php and setup for you
$config = include(__DIR__.'/config.php');

require __DIR__ . '/../vendor/autoload.php';

$config = new Config(
user: $config['login'],
password: $config['password'],
baseUri: $config['uri'],
port: $config['port']
);
$client = new PlankaClient($config);

if($client->getInfo()->getStatusCode() !== 200) {
die('Planka server not connected!');
}

if (!$client->authenticate()) {
die('User credentials not corrected!');
}

$list = $client->project->list();

$project = $list->items[0];

$projectInfo = $client->project->get($project->id);

$boards = [];

foreach ($list->included->boards as $item) {
if ($item->projectId === $project->id) {
$boards[] = $item;
}
}

$board = $boards[0];

$boardInfo = $client->board->get($board->id);

$user = $boardInfo->included->users[0];
$userId = $user->id;

$cards = [];

foreach ($boardInfo->included->cards as $item) {
// if user always subscribed - return SERVER ERROR 400
try {
$cardId = $item->id;
// subscribe user on cards
$client->card->subscribe($cardId, $userId);
} catch (Throwable $e) {}
}

$boardInfo = $client->board->get($board->id);

// on $boardInfo->included->cards not have info by memberships
foreach ($boardInfo->included->cards as $item) {
// see memberships at card info
$cardInfo = $client->card->get($item->id);

$info = [
'cardId' => $cardInfo->id,
'cardName' => $cardInfo->name,
// membershipId not equal userId
'memberships' => $cardInfo->included->cardMemberships,
'userId' => map($cardInfo->included->cardMemberships, fn(CardMembershipDto $dto) => [
'membershipId' => $dto->id,
'userId' => $dto->userId,
]),
];

var_dump($info);
}

// If you need unsubscribe user on cards use this - $client->card->unsubscribe($cardId, $userId);
// unsubscribe

$boardInfo = $client->board->get($board->id);

foreach ($boardInfo->included->cards as $item) {
// if user always unsubscribed - return SERVER ERROR 400
try {
$cardId = $item->id;

// subscribe user on cards
$client->card->unsubscribe($cardId, $userId);
} catch (Throwable $e) {}
}

```


https://github.com/plankanban/planka/blob/v1.16.4/server/config/routes.js
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
>
<projectFiles>
<directory name="src" />
Expand Down
7 changes: 4 additions & 3 deletions src/Actions/Attachment/AttachmentCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

final class AttachmentCreateAction implements ActionInterface, AuthenticateInterface, ResponseResultInterface
{
use AuthenticateTrait, AttachmentHydrateTrait;
use AuthenticateTrait;
use AttachmentHydrateTrait;

/**
* @throws FileExistException
*/
public function __construct(
private readonly string $cardId,
private readonly string $file,
string $token
string $token,
) {
$this->setToken($token);

Expand All @@ -49,4 +50,4 @@ public function getOptions(): array
'body' => $formData->bodyToIterable(),
];
}
}
}
5 changes: 3 additions & 2 deletions src/Actions/Attachment/AttachmentDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

final class AttachmentDeleteAction implements ActionInterface, AuthenticateInterface, ResponseResultInterface
{
use AuthenticateTrait, AttachmentHydrateTrait;
use AuthenticateTrait;
use AttachmentHydrateTrait;

public function __construct(private readonly string $attachmentId, string $token)
{
Expand All @@ -28,4 +29,4 @@ public function getOptions(): array
{
return [];
}
}
}
7 changes: 4 additions & 3 deletions src/Actions/Attachment/AttachmentUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

final class AttachmentUpdateAction implements ActionInterface, AuthenticateInterface, ResponseResultInterface
{
use AuthenticateTrait, AttachmentHydrateTrait;
use AuthenticateTrait;
use AttachmentHydrateTrait;

public function __construct(
private readonly string $attachmentId,
private readonly string $name,
string $token
string $token,
) {
$this->setToken($token);
}
Expand All @@ -35,4 +36,4 @@ public function getOptions(): array
],
];
}
}
}
Loading