Esempio n. 1
0
 /**
  * Edit content item
  *
  * @return     string
  */
 public function editItem()
 {
     // Incoming
     $id = Request::getInt('aid', 0);
     $props = Request::getVar('p', '');
     // Parse props for curation
     $parts = explode('-', $props);
     $block = isset($parts[0]) ? $parts[0] : 'content';
     $step = isset($parts[1]) && is_numeric($parts[1]) && $parts[1] > 0 ? $parts[1] : 1;
     $element = isset($parts[2]) && is_numeric($parts[2]) && $parts[2] > 0 ? $parts[2] : 0;
     if ($this->_task == 'editauthor') {
         // Get author information
         $row = new \Components\Publications\Tables\Author($this->_database);
         $error = Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR');
         $layout = 'author';
     } else {
         // Load attachment
         $row = new \Components\Publications\Tables\Attachment($this->_database);
         $error = Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_EDIT_CONTENT');
         $layout = 'attachment';
     }
     // We need attachment record
     if (!$id || !$row->load($id)) {
         $this->setError($error);
     }
     // Load publication
     $pub = new \Components\Publications\Models\Publication(NULL, NULL, $row->publication_version_id);
     if (!$pub->exists()) {
         $this->setError($error);
     }
     // Make sure the publication belongs to the project
     if (!$pub->belongsToProject($this->model->get('id'))) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_PROJECT_ASSOC'));
     }
     // On error
     if ($this->getError()) {
         // Output error
         $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'error'));
         $view->title = '';
         $view->option = $this->_option;
         $view->setError($this->getError());
         return $view->loadTemplate();
     }
     // Set curation
     $pub->setCuration();
     // On success
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'edititem', 'layout' => $layout));
     // Get project path
     if ($this->_task != 'editauthor') {
         $view->path = $pub->project()->repo()->get('path');
     }
     $view->step = $step;
     $view->block = $block;
     $view->element = $element;
     $view->database = $this->_database;
     $view->option = $this->_option;
     $view->project = $this->model;
     $view->pub = $pub;
     $view->row = $row;
     $view->backUrl = Request::getVar('HTTP_REFERER', NULL, 'server');
     $view->ajax = Request::getInt('ajax', 0);
     $view->props = $props;
     return $view->loadTemplate();
 }
Esempio n. 2
0
 /**
  * Delete attachment record
  *
  * @return  void
  */
 public function deleteItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0)
 {
     $aid = $aid ? $aid : Request::getInt('aid', 0);
     // Load attachment
     $row = new \Components\Publications\Tables\Attachment($this->_parent->_db);
     // We need attachment record
     if (!$aid || !$row->load($aid)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_EDIT_CONTENT'));
         return false;
     }
     // Attachment type
     $type = $row->type;
     // Get attachment type model
     $attModel = new \Components\Publications\Models\Attachments($this->_parent->_db);
     // Save incoming attachment info
     $attModel->remove($type, $row, $pub, $actor, $elementId, $manifest->elements->{$elementId}, $manifest->params);
     // Set success message
     if ($attModel->get('_message')) {
         $this->set('_message', $attModel->get('_message'));
     }
     // Set request to update curation record
     if ($attModel->get('_update')) {
         $this->_parent->set('_update', 1);
     }
     return true;
 }