Example #1
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;
 }
Example #2
0
 /**
  * Draw list
  *
  * @param   array    $attachments
  * @param   object   $element
  * @param   integer  $elementId
  * @param   object   $pub
  * @param   object   $blockParams
  * @param   boolean  $authorized
  * @return  string   HTML
  */
 public function drawList($attachments, $element, $elementId, $pub, $blockParams, $authorized)
 {
     // Get configs
     $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams);
     $html = '';
     if ($attachments) {
         // Serve individually
         foreach ($attachments as $attach) {
             $itemUrl = Route::url('index.php?option=com_publications&id=' . $attach->object_id);
             $publication = new \Components\Publications\Models\Publication($attach->object_id, 'default');
             $title = $publication->title ? $publication->title : $configs->title;
             $title = $title ? $title : $attach->path;
             $description = '';
             if ($publication->get('abstract')) {
                 $description = \Hubzero\Utility\String::truncate(stripslashes($publication->get('abstract')), 300) . "\n";
             } else {
                 if ($publication->get('description')) {
                     $description = \Hubzero\Utility\String::truncate(stripslashes($publication->get('description')), 300) . "\n";
                 }
             }
             $pop = Lang::txt('View link') . ' ' . $title;
             $html .= '<li>';
             $html .= $authorized === 'administrator' ? '[' . $this->_name . '] ' : '';
             $html .= '<p><a href="' . $itemUrl . '" title="' . $pop . '" target="_blank" class="link-type">' . $title . '</a></p>';
             $html .= '<p>' . $description . '</p>';
             $html .= '</li>';
         }
     }
     return $html;
 }