Example #1
0
 public function handleCatchError(Form $form, $e)
 {
     if ($e instanceof InvalidArgumentException) {
         $form->addError($e->getMessage());
         return TRUE;
     } else {
         if ($e instanceof DBALException && strpos($e->getMessage(), 'Duplicate entry') !== false) {
             $form->addError('Duplicate entry');
             return TRUE;
         }
     }
 }
 public function handleSave(Form $form)
 {
     $values = $form->values;
     if ($values['file']->isOk()) {
         if ($values['cleanout']) {
             foreach ($this->userRepository->findAll() as $user) {
                 $this->userRepository->delete($user);
             }
         }
         /** @var FileUpload $file */
         $file = $values['file'];
         $data = file_get_contents($file->getTemporaryFile());
         foreach (explode("\n", $data) as $row) {
             if (!$row) {
                 continue;
             }
             $items = explode(',', $row);
             if (!count($items)) {
                 continue;
             }
             try {
                 $user = new UserEntity(trim($items[0]));
             } catch (InvalidArgumentException $e) {
                 $form->addError($e->getMessage());
             }
             $this->userRepository->save($user);
         }
     }
 }
Example #3
0
 public function handleCatchError(Form $form, $e)
 {
     if ($e instanceof DBALException && $e->getCode() == '23000') {
         $form->addError('User is not unique');
         return TRUE;
     }
 }
Example #4
0
 public function handleCatchError(Form $form, $e)
 {
     if ($e instanceof PermissionDeniedException) {
         $form->addError('You have not writable permissions.');
         return TRUE;
     }
 }
Example #5
0
 public function handleValidate(Form $form)
 {
     if (!isset($this->sessionSection->captcha) || $form['_captcha']->value != $this->sessionSection->captcha) {
         $form->addError('Nesprávně opsaný obrázek, zkuste to prosím znovu');
         $form['_captcha']->setOption('description', Html::el('img')->src($this->getCaptchaBuilder()->inline()));
     }
 }
Example #6
0
 public function handleSuccess(Form $form)
 {
     $values = $form->getValues();
     $oldPath = $this->moduleHelpers->expandPath($form->data, 'Resources/layouts');
     $form->data = $this->getKeyByValues($values);
     $path = $this->moduleHelpers->expandPath($form->data, 'Resources/layouts');
     umask(00);
     if (!file_exists(dirname($path))) {
         if (!@mkdir(dirname($path), 0777, TRUE)) {
             $form->addError("File '{$path}' is not writable.");
         }
     }
     file_put_contents($path, $values['text']);
     if ($oldPath && $oldPath !== $path) {
         @unlink($oldPath);
     }
 }
Example #7
0
 public function handleCatchError(Form $form, $e)
 {
     $m = explode("'", $e->getMessage());
     $form->addError("Duplicate entry '{$m[1]}'");
     return true;
 }
Example #8
0
 public function handleSuccess(Form $form)
 {
     if ($form->isSubmitted() === $form->getSaveButton()) {
         $values = $form->values;
         if ($values['type'] == 'component') {
             $file = $this->getFileByClass($values['component']);
             $baseName = $file->getBasename('.php') . '.latte';
             $template = $file->getPath() . '/' . $baseName;
             $target = $this->moduleHelpers->expandPath('@' . $values['target'] . 'Module', 'Resources/layouts');
             if ($values['layout']) {
                 $target .= '/' . $values['layout'];
             }
             $target .= '/' . $baseName;
         } else {
             $presenter = explode(':', $values['presenter']);
             $module = lcfirst($presenter[0]);
             $page = lcfirst($presenter[2]);
             $presenter = lcfirst($presenter[3]);
             $template = $this->moduleHelpers->expandPath('@' . $module . 'Module/@' . $page . '.' . $presenter . '.latte', 'Resources/layouts');
             $target = $this->moduleHelpers->expandPath('@' . $values['target'] . 'Module/' . ($values['layout'] ? $values['layout'] . '/' : '') . '@' . $page . '.' . $presenter . '.latte', 'Resources/layouts');
         }
         if (!copy($template, $target)) {
             $form->addError("Unable to copy file '{$template}' to '{$target}'.");
         }
     }
 }
Example #9
0
 public function handleCatchError(Form $form, $e)
 {
     $form->addError($e->getMessage());
     return true;
 }