/** * Process parsed data * * @access public * @return string */ public function processRecord($item, &$out) { // Create publication record if (!$item['publication']->store()) { return false; } $pid = $item['publication']->id; // Create version record $item['version']->publication_id = $pid; $item['version']->version_number = 1; $item['version']->created_by = $this->_uid; $item['version']->created = Date::toSql(); $item['version']->secret = strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1)); $item['version']->access = 0; $item['version']->main = 1; $item['version']->state = 3; if (!$item['version']->store()) { // Roll back $item['publication']->delete(); return false; } $vid = $item['version']->id; // Build pub object $pub = new stdClass(); $pub = $item['version']; $pub->id = $pid; $pub->version_id = $vid; // Build version object $version = new stdClass(); $version->secret = $item['version']->secret; $version->id = $vid; $version->publication_id = $pid; // Create attachments records and attach files foreach ($item['files'] as $fileRecord) { $this->processFileData($fileRecord, $pub, $version); } // Create author records foreach ($item['authors'] as $authorRecord) { $this->processAuthorData($authorRecord['author'], $pid, $vid); } // Build tags string if ($item['tags']) { $tags = ''; $i = 0; foreach ($item['tags'] as $tag) { $i++; $tags .= trim($tag); $tags .= $i == count($item['tags']) ? '' : ','; } // Add tags $tagsHelper = new \Components\Publications\Helpers\Tags($this->database); $tagsHelper->tag_object($this->_uid, $pid, $tags, 1); } // Display results $out .= '<p class="publication">#' . $pid . ': <a href="' . trim($this->site, DS) . '/publications/' . $pid . DS . '1" rel="external">' . $item['version']->title . ' v.' . $item['version']->version_label . '</a></p>'; return true; }
/** * Save a review * * @return void */ public function savereview() { // Is the user logged in? if (User::isGuest()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE')); return; } $publication =& $this->publication; // Do we have a publication ID? if (!$publication->exists()) { // No ID - fail! Can't do anything else without an ID $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } $database = App::get('db'); // Bind the form data to our object $row = new \Components\Publications\Tables\Review($database); if (!$row->bind($_POST)) { $this->setError($row->getError()); return; } // Perform some text cleaning, etc. $row->id = Request::getInt('reviewid', 0); $row->state = 1; $row->comment = \Hubzero\Utility\Sanitize::stripAll($row->comment); $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0; $row->created = $row->created ? $row->created : Date::toSql(); $row->created_by = User::get('id'); $message = $row->id ? Lang::txt('PLG_PUBLICATIONS_REVIEWS_EDITS_SAVED') : Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_POSTED'); // Check for missing (required) fields if (!$row->check()) { $this->setError($row->getError()); return; } // Save the data if (!$row->store()) { $this->setError($row->getError()); return; } // Calculate the new average rating for the parent publication $publication->table()->calculateRating(); $publication->table()->updateRating(); // Process tags $tags = trim(Request::getVar('review_tags', '')); if ($tags) { $rt = new \Components\Publications\Helpers\Tags($database); $rt->tag_object($row->created_by, $publication->get('id'), $tags, 1, 0); } // Get version authors $users = $publication->table('Author')->getAuthors($publication->get('version_id'), 1, 1, true); // Build the subject $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS'); // Message $eview = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'emails')); $eview->option = $this->_option; $eview->juser = User::getInstance(); $eview->publication = $publication; $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); // Build the "from" data for the e-mail $from = array(); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS'); $from['email'] = Config::get('mailfrom'); // Send message if (!Event::trigger('xmessage.onSendMessage', array('publications_new_comment', $subject, $message, $from, $users, $this->_option))) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_FAILED_TO_MESSAGE')); } App::redirect(Route::url($publication->link('reviews')), $message); return; }
/** * Save block content * * @return string HTML */ public function save($manifest = NULL, $blockId = 0, $pub = NULL, $actor = 0, $elementId = 0) { // Set block manifest if ($this->_manifest === NULL) { $this->_manifest = $manifest ? $manifest : self::getManifest(); } // Make sure changes are allowed if ($this->_parent->checkFreeze($this->_manifest->params, $pub)) { return false; } // Load publication version $objP = new \Components\Publications\Tables\Publication($this->_parent->_db); if (!$objP->load($pub->id)) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND')); return false; } $tagsHelper = new \Components\Publications\Helpers\Tags($this->_parent->_db); $tags = trim(Request::getVar('tags', '', 'post')); $tagsHelper->tag_object($actor, $pub->id, $tags, 1); // Reflect the update in curation record $this->_parent->set('_update', 1); // Save category $cat = Request::getInt('pubtype', 0); if ($cat && $pub->_category->id != $cat) { $objP->category = $cat; $objP->store(); } return true; }