public function itemFormSucceeded(UI\Form $form, $values) { $goodsId = $this->getParameter('goodsId'); foreach ($values['photo'] as $file) { if (!$this->item->insertPhoto($file, $goodsId, $values['name'], $values['description'])) { $this->flashMessage('Nepodařilo se uložit fotografii: ' . $file->getName(), 'danger'); } } $this->flashMessage('Fotografie byly zpracovány.', 'success'); $this->redirect('Photo:default', $goodsId); }
public function itemFormSucceeded(UI\Form $form, $values) { if (isset($values['manufacturer_id']) && !$values['manufacturer_id']) { $values['manufacturer_id'] = $values['manufacturer_id'] ? $values['manufacturer_id'] : null; } foreach ($values as $k => $v) { if ($k != 'category_id' && $k != 'photo') { $updateOrInsert[$k] = $v; } } $itemId = $this->getParameter('id'); if ($itemId) { $item = $this->item->get($itemId); if (!$item) { $this->error('Data nebyla nalezena v databázi.', 404); } else { $item->update($updateOrInsert); } $this->categoryGoods->where('goods_id', $itemId)->delete(); $forInsert = array(); foreach ($values['category_id'] as $categoryId) { $forInsert[] = ['category_id' => $categoryId, 'goods_id' => $itemId]; } $this->categoryGoods->insert($forInsert); $this->flashMessage('Změny uloženy.', 'success'); } else { $item = $this->item->insert($updateOrInsert); // categories $forInsert = array(); foreach ($values['category_id'] as $categoryId) { $forInsert[] = ['category_id' => $categoryId, 'goods_id' => $item->id]; } $this->categoryGoods->insert($forInsert); $this->flashMessage('Výrobek vložen do databáze.', 'success'); } if ($item && $values['photo']) { if ($this->photo->insertPhoto($values['photo'], $item->id)) { $this->flashMessage('Byl přiložen obrázek.', 'success'); } } $this->redirect('edit', $item->id); }
public function photo() { require_once '../App/Model/photo.class.php'; $photo = new Photo(); $id = $this->getURL(); if (isset($_GET['action'])) { switch ($_GET['action']) { case 'insert': if (!empty($_FILES['photo']['name'])) { $photo_size = $_FILES['photo']['size']; $photo_type = $_FILES['photo']['type']; $photo_tmp_name = $_FILES['photo']['tmp_name']; $photo_type = substr($photo_type, 6); if (strstr('.jpg;.jpeg;.gif;.png', $photo_type)) { $photo_name = md5(uniqid(time())) . "." . $photo_type; if (file_exists('assets/img/photo/')) { $photo_path = "assets/img/photo/" . $photo_name; } else { echo '<h2>A imagem nao pode ser salva no diretorio assets/img/photo/ devido erro</h2>'; } move_uploaded_file($photo_tmp_name, $photo_path); $photo = new Photo($photo_name, $photo_size, $photo_type); $insertPhoto = $photo->insertPhoto(); if (!empty($insertPhoto)) { echo $insertPhoto; } } else { echo '<h2>Tipo de arquivo incorreto</h2>'; } } break; case 'edit': $selectOnePhoto_edit = $photo->selectOnePhoto($id); if (isset($_GET['operation']) && $_GET['operation'] == 'ok') { if (!empty($_FILES['photo_edit']['name'])) { if (file_exists('assets/img/photo/')) { unlink('assets/img/photo/' . $selectOnePhoto_edit[0]->content_photo_name); } else { echo '<h2>A imagem nao foi deletada do diretorio assets/img/photo/</h2>'; } $photo_edit_size = $_FILES['photo_edit']['size']; $photo_edit_type = $_FILES['photo_edit']['type']; $photo_edit_tmp_name = $_FILES['photo_edit']['tmp_name']; $photo_edit_type = substr($photo_edit_type, 6); if (strstr('.jpg;.jpeg;.gif;.png', $photo_edit_type)) { $photo_edit_name = md5(uniqid(time())) . "." . $photo_edit_type; $photo_edit_path = "assets/img/photo/" . $photo_edit_name; move_uploaded_file($photo_edit_tmp_name, $photo_edit_path); $photo = new Photo($photo_edit_name, $photo_edit_size, $photo_edit_type); $updateOnePhoto = $photo->updateOnePhoto($id); if (!empty($updateOnePhoto)) { echo $updateOnePhoto; } } else { echo '<h2>Tipo de arquivo incorreto</h2>'; } } } break; case 'delete': $selectOnePhoto_delete = $photo->selectOnePhoto($id); $deleteOnePhoto = $photo->deleteOnePhoto($id); if (!empty($selectOnePhoto_delete[0]->content_photo_name) && !empty($deleteOnePhoto)) { if (file_exists('assets/img/photo/')) { unlink('assets/img/photo/' . $selectOnePhoto_delete[0]->content_photo_name); } else { echo '<h2>A imagem nao foi deletada do diretorio assets/img/photo/</h2>'; } echo $deleteOnePhoto; } } } else { echo '<h2>Acao diferente de insert, edit e delete</h2>'; } $selectPhoto = $photo->selectPhoto(); require_once '../App/View/Adm_content/photo.php'; }