/** * Add a user as a manager of a course * * @return void */ public function addTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if ($this->getError()) { return $this->displayTask(); } // Incoming host $m = Request::getVar('author', ''); $mbrs = explode(',', $m); $mbrs = array_map('trim', $mbrs); foreach ($mbrs as $mbr) { $user = null; if (!strstr($mbr, ' ')) { $user = User::getInstance($mbr); } // Make sure the user exists if (!is_object($user) || !$user->get('username')) { $mbr = trim($mbr); $mbr = preg_replace('/\\s+/', ' ', $mbr); $user = new \Hubzero\User\User(); $user->set('name', $mbr); $parts = explode(' ', $mbr); if (count($parts) > 1) { $surname = array_pop($parts); $user->set('surname', $surname); $givenName = array_shift($parts); $user->set('givenName', $givenName); if (!empty($parts)) { $user->get('middleName', implode(' ', $parts)); } } } $author = new Author($this->database); $author->cid = $this->citation->id; $author->author = $user->get('name'); $author->uidNumber = $user->get('id', 0); $author->organization = $user->get('organization'); $author->givenName = $user->get('givenName'); $author->middleName = $user->get('middleName'); $author->surname = $user->get('surname'); $author->email = $user->get('email'); if (!$author->check()) { $this->setError($author->getError()); continue; } if (!$author->store()) { $this->setError($author->getError()); continue; } } $this->saveAuthorsList(); // Push through to the view $this->displayTask(); }
/** * Add a user as a manager of a course * * @return void */ public function addTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if ($this->getError()) { return $this->displayTask(); } // Incoming host $m = Request::getVar('author', ''); $mbrs = explode(',', $m); $mbrs = array_map('trim', $mbrs); foreach ($mbrs as $mbr) { $user = null; if (!strstr($mbr, ' ')) { $user = Profile::getInstance($mbr); } // Make sure the user exists if (!is_object($user) || !$user->get('username')) { $user = new Profile(); $user->set('name', $mbr); } $author = new Author($this->database); $author->cid = $this->citation->id; $author->author = $user->get('name'); $author->uidNumber = $user->get('uidNumber'); $author->organization = $user->get('organization'); $author->givenName = $user->get('givenName'); $author->middleName = $user->get('middleName'); $author->surname = $user->get('surname'); $author->email = $user->get('email'); if (!$author->check()) { $this->setError($author->getError()); continue; } if (!$author->store()) { $this->setError($author->getError()); continue; } } // Push through to the view $this->displayTask(); }