/** * Add new author * * @return void */ public function addItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0) { $email = Request::getVar('email', '', 'post'); $firstName = trim(Request::getVar('firstName', '', 'post')); $lastName = trim(Request::getVar('lastName', '', 'post')); $org = trim(Request::getVar('organization', '', 'post')); $credit = trim(Request::getVar('credit', '', 'post')); $uid = trim(Request::getInt('uid', 0, 'post')); $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; $email = preg_match($regex, $email) ? $email : ''; $name = $firstName . ' ' . $lastName; $sendInvite = 0; $exists = 0; $code = \Components\Projects\Helpers\Html::generateCode(); if (!$firstName || !$lastName) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); return false; } // Load classes $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); // Instantiate a new registration object include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'registration.php'; $xregistration = new \Components\Members\Models\Registration(); // Do we have a registered user with this email? if ($email && !$uid) { $uid = $xregistration->getEmailId($email); // Check that profile exists if ($uid) { $profile = User::getInstance($uid); $uid = $profile->get('id') ? $uid : 0; } } // Do we have an owner with this email/uid? $owner = NULL; if ($uid) { $owner = $objO->getOwnerId($pub->_project->get('id'), $uid); } elseif ($email) { $owner = $objO->checkInvited($pub->_project->get('id'), $email); } elseif (trim($name)) { // Check by invite name $owner = $objO->checkInvitedByName($pub->_project->get('id'), trim($name)); } if ($owner && $objO->load($owner)) { if ($email && $objO->invited_email != $email) { $sendInvite = 1; } $objO->status = $objO->userid ? 1 : 0; $objO->invited_name = $objO->userid ? $objO->invited_name : $name; $objO->invited_email = $objO->userid ? $objO->invited_email : $email; $objO->store(); } elseif ($email || trim($name)) { $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); $objO->projectid = $pub->_project->get('id'); $objO->userid = $uid; $objO->status = $uid ? 1 : 0; $objO->added = Date::toSql(); $objO->role = 2; $objO->invited_email = $email; $objO->invited_name = $name; if ($email) { $objO->invited_code = $code; } $objO->store(); $owner = $objO->id; $sendInvite = $email || $uid ? 1 : 0; } // Now we do need owner record if (!$owner) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO')); return false; } // Get author information $pAuthor = new \Components\Publications\Tables\Author($this->_parent->_db); if ($pAuthor->loadAssociationByOwner($owner, $pub->version_id)) { $pAuthor->modified = Date::toSql(); $pAuthor->modified_by = $actor; $exists = 1; } else { $pAuthor->created = Date::toSql(); $pAuthor->created_by = $actor; $pAuthor->publication_version_id = $pub->version_id; $pAuthor->project_owner_id = $owner; $pAuthor->user_id = intval($uid); $pAuthor->ordering = $pAuthor->getLastOrder($pub->version_id) + 1; $pAuthor->role = ''; } $pAuthor->status = 1; $pAuthor->name = $name; $pAuthor->firstName = $firstName; $pAuthor->lastName = $lastName; $pAuthor->organization = $org; if (!$pAuthor->store()) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO')); return false; } // Reflect the update in curation record $this->_parent->set('_update', 1); // (Re)send email invitation if ($sendInvite && ($email || $uid)) { // Get project model $project = new \Components\Projects\Models\Project($pub->_project->get('id')); // Load component language file Lang::load('com_projects') || Lang::load('com_projects', PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site'); // Plugin params $plugin_params = array($uid, $email, $code, 2, $project, 'com_projects'); // Send invite $output = Event::trigger('projects.sendInviteEmail', $plugin_params); $result = json_decode($output[0]); } $message = $exists ? Lang::txt('Author already in team, updated author information') : Lang::txt('New author added'); $this->set('_message', $message); return true; }