project creation request notification working

This commit is contained in:
isUnknown 2025-01-23 16:16:51 +01:00
parent c750001a2c
commit c75c5e1d8a
7 changed files with 93 additions and 13 deletions

View file

@ -7,6 +7,8 @@ return [
$json = file_get_contents('php://input');
$data = json_decode($json);
$user = kirby()->user();
$client = kirby()->user()->client()->toPage()->uuid();
$projectData = [
@ -23,7 +25,24 @@ return [
$projects = page("projects");
try {
$projects->createChild($projectData);
$newProject = $projects->createChild($projectData);
$date = new DateTime();
$formattedDate = $date->format(DateTime::ISO8601);
$notificationData = [
"location" => [
"page" => $newProject
],
"date" => (string) $formattedDate,
"text" => nl2br(esc($data->details)),
"author" => $user,
"id" => Str::uuid(),
"type" => "project-request",
];
$newProject->createNotification($notificationData);
return [
"status" => "success",
];

View file

@ -5,16 +5,12 @@ namespace adrienpayet\D2P\data\location;
class Location
{
protected PageDetails $page;
// protected ?string $dialogUri = null;
// protected ProjectDetails $project;
protected ?FileDetails $file = null;
protected ?array $parent = null;
public function __construct(array $data)
{
$this->page = new PageDetails($data["page"]);
// $this->dialogUri = $data["dialogUri"];
// $this->project = new ProjectDetails($data["project"]);
if (isset($data['file'])) {
$this->file = new FileDetails($data["file"]);
@ -33,13 +29,8 @@ class Location
public function toArray() {
$array = [
"page" => $this->page->toArray(),
// "project" => $this->project->toArray(),
];
// if ($this->dialogUri) {
// $array["dialogUri"] = $this->dialogUri;
// }
if ($this->file) {
$array["file"] = $this->file;
}

View file

@ -16,6 +16,7 @@ class PageDetails
return [
"uuid" => (string) $this->page->uuid(),
"template" => (string) $this->page->template(),
"panelUrl" => (string) $this->page->panel()->url(),
"uri" => (string) $this->page->uri(),
"title" => (string) $this->page->title(),
];

View file

@ -16,7 +16,7 @@ function getProjectData($project) {
}
try {
$children = $kirby->user()->role() == "admin" ? $page->children()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
$children = $kirby->user()->role() == "admin" ? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values() : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
} catch (\Throwable $th) {
throw new Exception($th->getMessage() . " line " . $th->getLine(), 1);
$children = [];