Beispiel #1
0
 public function edit(Request $request, Response $response, array $args)
 {
     $template = new \App\Template('form.twig');
     $template->title = 'Create';
     // Date granularities.
     $sql = "SELECT id, title FROM date_granularities ORDER BY id ASC";
     $template->date_granularities = $this->db->query($sql)->fetchAll();
     // Item.
     $item = new Item();
     if (isset($args['id'])) {
         $template->title = 'Editing #' . $args['id'];
         $item = new Item($args['id']);
     }
     $template->item = $item;
     // User.
     $item->setUser($this->user);
     if (!$this->user->getId()) {
         $msg = 'You have to ' . ' <a href="' . $this->config->baseUrl() . '/login" class="alert-link">log in</a> ' . ' before you can add or edit items.';
         $template->alert('info', $msg);
         $response->setContent($template->render());
         return $response;
     }
     $template->groups = $this->user->getGroups();
     // Other template data.
     $template->fileContents = $item->getFileContents();
     $template->itemTags = $item->getTagsString();
     $template->itemReadGroupId = $item->getReadGroup()->id;
     $template->itemEditGroupId = $item->getEditGroup()->id;
     $response->setContent($template->render());
     return $response;
 }