Exemple #1
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     // Initiate extended database class
     $row = new Wish($this->database);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         $this->editTask($row);
         return;
     }
     $row->anonymous = isset($fields['anonymous']) && $fields['anonymous'] ? 1 : 0;
     $row->private = isset($fields['private']) && $fields['private'] ? 1 : 0;
     $row->accepted = isset($fields['accepted']) && $fields['accepted'] ? 1 : 0;
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
         $this->editTask($row);
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->editTask($row);
         return;
     }
     include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'tags.php';
     $tagging = new Tags($row->id);
     $tagging->setTags($fields['tags'], User::get('id'));
     $plan = Request::getVar('plan', array(), 'post', 'none', 2);
     $plan['create_revision'] = isset($plan['create_revision']) ? $plan['create_revision'] : 0;
     $plan['wishid'] = $plan['wishid'] ? $plan['wishid'] : $row->id;
     // Initiate extended database class
     $page = new Plan($this->database);
     if (!$fields['id']) {
         // New page - save it to the database
         $old = new Plan($this->database);
     } else {
         // Existing page - load it up
         $page->load($plan['id']);
         // Get the revision before changes
         $old = $page;
     }
     $page->bind($plan);
     if ($plan['create_revision'] && rtrim(stripslashes($old->pagetext)) != rtrim(stripslashes($page->pagetext))) {
         $page->version = $page->version + 1;
         $page->id = 0;
     }
     if ($page->pagetext) {
         $page->version = $page->version ? $page->version : $page->version + 1;
         if (!$page->check()) {
             $this->setError($page->getError());
             $this->editTask($row);
             return;
         }
         if (!$page->store()) {
             $this->setError($page->getError());
             $this->editTask($row);
             return;
         }
     }
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&wishlist=' . $row->wishlist, false), Lang::txt('COM_WISHLIST_WISH_SAVED'));
 }
Exemple #2
0
 /**
  * Delete a record and any associated content
  *
  * @param   integer  $oid  Record ID
  * @return  boolean  True on success
  */
 public function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     // Dlete attachments
     $this->_db->setQuery("SELECT * FROM `#__wish_attachments` WHERE wish=" . $this->_db->quote($this->{$k}));
     if ($attachments = $this->_db->loadObjectList()) {
         $config = Component::params('com_wishlist');
         $path = PATH_APP . DS . trim($config->get('webpath', '/site/wishes'), DS) . DS . $oid;
         foreach ($attachments as $attachment) {
             if (file_exists($path . DS . $attachment->filename) or !$attachment->filename) {
                 // Attempt to delete the file
                 if (!\Filesystem::delete($path . DS . $attachment->filename)) {
                     $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
                 }
             }
         }
     }
     // Delete the plan
     $query = 'DELETE FROM `#__wishlist_implementation` WHERE wishid = ' . $this->_db->quote($this->{$k});
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Remove all tags
     include_once dirname(__DIR__) . DS . 'models' . DS . 'tags.php';
     $wt = new Tags($oid);
     $wt->setTags('', User::get('id'), 1);
     // Delete the wish
     return parent::delete($oid);
 }