diff --git a/lib/Controller/TakenController.php b/lib/Controller/TakenController.php index 3308b31..fed3e4d 100644 --- a/lib/Controller/TakenController.php +++ b/lib/Controller/TakenController.php @@ -1,132 +1,142 @@ -request->getParams(); - - // Fetch catalog objects based on filters and order - $data = $this->objectService->getResultArrayForRequest('taken', $requestParams); - - // Return JSON response - return new JSONResponse($data); - } - - /** - * Read a single object - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse - */ - public function show(string $id): JSONResponse - { - // Fetch the catalog object by its ID - $object = $this->objectService->getObject('taken', $id); - - // Return the catalog as a JSON response - return new JSONResponse($object); - } - - - /** - * Creatue an object - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse - */ - public function create(): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Remove the 'id' field if it exists, as we're creating a new object - unset($data['id']); - - // Save the new catalog object - $object = $this->objectService->saveObject('taken', $data); - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Update an object - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse - */ - public function update(string $id): JSONResponse - { - // Get all parameters from the request - $data = $this->request->getParams(); - - // Save the new catalog object - $object = $this->objectService->saveObject('taken', $data); - - // Return the created object as a JSON response - return new JSONResponse($object); - } - - /** - * Delate an object - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse - */ - public function destroy(string $id): JSONResponse - { - // Delete the catalog object - $result = $this->objectService->deleteObject('taken', $id); - - // Return the result as a JSON response - return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); - } - - /** - * Get audit trail for a specific klant - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return JSONResponse - */ - public function getAuditTrail(string $id): JSONResponse - { - $auditTrail = $this->objectService->getAuditTrail('taken', $id); - return new JSONResponse($auditTrail); - } -} +request->getParams(); + + // Fetch catalog objects based on filters and order + $data = $this->objectService->getResultArrayForRequest('taken', $requestParams); + + // Return JSON response + return new JSONResponse($data); + } + + /** + * Read a single object + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function show(string $id): JSONResponse + { + // Fetch the catalog object by its ID + $object = $this->objectService->getObject('taken', $id); + + // Return the catalog as a JSON response + return new JSONResponse($object); + } + + + /** + * Creatue an object + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function create(): JSONResponse + { + // Get all parameters from the request + $data = $this->request->getParams(); + + // Remove the 'id' field if it exists, as we're creating a new object + unset($data['id']); + + // Save the new catalog object + $object = $this->objectService->saveObject('taken', $data); + + $this->mailService->sendMail([], is_array($object) === true ? $object : $object->jsonSerialize()); + + // Return the created object as a JSON response + return new JSONResponse($object); + } + + /** + * Update an object + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function update(string $id): JSONResponse + { + // Get all parameters from the request + $data = $this->request->getParams(); + + $oldObject = $this->objectService->getObject('taken', $id); + + $data['id'] = $id; + + // Save the new catalog object + $object = $this->objectService->saveObject('taken', $data); + + $this->mailService->sendMail(is_array($oldObject) === true ? $oldObject : $oldObject->jsonSerialize(), is_array($object) === true ? $object : $object->jsonSerialize()); + + // Return the created object as a JSON response + return new JSONResponse($object); + } + + /** + * Delate an object + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function destroy(string $id): JSONResponse + { + // Delete the catalog object + $result = $this->objectService->deleteObject('taken', $id); + + // Return the result as a JSON response + return new JSONResponse(['success' => $result], $result === true ? '200' : '404'); + } + + /** + * Get audit trail for a specific klant + * + * @NoAdminRequired + * @NoCSRFRequired + * + * @return JSONResponse + */ + public function getAuditTrail(string $id): JSONResponse + { + $auditTrail = $this->objectService->getAuditTrail('taken', $id); + return new JSONResponse($auditTrail); + } +} diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php new file mode 100644 index 0000000..f990a22 --- /dev/null +++ b/lib/Service/MailService.php @@ -0,0 +1,64 @@ +mailer->createMessage(); + $message->setSubject('KISS: Er is een taak aan u toegewezen'); + $message->setTo([$email]); + $message->setHtmlBody(body: " + + +
+ Er is een taak aan u toegewezen. Klik + + hier + + om naar de taak te gaan. + + " + ); + + $this->mailer->send($message); + + return $newObject; + } + +}