Example #1
0
 /**
  * Save a collection
  *
  * @param   boolean  $redirect  Redirect the page after saving
  * @return  void
  */
 public function saveTask($redirect = true)
 {
     // Check for request forgeries
     Request::checkToken() or jexit('Invalid Token');
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     // Get the collection
     $collection = new Collection($fields['cId']);
     try {
         if (isset($fields['cName'])) {
             $collection->setName($fields['cName']);
         }
         if (isset($fields['state'])) {
             $collection->setActiveStatus($fields['state']);
         }
         if (isset($fields['alias'])) {
             $collection->setAlias($fields['alias']);
         }
         $collection->setType('category');
         // Make sure there are no integrity issues
         $this->checkIntegrity($collection);
         $collection->save();
     } catch (\Exception $e) {
         \Notify::error($e->getMessage());
         $this->editTask($collection);
         return;
     }
     if ($redirect) {
         // Redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_STOREFRONT_COLLECTION_SAVED'));
         return;
     }
     $this->editTask($collection);
 }