/** * 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_TOOLS_CONTRIBUTE_NO_CHILD_ID')); return $this->displayTask($pid); } // Ensure we have a parent ID to work with if (!$pid) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); return $this->displayTask($pid); } // Get the element moving down - item 1 $author1 = new \Components\Resources\Tables\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); }
?> </th> <th scope="col" colspan="3"><?php echo Lang::txt('Associations'); ?> </th> <th scope="col" colspan="2"><?php echo Lang::txt('Status'); ?> </th> </tr> </thead> <tbody> <?php $ra = new \Components\Resources\Tables\Assoc($database); $rc = new \Components\Resources\Tables\Contributor($database); $cls = 'even'; foreach ($submissions as $submission) { $cls = $cls == 'even' ? 'odd' : 'even'; switch ($submission->published) { case 1: $state = 'published'; break; // published // published case 2: $state = 'draft'; break; // draft // draft case 3:
* @package hubzero-cms * @author Shawn Rice <*****@*****.**> * @copyright Copyright 2005-2015 HUBzero Foundation, LLC. * @license http://opensource.org/licenses/MIT MIT */ // No direct access. defined('_HZEXEC_') or die; $attachments = 0; $authors = 0; $tags = array(); $state = 'pending'; $type = ''; if ($this->resource->id) { $database = App::get('db'); $ra = new \Components\Resources\Tables\Assoc($database); $rc = new \Components\Resources\Tables\Contributor($database); $rt = new \Components\Resources\Helpers\Tags($this->resource->id); switch ($this->resource->published) { case 1: $state = 'published'; break; // published // published case 2: $state = 'draft'; break; // draft // draft case 3: $state = 'pending'; break;
/** * Save a list of authors * * @param array $authors List of authors to add * @param string $version Tool version * @param integer $rid Resource ID * @param integer $revision Revision number * @param string $toolname Tool name * @return boolean False if errors, True if not */ public function saveAuthors($authors, $version = 'dev', $rid = 0, $revision = 0, $toolname = '') { if (!$rid) { return false; } if ($authors) { $authors = Utils::transform($authors, 'uidNumber'); } $dev_authors = $this->getToolAuthors('dev', $rid); $dev_authors = Utils::transform($dev_authors, 'uidNumber'); if ($dev_authors && $version == 'dev') { // update $to_delete = array_diff($current_authors, $authors); if ($to_delete) { foreach ($to_delete as $del) { $query = "DELETE FROM #__author_assoc WHERE authorid=" . $this->_db->quote($del) . " AND subid=" . $this->_db->quote($rid) . " AND subtable='resources'"; $this->_db->setQuery($query); $this->_db->query(); } } } // add new authors if ($version == 'dev') { // development version is updated $to_delete = array_diff($dev_authors, $authors); $rc = new \Components\Resources\Tables\Contributor($this->_db); $rc->subtable = 'resources'; $rc->subid = $rid; if ($to_delete) { foreach ($to_delete as $del) { $query = "DELETE FROM #__author_assoc WHERE authorid=" . $this->_db->quote($del) . " AND subid=" . $this->_db->quote($rid) . " AND subtable='resources'"; $this->_db->setQuery($query); $this->_db->query(); } } // Get the last child in the ordering $order = $rc->getLastOrder($rid, 'resources'); $order = $order + 1; // new items are always last foreach ($authors as $authid) { // Check if they're already linked to this resource $rc->loadAssociation($authid, $rid, 'resources'); if (!$rc->authorid) { $xprofile = User::getInstance($authid); // New record $rc->authorid = $authid; $rc->ordering = $order; $rc->name = addslashes($xprofile->get('name')); $rc->organization = addslashes($xprofile->get('organization')); $rc->createAssociation(); $order++; } } } else { if ($dev_authors) { // new version is being published, transfer data from author_assoc $i = 0; foreach ($dev_authors as $authid) { $name = ''; $organization = ''; // Check the author_assoc table first, as that's what gets updated when you edit the tool info $query = "SELECT name, organization FROM `#__author_assoc` "; $query .= "WHERE subid= " . $this->_db->quote($rid); $query .= " AND authorid=" . $this->_db->quote($authid); $query .= " AND subtable='resources'"; $this->_db->setQuery($query); $author = $this->_db->loadObject(); if ($author) { $name = $author->name; $organization = $author->organization; } if (!$name || !$organization) { // Do we have name/org info in previous version? $query = "SELECT name, organization FROM #__tool_authors "; $query .= "WHERE toolname=" . $this->_db->quote($toolname) . " AND uid=" . $this->_db->quote($authid) . " AND revision < " . $this->_db->quote($revision); $query .= " AND name IS NOT NULL AND organization IS NOT NULL "; $query .= " ORDER BY revision DESC LIMIT 1"; $this->_db->setQuery($query); $info = $this->_db->loadObjectList(); if ($info) { $name = $name ?: $info[0]->name; $organization = $organization ?: $info[0]->organization; } // If we still don't have it, try to grab it from the profile if (!$name || !$organization) { $xprofile = User::getInstance($authid); $name = $name ?: $xprofile->get('name'); $organization = $organization ?: $xprofile->get('organization'); } } $query = "INSERT INTO {$this->_tbl} (toolname, revision, uid, ordering, version_id, name, organization) VALUES ('" . $toolname . "','" . $revision . "','" . $authid . "','" . $i . "', '" . $version . "', '" . addslashes($name) . "', '" . addslashes($organization) . "')"; $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } $i++; } } } return true; }
/** * Check if the authors step is completed * * @param integer $id Resource ID * @return boolean True if step completed */ public function step_authors_check($id) { if ($id) { $database = App::get('db'); $rc = new \Components\Resources\Tables\Contributor($database); $contributors = $rc->getCount($id, 'resources'); } else { $contributors = 0; } return $contributors ? true : false; }