|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +namespace OCA\Deck\Controller; |
| 9 | + |
| 10 | +use OCA\Deck\Model\OptionalNullableValue; |
| 11 | +use OCA\Deck\Service\BoardService; |
| 12 | +use OCA\Deck\Service\CardService; |
| 13 | +use OCA\Deck\Service\ExternalBoardService; |
| 14 | +use OCA\Deck\Service\StackService; |
| 15 | +use OCP\AppFramework\Http\Attribute\NoAdminRequired; |
| 16 | +use OCP\AppFramework\Http\Attribute\NoCSRFRequired; |
| 17 | +use OCP\AppFramework\Http\Attribute\PublicPage; |
| 18 | +use OCP\AppFramework\Http\Attribute\RequestHeader; |
| 19 | +use OCP\AppFramework\Http\DataResponse; |
| 20 | +use OCP\AppFramework\OCSController; |
| 21 | +use OCP\IRequest; |
| 22 | + |
| 23 | +class CardOcsController extends OCSController { |
| 24 | + public function __construct( |
| 25 | + string $appName, |
| 26 | + IRequest $request, |
| 27 | + private CardService $cardService, |
| 28 | + private StackService $stackService, |
| 29 | + private BoardService $boardService, |
| 30 | + private ExternalBoardService $externalBoardService, |
| 31 | + private ?string $userId, |
| 32 | + ) { |
| 33 | + parent::__construct($appName, $request); |
| 34 | + } |
| 35 | + |
| 36 | + #[NoAdminRequired] |
| 37 | + #[PublicPage] |
| 38 | + #[NoCSRFRequired] |
| 39 | + #[RequestHeader(name: 'x-nextcloud-federation', description: 'Set to 1 when the request is performed by another Nextcloud Server to indicate a federation request', indirect: true)] |
| 40 | + public function create(string $title, int $stackId, ?int $boardId = null, ?string $type = 'plain', ?string $owner = null, ?int $order = 999, ?string $description = '', $duedate = null, ?array $labels = [], ?array $users = []) { |
| 41 | + if ($boardId) { |
| 42 | + $board = $this->boardService->find($boardId, false); |
| 43 | + if ($board->getExternalId()) { |
| 44 | + $card = $this->externalBoardService->createCardOnRemote($board, $title, $stackId, $type, $order, $description, $duedate, $users); |
| 45 | + return new DataResponse($card); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + if (!$owner) { |
| 50 | + $owner = $this->userId; |
| 51 | + } |
| 52 | + $card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate); |
| 53 | + |
| 54 | + // foreach ($labels as $label) { |
| 55 | + // $this->assignLabel($card->getId(), $label); |
| 56 | + // } |
| 57 | + |
| 58 | + // foreach ($users as $user) { |
| 59 | + // $this->assignmentService->assignUser($card->getId(), $user['id'], $user['type']); |
| 60 | + // } |
| 61 | + |
| 62 | + return new DataResponse($card); |
| 63 | + } |
| 64 | + |
| 65 | + #[NoAdminRequired] |
| 66 | + #[PublicPage] |
| 67 | + #[NoCSRFRequired] |
| 68 | + #[RequestHeader(name: 'x-nextcloud-federation', description: 'Set to 1 when the request is performed by another Nextcloud Server to indicate a federation request', indirect: true)] |
| 69 | + public function update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, int $boardId, array|string|null $owner = null, $archived = null): DataResponse { |
| 70 | + $done = array_key_exists('done', $this->request->getParams()) |
| 71 | + ? new OptionalNullableValue($this->request->getParam('done', null)) |
| 72 | + : null; |
| 73 | + if (!$owner) { |
| 74 | + $owner = $this->userId; |
| 75 | + } else { |
| 76 | + if (!is_string($owner)) { |
| 77 | + $owner = $owner['uid']; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + $localBoard = $this->boardService->find($boardId, false); |
| 82 | + if ($localBoard->getExternalId()) { |
| 83 | + return new DataResponse($this->externalBoardService->updateCardOnRemote( |
| 84 | + $localBoard, |
| 85 | + $id, |
| 86 | + $title, |
| 87 | + $stackId, |
| 88 | + $type, |
| 89 | + $owner, |
| 90 | + $description, |
| 91 | + $order, |
| 92 | + $duedate, |
| 93 | + $deletedAt, |
| 94 | + $archived, |
| 95 | + $done |
| 96 | + )); |
| 97 | + } |
| 98 | + |
| 99 | + return new DataResponse($this->cardService->update($id, |
| 100 | + $title, |
| 101 | + $stackId, |
| 102 | + $type, |
| 103 | + $owner, |
| 104 | + $description, |
| 105 | + $order, |
| 106 | + $duedate, |
| 107 | + $deletedAt, |
| 108 | + $archived, |
| 109 | + $done |
| 110 | + )); |
| 111 | + } |
| 112 | +} |
0 commit comments