@@ -29,100 +29,100 @@ |
||
| 29 | 29 | |
| 30 | 30 | class FlowOperations extends Controller { |
| 31 | 31 | |
| 32 | - /** @var Manager */ |
|
| 33 | - protected $manager; |
|
| 32 | + /** @var Manager */ |
|
| 33 | + protected $manager; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IRequest $request |
|
| 37 | - * @param Manager $manager |
|
| 38 | - */ |
|
| 39 | - public function __construct(IRequest $request, Manager $manager) { |
|
| 40 | - parent::__construct('workflowengine', $request); |
|
| 41 | - $this->manager = $manager; |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * @param IRequest $request |
|
| 37 | + * @param Manager $manager |
|
| 38 | + */ |
|
| 39 | + public function __construct(IRequest $request, Manager $manager) { |
|
| 40 | + parent::__construct('workflowengine', $request); |
|
| 41 | + $this->manager = $manager; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @NoCSRFRequired |
|
| 46 | - * |
|
| 47 | - * @param string $class |
|
| 48 | - * @return JSONResponse |
|
| 49 | - */ |
|
| 50 | - public function getOperations($class) { |
|
| 51 | - $operations = $this->manager->getOperations($class); |
|
| 44 | + /** |
|
| 45 | + * @NoCSRFRequired |
|
| 46 | + * |
|
| 47 | + * @param string $class |
|
| 48 | + * @return JSONResponse |
|
| 49 | + */ |
|
| 50 | + public function getOperations($class) { |
|
| 51 | + $operations = $this->manager->getOperations($class); |
|
| 52 | 52 | |
| 53 | - foreach ($operations as &$operation) { |
|
| 54 | - $operation = $this->prepareOperation($operation); |
|
| 55 | - } |
|
| 53 | + foreach ($operations as &$operation) { |
|
| 54 | + $operation = $this->prepareOperation($operation); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return new JSONResponse($operations); |
|
| 58 | - } |
|
| 57 | + return new JSONResponse($operations); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @PasswordConfirmationRequired |
|
| 62 | - * |
|
| 63 | - * @param string $class |
|
| 64 | - * @param string $name |
|
| 65 | - * @param array[] $checks |
|
| 66 | - * @param string $operation |
|
| 67 | - * @return JSONResponse The added element |
|
| 68 | - */ |
|
| 69 | - public function addOperation($class, $name, $checks, $operation) { |
|
| 70 | - try { |
|
| 71 | - $operation = $this->manager->addOperation($class, $name, $checks, $operation); |
|
| 72 | - $operation = $this->prepareOperation($operation); |
|
| 73 | - return new JSONResponse($operation); |
|
| 74 | - } catch (\UnexpectedValueException $e) { |
|
| 75 | - return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); |
|
| 76 | - } |
|
| 77 | - } |
|
| 60 | + /** |
|
| 61 | + * @PasswordConfirmationRequired |
|
| 62 | + * |
|
| 63 | + * @param string $class |
|
| 64 | + * @param string $name |
|
| 65 | + * @param array[] $checks |
|
| 66 | + * @param string $operation |
|
| 67 | + * @return JSONResponse The added element |
|
| 68 | + */ |
|
| 69 | + public function addOperation($class, $name, $checks, $operation) { |
|
| 70 | + try { |
|
| 71 | + $operation = $this->manager->addOperation($class, $name, $checks, $operation); |
|
| 72 | + $operation = $this->prepareOperation($operation); |
|
| 73 | + return new JSONResponse($operation); |
|
| 74 | + } catch (\UnexpectedValueException $e) { |
|
| 75 | + return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @PasswordConfirmationRequired |
|
| 81 | - * |
|
| 82 | - * @param int $id |
|
| 83 | - * @param string $name |
|
| 84 | - * @param array[] $checks |
|
| 85 | - * @param string $operation |
|
| 86 | - * @return JSONResponse The updated element |
|
| 87 | - */ |
|
| 88 | - public function updateOperation($id, $name, $checks, $operation) { |
|
| 89 | - try { |
|
| 90 | - $operation = $this->manager->updateOperation($id, $name, $checks, $operation); |
|
| 91 | - $operation = $this->prepareOperation($operation); |
|
| 92 | - return new JSONResponse($operation); |
|
| 93 | - } catch (\UnexpectedValueException $e) { |
|
| 94 | - return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); |
|
| 95 | - } |
|
| 96 | - } |
|
| 79 | + /** |
|
| 80 | + * @PasswordConfirmationRequired |
|
| 81 | + * |
|
| 82 | + * @param int $id |
|
| 83 | + * @param string $name |
|
| 84 | + * @param array[] $checks |
|
| 85 | + * @param string $operation |
|
| 86 | + * @return JSONResponse The updated element |
|
| 87 | + */ |
|
| 88 | + public function updateOperation($id, $name, $checks, $operation) { |
|
| 89 | + try { |
|
| 90 | + $operation = $this->manager->updateOperation($id, $name, $checks, $operation); |
|
| 91 | + $operation = $this->prepareOperation($operation); |
|
| 92 | + return new JSONResponse($operation); |
|
| 93 | + } catch (\UnexpectedValueException $e) { |
|
| 94 | + return new JSONResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @PasswordConfirmationRequired |
|
| 100 | - * |
|
| 101 | - * @param int $id |
|
| 102 | - * @return JSONResponse |
|
| 103 | - */ |
|
| 104 | - public function deleteOperation($id) { |
|
| 105 | - $deleted = $this->manager->deleteOperation((int) $id); |
|
| 106 | - return new JSONResponse($deleted); |
|
| 107 | - } |
|
| 98 | + /** |
|
| 99 | + * @PasswordConfirmationRequired |
|
| 100 | + * |
|
| 101 | + * @param int $id |
|
| 102 | + * @return JSONResponse |
|
| 103 | + */ |
|
| 104 | + public function deleteOperation($id) { |
|
| 105 | + $deleted = $this->manager->deleteOperation((int) $id); |
|
| 106 | + return new JSONResponse($deleted); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @param array $operation |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - protected function prepareOperation(array $operation) { |
|
| 114 | - $checkIds = json_decode($operation['checks'], true); |
|
| 115 | - $checks = $this->manager->getChecks($checkIds); |
|
| 109 | + /** |
|
| 110 | + * @param array $operation |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + protected function prepareOperation(array $operation) { |
|
| 114 | + $checkIds = json_decode($operation['checks'], true); |
|
| 115 | + $checks = $this->manager->getChecks($checkIds); |
|
| 116 | 116 | |
| 117 | - $operation['checks'] = []; |
|
| 118 | - foreach ($checks as $check) { |
|
| 119 | - // Remove internal values |
|
| 120 | - unset($check['id']); |
|
| 121 | - unset($check['hash']); |
|
| 117 | + $operation['checks'] = []; |
|
| 118 | + foreach ($checks as $check) { |
|
| 119 | + // Remove internal values |
|
| 120 | + unset($check['id']); |
|
| 121 | + unset($check['hash']); |
|
| 122 | 122 | |
| 123 | - $operation['checks'][] = $check; |
|
| 124 | - } |
|
| 123 | + $operation['checks'][] = $check; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $operation; |
|
| 127 | - } |
|
| 126 | + return $operation; |
|
| 127 | + } |
|
| 128 | 128 | } |