Example #1
0
 /**
  * Edit action - edit the tariff
  *
  * @package     las
  * @version     1.0
  */
 public function editAction()
 {
     // Get id from url params and check if record exist
     $params = $this->router->getParams();
     if (isset($params[0]) && ($tariff = Tariffs::findFirst($params[0]))) {
         $networks = Networks::find(['type=:type:', 'bind' => ['type' => Networks::WAN]]);
         if (!count($networks)) {
             $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the network first") . ': ' . $this->tag->linkTo('admin/networks/add', __('Add')));
         }
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Tariffs') . ' / ' . __('Edit'));
         $this->view->pick('tariffs/write');
         $this->view->setVars(['status' => Tariffs::status(true), 'bitRate' => \Las\Models\Settings::options('bitRate', $this->las['general']['bitRate'])]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $valid = $tariff->write('update');
             // Check if data are valid
             if ($valid instanceof Tariffs) {
                 $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."));
             }
         } else {
             // Values to fill out the form
             $this->tag->setDefaults(get_object_vars($tariff));
         }
     } else {
         parent::notFoundAction();
     }
 }