Ejemplo n.º 1
0
 /**
  * Add action - add the new task
  *
  * @package     las
  * @version     1.0
  */
 public function addAction()
 {
     $firewalls = Firewalls::find();
     if (!count($firewalls)) {
         $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the firewall first") . ': ' . $this->tag->linkTo('admin/firewalls/add', __('Add')));
     }
     // Set title, pick view and send variables
     $this->tag->setTitle(__('Tasks') . ' / ' . __('Add'));
     $this->view->pick('tasks/write');
     $this->view->setVars(['type' => Tasks::type(true), 'status' => Tasks::status(true), 'firewalls' => $firewalls]);
     // Check if the form has been sent
     if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
         $task = new Tasks();
         $task->__set('firewalls', $firewalls);
         $valid = $task->write();
         // Check if data are valid
         if ($valid instanceof Tasks) {
             unset($_POST);
             $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The data has been saved."));
         } else {
             $this->view->setVar('errors', $valid);
             $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
         }
     }
 }