Skip to content
Snippets Groups Projects
Commit eddd1661 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #17999 TIME 1:45 only configure position and text of watermark

parent 7e93327a
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,7 @@ $app->get('/connectors/{id}/currentVisa', \ExternalSignatoryBook\controllers\Ext ...@@ -86,6 +86,7 @@ $app->get('/connectors/{id}/currentVisa', \ExternalSignatoryBook\controllers\Ext
//Customization //Customization
$app->put('/customization', \Configuration\controllers\ConfigurationController::class . ':updateCustomization'); $app->put('/customization', \Configuration\controllers\ConfigurationController::class . ':updateCustomization');
$app->get('/customization/watermark', \Configuration\controllers\ConfigurationController::class . ':getWatermarkConfiguration');
//Documents //Documents
$app->post('/documents', \Document\controllers\DocumentController::class . ':create'); $app->post('/documents', \Document\controllers\DocumentController::class . ':create');
......
...@@ -386,21 +386,25 @@ class ConfigurationController ...@@ -386,21 +386,25 @@ class ConfigurationController
$data['applicationUrl'] = $body['applicationUrl'] ?: null; $data['applicationUrl'] = $body['applicationUrl'] ?: null;
if (!empty($body['watermark'])) { if (!empty($body['watermark'])) {
$possibleAlign = ['left' => 'L', 'center' => 'C', 'right' => 'R'];
if (!Validator::notEmpty()->boolType()->validate($body['watermark']['enabled'])) { if (!Validator::notEmpty()->boolType()->validate($body['watermark']['enabled'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[enabled] is empty or not a boolean']); return $response->withStatus(400)->withJson(['errors' => 'Body watermark[enabled] is empty or not a boolean']);
} elseif (!Validator::notEmpty()->intVal()->validate($body['watermark']['posX'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[posX] is empty or not an integer']);
} elseif (!Validator::notEmpty()->intVal()->validate($body['watermark']['posY'])) { } elseif (!Validator::notEmpty()->intVal()->validate($body['watermark']['posY'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[posY] is empty or not an integer']); return $response->withStatus(400)->withJson(['errors' => 'Body watermark[posY] is empty or not an integer']);
} elseif (!Validator::notEmpty()->stringType()->validate($body['watermark']['text'])) { } elseif (!Validator::notEmpty()->stringType()->validate($body['watermark']['text'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[label] is empty or not a string']); return $response->withStatus(400)->withJson(['errors' => 'Body watermark[text] is empty or not a string']);
} elseif (!Validator::notEmpty()->stringType()->validate($body['watermark']['align'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[align] is empty or not a string']);
} elseif (!in_array($body['watermark']['align'], array_keys($possibleAlign))) {
return $response->withStatus(400)->withJson(['errors' => 'Body watermark[align] can only be "left", "right" or "center"']);
} }
$data['watermark'] += [ $data['watermark'] = [
'enabled' => $body['watermark']['enabled'], 'enabled' => $body['watermark']['enabled'],
'posX' => $body['watermark']['posX'],
'posY' => $body['watermark']['posY'], 'posY' => $body['watermark']['posY'],
'text' => $body['watermark']['text'] 'text' => $body['watermark']['text'],
'align' => $possibleAlign[$body['watermark']['align']]
]; ];
} }
...@@ -420,6 +424,21 @@ class ConfigurationController ...@@ -420,6 +424,21 @@ class ConfigurationController
return $response->withStatus(204); return $response->withStatus(204);
} }
public function getWatermarkConfiguration(Request $request, Response $response)
{
if (!PrivilegeController::hasPrivilege(['userId' => $GLOBALS['id'], 'privilege' => 'manage_customization'])) {
return $response->withStatus(403)->withJson(['errors' => 'Privilege forbidden']);
}
$configuration = ConfigurationModel::getByIdentifier(['identifier' => 'customization']);
if (empty($configuration[0])) {
return $response->withStatus(400)->withJson(['errors' => 'Configuration does not exist']);
}
$configuration = json_decode($configuration[0]['value'], true);
return $response->withJson(['configuration' => $configuration['watermark'] ?? []]);
}
private static function checkMailer(array $args) private static function checkMailer(array $args)
{ {
if (!Validator::stringType()->notEmpty()->validate($args['type'])) { if (!Validator::stringType()->notEmpty()->validate($args['type'])) {
......
...@@ -77,7 +77,7 @@ class WatermarkController ...@@ -77,7 +77,7 @@ class WatermarkController
$pdf->SetTextColor(0, 0, 0); // Color black $pdf->SetTextColor(0, 0, 0); // Color black
$pdf->SetAlpha(0.5); // Opacity $pdf->SetAlpha(0.5); // Opacity
$pdf->Rotate(0); // No rotation $pdf->Rotate(0); // No rotation
$pdf->Text($watermark['posX'], $watermark['posY'], $text, false, false, true, 0, 0, 'R'); $pdf->Text(8, $watermark['posY'], $text, false, false, true, 0, 0, $watermark['align']); // Position X = 8
} }
$fileContent = $pdf->Output('', 'S'); $fileContent = $pdf->Output('', 'S');
} catch (\Exception $e) { } catch (\Exception $e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment