Example #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;
 }
Example #2
0
 /**
  * @testdox A text file can be updated to be an image file.
  * @test
  */
 public function fileModifyTextToImage()
 {
     $img = Image::canvas(200, 100, '#ccc');
     $tmpFilename = $this->dataDir() . '/test-image.jpg';
     $img->save($tmpFilename);
     // Create an item, and save it twice with different text content.
     $item = new Item(null, $this->testUser);
     $item->save([], null, null, 'First contents');
     $this->assertEquals('First contents', $item->getFileContents());
     $item->save(null, null, $tmpFilename);
     $this->assertFileEquals($tmpFilename, $item->getCachePath());
     // Check that the version numbers and mime types are what we'd expect.
     $this->assertEquals('First contents', $item->getFileContents(1));
     $this->assertEquals('text/plain', $item->getMimeType(1));
     $this->assertFileEquals($tmpFilename, $item->getCachePath('o', 2));
     $this->assertEquals('image/jpeg', $item->getMimeType(2));
 }