/** * Update attachment record * * @return void */ public function saveItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0) { $aid = $aid ? $aid : Request::getInt('aid', 0); // Load classes $row = new \Components\Publications\Tables\Author($this->_parent->_db); $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); // We need attachment record if (!$aid || !$row->load($aid) || $row->publication_version_id != $pub->version_id) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR')); return false; } // 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(); // Get current owners $owners = $objO->getIds($pub->_project->get('id'), 'all', 1); $email = Request::getVar('email', '', 'post'); $firstName = Request::getVar('firstName', '', 'post'); $lastName = Request::getVar('lastName', '', 'post'); $org = Request::getVar('organization', '', 'post'); $credit = Request::getVar('credit', '', 'post'); $sendInvite = 0; $code = \Components\Projects\Helpers\Html::generateCode(); $uid = Request::getInt('uid', 0, 'post'); $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; $email = preg_match($regex, $email) ? $email : ''; if (!$firstName || !$lastName) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); return false; } $row->organization = $org; $row->firstName = $firstName; $row->lastName = $lastName; $row->name = $row->firstName . ' ' . $row->lastName; $row->credit = $credit; $row->modified_by = $actor; $row->modified = Date::toSql(); // Check that profile exists if ($uid) { $profile = User::getInstance($uid); $uid = $profile->get('id') ? $uid : 0; } // Tying author to a user account? if ($uid && !$row->user_id) { // Do we have an owner with this user id? $owner = $objO->getOwnerId($pub->_project->get('id'), $uid); if ($owner) { // Update owner assoc $row->project_owner_id = $owner; } else { // Update associated project owner account if ($objO->load($row->project_owner_id) && !$objO->userid) { $objO->userid = $uid; $objO->status = 1; $objO->store(); } } } $row->user_id = $uid; if ($row->store()) { $this->set('_message', Lang::txt('Author record saved')); // Reflect the update in curation record $this->_parent->set('_update', 1); } else { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_AUTHORS_ERROR_SAVING_AUTHOR_INFO')); return false; } // Update project owner (invited) if ($email && !$row->user_id && $objO->load($row->project_owner_id)) { $invitee = $objO->checkInvited($pub->_project->get('id'), $email); // Do we have a registered user with this email? $user = $xregistration->getEmailId($email); if ($invitee && $invitee != $row->project_owner_id) { // Stop, must have owner record } elseif (in_array($user, $owners)) { // Stop, already in team } elseif ($email != $objO->invited_email) { $objO->invited_email = $email; $objO->invited_name = $row->name; $objO->userid = $row->user_id; $objO->invited_code = $code; $objO->store(); $sendInvite = 1; } } // (Re)send email invitation if ($sendInvite && $email) { // Get project model $project = new \Components\Projects\Models\Project($pub->_project->get('id')); // Plugin params $plugin_params = array(0, $email, $code, 2, $project, 'com_projects'); // Send invite $output = Event::trigger('projects.sendInviteEmail', $plugin_params); $result = json_decode($output[0]); } return true; }
/** * Save publication submitter * * @param integer $vid Pub version ID * @param integer $by Publication creator * @return mixed False if error, Object on success */ public function saveSubmitter($vid = NULL, $by = 0, $projectid = 0) { if (!$vid) { $vid = $this->publication_version_id; } if (!$vid || !$by) { return false; } // Get name/org $author = $this->getAuthorByUid($vid, $by); if (!$author) { return false; } require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'owner.php'; // Get project owner info $objO = new \Components\Projects\Tables\Owner($this->_db); $owner_id = $objO->getOwnerId($projectid, $by); // Load submitter record if exists $query = "SELECT * FROM {$this->_tbl} WHERE role='submitter' AND publication_version_id=" . $this->_db->quote($vid); $this->_db->setQuery($query); if ($result = $this->_db->loadAssoc()) { $this->bind($result); $this->modified = Date::toSql(); $this->modified_by = User::get('id'); } else { $this->publication_version_id = $vid; $this->role = 'submitter'; $this->created = Date::toSql(); $this->created_by = User::get('id'); $this->ordering = 1; } $this->project_owner_id = $owner_id; $this->user_id = $by; $this->status = 1; $this->name = $author->name ? $author->name : $author->p_name; $this->organization = $author->organization ? $author->organization : $author->p_organization; $this->firstName = $author->firstName ? $author->firstName : NULL; $this->lastName = $author->lastName ? $author->lastName : NULL; $this->credit = 'Submitter'; $this->store(); }