/** * Approve membership for one or more users * * @return void */ private function approve() { if ($this->authorized != 'manager' && $this->authorized != 'admin') { return false; } if ($this->membership_control == 0) { return false; } $database = App::get('db'); // Set a flag for emailing any changes made $admchange = ''; // Note: we use two different lists to avoid situations where the user is already a member but somehow an applicant too. // Recording the list of applicants for removal separate allows for removing the duplicate entry from the applicants list // without trying to add them to the members list (which they already belong to). $users = array(); $applicants = array(); // Get all normal members (non-managers) of this group $members = $this->group->get('members'); // Incoming array of users to promote $mbrs = Request::getVar('users', array(0)); foreach ($mbrs as $mbr) { // Retrieve user's account info $targetuser = User::getInstance($mbr); // Ensure we found an account if (is_object($targetuser)) { $uid = $targetuser->get('id'); // The list of applicants to remove from the applicant list $applicants[] = $uid; // Loop through existing members and make sure the user isn't already a member if (in_array($uid, $members)) { $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_ALREADY_A_MEMBER', $mbr)); continue; } // Remove record of reason wanting to join group $reason = new Components\Groups\Tables\Reason($database); $reason->deleteReason($targetuser->get('id'), $this->group->get('gidNumber')); // Are they approved for membership? $admchange .= "\t\t" . $targetuser->get('name') . "\r\n"; $admchange .= "\t\t" . $targetuser->get('username') . ' (' . $targetuser->get('email') . ')'; $admchange .= count($mbrs) > 1 ? "\r\n" : ''; // They user is not already a member, so we can go ahead and add them $users[] = $uid; // E-mail the user, letting them know they've been approved $this->notifyUser($targetuser); } else { $this->setError(Lang::txt('PLG_GROUPS_MESSAGES_ERROR_USER_NOTFOUND') . ' ' . $mbr); } } // Remove users from applicants list $this->group->remove('applicants', $applicants); // Add users to members list $this->group->add('members', $users); // Save changes $this->group->update(); // log invites \Components\Groups\Models\Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'membership_approved', 'comments' => $users)); }