new content notification working for client brief
This commit is contained in:
parent
8ae00d7657
commit
c1d2c73118
9 changed files with 277 additions and 70 deletions
|
|
@ -1,32 +1,49 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)validate-brief.json',
|
||||
'pattern' => 'validate-brief.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
try {
|
||||
$newPage = $page->update([
|
||||
'isValidated' => 'true'
|
||||
]);
|
||||
echo json_encode([
|
||||
"success" => "'" . $newPage->title()->value() . "' brief validated."
|
||||
]);
|
||||
$brief = page($data->briefUri);
|
||||
$project = $brief->parent();
|
||||
$href = $data->dialogUri ? $data->dialogUri : $brief->url();
|
||||
|
||||
try {
|
||||
$newPage = $brief->update([
|
||||
'isValidated' => 'true'
|
||||
]);
|
||||
|
||||
kirby()->user()->sendNotification($newPage->parent(), [
|
||||
'date' => $newPage->modified('YYYY-MM-DD'),
|
||||
'author' => kirby()->user()->name()->isNotEmpty() ? kirby()->user()->name() : kirby()->user()->email(),
|
||||
'url' => $newPage->url(),
|
||||
'type' => 'content'
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
"error" => "Can't validate '" . $page->title()->value() . "' brief.",
|
||||
'details' => $th->getMessage()
|
||||
];
|
||||
}
|
||||
$notification = [
|
||||
'location' => [
|
||||
'href' => (string) $href,
|
||||
'project' => [
|
||||
'title' => (string) $project->title(),
|
||||
'uri' => (string) $project->url()
|
||||
]
|
||||
],
|
||||
'date' => $newPage->modified('YYYY-MM-DD'),
|
||||
'author' => [
|
||||
'name' => (string) kirby()->user()->name(),
|
||||
'email' => (string) kirby()->user()->email(),
|
||||
'uuid' => (string) kirby()->user()->uuid(),
|
||||
'role' => (string) kirby()->user()->role(),
|
||||
],
|
||||
'type' => 'content'
|
||||
];
|
||||
|
||||
kirby()->user()->sendNotification($project, $notification);
|
||||
|
||||
return [
|
||||
"success" => "'" . $project->title()->value() . "' brief validated."
|
||||
];
|
||||
} catch (\Throwable $th) {
|
||||
return [
|
||||
"error" => "Can't validate '" . $brief->title()->value() . "' brief.",
|
||||
'details' => $th->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
];
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class ProjectPage extends Page {
|
|||
'slug' => $child->slug(),
|
||||
'index' => intval($child->stepIndex()->value()),
|
||||
'modified' => $child->modified('Y-MM-dd'),
|
||||
'isValidated' => $child->isValidated()->value() ?? false,
|
||||
'isValidated' => (bool) $child->isValidated()->value() ?? false,
|
||||
'uri' => $uri,
|
||||
'files' => $files,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ return [
|
|||
'y' => $data->position->y
|
||||
],
|
||||
'replies' => [],
|
||||
'text' => $data->text,
|
||||
'text' => $user->name()->isNotEmpty() ? $user->name()->value() . ' : ' . $data->text : $user->email()->value() . ' : ' . $data->text,
|
||||
'author' => $user,
|
||||
'date' => (string) $data->date,
|
||||
'id' => $data->id,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,14 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
$parsedUrl = parse_url($data->path);
|
||||
$query = $parsedUrl['query'] ?? null;
|
||||
parse_str($query, $queryParams);
|
||||
$stepSlug = $queryParams['dialog'] ?? null;
|
||||
|
||||
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
|
||||
|
||||
$page = page($targetPageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
|
@ -17,6 +24,7 @@ return [
|
|||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$data = [
|
||||
'href' => $data->path,
|
||||
'page' => $page,
|
||||
'parentId' => $data->parentId,
|
||||
'file' => $file,
|
||||
|
|
|
|||
|
|
@ -13,25 +13,27 @@
|
|||
* @throws Exception If an error occurs while updating a user's notifications.
|
||||
*/
|
||||
|
||||
return function ($project, $notificationData) {
|
||||
return function ($project, $notificationData) {
|
||||
$recipients = $project->managers()->without($this);
|
||||
|
||||
if (!$recipients) return;
|
||||
|
||||
$notificationData['isRead'];
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $notificationData;
|
||||
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
if ($recipients->isEmpty()) return;
|
||||
|
||||
$notificationData['isRead'] = false;
|
||||
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $notificationData;
|
||||
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue