/** * 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 member * * @return void, redirect */ protected function _save() { // Incoming $members = urldecode(trim(Request::getVar('newmember', '', 'post'))); $groups = urldecode(trim(Request::getVar('newgroup', ''))); $role = Request::getInt('role', 0); // Result collectors $m_added = 0; // count of individual members added $m_invited = 0; // count of individuals invited $g_added = 0; // count of members from new group $uids = array(); // ids/emails of added people $names = array(); // names/emails of added people $invalid = array(); // collector for invalid names // Setup stage? $setup = $this->model->inSetup(); // Get owner class $objO = $this->model->table('Owner'); // 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(); // Owner names not supplied if (!$members && !$groups) { if (!$setup) { $this->setError(Lang::txt('PLG_PROJECTS_TEAM_NO_NAMES_SUPPLIED')); } else { return; } } else { if ($members) { $newm = explode(',', $members); // Do we have new authors? if ($newm) { for ($i = 0, $n = count($newm); $i < $n; $i++) { $cid = strtolower(trim($newm[$i])); $uid = 0; if ($cid == '') { continue; } $parts = preg_split("/[(]/", $cid); if (count($parts) == 2) { $name = $parts[0]; $uid = preg_replace('/[)]/', '', $parts[1]); } elseif (intval($cid) && ($validUser = User::getInstance($cid))) { $uid = $cid; } else { $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; if (preg_match($regex, $cid)) { // This is an email - check if user with the email exists $uid = $xregistration->getEmailId($cid); if (!$uid) { // Make sure we aren't inviting twice $invitee = $objO->checkInvited($this->model->get('id'), $cid); if (!$invitee) { // Generate invitation code $code = \Components\Projects\Helpers\Html::generateCode(); // Add invitee record if ($objO->saveInvite($this->model->get('id'), $cid, $code, '', $role)) { $uids[] = $cid; $m_invited++; if (!$setup && $this->_config->get('messaging') == 1) { $this->sendInviteEmail(0, $cid, $code, $role); } } } elseif ($objO->load($invitee)) { // Previously deleted invite if ($objO->status == 2) { $objO->status = 0; $objO->role = $role; $uids[] = $cid; $objO->store(); $m_invited++; if (!$setup && $this->_config->get('messaging') == 1) { $this->sendInviteEmail(0, $cid, $objO->invited_code, $objO->role); } } } } } else { $invalid[] = $cid; } } if (!$uid or !is_numeric($uid)) { continue; } else { if (!User::getInstance($uid)) { $invalid[] = $uid; continue; } } // Save new author $native = $this->model->access('owner') ? 1 : 0; if ($objO->saveOwners($this->model->get('id'), $this->_uid, $uid, 0, $role, $status = 1, $native)) { $uids[] = $uid; } } } } if ($groups) { // Save new authors from group $g_added = $objO->saveOwners($this->model->get('id'), $this->_uid, 0, $groups, $role, $status = 1, $native = 0); if ($objO->getError()) { $this->setError($objO->getError()); } if ($g_added) { $uids = array_merge($uids, $g_added); } } } // Did we add anyone new? $uids = array_unique($uids); if (count($uids) > 0) { $this->_msg = Lang::txt('PLG_PROJECTS_TEAM_SUCCESS_ADDED_OR_INVITED') . ' ' . count($uids) . ' ' . Lang::txt('PLG_PROJECTS_TEAM_NEW') . ' ' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS'); if (count($invalid) > 0) { $this->_msg .= '<br />' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES'); } if (!$setup) { $note = strtolower(Lang::txt('PLG_PROJECTS_TEAM_SUCCESS_ADDED_OR_INVITED')) . ' '; for ($i = 0; $i < count($uids); $i++) { $uu = $uids[$i]; if ($uu && is_numeric($uu)) { $xuser = User::getInstance($uids[$i]); $note .= is_numeric($uids[$i]) && is_object($xuser) ? $xuser->get('name') : $uids[$i]; } else { $note .= $uids[$i]; } if ($i > 1) { $left = count($uids) - 3; if ($left) { $note .= ' ' . Lang::txt('PLG_PROJECTS_TEAM_AND') . ' ' . $left . ' ' . Lang::txt('PLG_PROJECTS_TEAM_MORE') . ' '; $note .= $left == 1 ? Lang::txt('PLG_PROJECTS_TEAM_ACTIVITY_PERSON') : Lang::txt('PLG_PROJECTS_TEAM_ACTIVITY_PERSONS'); } break; } $note .= $i == count($uids) - 1 ? '' : ', '; } $note .= ' ' . Lang::txt('PLG_PROJECTS_TEAM_TO_PROJECT_TEAM'); // Send out emails if ($this->_config->get('messaging') == 1) { foreach ($uids as $user) { $this->sendInviteEmail($user, '', '', $role); } } } // Sync with system group $objO->sysGroup($this->model->get('alias'), $this->_config->get('group_prefix', 'pr-')); } elseif (count($invalid) > 0) { $this->setError(Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES') . '<br />' . Lang::txt('PLG_PROJECTS_TEAM_MEMBERS_INVALID_NAMES_EXPLAIN')); } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } $url = $setup ? Route::url($this->model->link('setup') . '§ion=team') : Route::url($this->model->link('edit') . '§ion=team'); App::redirect($url); return; }