本文整理汇总了PHP中company::assign_user_to_company方法的典型用法代码示例。如果您正苦于以下问题:PHP company::assign_user_to_company方法的具体用法?PHP company::assign_user_to_company怎么用?PHP company::assign_user_to_company使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类company
的用法示例。
在下文中一共展示了company::assign_user_to_company方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process()
{
global $DB;
if ($this->selectedcompany) {
$company = new company($this->selectedcompany);
$companyshortname = $company->get_shortname();
$companydefaultdepartment = company::get_company_parentnode($company->id);
// Process incoming assignments.
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $this->potentialusers->get_selected_users();
if (!empty($userstoassign)) {
foreach ($userstoassign as $adduser) {
$allow = true;
if ($allow) {
$user = $DB->get_record('user', array('id' => $adduser->id));
// Add user to default company department.
$company->assign_user_to_company($adduser->id);
}
}
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
// Process incoming unassignments.
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstounassign = $this->currentusers->get_selected_users();
if (!empty($userstounassign)) {
foreach ($userstounassign as $removeuser) {
// Check if the user was a company manager.
if ($DB->get_records('company_users', array('userid' => $removeuser->id, 'managertype' => 1))) {
$companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
role_unassign($companymanagerrole->id, $removeuser->id, $this->context->id);
}
if ($DB->get_records('company_users', array('userid' => $removeuser->id, 'managertype' => 2))) {
$departmentmanagerrole = $DB->get_record('role', array('shortname' => 'departmentmanager'));
role_unassign($departmentmanagerrole->id, $removeuser->id, $this->context->id);
}
$DB->delete_records('company_users', array('userid' => $removeuser->id));
// Deal with the company theme.
$DB->set_field('user', 'theme', '', array('id' => $removeuser->id));
}
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
}
}
示例2: process
public function process($departmentid, $roletype)
{
global $DB, $USER;
$companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
$departmentmanagerrole = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'));
$companycoursenoneditorrole = $DB->get_record('role', array('shortname' => 'companycoursenoneditor'));
$companycourseeditorrole = $DB->get_record('role', array('shortname' => 'companycourseeditor'));
// Process incoming assignments.
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $this->potentialusers->get_selected_users();
if (!empty($userstoassign)) {
foreach ($userstoassign as $adduser) {
$allow = true;
// GWL : Check the userid is valid.
if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
print_error('invaliduserdepartment', 'block_iomad_company_management');
}
if ($allow) {
if ($roletype != 0) {
// Adding a manager type.
// Add user to the company manager table.
if ($userrecord = $DB->get_record('company_users', array('companyid' => $this->selectedcompany, 'userid' => $adduser->id))) {
if ($roletype == 1 && $userrecord->managertype == 0) {
// Give them the company manager role.
role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
// Deal with company courses.
if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
foreach ($companycourses as $companycourse) {
if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
if ($DB->record_exists('company_created_courses', array('companyid' => $companycourse->companyid, 'courseid' => $companycourse->courseid))) {
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
} else {
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
}
}
}
}
} else {
if ($roletype == 2 && $userrecord->managertype == 0) {
// Give them the department manager role.
role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
// Deal with company courses.
if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
foreach ($companycourses as $companycourse) {
if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
}
}
}
} else {
if ($roletype == 1 && ($userrecord->managertype = 2)) {
// Give them the department manager role.
role_unassign($departmentmanagerrole->id, $adduser->id, $this->context->id);
role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
// Deal with course permissions.
if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
foreach ($companycourses as $companycourse) {
if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
// If its a company created course then assign the editor role to the user.
if ($DB->record_exists('company_created_courses', array('companyid' => $this->selectedcompany, 'courseid' => $companycourse->courseid))) {
company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
} else {
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
}
}
}
}
} else {
if ($roletype == 2 && ($userrecord->managertype = 1)) {
// Give them the department manager role.
role_unassign($companymanagerrole->id, $adduser->id, $this->context->id);
role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
// Deal with company course roles.
if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
foreach ($companycourses as $companycourse) {
if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
}
}
}
}
}
}
}
$userrecord->managertype = $roletype;
$DB->update_record('company_users', $userrecord);
} else {
if ($roletype == 1 && $DB->get_records_sql('SELECT id FROM {company_users}
WHERE
userid = :userid
AND managertype = :roletype
AND companyid != :companyid', array('userid' => $adduser->id, 'roletype' => 1, 'companyid' => $this->selectedcompany))) {
// We have a company manager from another company.
// We need to add another record.
$company = new company($this->selectedcompany);
$company->assign_user_to_company($adduser->id);
$DB->set_field('company_users', 'managertype', 1, array('userid' => $adduser->id, 'companyid' => $this->selectedcompany));
// Deal with company courses.
//.........这里部分代码省略.........
示例3: foreach
if ($createpasswords && $isinternalauth) {
if (empty($user->password) || $forcechangepassword) {
// Passwords will be created and sent out on cron.
set_user_preference('create_password', 1, $user->id);
set_user_preference('auth_forcepasswordchange', 1, $user->id);
$upt->track('password', get_string('new'));
} else {
set_user_preference('auth_forcepasswordchange', 1, $user->id);
}
}
// Save custom profile fields data.
profile_save_data($user);
// Make sure user context exists.
context_user::instance($user->id);
// Add the user to the company
$company->assign_user_to_company($user->id);
// Add the user to the company default hierarchy level.
company::assign_user_to_department($formdata->userdepartment, $user->id);
\core\event\user_created::create_from_userid($user->id)->trigger();
if ($bulk == 1 or $bulk == 3) {
if (!in_array($user->id, $SESSION->bulk_users)) {
$SESSION->bulk_users[] = $user->id;
}
}
}
// Find course enrolments, groups, roles/types and enrol periods.
foreach ($columns as $column) {
if (preg_match('/^course\\d+$/', $column)) {
$i = substr($column, 6);
if (empty($user->{'course' . $i})) {
continue;