示例#1
0
 public function save(Nette\Application\UI\Form $form)
 {
     $flag = $this->context->createServiceFlags();
     try {
         $vars = $form->getValues();
         if ($vars['www'] !== '') {
             $form->addError('Are you a spam robot, right?');
             throw new AuthorizationException('Are you a spam robot, right?');
         }
         unset($vars['www']);
         $flag->flag = $vars;
         $flag->save();
         $cache = new Nette\Caching\Cache($this->context->cacheStorage);
         $cache->clean(array('flags', 'flag'));
         $this->flashMessage('Děkujeme! Váš podnět k aktualizaci zpracujeme. Peknyden.cz.', 'success');
         $this->hide = true;
     } catch (AuthorizationException $e) {
         $this->flashMessage($e->getMessage(), 'error');
     } catch (Exception $e) {
         $this->flashMessage('There is error during saving flag! We know about this. Try it later, please.', 'error');
     }
     if ($this->parent->isAjax()) {
         $this->redrawControl('form');
     }
 }
示例#2
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $image) {
             $file = new \File();
             $d = $image->getImageSize();
             if ($d[0] < 300 && $d[1] < 300) {
                 throw new InvalidArgumentException('Obrázek je příliš malý. Musí mít minimálně jeden rozměr vyšší než 300px. Nahrajte prosím větší obrázek.');
             }
             if ($d[0] > 3000 || $d[1] > 3000) {
                 throw new InvalidArgumentException('Obrázek je až zbytečně veliký. Žádný rozměr by neměl být vyšší než 3000px. Nahrajte prosím menší obrázek.');
             }
             $file->file_prefix = "";
             $file->file_sufix = "_u" . $this->context->user->id . "_" . substr(sha1(time()), 0, 4);
             $file->user_id = $this->context->user->id;
             $file->insertUploaded($image, FILESTORAGE_DIR);
             $file->visible = 1;
             // automaticka publikace
             $file->save();
             if ($form->values->type == "event") {
                 dibi::query('INSERT INTO event_x_file', array('event_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('event_x_file')->where('first', '=', 1)->where('event_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('event_x_file')->where('event_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE event_x_file SET ', array('first' => 1), 'WHERE event_id = ', $res->event_id, 'AND file_id =', $res->file_id);
                 }
             } elseif ($form->values->type == "place") {
                 dibi::query('INSERT INTO subject_x_file', array('subject_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('subject_x_file')->where('first', '=', 1)->where('subject_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('subject_x_file')->where('subject_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE subject_x_file SET ', array('first' => 1), 'WHERE subject_id = ', $res->subject_id, 'AND file_id =', $res->file_id);
                 }
             }
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $cache = new \Nette\Caching\Cache($this->context->cacheStorage);
         $cache->clean(array('files', 'images', 'file', 'image', $form->values->type, $form->values->type . 's'));
         $this->presenter->flashMessage('Dobrá zpráva, fotografie se podařilo vložit!', 'success');
         $this->redirect('this');
     }
 }