예제 #1
0
 /**
  * View/Edit publication draft
  *
  * @return     string
  */
 public function editDraft()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $version = Request::getVar('version', 'default');
     $block = Request::getVar('section', 'status');
     $blockId = Request::getInt('step', 0);
     // Provision draft
     if (!$pid) {
         $pub = $this->createDraft();
         if (!$pub || !$pub->exists()) {
             throw new Exception(Lang::txt('Error creating a publication draft'), 500);
             return;
         }
         // Get curation model
         $pub->setCuration();
         $blockId = $pub->_curationModel->getFirstBlock();
         $firstBlock = $pub->_curationModel->_blocks->{$blockId}->name;
         // Redirect to first block
         App::redirect(htmlspecialchars_decode(Route::url($pub->link('editversion') . '&move=continue&step=' . $blockId . '&section=' . $firstBlock)));
         return;
     } else {
         $pub = new \Components\Publications\Models\Publication($pid, $version);
     }
     // If publication not found, raise error
     if (!$pub->exists() || $pub->isDeleted()) {
         \Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND'), 'error', 'projects');
         App::redirect(Route::url($pub->link('editbase')));
         return;
     }
     // 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;
     }
     // Get curation model
     $pub->setCuration();
     // For publications created in a non-curated flow - convert
     $pub->_curationModel->convertToCuration($pub);
     // Go to last incomplete section
     if ($this->_task == 'continue') {
         $blocks = $pub->curation('blocks');
         $blockId = $pub->curation('firstBlock');
         $block = $blockId ? $blocks->{$blockId}->name : 'status';
     }
     // Go to review screen
     if ($this->_task == 'review' || $this->_task == 'continue' && $pub->curation('complete') == 1) {
         $blockId = $pub->curation('lastBlock');
         $block = 'review';
     }
     // Certain publications go to status page
     if ($pub->state == 5 || $pub->state == 0 || $block == 'review' && $pub->state == 1) {
         $block = 'status';
         $blockId = 0;
     }
     // Make sure block exists, else redirect to status
     if (!$pub->_curationModel->setBlock($block, $blockId) || !$this->model->access('content')) {
         $block = 'status';
     }
     // Get requested block
     $name = $block == 'status' ? 'status' : 'draft';
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name));
     // Output HTML
     $view->option = $this->_option;
     $view->database = $this->_database;
     $view->project = $this->model;
     $view->uid = $this->_uid;
     $view->config = $this->model->config();
     $view->title = $this->_area['title'];
     $view->active = $block;
     $view->pub = $pub;
     $view->pubconfig = $this->_pubconfig;
     $view->task = $this->_task;
     // Append breadcrumbs
     $this->_appendBreadcrumbs($pub->get('title'), $pub->link('edit'), $version);
     // Get messages	and errors
     $view->msg = $this->_msg;
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     return $view->loadTemplate();
 }