Exemplo n.º 1
0
 public function addPageModuleToPageFormSucceeded(UI\Form $form, $values)
 {
     $settings = array();
     $settings['title'] = $values['title'];
     $settings['keywords'] = $values['keywords'];
     $settings['description'] = $values['description'];
     $settings['layout'] = $values['layout'];
     $settings['email'] = $values['email'];
     if (0 == $values['logo']->error) {
         $imageUploader = new \ImageUploader($this->request->getFiles());
         $imageUploader->setNewFileName("logo");
         $imageUploader->setMaxWidth($this->maxLogoWidth);
         $uploadedImages = $imageUploader->startUpload();
         if (true === isset($uploadedImages[0]["error"])) {
             $this->flashMessage("Error '" . $uploadedImages[0]["error"] . "' while uploading file '" . $uploadedImages[0]["original"] . "'.");
         } else {
             // delete old logo:
             if (isset($settings["logo"])) {
                 $imageUploader->deleteImage($settings["logo"]);
             }
             $settings["logo"] = $uploadedImages[0]["name"] . $uploadedImages[0]["extension"];
         }
     }
     if (false === empty($settings)) {
         $this->saveSettings($settings);
     }
     $this->flashMessage("Nastavení bylo uloženo.");
     $this->redirect('WebSettings:Default');
 }
 private function saveMainImage($product_id)
 {
     $files = $this->request->getFiles();
     if ($files["main_image"]) {
         if (0 === $files["main_image"]->error) {
             $imageUploader = new \ImageUploader($files, "module" . $this->moduleName . "/" . $this->module->id . "/" . $product_id, true, true);
             $uploadedImages = $imageUploader->startUpload();
             $this->createAdditionalThumbnail($uploadedImages[0]["name"], $uploadedImages[0]["extension"], $product_id);
             if (true === isset($uploadedImages[0]["error"])) {
                 $this->flashMessage("Error '" . $uploadedImages[0]["error"] . "' while uploading file '" . $uploadedImages[0]["original"] . "'.");
             } else {
                 $data["product_id"] = $product_id;
                 $data["filename"] = $uploadedImages[0]["name"];
                 $data["file_extension"] = $uploadedImages[0]["extension"];
                 $this->db->insertMainImage($data);
             }
         }
     }
 }
 public function editFormSucceeded(\Nette\Application\UI\Form $form, $values)
 {
     $item = $this->context->moduleCarouselBootstrap3Model->find($this->params['id']);
     $this->loadModule($item->page_page_modules_id);
     if (is_null($form->getHttpData($form::DATA_TEXT, 'cancel'))) {
         if ($values['img']->name != NULL) {
             // upload new image:
             $imageUploader = new \ImageUploader($this->request->getFiles(), "module" . $this->moduleName . "/" . $this->module->page_id);
             $uploadedImages = $imageUploader->startUpload();
             if (isset($uploadedImages[0]["name"])) {
                 $data['image'] = $uploadedImages[0]["name"] . $uploadedImages[0]["extension"];
                 // delete old image:
                 if (NULL !== $item->image) {
                     $imageUploader->deleteImage($item->image);
                 }
             }
         }
         $data['title'] = $values['title'];
         $data['subtitle'] = $values['subtitle'];
         $data['text'] = $values['text'];
         $data['link'] = $values['link'];
         $data['link_text'] = $values['link_text'];
         $item->update($data);
         if (false === isset($uploadedImages[0]["error"])) {
             $this->flashMessage('Úprava proběhla úspěšně.');
         } else {
             $this->flashMessage("Error '" . $uploadedImages[0]["error"] . "' while uploading file '" . $uploadedImages[0]["original"] . "'.");
         }
     }
     $this->redirect('Page:edit', array('id' => $this->module->page_id));
 }