/** * Map Resource Contributors * * @return void */ private function _mapContributorData() { // get any contributors $contributors = isset($this->raw->contributors) ? $this->raw->contributors : new stdClass(); // get roles for resource type $contributorRoles = new Tables\Contributor\RoleType($this->_database); $rolesForType = $contributorRoles->getRolesForType($this->record->resource->type); $rolesForType = is_array($rolesForType) ? $rolesForType : array(); // get valid role aliases $existingRoles = array_map(function ($role) { return $role->alias; }, $rolesForType); // handle contributors as string if (is_string($contributors)) { $contributors = array_map("trim", explode(';', $contributors)); $contributors = array_values(array_filter($contributors)); $contributors = array_map(function ($c) { $cc = new stdClass(); $cc->name = $c; return $cc; }, $contributors); } // loop through each contributor foreach ($contributors as $contributor) { // create resource contributor object $resourceContributor = new Tables\Contributor($this->_database); // check to see if we have an author id $authorid = isset($contributor->authorid) ? $contributor->authorid : null; // load name if ($authorid != null) { if ($profile = \Hubzero\User\User::oneOrNew($authorid)) { $resourceContributor->authorid = $profile->get('id'); } } $resourceContributor->name = isset($contributor->name) ? $contributor->name : ''; $resourceContributor->organization = isset($contributor->organization) ? $contributor->organization : ''; $resourceContributor->role = isset($contributor->role) && in_array($contributor->role, $existingRoles) ? $contributor->role : ''; $resourceContributor->subtable = 'resources'; array_push($this->record->contributors, $resourceContributor); } }
/** * Display a list of authors * * @param integer $id Resource ID * @return void */ public function displayTask($id = null) { $this->view->setLayout('display'); // Incoming if (!$id) { $id = Request::getInt('id', 0); } // Ensure we have an ID to work with if (!$id) { throw new Exception(Lang::txt('CONTRIBUTE_NO_ID'), 500); } // Get all contributors of this resource $helper = new Helper($id, $this->database); $helper->getCons(); // Get a list of all existing contributors include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'profile.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'association.php'; include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor' . DS . 'roletype.php'; $resource = new Resource($this->database); $resource->load($id); $rt = new RoleType($this->database); // Output HTML $this->view->config = $this->config; $this->view->contributors = $helper->_contributors; $this->view->id = $id; $this->view->roles = $rt->getRolesForType($resource->type); foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }