/** * 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; }