Пример #1
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param   object   $publication  Current publication
  * @param   string   $option       Name of the component
  * @param   array    $areas        Active area(s)
  * @param   string   $rtrn         Data to be returned
  * @param   string   $version      Version name
  * @param   boolean  $extended     Whether or not to show panel
  * @param   boolean  $authorized
  * @return  array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true, $authorized = false)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) {
             $rtrn = 'metadata';
         }
     }
     if ($rtrn == 'all' || $rtrn == 'html') {
         // Get pub configs
         $config = Component::params($option);
         $database = App::get('db');
         $objV = new \Components\Publications\Tables\Version($database);
         $versions = $objV->getVersions($publication->id, $filters = array('public' => 1));
         // Are we allowing contributions
         $contributable = Plugin::isEnabled('projects', 'publications') ? 1 : 0;
         // Instantiate a view
         $view = $this->view('default', 'browse')->set('option', $option)->set('publication', $publication)->set('versions', $versions)->set('config', $config)->set('authorized', $authorized)->set('contributable', $contributable);
         // Return the output
         $arr['html'] = $view->setErrors($this->getErrors())->loadTemplate();
     }
     return $arr;
 }
Пример #2
0
 /**
  * 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
     $row = new \Components\Publications\Tables\Version($this->_parent->_db);
     if (!$row->load($pub->version_id)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'));
         return false;
     }
     $originalType = $row->license_type;
     $originalText = $row->license_text;
     // Load license class
     $objL = new \Components\Publications\Tables\License($this->_parent->_db);
     // Incoming - license screen agreements
     $license = Request::getInt('license', 0, 'post');
     $text = \Hubzero\Utility\Sanitize::clean(Request::getVar('license_text', '', 'post'));
     $agree = Request::getInt('agree', 0, 'post');
     $custom = Request::getVar('substitute', array(), 'request', 'array');
     if ($license) {
         if (!$objL->load($license)) {
             $this->setError(Lang::txt('There was a problem saving license selection'));
             return false;
         }
         if ($objL->agreement == 1 && !$agree) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_LICENSE_NEED_AGREEMENT'));
             return false;
         } elseif ($objL->customizable == 1 && !$text) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_LICENSE_NEED_TEXT'));
             return false;
         }
         $row->license_type = $license;
         $text = preg_replace("/\r/", '', $text);
         $row->license_text = $text;
         // Pre-defined license text
         if ($objL->text && $objL->customizable == 0) {
             $row->license_text = $objL->text;
             // Do we have template items to replace?
             preg_match_all('/\\[([^\\]]*)\\]/', $objL->text, $substitutes);
             if (count($substitutes) > 1) {
                 foreach ($substitutes[1] as $sub) {
                     if (!isset($custom[$sub]) || !$custom[$sub]) {
                         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_LICENSE_NEED_CUSTOM'));
                         return false;
                     } else {
                         $row->license_text = preg_replace('/\\[' . $sub . '\\]/', trim($custom[$sub]), $row->license_text);
                     }
                 }
             }
         }
         $row->store();
         // Save agreement
         $row->saveParam($pub->version_id, 'licenseagreement', 1);
         // Save custom fields in version params
         foreach ($custom as $label => $value) {
             $row->saveParam($pub->version_id, 'licensecustom' . strtolower($label), trim($value));
         }
         if ($license != $originalType || $text != $originalText) {
             $this->_parent->set('_update', 1);
         }
         // Check agreements
         return true;
     }
     // Incoming - selector screen
     $selections = Request::getVar('selecteditems', '');
     $toAttach = explode(',', $selections);
     $i = 0;
     foreach ($toAttach as $license) {
         if (!trim($license)) {
             continue;
         }
         // Make sure license exists
         if ($objL->load($license)) {
             $row->license_type = $license;
             $i++;
             $row->store();
             // Clear agreement if license is changed
             if ($originalType != $license) {
                 // Save agreement
                 $row->saveParam($pub->version_id, 'licenseagreement', 0);
                 $this->_parent->set('_update', 1);
             }
             // Only one choice
             break;
         }
     }
     if ($i) {
         $this->set('_message', Lang::txt('License selection saved'));
         return true;
     } else {
         $this->setError(Lang::txt('There was a problem saving license selection'));
         return false;
     }
 }
Пример #3
0
 /**
  * Start/save a new version
  *
  * @return     string
  */
 public function newVersion()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $ajax = Request::getInt('ajax', 0);
     $label = trim(Request::getVar('version_label', '', 'post'));
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load default version
     $pub = new \Components\Publications\Models\Publication($pid, 'default');
     if (!$pub->exists()) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND'));
         $this->_task = '';
         return $this->browse();
     }
     // Make sure the publication belongs to the project
     if (!$pub->belongsToProject($this->model->get('id'))) {
         Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_PROJECT_ASSOC'), 'error', 'projects');
         App::redirect(Route::url($this->model->link('publications')));
         return;
     }
     // Set curation model
     $pub->setCuration();
     // Check if dev version is already there
     if ($pub->version->checkVersion($pid, 'dev')) {
         // Redirect
         App::redirect(Route::url($pub->link('editdev')));
         return;
     }
     // Can't start a new version if there is a finalized or submitted draft
     if ($pub->version->get('state') == 4 || $pub->version->get('state') == 5 || $pub->version->get('state') == 7) {
         // Determine redirect path
         App::redirect(Route::url($pub->link('editdefault')));
         return;
     }
     // Saving new version
     if ($this->_task == 'savenew') {
         $used_labels = $pub->version->getUsedLabels($pid, 'dev');
         if (!$label) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_NONE'));
         } elseif ($label && in_array($label, $used_labels)) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_USED'));
         } else {
             // Create new version
             $new = new \Components\Publications\Tables\Version($this->_database);
             // Copy from previous version
             $new->publication_id = $pub->get('publication_id');
             $new->title = $pub->get('title');
             $new->abstract = $pub->get('abstract');
             $new->description = $pub->get('description');
             $new->metadata = $pub->get('metadata');
             $new->release_notes = $pub->get('release_notes');
             $new->license_type = $pub->get('license_type');
             $new->license_text = $pub->get('license_text');
             $new->access = $pub->get('access');
             $new->created = Date::toSql();
             $new->created_by = $this->_uid;
             $new->modified = Date::toSql();
             $new->modified_by = $this->_uid;
             $new->state = 3;
             $new->main = 0;
             $new->version_label = $label;
             $new->version_number = $pub->versionCount() + 1;
             $new->secret = strtolower(\Components\Projects\Helpers\Html::generateCode(10, 10, 0, 1, 1));
             if ($new->store()) {
                 // Transfer data
                 $pub->_curationModel->transfer($pub, $pub->version, $new);
                 // Set response message
                 $this->set('_msg', Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NEW_VERSION_STARTED'));
                 // Set activity message
                 $pubTitle = \Hubzero\Utility\String::truncate($new->title, 100);
                 $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ACTIVITY_STARTED_VERSION') . ' ' . $new->version_label . ' ';
                 $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubTitle . '"';
                 $this->set('_activity', $action);
                 // Record action, notify team
                 $pub->set('version_number', $new->version_number);
                 $pub->set('version_label', $new->version_label);
                 $this->onAfterSave($pub);
             } else {
                 $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_SAVING_NEW_VERSION'));
             }
         }
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'newversion'));
         // Output HTML
         $view->option = $this->_option;
         $view->database = $this->_database;
         $view->project = $this->model;
         $view->uid = $this->_uid;
         $view->pid = $pid;
         $view->pub = $pub;
         $view->task = $this->_task;
         $view->config = $this->model->config();
         $view->pubconfig = $this->_pubconfig;
         $view->ajax = $ajax;
         $view->title = $this->_area['title'];
         // Get messages	and errors
         $view->msg = $this->_msg;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         return $view->loadTemplate();
     }
     // Pass success or error message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     // Redirect
     App::redirect(Route::url($pub->link('editdev')));
     return;
 }
Пример #4
0
 /**
  * Archive publications beyond grace period
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function runMkAip(\Components\Cron\Models\Job $job)
 {
     $database = \App::get('db');
     $config = Component::params('com_publications');
     require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'helpers' . DS . 'utilities.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'version.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php';
     // Check that mkAIP script exists
     if (!\Components\Publications\Helpers\Utilities::archiveOn()) {
         return;
     }
     // Check for grace period
     $gracePeriod = $config->get('graceperiod', 0);
     if (!$gracePeriod) {
         // If no grace period, this cron is unnecessary (archived as approval)
         return;
     }
     $aipBasePath = trim($config->get('aip_path', NULL), DS);
     $aipBasePath = $aipBasePath && is_dir(DS . $aipBasePath) ? DS . $aipBasePath : NULL;
     // Check for base path
     if (!$aipBasePath) {
         $this->setError('Missing archival base directory');
         return;
     }
     // Get all unarchived publication versions
     $query = "SELECT V.*, C.id as id, V.id as version_id ";
     $query .= " FROM #__publication_versions as V, #__publications as C ";
     $query .= " WHERE C.id=V.publication_id AND V.state=1 ";
     $query .= " AND V.doi IS NOT NULL ";
     $query .= " AND V.accepted IS NOT NULL AND V.accepted !='0000-00-00 00:00:00' ";
     $query .= " AND (V.archived IS NULL OR V.archived ='0000-00-00 00:00:00') ";
     $database->setQuery($query);
     if (!($rows = $database->loadObjectList())) {
         return true;
     }
     // Start email message
     $subject = Lang::txt('Update on recently archived publications');
     $body = Lang::txt('The following publications passed the grace period and were archived:') . "\n";
     $aipGroup = $config->get('aip_group');
     $counter = 0;
     foreach ($rows as $row) {
         // Grace period unexpired?
         $monthFrom = Date::of($row->accepted . '+1 month')->toSql();
         if (strtotime($monthFrom) > strtotime(Date::of('now'))) {
             continue;
         }
         // Load version
         $pv = new \Components\Publications\Tables\Version($database);
         if (!$pv->load($row->version_id)) {
             continue;
         }
         // Create aip path
         $doiParts = explode('/', $row->doi);
         $aipName = count($doiParts) > 1 ? $doiParts[0] . '__' . $doiParts[1] : '';
         // Archival package exists?
         if ($aipBasePath && $aipName && is_dir($aipBasePath . DS . $aipName)) {
             // Save approved date and archive date
             $pv->archived = $pv->accepted;
             $pv->store();
             // Do not overwrite existing archives !!
             continue;
         }
         // Run mkAIP and save archived date
         if (\Components\Publications\Helpers\Utilities::mkAip($row)) {
             $pv->archived = Date::toSql();
             $pv->store();
             $counter++;
             $body .= $row->title . ' v.' . $row->version_label . ' (id #' . $row->id . ')' . "\n";
         }
     }
     // Email update to admins
     if ($counter > 0 && $aipGroup) {
         // Set email config
         $from = array('name' => Config::get('fromname') . ' ' . Lang::txt('Publications'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
         $admins = \Components\Projects\Helpers\Html::getGroupMembers($aipGroup);
         // Build message
         if (!empty($admins)) {
             foreach ($admins as $admin) {
                 // Get the user's account
                 $user = User::getInstance($admin);
                 if (!$user->get('id')) {
                     continue;
                 }
                 $message = new \Hubzero\Mail\Message();
                 $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications');
                 $message->addPart($body, 'text/plain');
                 $message->send();
             }
         }
     }
     // All done
     return true;
 }
Пример #5
0
 /**
  * Collect overall projects stats
  *
  * @return  array
  */
 public function getStats($model, $cron = false, $publishing = false, $period = 'alltime', $limit = 3)
 {
     // Incoming
     $period = Request::getVar('period', $period);
     $limit = Request::getInt('limit', $limit);
     if ($cron == true) {
         $publicOnly = false;
         $saveLog = true;
     } else {
         $publicOnly = $model->reviewerAccess('admin') ? false : true;
         $saveLog = false;
     }
     // Collectors
     $stats = array();
     $updated = NULL;
     $lastLog = NULL;
     $pastMonth = Date::of(time() - 32 * 24 * 60 * 60)->toSql('Y-m-d');
     $thisYearNum = Date::format('y');
     $thisMonthNum = Date::format('m');
     $thisWeekNum = Date::format('W');
     // Pull recent stats
     if ($this->loadLog($thisYearNum, $thisMonthNum, $thisWeekNum)) {
         $lastLog = json_decode($this->stats, true);
         $updated = $this->processed;
     } else {
         // Save stats
         $saveLog = true;
     }
     // Get project table class
     $tbl = $model->table();
     // Get inlcude /exclude lists
     $exclude = $tbl->getProjectsByTag('test', true, 'id');
     $include = $tbl->getProjectsByTag('test', false, 'id');
     $validProjects = $tbl->getProjectsByTag('test', false, 'alias');
     $validCount = count($validProjects) > 0 ? count($validProjects) : 1;
     // Collect overview stats
     $stats['general'] = array('total' => $tbl->getCount(array('exclude' => $exclude, 'all' => 1), true), 'setup' => $tbl->getCount(array('exclude' => $exclude, 'setup' => 1), true), 'active' => $tbl->getCount(array('exclude' => $exclude, 'active' => 1), true), 'public' => $tbl->getCount(array('exclude' => $exclude, 'private' => '0'), true), 'sponsored' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sponsored'), true), 'sensitive' => $tbl->getCount(array('exclude' => $exclude, 'reviewer' => 'sensitive'), true), 'new' => $tbl->getCount(array('exclude' => $exclude, 'created' => date('Y-m', time()), 'all' => 1), true));
     $active = $stats['general']['active'] ? $stats['general']['active'] : 1;
     $total = $stats['general']['total'] ? $stats['general']['total'] : 1;
     // Activity stats
     $objAA = new Activity($this->_db);
     $recentlyActive = $tbl->getCount(array('exclude' => $exclude, 'timed' => $pastMonth, 'active' => 1), true);
     $perc = round($recentlyActive * 100 / $active) . '%';
     $stats['activity'] = array('total' => $objAA->getActivityStats($include, 'total'), 'average' => $objAA->getActivityStats($include, 'average'), 'usage' => $perc);
     $stats['topActiveProjects'] = $objAA->getTopActiveProjects($exclude, 5, $publicOnly);
     // Collect team stats
     $objO = new Owner($this->_db);
     $multiTeam = $objO->getTeamStats($exclude, 'multi');
     $activeTeam = $objO->getTeamStats($exclude, 'registered');
     $invitedTeam = $objO->getTeamStats($exclude, 'invited');
     $multiProjectUsers = $objO->getTeamStats($exclude, 'multiusers');
     $teamTotal = $activeTeam + $invitedTeam;
     $perc = round($multiTeam * 100 / $total) . '%';
     $stats['team'] = array('total' => $teamTotal, 'average' => $objO->getTeamStats($exclude, 'average'), 'multi' => $perc, 'multiusers' => $multiProjectUsers);
     $stats['topTeamProjects'] = $objO->getTopTeamProjects($exclude, $limit, $publicOnly);
     // Collect files stats
     if ($lastLog) {
         $stats['files'] = $lastLog['files'];
     } else {
         // Get repo model
         require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'repo.php';
         // Compute
         $repo = new \Components\Projects\Models\Repo();
         $fTotal = $repo->getStats($validProjects);
         $fAverage = number_format($fTotal / $validCount, 0);
         $fUsage = $repo->getStats($validProjects, 'usage');
         $fDSpace = $repo->getStats($validProjects, 'diskspace');
         $fCommits = $repo->getStats($validProjects, 'commitCount');
         $pDSpace = $repo->getStats($validProjects, 'pubspace');
         $perc = round($fUsage * 100 / $active) . '%';
         $stats['files'] = array('total' => $fTotal, 'average' => $fAverage, 'usage' => $perc, 'diskspace' => \Hubzero\Utility\Number::formatBytes($fDSpace), 'commits' => $fCommits, 'pubspace' => \Hubzero\Utility\Number::formatBytes($pDSpace));
     }
     // Collect publication stats
     if ($publishing) {
         $objP = new \Components\Publications\Tables\Publication($this->_db);
         $objPV = new \Components\Publications\Tables\Version($this->_db);
         $prPub = $objP->getPubStats($include, 'usage');
         $perc = round($prPub * 100 / $total) . '%';
         $stats['pub'] = array('total' => $objP->getPubStats($include, 'total'), 'average' => $objP->getPubStats($include, 'average'), 'usage' => $perc, 'released' => $objP->getPubStats($include, 'released'), 'versions' => $objPV->getPubStats($include));
     }
     // Save weekly stats
     if ($saveLog) {
         $this->year = $thisYearNum;
         $this->month = $thisMonthNum;
         $this->week = $thisWeekNum;
         $this->processed = Date::toSql();
         $this->stats = json_encode($stats);
         $this->store();
     }
     $stats['updated'] = $updated ? $updated : NULL;
     return $stats;
 }
 /**
  * Checks if the ID exists in the database.
  *
  * @param int $id   ID to check
  * @return boolean  True if exists, false otherwise.
  */
 public static function idExists($id)
 {
     if (!empty($id) && $id != -1) {
         // Grabs the database object
         $database = \App::get('db');
         // Attempts to load $id on this database object.
         $resource = new \Components\Publications\Tables\Version($database);
         return $resource->getLastPubRelease($id);
     }
     return false;
 }
Пример #7
0
 /**
  * Return data on a publication view (this will be some form of HTML)
  *
  * @param      object  	$publication 	Current publication
  * @param      string  	$option    		Name of the component
  * @param      array   	$areas     		Active area(s)
  * @param      string  	$rtrn      		Data to be returned
  * @param      string 	$version 		Version name
  * @param      boolean 	$extended 		Whether or not to show panel
  * @param      string 	$authorized
  * @return     array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true, $authorized = false)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) {
             $rtrn = 'metadata';
         }
     }
     $database = App::get('db');
     // Get pub configs
     $config = Component::params($option);
     if ($rtrn == 'all' || $rtrn == 'html') {
         $objV = new \Components\Publications\Tables\Version($database);
         $versions = $objV->getVersions($publication->id, $filters = array('public' => 1));
         // Instantiate a view
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'versions', 'name' => 'browse'));
         // Are we allowing contributions
         $view->contributable = Plugin::isEnabled('projects', 'publications') ? 1 : 0;
         // Pass the view some info
         $view->option = $option;
         $view->publication = $publication;
         $view->versions = $versions;
         $view->config = $config;
         $view->authorized = $authorized;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     return $arr;
 }
Пример #8
0
 /**
  * Save block
  *
  * @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
     $row = new \Components\Publications\Tables\Version($this->_parent->_db);
     if (!$row->load($pub->version_id)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'));
         return false;
     }
     // Track changes
     $changed = 0;
     $missed = 0;
     $collapse = $this->_manifest->params->collapse_elements == 0 ? 0 : 1;
     // Incoming
     $nbtags = Request::getVar('nbtag', array(), 'request', 'array');
     // Parse metadata
     $data = array();
     preg_match_all("#<nb:(.*?)>(.*?)</nb:(.*?)>#s", $pub->metadata, $matches, PREG_SET_ORDER);
     if (count($matches) > 0) {
         foreach ($matches as $match) {
             $data[$match[1]] = \Components\Publications\Helpers\Html::_txtUnpee($match[2]);
         }
     }
     // Save each element
     foreach ($this->_manifest->elements as $id => $element) {
         // Are we saving just one element?
         if ($elementId && $id != $elementId && $collapse) {
             continue;
         }
         $field = $element->params->field;
         $aliasmap = $element->params->aliasmap;
         $input = $element->params->input;
         $required = $element->params->required;
         if ($field == 'metadata') {
             $value = isset($nbtags[$aliasmap]) ? trim(stripslashes($nbtags[$aliasmap])) : NULL;
             if (!$value && $required) {
                 $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED'));
             } else {
                 if ($value && !isset($data[$aliasmap]) || isset($data[$aliasmap]) && $data[$aliasmap] != $value) {
                     $changed++;
                 }
                 // Replace data
                 $data[$aliasmap] = $value;
                 // Save all in one field
                 $tagCollect = '';
                 foreach ($data as $tagname => $tagcontent) {
                     $tagCollect .= "\n" . '<nb:' . $tagname . '>' . $tagcontent . '</nb:' . $tagname . '>' . "\n";
                 }
                 $row->metadata = $tagCollect;
             }
         } else {
             $value = trim(Request::getVar($field, '', 'post', 'none', 2));
             $value = $input == 'editor' ? stripslashes($value) : \Hubzero\Utility\Sanitize::clean($value);
             if (!$value && $required) {
                 $missed++;
             }
             if ($row->{$field} != $value) {
                 $lastRecord = $pub->_curationModel->getLastUpdate($id, $this->_name, $blockId);
                 $changed++;
                 // Record update time
                 $data = new stdClass();
                 $data->updated = Date::toSql();
                 $data->updated_by = $actor;
                 // Unmark as skipped
                 if ($lastRecord && $lastRecord->review_status == 3) {
                     $data->review_status = 0;
                     $data->update = '';
                 }
                 if ($value) {
                     $data->update = '';
                     // remove dispute message if requirement satisfied
                 }
                 $pub->_curationModel->saveUpdate($data, $id, $this->_name, $pub, $blockId);
             }
             $row->{$field} = $value;
         }
     }
     // Update modified info
     if ($changed) {
         $row->modified = Date::toSql();
         $row->modified_by = $actor;
         $this->_parent->set('_update', 1);
     }
     // Report error
     if ($missed && $collapse == 0) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED'));
     }
     // Save
     if (!$row->store()) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_SAVE_PUBLICATION'));
         return false;
     }
     // Set success message
     $this->_parent->set('_message', $this->get('_message'));
     return true;
 }
Пример #9
0
 /**
  * Save incoming
  *
  * @param   object   $element
  * @param   integer  $elementId
  * @param   object   $pub
  * @param   object   $blockParams
  * @param   array    $toAttach
  * @return  boolean
  */
 public function save($element, $elementId, $pub, $blockParams, $toAttach = array())
 {
     if (empty($toAttach)) {
         $selections = Request::getVar('selecteditems', '');
         $toAttach = explode(',', $selections);
     }
     // Get configs
     $configs = $this->getConfigs($element, $elementId, $pub, $blockParams);
     // Cannot make changes
     if ($configs->freeze) {
         return false;
     }
     // Nothing to change
     if (empty($toAttach) && !$configs->replace) {
         return false;
     }
     // Get existing attachments for the elemnt
     $attachments = $pub->_attachments;
     $attachments = isset($attachments['elements'][$elementId]) ? $attachments['elements'][$elementId] : NULL;
     // Sort out attachments for this element
     $attachments = $this->_parent->getElementAttachments($elementId, $attachments, $this->_name);
     // Counters
     $i = 0;
     $a = 0;
     // Default title for publication
     $defaultTitle = $pub->_curationModel->_manifest->params->default_title;
     // Attach/refresh each selected item
     foreach ($toAttach as $identifier) {
         if (!trim($identifier)) {
             continue;
         }
         $a++;
         $ordering = $i + 1;
         $row = new \Components\Publications\Tables\Version($this->_parent->_db);
         if (!$row->loadVersion($identifier, 'current')) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND'));
             return false;
         }
         $title = $row->title;
         $desc = strip_tags($row->description);
         if ($this->addAttachment($identifier, $title, $pub, $configs, User::get('id'), $elementId, $element, $ordering)) {
             $i++;
         }
     }
     // Success
     if ($i > 0 && $i == $a) {
         $message = $this->get('_message') ? $this->get('_message') : Lang::txt('Selection successfully saved');
         $this->set('_message', $message);
     }
     return true;
 }
Пример #10
0
 /**
  * Save incoming
  *
  * @return  boolean
  */
 public function save($element, $elementId, $pub, $blockParams, $toAttach = array())
 {
     $toAttach = $toAttach ? $toAttach : Request::getVar('url', '', 'post', 'array');
     $titles = Request::getVar('title', '', 'post', 'array');
     $desc = Request::getVar('desc', '', 'post', 'array');
     // Incoming selections
     if (empty($toAttach)) {
         $toAttach = array($url);
     }
     // Get configs
     $configs = $this->getConfigs($element, $elementId, $pub, $blockParams);
     // Cannot make changes
     if ($configs->freeze) {
         return false;
     }
     // Nothing to change
     if (empty($toAttach) && !$configs->replace) {
         return false;
     }
     // Get existing attachments for the elemnt
     $attachments = $pub->_attachments;
     $attachments = isset($attachments['elements'][$elementId]) ? $attachments['elements'][$elementId] : NULL;
     // Sort out attachments for this element
     $attachments = $this->_parent->getElementAttachments($elementId, $attachments, $this->_name);
     // Counters
     $i = 0;
     $a = 0;
     // Default title for publication
     $defaultTitle = $pub->_curationModel->_manifest->params->default_title;
     // Attach/refresh each selected item
     foreach ($toAttach as $identifier) {
         if (!trim($identifier)) {
             continue;
         }
         $a++;
         $ordering = $i + 1;
         $title = isset($titles[$i]) ? $titles[$i] : NULL;
         $desc = isset($desc[$i]) ? $desc[$i] : NULL;
         if ($this->addAttachment($identifier, $title, $pub, $configs, User::get('id'), $elementId, $element, $ordering)) {
             // Do we also set draft title and metadata from the link?
             if ($i == 0 && $title && $element->role == 1 && stripos($pub->title, $defaultTitle) !== false) {
                 // Load publication version
                 $row = new \Components\Publications\Tables\Version($this->_parent->_db);
                 if (!$row->load($pub->version_id)) {
                     $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'));
                     return false;
                 }
                 $row->title = $title;
                 $description = \Hubzero\Utility\Sanitize::clean($desc);
                 $row->description = $description;
                 $row->abstract = \Hubzero\Utility\String::truncate($description, 255);
                 $row->store();
             }
             $i++;
         }
     }
     // Success
     if ($i > 0 && $i == $a) {
         $message = $this->get('_message') ? $this->get('_message') : Lang::txt('Selection successfully saved');
         $this->set('_message', $message);
     }
     return true;
 }