/** * Save a citation * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); $citation = array_map('trim', Request::getVar('citation', array(), 'post')); $exclude = Request::getVar('exclude', '', 'post'); $rollover = Request::getInt("rollover", 0); $this->tags = Request::getVar('tags', ''); $this->badges = Request::getVar('badges', ''); $this->sponsors = Request::getVar('sponsors', array(), 'post'); // toggle the affiliation if (!isset($citation['affiliated']) || $citation['affiliated'] == NULL) { $citation['affiliated'] = 0; } // toggle fundeby if (!isset($citation['fundedby']) || $citation['fundedby'] == NULL) { $citation['fundedby'] = 0; } // Bind incoming data to object $row = new Citation($this->database); if (!$row->bind($citation)) { $this->row = $row; $this->setError($row->getError()); $this->editTask(); return; } //set params $cparams = new Registry($this->_getParams($row->id)); $cparams->set('exclude', $exclude); $cparams->set('rollover', $rollover); $row->params = $cparams->toString(); // New entry so set the created date if (!$row->id) { $row->created = \Date::toSql(); } // Check content for missing required data if (!$row->check()) { $this->row = $row; $this->setError($row->getError()); $this->editTask(); return; } // Store new content if (!$row->store()) { $this->row = $row; $this->setError($row->getError()); $this->editTask(); return; } // Incoming associations $arr = Request::getVar('assocs', array(), 'post'); $ignored = array(); foreach ($arr as $a) { $a = array_map('trim', $a); // Initiate extended database class $assoc = new Association($this->database); //check to see if we should delete if (isset($a['id']) && $a['tbl'] == '' && $a['oid'] == '') { // Delete the row if (!$assoc->delete($a['id'])) { throw new Exception($assoc->getError(), 500); } } else { if ($a['tbl'] != '' || $a['oid'] != '') { $a['cid'] = $row->id; // bind the data if (!$assoc->bind($a)) { throw new Exception($assoc->getError(), 500); } // Check content if (!$assoc->check()) { throw new Exception($assoc->getError(), 500); } // Store new content if (!$assoc->store()) { throw new Exception($assoc->getError(), 500); } } } } //save sponsors on citation if ($this->sponsors) { $cs = new Sponsor($this->database); $cs->addSponsors($row->id, $this->sponsors); } //add tags & badges $ct = new Tags($row->id); $ct->setTags($this->tags, User::get('id'), 0, 1, ''); $ct->setTags($this->badges, User::get('id'), 0, 1, 'badge'); // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_SAVED')); }
/** * Remove one or more types * * @return void */ public function removeTask() { // Incoming (expecting an array) $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Ensure we have an ID to work with if (empty($ids)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_NO_SPONSOR'), 'error'); return; } $cs = new Sponsor($this->database); foreach ($ids as $id) { // Delete the type $cs->delete($id); } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_SPONSOR_REMOVED')); }