You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
ygdc/site/controllers/home.php

54 lines
1.5 KiB

<?php
use Kirby\Uuid\Uuid;
return function ($page, $site, $kirby) {
$error = "";
$json = [];
$type = "html";
if ($kirby->request()->is('POST')) {
$action = $kirby->request()->get("action");
if ($action == "createGame") {
// $name = $kirby->request()->get("name");
$name = Uuid::generate($length = 8);
$tournament = $kirby->request()->get("tournament");
$content = [
'title' => $name
];
try {
$kirby->impersonate('kirby');
if ($site->find($tournament)->default()->toPage()){
$json["error"] = $site->find($tournament)->default()->toPage()->out();
$id = $site->find($tournament)->default()->toPage()->copy(
[
'slug' => Str::slug($name),
'parent' => $site->find($tournament),
'children' => false, // copy children
'files' => false, // don't copy files
'isDraft' => false,
]
);
} else {
$id = $site->find($tournament)->createChild([
'content' => $content,
'slug' => Str::slug($name),
'template' => 'xoi',
'isDraft' => false
]);
}
$json["status"] = "ok";
$json["url"] = $id->url();
} catch (\Exception $e) {
$error = $e->getMessage();
}
}
$data = $kirby->request()->get("name");
}
return [
'type' => $type,
'json' => $json,
'error' => $error
];
};