Example #1
0
 /**
  * Assign curation
  *
  * @return  void
  */
 public function assignTask()
 {
     // Incoming
     $pid = $this->_id ? $this->_id : Request::getInt('id', 0);
     $vid = Request::getInt('vid', 0);
     $owner = Request::getInt('owner', 0);
     $confirm = Request::getInt('confirm', 0);
     $ajax = Request::getInt('ajax', 0);
     // Load publication model
     $this->_pub = new \Components\Publications\Models\Publication($pid, NULL, $vid);
     if (!$this->_pub->exists()) {
         if ($ajax) {
             $this->view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => 'restricted'));
             $this->view->error = Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_LOAD');
             $this->view->title = $this->title;
             $this->view->display();
             return;
         }
         throw new Exception(Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_LOAD'), 404);
     }
     if (!$this->_pub->access('curator')) {
         if ($ajax) {
             $this->view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => 'restricted'));
             $this->view->error = Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_UNAUTHORIZED');
             $this->view->title = $this->title;
             $this->view->display();
             return;
         }
         throw new Exception(Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_UNAUTHORIZED'), 403);
     }
     // Perform assignment
     if ($confirm) {
         $previousOwner = $this->_pub->version->get('curator');
         $selected = Request::getInt('selected', 0);
         // Make sure owner profile exists
         if ($owner) {
             $ownerProfile = User::getInstance($owner);
             if (!$ownerProfile) {
                 $this->setError(Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_ASSIGN_PROFILE'));
             }
         } elseif ($selected && Request::getVar('owner', '')) {
             $owner = $selected;
         }
         // Assign
         if (!$this->getError()) {
             $this->_pub->version->set('curator', $owner);
             if (!$this->_pub->version->store()) {
                 $this->setError(Lang::txt('COM_PUBLICATIONS_CURATION_ASSIGN_FAILED'));
             }
             // Notify curator
             if ($owner && $owner != $previousOwner) {
                 $item = '"' . html_entity_decode($this->_pub->version->title) . '"';
                 $item .= ' v.' . $this->_pub->version->version_label . ' ';
                 $item = htmlentities($item, ENT_QUOTES, "UTF-8");
                 $message = Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_ASSIGNED') . ' ' . $item . "\n" . "\n";
                 $message .= Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_ASSIGNED_CURATE') . ' ' . rtrim(Request::base(), DS) . DS . trim(Route::url($this->_pub->link('curate')), DS) . "\n" . "\n";
                 $message .= Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_ASSIGNED_PREVIEW') . ' ' . rtrim(Request::base(), DS) . DS . trim(Route::url($this->_pub->link('version')), DS);
                 Helpers\Html::notify($this->_pub, array($owner), Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_ASSIGNED_SUBJECT'), $message);
             }
             // Log assignment in history
             if (!$this->getError() && $owner != $previousOwner) {
                 $obj = new Tables\CurationHistory($this->database);
                 if (!empty($ownerProfile)) {
                     $changelog = '<p>Curation assigned to ' . $ownerProfile->get('name') . ' (' . $ownerProfile->get('username') . ')</p>';
                 } else {
                     $changelog = '<p>Curator assignment was removed</p>';
                 }
                 // Create new record
                 $obj->publication_version_id = $this->_pub->version->id;
                 $obj->created = Date::toSql();
                 $obj->created_by = User::get('id');
                 $obj->changelog = $changelog;
                 $obj->curator = 1;
                 $obj->newstatus = $this->_pub->version->state;
                 $obj->oldstatus = $this->_pub->version->state;
                 $obj->store();
             }
         }
     } else {
         if (!$ajax) {
             // Set page title
             $this->_buildTitle();
             // Set the pathway
             $this->_buildPathway();
             // Add plugin style
             \Hubzero\Document\Assets::addPluginStylesheet('projects', 'publications', 'curation.css');
         }
         $this->view->pub = $this->_pub;
         $this->view->title = $this->_title;
         $this->view->option = $this->_option;
         $this->view->ajax = $ajax;
         $this->view->display();
         return;
     }
     $message = $this->getError() ? $this->getError() : Lang::txt('COM_PUBLICATIONS_CURATION_SUCCESS_ASSIGNED');
     $class = $this->getError() ? 'error' : 'success';
     // Redirect to main listing
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=curation'), $message, $class);
     return;
 }
Example #2
0
 /**
  * Save history log
  *
  * @param   integer $actor		Actor user ID
  * @param   integer $oldStatus	Previous version state
  * @param   integer $newStatus	New version state
  * @param   integer $curator	Author or curator
  * @return  boolean
  */
 public function saveHistory($actor = 0, $oldStatus = 0, $newStatus = 0, $curator = 0)
 {
     if (empty($this->_pub)) {
         return false;
     }
     // Incoming
     $comment = Request::getVar('comment', '', 'post');
     // Collect details
     $changelog = $this->getChangeLog($oldStatus, $newStatus, $curator);
     if (!$changelog) {
         return false;
     }
     $obj = new Tables\CurationHistory($this->_db);
     // Create new record
     $obj->publication_version_id = $this->_pub->version_id;
     $obj->created = Date::toSql();
     $obj->created_by = $actor;
     $obj->changelog = $changelog;
     $obj->curator = $curator;
     $obj->newstatus = $newStatus;
     $obj->oldstatus = $oldStatus;
     $obj->comment = \Hubzero\Utility\Sanitize::clean(htmlspecialchars($comment));
     if ($obj->store()) {
         return true;
     }
     return false;
 }