本文整理汇总了PHP中company::check_valid_user方法的典型用法代码示例。如果您正苦于以下问题:PHP company::check_valid_user方法的具体用法?PHP company::check_valid_user怎么用?PHP company::check_valid_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类company
的用法示例。
在下文中一共展示了company::check_valid_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.
//.........这里部分代码省略.........
示例2: process
public function process()
{
global $DB, $CFG;
$this->create_user_selectors();
// Process incoming enrolments.
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) {
company_user::enrol($adduser, array($this->course->id), $this->selectedcompany);
EmailTemplate::send('user_added_to_course', array('course' => $this->course, 'user' => $adduser));
}
}
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
// Process incoming unenrolments.
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstounassign = $this->currentusers->get_selected_users();
if (!empty($userstounassign)) {
foreach ($userstounassign as $removeuser) {
// GWL : Check the userid is valid.
if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
print_error('invaliduserdepartment', 'block_iomad_company_management');
}
company_user::unenrol($removeuser, array($this->course->id), $this->selectedcompany);
}
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
}
示例3: redirect
// redirect($returnurl);
// Code by sumit
redirect(new moodle_url('/blocks/iomad_company_admin/editusers.php'));
// end of code
} else {
redirect($linkurl . "?createdok=1");
}
}
}
$blockpage->display_header();
// GWL : Check the department is valid.
if (!empty($departmentid) && !company::check_valid_department($companyid, $departmentid)) {
print_error('invaliddepartment', 'block_iomad_company_admin');
}
// GWL : Check the userid is valid.
if (!empty($userid) && !company::check_valid_user($companyid, $userid, $departmentid)) {
print_error('invaliduserdepartment', 'block_iomad_company_management');
}
?>
<!-- GWL : Add Js -->
<script type="text/javascript">
Y.on('change', submit_form, '#licenseidselector');
function submit_form() {
var nValue = Y.one('#licenseidselector').get('value');
$.ajax({
type: "GET",
url: "<?php
echo $CFG->wwwroot;
?>
/blocks/iomad_company_admin/js/company_user_create_form.ajax.php?licenseid=" + nValue,
datatype: "HTML",
示例4: process
public function process()
{
global $DB, $CFG;
$this->create_user_selectors();
// Get the courses to send to if emails are configured.
$courses = company::get_courses_by_license($this->license->id);
// Process incoming allocations.
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $this->potentialusers->get_selected_users();
$numberoflicenses = $this->license->allocation;
$count = $this->license->used;
$licenserecord = (array) $this->license;
if (!empty($userstoassign)) {
foreach ($userstoassign as $adduser) {
if ($count >= $numberoflicenses) {
// Set the used amount.
$licenserecord['used'] = $count;
$DB->update_record('companylicense', $licenserecord);
redirect(new moodle_url("/blocks/iomad_company_admin/company_license_users_form.php", array('licenseid' => $this->licenseid, 'error' => 1)));
}
$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) {
$count++;
$DB->insert_record('companylicense_users', array('userid' => $adduser->id, 'licenseid' => $this->licenseid));
}
// Create an email event.
foreach ($courses as $course) {
$license = new stdclass();
$license->length = $licenserecord['validlength'];
$license->valid = date('d M Y', $licenserecord['expirydate']);
EmailTemplate::send('license_allocated', array('course' => $course, 'user' => $adduser, 'license' => $license));
}
}
// Set the used amount for the license.
$licenserecord['used'] = $count;
$DB->update_record('companylicense', $licenserecord);
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
// Process incoming unallocations.
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstounassign = $this->currentusers->get_selected_users();
$count = $this->license->used;
$licenserecord = (array) $this->license;
if (!empty($userstounassign)) {
foreach ($userstounassign as $removeuser) {
// GWL : Check the userid is valid.
if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
print_error('invaliduserdepartment', 'block_iomad_company_management');
}
if ($licensedata = $DB->get_record('companylicense_users', array('userid' => $removeuser->id, 'licenseid' => $this->licenseid))) {
if (!$licensedata->isusing) {
$DB->delete_records('companylicense_users', array('id' => $licensedata->id));
$count--;
}
}
// Create an email event.
foreach ($courses as $course) {
EmailTemplate::send('license_removed', array('course' => $course, 'user' => $removeuser));
}
}
// Update the number of allocated records..
if ($count < 0) {
// Cant have less than 0 licenses.
$count = 0;
}
$licenserecord['used'] = $count;
$DB->update_record('companylicense', $licenserecord);
$this->potentialusers->invalidate_selected_users();
$this->currentusers->invalidate_selected_users();
}
}
}