本文整理汇总了PHP中user_has_role_assignment函数的典型用法代码示例。如果您正苦于以下问题:PHP user_has_role_assignment函数的具体用法?PHP user_has_role_assignment怎么用?PHP user_has_role_assignment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_has_role_assignment函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: test_build
public function test_build()
{
$fm = mr_fixture_manager::instance();
$userid = $fm->get('user')->get('id');
$roleid = $fm->get('role')->get('id');
$context = context_course::instance($fm->get('course')->get('id'));
$this->assertFalse(user_has_role_assignment($userid, $roleid, $context->id));
$this->assertFalse(is_enrolled($context, $fm->get('user')->get_results()));
$enrollment = new mr_fixture_enrollment($fm->get('course'), $fm->get('user'), enrol_get_plugin('manual'), $fm->get('role'));
$enrollment->build();
$this->assertTrue(user_has_role_assignment($userid, $roleid, $context->id));
$this->assertTrue(is_enrolled($context, $fm->get('user')->get_results()));
}
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:13,代码来源:testfixtureenrollment.php
示例2: test_destroy
public function test_destroy()
{
$fm = mr_fixture_manager::instance();
$userid = $fm->get('user')->get('id');
$roleid = $fm->get('role')->get('id');
$contextid = context_course::instance($fm->get('course')->get('id'))->id;
$this->assertFalse(user_has_role_assignment($userid, $roleid, $contextid));
$ra = new mr_fixture_role_assignment($fm->get('role'), $fm->get('user'), $fm->get('course'));
$ra->build();
$this->assertTrue(user_has_role_assignment($userid, $roleid, $contextid));
$ra->destroy();
$this->assertFalse(user_has_role_assignment($userid, $roleid, $contextid));
}
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:13,代码来源:testfixtureroleassignment.php
示例3: theme_mmcmonkwearmouth_get_user_role
function theme_mmcmonkwearmouth_get_user_role($id)
{
//Requires a setting save to change these in database for news.
$roles = ["teacher" => 20, "staff" => 21, "parent" => 22, "student" => 19, "governor" => 23];
$admins = get_admins();
foreach ($admins as $admin) {
if ($id == $admin->id) {
return "admin";
}
}
foreach ($roles as $roleTitle => $roleNumber) {
if (user_has_role_assignment($id, $roleNumber)) {
return $roleTitle;
}
}
}
开发者ID:markmcdermid,项目名称:mmcmonkwearmouth,代码行数:16,代码来源:lib.php
示例4: equella_getssotoken
/**
* Create EQUELLA single sign on token for current user
*
* @return string
*/
function equella_getssotoken($course = null)
{
global $USER, $CFG, $COURSE;
if (empty($course)) {
$course = $COURSE;
}
$context_sys = context_system::instance();
$context_cc = null;
if (!empty($course->category) && is_int($course->category)) {
$context_cc = context_coursecat::instance($course->category);
}
$context_c = context_course::instance($course->id);
// roles are ordered by shortname
$editingroles = get_all_editing_roles();
foreach ($editingroles as $role) {
$hassystemrole = false;
if (!empty($context_sys)) {
$hassystemrole = user_has_role_assignment($USER->id, $role->id, $context_sys->id);
}
$hascategoryrole = false;
if (!empty($context_cc)) {
$hascategoryrole = user_has_role_assignment($USER->id, $role->id, $context_cc->id);
}
$hascourserole = false;
if (!empty($context_c)) {
$hascourserole = user_has_role_assignment($USER->id, $role->id, $context_c->id);
}
if ($hassystemrole || $hascategoryrole || $hascourserole) {
// see if the user has a role that is linked to an equella role
$shareid = $CFG->{"equella_{$role->shortname}_shareid"};
if (!empty($shareid)) {
return equella_getssotoken_raw($USER->username, $shareid, $CFG->{"equella_{$role->shortname}_sharedsecret"});
}
}
}
// no roles found, use the default shareid and secret
$shareid = $CFG->equella_shareid;
if (!empty($shareid)) {
return equella_getssotoken_raw($USER->username, $shareid, $CFG->equella_sharedsecret);
}
}
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:46,代码来源:lib.php
示例5: get_content
public function get_content()
{
global $DB, $USER, $CFG;
if ($this->content !== null) {
return $this->content;
}
if (user_has_role_assignment($USER->id, 5)) {
$config = get_config('domoscio');
$count = $this->count_tests($config);
if (count($count) > 1) {
$plural = "s";
} else {
$plural = "";
}
$this->content = new stdClass();
$this->content->text = '<span class="badge badge-important" style="font-size:18px">' . count($count) . '</span>' . get_string('text2', 'block_domoscio_reminder') . $plural . get_string('text3', 'block_domoscio_reminder');
if (!empty($count)) {
$this->content->footer = "<a href=" . $CFG->wwwroot . "/mod/domoscio/index.php>Let's go !</a>";
}
}
return $this->content;
}
开发者ID:Celumproject,项目名称:moodle-block_domoscioreminder,代码行数:22,代码来源:block_domoscio_reminder.php
示例6: getssotoken
/**
* Generate equella sso token
*
* @param string $readwrite
* @return string
*/
private function getssotoken($readwrite = 'read') {
global $USER;
if (empty($USER->username)) {
return false;
}
if ($readwrite == 'write') {
foreach (self::get_all_editing_roles() as $role) {
if (user_has_role_assignment($USER->id, $role->id, $this->context->id)) {
// See if the user has a role that is linked to an equella role.
$shareid = $this->get_option("equella_{$role->shortname}_shareid");
if (!empty($shareid)) {
return $this->getssotoken_raw($USER->username, $shareid,
$this->get_option("equella_{$role->shortname}_sharedsecret"));
}
}
}
}
// If we are only reading, use the unadorned shareid and secret.
$shareid = $this->get_option('equella_shareid');
if (!empty($shareid)) {
return $this->getssotoken_raw($USER->username, $shareid, $this->get_option('equella_sharedsecret'));
}
}
开发者ID:Burick,项目名称:moodle,代码行数:32,代码来源:lib.php
示例7: is_student
/**
* Verify if the user is a student
*
* @param int
* @param int
* @return bool
*/
function is_student($userid)
{
return user_has_role_assignment($userid, 5);
}
开发者ID:ramcoelho,项目名称:moodle-block_ranking,代码行数:11,代码来源:lib.php
示例8: add_to_egr
/**
* Enrol the user, add him to groups and assign him roles.
*
* @return bool false if an error occured
*/
protected function add_to_egr()
{
global $DB;
foreach ($this->rawdata as $field => $value) {
if (preg_match('/^sysrole\\d+$/', $field)) {
$removing = false;
if (!empty($value)) {
$sysrolename = $value;
// Removing sysrole.
if ($sysrolename[0] == '-') {
$removing = true;
$sysrolename = substr($sysrolename, 1);
}
// System roles lookup.
$sysrolecache = uu_allowed_sysroles_cache();
if (array_key_exists($sysrolename, $sysrolecache)) {
$sysroleid = $sysrolecache[$sysrolename]->id;
} else {
$this->set_status('unknownrole', new lang_string('unknownrole', 'error', s($sysrolename)));
continue;
}
$isassigned = user_has_role_assignment($this->finaldata->id, $sysroleid, SYSCONTEXTID);
if ($removing) {
if ($isassigned) {
role_unassign($sysroleid, $this->finaldata->id, SYSCONTEXTID);
}
} else {
if (!$isassigned) {
role_assign($sysroleid, $this->finaldata->id, SYSCONTEXTID);
}
}
}
} else {
if (preg_match('/^course\\d+$/', $field)) {
// Course number.
$i = substr($field, 6);
$shortname = $value;
$course = $DB->get_record('course', array('shortname' => $shortname));
$course->groups = NULL;
if (!$course) {
$this->set_status('unknowncourse', new lang_string('unknowncourse', 'error', s($shortname)));
continue;
}
$courseid = $course->id;
$coursecontext = context_course::instance($courseid);
$roles = uu_allowed_roles_cache();
// TODO: manualcache
if ($instances = enrol_get_instances($courseid, false)) {
foreach ($instances as $instance) {
if ($instance->enrol === 'manual') {
$coursecache = $instance;
break;
}
}
}
// Checking if manual enrol is enabled. If it's not, no
// enrolment is done.
if (enrol_is_enabled('manual')) {
$manual = enrol_get_plugin('manual');
} else {
$manual = NULL;
}
if ($courseid == SITEID) {
if (!empty($this->rawdata['role' . $i])) {
$rolename = $this->rawdata['role' . $i];
if (array_key_exists($rolename, $roles)) {
$roleid = $roles[$rolename]->id;
} else {
$this->set_status('unknownrole', new lang_string('unknownrole', 'error', s($rolename)));
continue;
}
role_assign($roleid, $this->finaldata->id, context_course::instance($courseid));
}
} else {
if ($manual) {
$roleid = false;
if (!empty($this->rawdata['role' . $i])) {
$rolename = $this->rawdata['role' . $i];
if (array_key_exists($rolename, $roles)) {
$roleid = $roles[$rolename]->id;
} else {
$this->set_status('unknownrole', new lang_string('unknownrole', 'error', s($rolename)));
continue;
}
} else {
if (!empty($this->rawdata['type' . $i])) {
// If no role, find "old" enrolment type.
$addtype = $this->rawdata['type' . $i];
if ($addtype < 1 or $addtype > 3) {
$this->set_status('typeerror', new lang_string('typeerror', 'tool_uploadusercli'));
continue;
} else {
$roleid = $this->rawdata['type' . $i];
}
} else {
//.........这里部分代码省略.........
开发者ID:alexandru-elisei,项目名称:moodle-tool_uploadusercli,代码行数:101,代码来源:user.php
示例9: equella_is_instructor
function equella_is_instructor($user, $cm, $courseid)
{
global $CFG, $DB;
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context_sys = context_system::instance();
$context_cc = null;
if (!empty($course->category)) {
$context_cc = context_coursecat::instance($course->category);
}
$context_c = context_course::instance($courseid);
// roles are ordered by shortname
$editingroles = get_all_editing_roles();
$isinstructor = false;
foreach ($editingroles as $role) {
$hassystemrole = user_has_role_assignment($user->id, $role->id, $context_sys->id);
$hascategoryrole = false;
if (!empty($context_cc)) {
$hascategoryrole = user_has_role_assignment($user->id, $role->id, $context_cc->id);
}
$hascourserole = user_has_role_assignment($user->id, $role->id, $context_c->id);
if ($hassystemrole || $hascategoryrole || $hascourserole) {
return true;
}
}
return false;
}
开发者ID:CTANZ,项目名称:moodle-mod_equella,代码行数:26,代码来源:locallib.php
示例10: get_user_roles
$roles = get_user_roles($context, $USER->id, true);
$participants = $streamline->participants;
if ($streamline->participants == null || $streamline->participants == "[]") {
//The room that is being used comes from a previous version
$moderator = has_capability('mod/streamline:moderate', $context);
} else {
$moderator = bigbluebuttonbn_is_moderator($userID, $roles, $participants);
}
$administrator = has_capability('moodle/category:manage', $context);
//104.155.215.138
$ipaddress = trim($CFG->ServerURLforBigBlueButton);
$variable2 = substr($ipaddress, 0, strpos($ipaddress, "b"));
$variable = trim(trim($variable2), '/') . '/';
$moodle_dir = $CFG->wwwroot;
//Determine if user is the teacher
$teacher_role = user_has_role_assignment($USER->id, 3);
if ($teacher_role == 1) {
$teacher = true;
} else {
$teacher = false;
}
//Determine if the meeting has ended based on on the 'meetingended' field in the DB
if ($streamline->meetingended == 1) {
$meetingEnded = true;
} else {
$meetingEnded = false;
}
?>
<link rel="stylesheet" type="text/css" href="streamline.css">
开发者ID:Brotality,项目名称:moodle-mod_streamline,代码行数:30,代码来源:BBB.php
示例11: get_content
public function get_content()
{
global $DB, $USER;
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
if (user_has_role_assignment($USER->id, 5)) {
$eventsarray = content_unlock_generate_events_list();
$us = $DB->get_records('content_unlock_system', array('deleted' => 0, 'blockinstanceid' => $this->instance->id));
if (!empty($us)) {
$unlocklist = '';
$course = $DB->get_record('course', array('id' => $this->page->course->id));
$info = get_fast_modinfo($course);
foreach ($us as $unlocksystem) {
$sql = "SELECT *\n\t\t\t\t\t\t\tFROM {content_unlock_log} c\n\t\t\t\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\t\t\tAND c.unlocksystemid = :unlocksystemid";
$params['userid'] = $USER->id;
$params['unlocksystemid'] = $unlocksystem->id;
$unlocked_content = $DB->record_exists_sql($sql, $params);
if ($unlocked_content) {
continue;
}
$ccm = get_course_and_cm_from_cmid($unlocksystem->coursemoduleid);
if ($this->page->course->id != $ccm[0]->id) {
continue;
}
if (!(content_unlock_satisfies_conditions($unlocksystem->restrictions, $this->page->course->id, $USER->id) && (in_array($unlocksystem->conditions, self::$resource_events) || content_unlock_satisfies_block_conditions($unlocksystem, $this->page->course->id, $USER->id)))) {
continue;
}
$cm = $info->get_cm($unlocksystem->coursemoduleid);
$eventdescription = is_null($unlocksystem->eventdescription) ? $eventsarray[$unlocksystem->conditions] : $unlocksystem->eventdescription;
$unlocklist = $unlocklist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($unlocksystem->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($unlocksystem) : $eventdescription) . '</li>';
}
if (strlen($unlocklist) > 0) {
$this->content->text = '<p>Você pode desbloquear:<ul>' . $unlocklist . '</ul></p>';
}
}
if (isset($this->config)) {
$lastunlocksnumber = isset($this->config->lastunlocksnumber) ? $this->config->lastunlocksnumber : 1;
} else {
$lastunlocksnumber = 0;
}
if ($lastunlocksnumber > 0) {
$sql = "SELECT c.id as id, s.coursemoduleid as coursemoduleid, s.eventdescription as eventdescription, s.conditions as conditions, s.connective as connective\n\t\t\t\t\tFROM\n\t\t\t\t\t\t{content_unlock_log} c\n\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\tINNER JOIN {content_unlock_system} s ON c.unlocksystemid = s.id\n\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\tAND l.courseid = :courseid\n\t\t\t\t\t\tAND s.blockinstanceid = :blockinstanceid\n\t\t\t\t\tORDER BY c.id DESC";
$params['userid'] = $USER->id;
$params['courseid'] = $this->page->course->id;
$params['blockinstanceid'] = $this->instance->id;
$lastunlocks = $DB->get_records_sql($sql, $params, 0, $lastunlocksnumber);
if (!empty($lastunlocks)) {
$lastunlockslist = '';
foreach ($lastunlocks as $lu) {
$ccm = get_course_and_cm_from_cmid($lu->coursemoduleid);
$course = $DB->get_record('course', array('id' => $ccm[0]->id));
$info = get_fast_modinfo($course);
$cm = $info->get_cm($lu->coursemoduleid);
$eventdescription = is_null($lu->eventdescription) ? $eventsarray[$lu->conditions] : $lu->eventdescription;
$lastunlockslist = $lastunlockslist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($lu->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($lu) : $eventdescription) . '</li>';
}
$this->content->text = $this->content->text . '<p>Você desbloqueou recentemente:<ul>' . $lastunlockslist . '</ul></p>';
}
}
}
return $this->content;
}
开发者ID:LoysGibertoni,项目名称:mdl_block_content_unlock,代码行数:63,代码来源:block_game_content_unlock.php
示例12: require_login
require_login($course);
$completion = new completion_info($course);
$trackeduser = $user ? $user : $USER->id;
if (!$completion->is_enabled()) {
throw new moodle_exception('completionnotenabled', 'completion');
} else {
if (!$completion->is_tracked_user($trackeduser)) {
throw new moodle_exception('nottracked', 'completion');
}
}
if ($user && $rolec) {
require_sesskey();
completion_criteria::factory(array('id' => $rolec, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ROLE));
//TODO: this is dumb, because it does not fetch the data?!?!
$criteria = completion_criteria_role::fetch(array('id' => $rolec));
if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
$criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);
foreach ($criteria_completions as $criteria_completion) {
if ($criteria_completion->criteriaid == $rolec) {
$criteria->complete($criteria_completion);
break;
}
}
}
// Return to previous page
$referer = clean_param($_SERVER['HTTP_REFERER'], PARAM_LOCALURL);
if (!empty($referer)) {
redirect($referer);
} else {
redirect('view.php?id=' . $course->id);
}
开发者ID:Keneth1212,项目名称:moodle,代码行数:31,代码来源:togglecompletion.php
示例13: mass_enroll
/**
* process the mass enrolment
* @param csv_import_reader $cir an import reader created by caller
* @param Object $course a course record from table mdl_course
* @param Object $context course context instance
* @param Object $data data from a moodleform
* @return string log of operations
*/
function mass_enroll($cir, $course, $context, $data) {
global $CFG,$DB;
require_once ($CFG->dirroot . '/group/lib.php');
$result = '';
$courseid=$course->id;
$roleid = $data->roleassign;
$useridfield = $data->firstcolumn;
$enrollablecount = 0;
$createdgroupscount = 0;
$createdgroupingscount = 0;
$createdgroups = '';
$createdgroupings = '';
$plugin = enrol_get_plugin('manual');
//Moodle 2.x enrolment and role assignment are different
// make sure couse DO have a manual enrolment plugin instance in that course
//that we are going to use (only one instance is allowed @see enrol/manual/lib.php get_new_instance)
// thus call to get_record is safe
$instance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'));
if (empty($instance)) {
// Only add an enrol instance to the course if non-existent
$enrolid = $plugin->add_instance($course);
$instance = $DB->get_record('enrol', array('id' => $enrolid));
}
// init csv import helper
$cir->init();
while ($fields = $cir->next()) {
$a = new StdClass();
if (empty ($fields))
continue;
// print_r($fields);
// $enrollablecount++;
// continue;
// 1rst column = id Moodle (idnumber,username or email)
// get rid on eventual double quotes unfortunately not done by Moodle CSV importer
$fields[0]= str_replace('"', '', trim($fields[0]));
if (!$user = $DB->get_record('user', array($useridfield => $fields[0]))) {
$result .= '<div class="alert alert-error">'.get_string('im:user_unknown', 'local_mass_enroll', $fields[0] ). '</div>';
continue;
}
if(!$DB->record_exists_sql("select id from {local_userdata} where costcenterid=$course->costcenter AND userid=$user->id")){
$costcentername = $DB->get_field('local_costcenter','fullname',array('id'=>$course->costcenter));
$cs_object = new stdClass();
$cs_object->csname = $costcentername;
$cs_object->user = fullname($user);
$result .= '<div class="alert alert-error">'.get_string('im:user_notcostcenter', 'local_mass_enroll',$cs_object ). '</div>';
continue;
}
//already enroled ?
if (user_has_role_assignment($user->id, $roleid, $context->id)) {
$result .= '<div class="alert alert-error">'.get_string('im:already_in', 'local_mass_enroll', fullname($user)). '</div>';
} else {
//TODO take care of timestart/timeend in course settings
// done in rev 1.1
$timestart = time();
// remove time part from the timestamp and keep only the date part
$timestart = make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0);
if ($instance->enrolperiod) {
$timeend = $timestart + $instance->enrolperiod;
} else {
$timeend = 0;
}
// not anymore so easy in Moodle 2.x
// if (!role_assign($roleid, $user->id, null, $context->id, $timestart, $timeend, 0, 'flatfile')) {
// $result .= get_string('im:error_in', 'local_mass_enroll', fullname($user)) . "";
// continue;
//}
//
// Enrol the user with this plugin instance (unfortunately return void, no more status )
$plugin->enrol_user($instance, $user->id,$roleid,$timestart,$timeend);
$result .= '<div class="alert alert-success">'.get_string('im:enrolled_ok', 'local_mass_enroll', fullname($user)).'</div>';
$enrollablecount++;
}
$group = str_replace('"','',trim($fields[1]));
// 2nd column ?
if (empty ($group)) {
$result .= "";
continue; // no group for this one
}
//.........这里部分代码省略.........
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:101,代码来源:lib.php
示例14: user_has_role_assignment
<?php
global $CFG, $DB, $OUTPUT, $HStuList, $StuList, $course;
$a1 = user_has_role_assignment($USER->id, 1);
$a2 = user_has_role_assignment($USER->id, 2);
$a3 = user_has_role_assignment($USER->id, 3);
$a4 = user_has_role_assignment($USER->id, 4);
$sadmin = is_siteadmin();
//echo $a1.','.$a2.','.$a3.','.$a4.','.$sadmin.'</br> ---';
if ($a2 == 1 || $a3 == 1 || $a4 == 1 || $sadmin == 1) {
$sql = "SELECT u.username\n\t\t\tFROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt\n\t\t\tWHERE ra.userid = u.id\n\t\t\tAND ra.contextid = cxt.id\n\t\t\tAND cxt.contextlevel =50\n\t\t\tAND cxt.instanceid = c.id\n\t\t\tAND c.shortname = ?\n\t\t\tAND (roleid = 5 OR roleid = 3 )";
$p = $DB->get_records_sql($sql, array($course->shortname));
foreach ($p as $k => $v) {
foreach ($v as $r => $o) {
$Sval = bin2hex($o);
$HStuList .= $Sval . ',';
$StuList .= $o . ',';
}
}
$HStuList .= '-';
$StuList .= '-';
// echo '<html><body onload="myFunction()"></body></html>';
// echo 'List of H students :'.$HStuList;
// echo '</br>';
// echo 'List of students :'.$StuList;
// echo '</br>';
// echo 'name: '.$course->shortname;
}
开发者ID:Akshay224,项目名称:moodle-mod_streamline,代码行数:28,代码来源:DataPrep.php
示例15: array
}
}
// Group members
if ($canseemembers) {
if ($members = groups_get_members($group->id)) {
$membernames = array();
foreach ($members as $member) {
$pic = $OUTPUT->user_picture($member, array('courseid' => $course->id));
if ($member->id == $USER->id) {
$membernames[] = '<span class="me">' . $pic . ' ' . fullname($member, $viewfullnames) . '</span>';
} else {
$membernames[] = $pic . ' <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $member->id . '&course=' . $course->id . '">' . fullname($member, $viewfullnames) . '</a>';
}
}
// Show assigned teacher, if exists, when enabled or when user is non-assigned teacher
if ($groupselect->showassignedteacher or user_has_role_assignment($USER->id, $ASSIGNROLE, context_course::instance($course->id)->id)) {
$teacherid = null;
foreach ($assigned_relation as $r) {
if ($r->groupid === $group->id) {
$teacherid = $r->id;
break;
}
}
if ($teacherid) {
$teacher = null;
foreach ($assigned_teachers as $a) {
if ($a->id === $teacherid) {
$teacher = $a;
$break;
}
}
开发者ID:nwp90,项目名称:moodle-mod_groupselect,代码行数:31,代码来源:view.php
示例16: tao_create_lp
function tao_create_lp($data, $author, $creatorroleid, $createtemplate = 0, $preferences = array())
{
global $CFG;
if (empty($data)) {
error("invalid call to tao_create_lp");
}
// get course template
if (!($course = get_record('course', 'id', $data->course_template))) {
error('Invalid course id');
}
// get a handle on the most recent backup for the selected course
$wdir = "/backupdata";
$fullpath = $CFG->dataroot . "/" . $course->id . $wdir;
$dirlist = array();
$filelist = array();
if (!is_dir($fullpath)) {
error("No templates for selected course");
}
$directory = opendir($fullpath);
// Find all files
while (false !== ($file = readdir($directory))) {
if ($file == "." || $file == "..") {
continue;
}
if (strchr($file, ".") != ".zip") {
continue;
}
if (is_dir($fullpath . "/" . $file)) {
$dirlist[] = $file;
} else {
$filelist[] = $file;
}
}
closedir($directory);
asort($filelist);
// get the last file
$file = array_pop($filelist);
$fullpathtofile = "{$fullpath}/{$file}";
if (!$file) {
error("No templates for selected course");
}
// attempt to create the new course
if (!($newcourse = create_course($data))) {
print_error('coursenotcreated');
}
$context = get_context_instance(CONTEXT_COURSE, $newcourse->id);
$sitecontext = get_context_instance(CONTEXT_COURSE, SITEID);
// assign our initial user - note this means automatic assigning by the backup should be skipped, which is based
// the on the manage:activities role being present
role_assign($creatorroleid, $author->id, 0, $context->id);
if ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
//now set role override for PT users to prevent them from being able to add blocks and activities.
$ptroleid = get_field('role', 'id', 'shortname', ROLE_PT);
$ispt = user_has_role_assignment($author->id, $ptroleid, $sitecontext->id);
if ($ispt) {
//prevent from being able to change the structure of the pages.
assign_capability('format/learning:manageactivities', CAP_PREVENT, $creatorroleid, $context->id);
}
}
// create default the TAO Course (LP) Forum
/// ** load this in template instead? ** local_create_forum($newcourse->id, SEPARATEGROUPS, get_string('defaultforumname', 'local'), get_string('defaultforumintro', 'local'));
// create default the TAO Course (LP) Wiki
/// ** load this in template instead? ** local_create_wiki($newcourse->id, SEPARATEGROUPS, get_string('defaultwikiname', 'local'), get_string('defaultwikisummary', 'local'));
if (!$createtemplate) {
// set course status
if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
error('could not update status');
}
}
//set up preferences for pasign to backup_file_silently
$preferences['course_format'] = 1;
if ($data->learning_path_mode == LEARNING_PATH_MODE_STANDARD) {
// load the backup data into course //TODO some way of validating this
import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences, RESTORETO_CURRENT_DELETING);
// if valid
// set course status
if (!tao_update_course_status(COURSE_STATUS_NOTSUBMITTED, "Created new learning path from template", $newcourse)) {
error('could not update status');
}
// ensure we can use the course right after creating it
// this means trigger a reload of accessinfo...
mark_context_dirty($context->path);
$author->raflmode = 0;
// Redirect to course page
return $newcourse->id;
} elseif ($data->learning_path_mode == LEARNING_PATH_MODE_RAFL) {
//set pref to not restore pages for all RAFL imports:
$preferences['nopages'] = 1;
// load the template, but leave out actual content pages - they are created by rafl structure.
// note: we must do this before adding the new pages otherwise this process will remove them
import_backup_file_silently($fullpathtofile, $newcourse->id, false, false, $preferences);
// todo do a non-fatal check for rafl module, and give a friendly message if not found
require_once $CFG->dirroot . '/mod/rafl/lib.php';
require_once $CFG->dirroot . '/mod/rafl/locallib.php';
require_once $CFG->dirroot . '/course/format/learning/lib.php';
require_once $CFG->dirroot . '/course/format/learning/pagelib.php';
$rafl = new localLibRafl();
$pageid = $newcourse->id;
// pageid is actually courseid in the blockinstance context. i know!
$pagetype = 'course-view';
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:tao.php
示例17: optional_param
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT);
// how many per page
if (!($COURSE = get_record('course', 'id', $courseid))) {
error('Invalid course idnumber');
}
if (!empty($groupid) && !($group = get_record('groups', 'id', $groupid, 'courseid', $courseid))) {
error('Invalid group id');
}
require_login();
$ptrole = get_record('role', 'shortname', ROLE_PT);
$mtrole = get_record('role', 'shortname', ROLE_MT);
$sitecontext = get_context_instance(CONTEXT_COURSE, SITEID);
$ispt = user_has_role_assignment($USER->id, $ptrole->id, $sitecontext->id);
$ismt = user_has_role_assignment($USER->id, $mtrole->id, $sitecontext->id);
print_header_simple($strheading, $strheading, build_navigation($strheading));
if ($action == 'joingroup') {
if ($COURSE->groupmode == '1') {
//if groupmode for this course is set to seperate.
$groups = groups_get_all_groups($COURSE->id, $USER->id);
if (empty($groups)) {
//if user isn't in a Group - display invites and add group stuff.
echo tao_show_user_invites($USER->id, $COURSE->id);
echo tao_new_group_form($COURSE->id);
print_footer();
exit;
} else {
notify(get_string('alreadyinagroup', 'block_tao_team_groups'));
print_continue($CFG->wwwroot . "/course/view.php?id={$COURSE->id}");
print_footer();
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:31,代码来源:managegroup.php
示例18: is_student
protected static function is_student($userid)
{
return user_has_role_assignment($userid, 5);
}
开发者ID:LoysGibertoni,项目名称:mdl_block_content_unlock,代码行数:4,代码来源:helper.php
示例19: adobeconnect_add_instance
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
*
* @param object $adobeconnect An object from the form in mod_form.php
* @return int The id of the newly inserted adobeconnect record
*/
function adobeconnect_add_instance($adobeconnect)
{
global $COURSE, $USER, $DB;
$adobeconnect->timecreated = time();
$adobeconnect->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl);
$return = false;
$meeting = new stdClass();
// Assign the current user with the Adobe Presenter role
$context = get_context_instance(CONTEXT_COURSE, $adobeconnect->course);
if (!has_capability('mod/adobeconnect:meetinghost', $context, $USER->id, false)) {
$param = array('shortname' => 'adobeconnecthost');
$roleid = $DB->get_field('role', 'id', $param);
if (role_assign($roleid, $USER->id, $context->id, 'mod_adobeconnect')) {
//DEBUG
} else {
echo 'role assignment failed';
die;
}
}
$recid = $DB->insert_record('adobeconnect', $adobeconnect);
if (empty($recid)) {
return false;
}
$aconnect = aconnect_login();
$meetfldscoid = aconnect_get_folder($aconnect, 'my-meetings');
$meeting = clone $adobeconnect;
if (0 != $adobeconnect->groupmode) {
// Allow for multiple groups
// get all groups for the course
$crsgroups = groups_get_all_groups($COURSE->id);
if (empty($crsgroups)) {
return 0;
}
require_once dirname(dirname(dirname(__FILE__))) . '/group/lib.php';
// Create the meeting for each group
foreach ($crsgroups as $crsgroup) {
// The teacher role if they don't already have one and
// Assign them to each group
if (!groups_is_member($crsgroup->id, $USER->id)) {
$param = array('shortname' => 'editingteacher');
$roleid = $DB->get_field('role', 'id', $param);
if (!user_has_role_assignment($USER->id, $roleid, $context->id)) {
role_assign($roleid, $USER->id, $context->id, 'mod_adobeconnect');
}
groups_add_member($crsgroup->id, $USER->id);
}
$meeting->name = $adobeconnect->name . '_' . $crsgroup->name;
if (!empty($adobeconnect->meeturl)) {
$meeting->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl . '_' . $crsgroup->name);
}
if (!($meetingscoid = aconnect_create_meeting($aconnect, $meeting, $meetfldscoid))) {
debugging('error creating meeting', DEBUG_DEVELOPER);
}
// Update permissions for meeting
if (empty($adobeconnect->meetingpublic)) {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PRIVATE);
} else {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PUBLIC);
}
// Insert record to activity instance in meeting_groups table
$record = new stdClass();
$record->instanceid = $recid;
$record->meetingscoid = $meetingscoid;
$record->groupid = $crsgroup->id;
$record->id = $DB->insert_record('adobeconnect_meeting_groups', $record);
// Add event to calendar
$event = new stdClass();
$event->name = $meeting->name;
$event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule);
$event->courseid = $adobeconnect->course;
$event->groupid = $crsgroup->id;
$event->userid = 0;
$event->instance = $recid;
$event->eventtype = 'group';
$
|
请发表评论