本文整理汇总了PHP中get_course函数的典型用法代码示例。如果您正苦于以下问题:PHP get_course函数的具体用法?PHP get_course怎么用?PHP get_course使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_course函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: block_my_course_progress_get_course_image_url
/**
* Returns the url of the first image contained in the course summary file area
* @param int $id the course id
* @return string the url to the image
*/
function block_my_course_progress_get_course_image_url($id)
{
global $CFG;
require_once $CFG->libdir . "/filelib.php";
$course = get_course($id);
if ($course instanceof stdClass) {
require_once $CFG->libdir . '/coursecatlib.php';
$course = new course_in_list($course);
}
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
if ($isimage) {
return file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
}
}
return false;
}
示例2: mycourses
protected function mycourses($CFG, $sidebar)
{
$mycourses = enrol_get_users_courses($_SESSION['USER']->id);
$courselist = array();
foreach ($mycourses as $key => $val) {
$courselist[] = $val->id;
}
$content = '';
for ($x = 1; $x <= sizeof($courselist); $x++) {
$course = get_course($courselist[$x - 1]);
$title = $course->fullname;
if ($course instanceof stdClass) {
require_once $CFG->libdir . '/coursecatlib.php';
$course = new course_in_list($course);
}
$url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
if (!$isimage) {
$url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
}
}
$content .= '<div class="view view-second view-mycourse ' . ($x % 3 == 0 ? 'view-nomargin' : '') . '">
<img src="' . $url . '" />
<div class="mask">
<h2>' . $title . '</h2>
<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $courselist[$x - 1] . '" class="info">Enter</a>
</div>
</div>';
}
return $content;
}
示例3: definition
function definition()
{
global $DB, $PAGE, $OUTPUT;
$id = required_param('id', PARAM_INT);
// course module
if (!($cm = get_coursemodule_from_id('blended', $id))) {
error("Course Module ID was incorrect");
}
if (!($course = get_course($cm->course))) {
error("Course is misconfigured");
}
if (!($blended = $DB->get_record('blended', array('id' => $cm->instance)))) {
error("Course module is incorrect");
}
$form =& $this->_form;
$calificables = new grade_tree($course->id);
$items = $calificables->items;
$ins = array();
$assignmentname = array();
// Obtenemos las referencias a toda la informaci�n sobre los modulos dentro del curso
$modinfo = get_fast_modinfo($course->id);
foreach ($modinfo->instances as $abc) {
foreach ($abc as $cmd) {
foreach ($items as $r => $ite) {
$ins[$r] = $ite->iteminstance;
if ($cmd->instance == $ins[$r]) {
$assignmentname[$r] = $cmd->name;
}
}
}
}
$form->addElement('select', 'activities', 'Selecciona la Tarea', $assignmentname);
}
示例4: local_compile_extends_settings_navigation
/**
* Add a "Compile" menu link to the Course Admin block as the top link.
*
* @author Gerald Albion
* date 2014-10-31
* @copyright 2014 Royal Roads University
* @param object $settingsnav Main navigation object.
* @param object $context Course context.
*/
function local_compile_extends_settings_navigation($settingsnav, $context)
{
// Context must be course.
if ($context->contextlevel != CONTEXT_COURSE) {
return;
}
// Must be in a valid course: Cannot be course id 0.
if ($context->instanceid == 0) {
return;
}
// Must be in a valid course: Course must be retrievable.
if (!($course = get_course($context->instanceid))) {
return;
}
// Must be enrolled or otherwise allowed to view the course.
if (!(is_enrolled($context) || is_viewing($context))) {
return;
}
// Must have a course admin menu in which to add link.
if (!($coursenode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE))) {
return;
}
// Good to go. Build the menu item.
$url = new moodle_url('/local/compile/list_modules.php', array('id' => $course->id));
$newnode = navigation_node::create(get_string('menucaption', 'local_compile'), $url, navigation_node::NODETYPE_LEAF, 'compile', 'compile', new pix_icon('i/settings', ''));
// We want to put this link at the top: find the existing top (first) node.
$firstnode = $coursenode->get_children_key_list()[0];
// Add the menu item to the menu, before the first node.
$coursenode->add_node($newnode, $firstnode);
}
示例5: section_activities
function section_activities($secid,$cid){
$course=get_course($cid);
$modinfo = get_fast_modinfo($course);
$mods = $modinfo->get_cms();
$sections = $modinfo->get_section_info_all();
$sec_array = get_sections($sections);
$arr = array();
$cnt=0;
//preparing an array which contains sections and activities
foreach ($mods as $mod) {
$arr[$cnt++]=array('secid'=>$mod->section,'modid'=>$mod->id,'modname'=>$mod->name,'modcontent'=>$mod->content);
//print_r($mod->name);
}
//returns the all activities associated to perticular section in a course
function get_activities($sectionid,$arr)
{
$cnt=0;
$sec_activity_array = array();
for($i=0;$i<count($arr);$i++) {
if($arr[$i]['secid']==$sectionid){
$sec_activity_array[$cnt] = array('modid'=>$arr[$i]['modid'],'modname'=>$arr[$i]['modname'],'modcontent'=>$arr[$i]['modcontent']);
$cnt++;
}
}
return $sec_activity_array;
}
// Get all course sections in a array
function get_sections($sections)
{ $cnt=0;
$sec_array = array();
foreach ($sections as $sec) {
$sec_array[$cnt++] = array('secid'=>$sec->id,'secname'=>$sec->name);
}
return $sec_array;
}
$activities=get_activities($secid,$arr);
$html='';global $CFG;
for($i=0;$i<count($activities);$i++) {
$html .= '<tr >
<td ><span class="mod' . $activities[$i]['modid'] . '">' . ($i + 1) . '</span></td>
<td ><span class="mod' . $activities[$i]['modid'] . '">' . $activities[$i]['modname'] . '</span></td>
<td ><span class="mod' . $activities[$i]['modid'] . '">' . $activities[$i]['modcontent'] . '</span></td>
<td >
<button class="showhide" id="show" value=' . $activities[$i]['modid'] . '>
<img alt="start" src="'.$CFG->wwwroot.'/teacher/testcenter/images/start.png" width="16px"/></button>
<button class="showhide" id="hide" value=' . $activities[$i]['modid'] . '>
<img alt="stop" src="'.$CFG->wwwroot.'/teacher/testcenter/images/stop.png" width="16px"/></button>
</td>
</tr>';
}
echo $html;
}//end of section_activities() function
示例6: get_assign
/**
* Get assign instance.
*
* NOTE: to be used from observers only.
*
* @throws \coding_exception
* @return \assign
*/
public function get_assign()
{
if ($this->is_restored()) {
throw new \coding_exception('get_assign() is intended for event observers only');
}
if (!isset($this->assign)) {
debugging('assign property should be initialised in each event', DEBUG_DEVELOPER);
global $CFG;
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$this->assign = new \assign($this->get_context(), $cm, $course);
}
return $this->assign;
}
示例7: definition
function definition()
{
global $DB, $PAGE, $OUTPUT;
$id = optional_param('id', 0, PARAM_INT);
$a = optional_param('a', 0, PARAM_INT);
if ($id) {
if (!($cm = get_coursemodule_from_id('blended', $id))) {
print_error("Course Module ID was incorrect");
}
if (!($course = get_course($cm->course))) {
print_error("Course is misconfigured");
}
if (!($blended = $DB->get_record('blended', array('id' => $cm->instance)))) {
print_error("Course module is incorrect");
}
if (!($context = context_course::instance($course->id))) {
print_error("Context ID is incorrect");
}
} else {
if (!($blended = $DB->get_record('blended', array('id' => $a)))) {
print_error("Course module is incorrect");
}
if (!($course = $DB->get_record('course', array('id' => $blended->course)))) {
print_error("Course is misconfigured");
}
if (!($cm = get_coursemodule_from_instance("blended", $blended->id, $course->id))) {
print_error("Course Module ID was incorrect");
}
if (!($context = context_course::instance($course->id))) {
print_error("Context ID is incorrect");
}
}
$form =& $this->_form;
$t = 0;
$agrupamientos = array();
$agrupamientos[$t] = 'Eliga';
if ($groups = groups_get_all_groupings($course->id)) {
foreach ($groups as $group) {
$t++;
$agrupamientos[$t] = $group->name;
}
}
//Select Elements
$form->addElement('select', 'grouping', get_string('select_grouping', 'blended'), $agrupamientos);
}
示例8: create_instance
/**
* Create a questionnaire activity.
* @param array $record Will be changed in this function.
* @param array $options
* @return questionnaire
*/
public function create_instance($record = array(), array $options = array())
{
if (is_array($record)) {
$record = (object) $record;
}
$defaultquestionnairesettings = array('qtype' => 0, 'respondenttype' => 'fullname', 'resp_eligible' => 'all', 'resp_view' => 0, 'useopendate' => true, 'opendate' => 0, 'useclosedate' => true, 'closedate' => 0, 'resume' => 0, 'navigate' => 0, 'grade' => 0, 'sid' => 0, 'timemodified' => time(), 'completionsubmit' => 0, 'autonum' => 3, 'create' => 'new-0');
foreach ($defaultquestionnairesettings as $name => $value) {
if (!isset($record->{$name})) {
$record->{$name} = $value;
}
}
$instance = parent::create_instance($record, $options);
$cm = get_coursemodule_from_instance('questionnaire', $instance->id);
$course = get_course($cm->course);
$questionnaire = new questionnaire(0, $instance, $course, $cm, false);
$this->questionnaires[$instance->id] = $questionnaire;
return $questionnaire;
}
示例9: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mod/ratingallocate/locallib.php';
$site = get_site();
// parse customdata passed
$customdata = $this->get_custom_data();
$userid = $customdata->userid;
$ratingallocateid = $customdata->ratingallocateid;
//get instance of ratingallocate
$ratingallocate = $DB->get_record(this_db\ratingallocate::TABLE, array(this_db\ratingallocate::ID => $ratingallocateid), '*', MUST_EXIST);
$courseid = $ratingallocate->course;
$course = get_course($courseid);
$cm = get_coursemodule_from_instance('ratingallocate', $ratingallocate->id, $courseid);
$context = \context_module::instance($cm->id);
$ratingallocateobj = new \ratingallocate($ratingallocate, $course, $cm, $context);
$ratingallocateobj->notify_users_distribution($userid);
}
示例10: local_metagroups_sync
/**
* Run synchronization process
*
* @param progress_trace $trace
* @param int|null $courseid or null for all courses
* @return void
*/
function local_metagroups_sync(progress_trace $trace, $courseid = null)
{
global $DB;
if ($courseid !== null) {
$courseids = array($courseid);
} else {
$courseids = local_metagroups_parent_courses();
}
foreach (array_unique($courseids) as $courseid) {
$parent = get_course($courseid);
// If parent course doesn't use groups, we can skip synchronization.
if (groups_get_course_groupmode($parent) == NOGROUPS) {
continue;
}
$trace->output($parent->fullname, 1);
$children = local_metagroups_child_courses($parent->id);
foreach ($children as $childid) {
$child = get_course($childid);
$trace->output($child->fullname, 2);
$groups = groups_get_all_groups($child->id);
foreach ($groups as $group) {
if (!($metagroup = $DB->get_record('groups', array('courseid' => $parent->id, 'idnumber' => $group->id)))) {
$metagroup = new stdClass();
$metagroup->courseid = $parent->id;
$metagroup->idnumber = $group->id;
$metagroup->name = $group->name;
$metagroup->id = groups_create_group($metagroup, false, false);
}
$trace->output($metagroup->name, 3);
$users = groups_get_members($group->id);
foreach ($users as $user) {
groups_add_member($metagroup->id, $user->id, 'local_metagroups', $group->id);
}
}
}
}
}
示例11: course_grid
/**
* Output the HTML grid of courses
* @param array $courses the list of enrolled courses
* @return string HTML fragment
*/
function course_grid($courses)
{
global $CFG;
require_once $CFG->dirroot . '/blocks/my_course_progress/locallib.php';
$html = sprintf('<div class="grid__container">');
// LOOP THROUGH EACH COURSE AND GET THE OUTPUT
foreach ($courses as $c) {
$course = get_course($c->id);
// OPEN GRID ITEM
$html .= sprintf('<div class="grid__item">');
// RENDER THE COURSE DETAILS
$html .= $this->course($course);
// IF COURSE HAS COMPLETION STATS, DO
if (!!$course->enablecompletion) {
// TODO: GET COMPLETION PERCENTAGE
$percentage = block_my_course_progress_get_completion_percentage((int) $course->id);
// RENDER THE COURSE PROGRESS
$html .= $this->progress($percentage);
}
// CLOSE GRID ITEM
$html .= sprintf('</div>');
}
return $html;
}
示例12: while
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while ($a = mysqli_fetch_array($papers)) {
?>
<tr>
<td><?php
echo get_course($a['course']);
?>
</td>
<td><?php
echo get_branch($a['course'], $a['branch']);
?>
</td>
<td><?php
echo $a['semester'];
?>
</td>
<td><?php
echo $a['file_name'];
?>
</td>
<td>
示例13: test_get_course
public function test_get_course()
{
global $DB, $PAGE, $SITE;
$this->resetAfterTest();
// First test course will be current course ($COURSE).
$course1obj = $this->getDataGenerator()->create_course(array('shortname' => 'FROGS'));
$PAGE->set_course($course1obj);
// Second test course is not current course.
$course2obj = $this->getDataGenerator()->create_course(array('shortname' => 'ZOMBIES'));
// Check it does not make any queries when requesting the $COURSE/$SITE.
$before = $DB->perf_get_queries();
$result = get_course($course1obj->id);
$this->assertEquals($before, $DB->perf_get_queries());
$this->assertSame('FROGS', $result->shortname);
$result = get_course($SITE->id);
$this->assertEquals($before, $DB->perf_get_queries());
// Check it makes 1 query to request other courses.
$result = get_course($course2obj->id);
$this->assertSame('ZOMBIES', $result->shortname);
$this->assertEquals($before + 1, $DB->perf_get_queries());
}
示例14: enrol_user
/**
* Self enrol the current user in the given course.
*
* @param int $courseid id of course
* @param string $password enrolment key
* @param int $instanceid instance id of self enrolment plugin
* @return array of warnings and status result
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function enrol_user($courseid, $password = '', $instanceid = 0)
{
global $CFG;
require_once $CFG->libdir . '/enrollib.php';
$params = self::validate_parameters(self::enrol_user_parameters(), array('courseid' => $courseid, 'password' => $password, 'instanceid' => $instanceid));
$warnings = array();
$course = get_course($params['courseid']);
$context = context_course::instance($course->id);
self::validate_context(context_system::instance());
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
throw new moodle_exception('coursehidden');
}
// Retrieve the self enrolment plugin.
$enrol = enrol_get_plugin('self');
if (empty($enrol)) {
throw new moodle_exception('canntenrol', 'enrol_self');
}
// We can expect multiple self-enrolment instances.
$instances = array();
$enrolinstances = enrol_get_instances($course->id, true);
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "self") {
// Instance specified.
if (!empty($params['instanceid'])) {
if ($courseenrolinstance->id == $params['instanceid']) {
$instances[] = $courseenrolinstance;
break;
}
} else {
$instances[] = $courseenrolinstance;
}
}
}
if (empty($instances)) {
throw new moodle_exception('canntenrol', 'enrol_self');
}
// Try to enrol the user in the instance/s.
$enrolled = false;
foreach ($instances as $instance) {
$enrolstatus = $enrol->can_self_enrol($instance);
if ($enrolstatus === true) {
if ($instance->password and $params['password'] !== $instance->password) {
// Check if we are using group enrolment keys.
if ($instance->customint1) {
require_once $CFG->dirroot . "/enrol/self/locallib.php";
if (!enrol_self_check_group_enrolment_key($course->id, $params['password'])) {
$warnings[] = array('item' => 'instance', 'itemid' => $instance->id, 'warningcode' => '2', 'message' => get_string('passwordinvalid', 'enrol_self'));
continue;
}
} else {
if ($enrol->get_config('showhint')) {
$hint = core_text::substr($instance->password, 0, 1);
$warnings[] = array('item' => 'instance', 'itemid' => $instance->id, 'warningcode' => '3', 'message' => s(get_string('passwordinvalidhint', 'enrol_self', $hint)));
continue;
} else {
$warnings[] = array('item' => 'instance', 'itemid' => $instance->id, 'warningcode' => '4', 'message' => get_string('passwordinvalid', 'enrol_self'));
continue;
}
}
}
// Do the enrolment.
$data = array('enrolpassword' => $params['password']);
$enrol->enrol_self($instance, (object) $data);
$enrolled = true;
break;
} else {
$warnings[] = array('item' => 'instance', 'itemid' => $instance->id, 'warningcode' => '1', 'message' => $enrolstatus);
}
}
$result = array();
$result['status'] = $enrolled;
$result['warnings'] = $warnings;
return $result;
}
示例15: forum_get_discussions
/**
* Get all discussions in a forum
*
* @global object
* @global object
* @global object
* @uses CONTEXT_MODULE
* @uses VISIBLEGROUPS
* @param object $cm
* @param string $forumsort
* @param bool $fullpost
* @param int $unused
* @param int $limit
* @param bool $userlastmodified
* @param int $page
* @param int $perpage
* @param int $groupid if groups enabled, get discussions for this group overriding the current group.
* Use FORUM_POSTS_ALL_USER_GROUPS for all the user groups
* @param int $updatedsince retrieve only discussions updated since the given time
* @return array
*/
function forum_get_discussions($cm, $forumsort = "", $fullpost = true, $unused = -1, $limit = -1, $userlastmodified = false, $page = -1, $perpage = 0, $groupid = -1, $updatedsince = 0)
{
global $CFG, $DB, $USER;
$timelimit = '';
$now = round(time(), -2);
$params = array($cm->instance);
$modcontext = context_module::instance($cm->id);
if (!has_capability('mod/forum:viewdiscussion', $modcontext)) {
/// User must have perms to view discussions
return array();
}
if (!empty($CFG->forum_enabletimedposts)) {
/// Users must fulfill timed posts
if (!has_capability('mod/forum:viewhiddentimedposts', $modcontext)) {
$timelimit = " AND ((d.timestart <= ? AND (d.timeend = 0 OR d.timeend > ?))";
$params[] = $now;
$params[] = $now;
if (isloggedin()) {
$timelimit .= " OR d.userid = ?";
$params[] = $USER->id;
}
$timelimit .= ")";
}
}
if ($limit > 0) {
$limitfrom = 0;
$limitnum = $limit;
} else {
if ($page != -1) {
$limitfrom = $page * $perpage;
$limitnum = $perpage;
} else {
$limitfrom = 0;
$limitnum = 0;
}
}
$groupmode = groups_get_activity_groupmode($cm);
if ($groupmode) {
if (empty($modcontext)) {
$modcontext = context_module::instance($cm->id);
}
// Special case, we received a groupid to override currentgroup.
if ($groupid > 0) {
$course = get_course($cm->course);
if (!groups_group_visible($groupid, $course, $cm)) {
// User doesn't belong to this group, return nothing.
return array();
}
$currentgroup = $groupid;
} else {
if ($groupid === -1) {
$currentgroup = groups_get_activity_group($cm);
} else {
// Get discussions for all groups current user can see.
$currentgroup = null;
}
}
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($currentgroup) {
$groupselect = "AND (d.groupid = ? OR d.groupid = -1)";
$params[] = $currentgroup;
} else {
$groupselect = "";
}
} else {
// Separate groups.
// Get discussions for all groups current user can see.
if ($currentgroup === null) {
$mygroups = array_keys(groups_get_all_groups($cm->course, $USER->id, $cm->groupingid, 'g.id'));
if (empty($mygroups)) {
$groupselect = "AND d.groupid = -1";
} else {
list($insqlgroups, $inparamsgroups) = $DB->get_in_or_equal($mygroups);
$groupselect = "AND (d.groupid = -1 OR d.groupid {$insqlgroups})";
$params = array_merge($params, $inparamsgroups);
}
} else {
if ($currentgroup) {
$groupselect = "AND (d.groupid = ? OR d.groupid = -1)";
//.........这里部分代码省略.........