private function createPicture(FileUpload $upload) { $path = $this->imageManager->put($upload); if ($path) { $picture = new PlatformPicture(); $picture->path = $path; $picture->platform = $this->platform; return $picture; } return null; }
public function handleDelete($id) { /** @var Picture $picture */ $picture = $this->pictures->find($id); dump($picture); exit; try { $this->pictures->delete($picture); } catch (ForeignKeyConstraintViolationException $ex) { $this->flashMessage("Nelze odstranit primární obrázek hry"); $this->redirect('default'); } $this->imageManager->delete($picture); }
public function createComponentEditPlatformForm() { $form = $this->editPlatformFormFactory->create(); $form->onSave[] = function (Form $form, Platform $platform, PlatformPicture $picture = null) { if ($picture) { $this->pictures->save($picture); if ($platform->picture) { $this->pictures->delete($platform->picture); $this->imageManager->delete($platform->picture); } $platform->picture = $picture; } $this->platforms->save($platform); $this->flashMessage('Platforma ' . $platform->title . ' byla uložena.'); $this->redirect('default'); }; return $form; }
public function processForm(Form $form, $values) { $game = $this->games->find($values['id_game']); if (!$game) { $form['id_game']->addError("Hra nebyla nalezena"); return; } $pictures = []; /** @var FileUpload $upload */ foreach ($values['pictures'] as $upload) { $path = $this->imageManager->put($upload); if (!$path) { $form->addError("Obrázek {$upload->name} se nepodařilo nahrát"); continue; } $picture = new Picture(); $picture->path = $path; $picture->game = $game; $pictures[] = $picture; } $this->onSave($form, $pictures, $game); }