/** * Reorder the list of authors * * @return void */ public function reorderTask() { // Incoming $id = Request::getInt('id', 0); $pid = Request::getInt('pid', 0); $move = 'order' . Request::getVar('move', 'down'); // Ensure we have an ID to work with if (!$id) { $this->setError(Lang::txt('COM_CONTRIBUTE_NO_CHILD_ID')); $this->displayTask($pid); return; } // Ensure we have a parent ID to work with if (!$pid) { $this->setError(Lang::txt('COM_CONTRIBUTE_NO_ID')); $this->displayTask($pid); return; } // Get the element moving down - item 1 $author1 = new Contributor($this->database); $author1->loadAssociation($id, $pid, 'resources'); // Get the element directly after it in ordering - item 2 $author2 = clone $author1; $author2->getNeighbor($move); switch ($move) { case 'orderup': // Switch places: give item 1 the position of item 2, vice versa $orderup = $author2->ordering; $orderdn = $author1->ordering; $author1->ordering = $orderup; $author2->ordering = $orderdn; break; case 'orderdown': // Switch places: give item 1 the position of item 2, vice versa $orderup = $author1->ordering; $orderdn = $author2->ordering; $author1->ordering = $orderdn; $author2->ordering = $orderup; break; } // Save changes $author1->updateAssociation(); $author2->updateAssociation(); // Push through to the attachments view $this->displayTask($pid); }
/** * Save an entry * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post'); $authorid = Request::getVar('authorid', 0); $id = Request::getVar('id', 0); if (!$authorid) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); return; } $rows = array(); if (is_array($fields)) { foreach ($fields as $fieldset) { $rc = new Contributor($this->database); $rc->subtable = 'resources'; $rc->subid = trim($fieldset['subid']); $rc->authorid = $authorid; $rc->name = trim($fieldset['name']); $rc->organization = trim($fieldset['organization']); $rc->role = $fieldset['role']; $rc->ordering = $fieldset['ordering']; if ($authorid != $id) { if (!$rc->createAssociation()) { $this->setError($rc->getError()); } if (!$rc->deleteAssociation($id, $rc->subid, $rc->subtable)) { $this->setError($rc->getError()); } } else { if (!$rc->updateAssociation()) { $this->setError($rc->getError()); } } $rows[] = $rc; } } // Instantiate a resource/contributor association object $rc = new Contributor($this->database); if ($this->_task == 'apply') { return $this->editTask($rows); } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * Gets the full name of a user from their ID # * * @return string */ public function authorTask() { $this->view->id = Request::getVar('u', ''); $this->view->role = Request::getVar('role', ''); $rid = Request::getInt('rid', 0); // Get the member's info $profile = new \Hubzero\User\Profile(); $profile->load($this->view->id); if (!is_object($profile) || !$profile->get('uidNumber')) { $this->database->setQuery("SELECT id FROM `#__users` WHERE `name`=" . $this->database->Quote($this->view->id)); if ($id = $this->database->loadResult()) { $profile->load($id); } } if (is_object($profile) && $profile->get('uidNumber')) { if (!$profile->get('name')) { $this->view->name = $profile->get('givenName') . ' '; $this->view->name .= $profile->get('middleName') ? $profile->get('middleName') . ' ' : ''; $this->view->name .= $profile->get('surname'); } else { $this->view->name = $profile->get('name'); } $this->view->org = $profile->get('organization'); $this->view->id = $profile->get('uidNumber'); } else { $this->view->name = null; include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor.php'; $rcc = new Contributor($this->database); if (is_numeric($this->view->id)) { $this->database->setQuery("SELECT name, organization FROM `#__author_assoc` WHERE authorid=" . $this->database->Quote($this->view->id) . " LIMIT 1"); $author = $this->database->loadObject(); if (is_object($author) && $author->name) { $this->view->name = $author->name; $this->view->org = $author->organization; } } if (!$this->view->name) { $this->view->org = ''; $this->view->name = str_replace('_', ' ', $this->view->id); $this->view->id = $rcc->getUserId($this->view->name); } } $row = new Resource($this->database); $row->load($rid); $rt = new Type($this->database); $this->view->roles = $rt->getRolesForType($row->type); $this->view->display(); }
/** * Check if the authors step is completed * * @param integer $id Resource ID * @return integer # > 1 = step completed, 0 = not completed */ public function step_authors_check($id) { if ($id) { $rc = new Contributor($this->database); $contributors = $rc->getCount($id, 'resources'); } else { $contributors = 0; } return $contributors; }