当前位置: 首页>>代码示例>>PHP>>正文


PHP get_my_courses函数代码示例

本文整理汇总了PHP中get_my_courses函数的典型用法代码示例。如果您正苦于以下问题:PHP get_my_courses函数的具体用法?PHP get_my_courses怎么用?PHP get_my_courses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_my_courses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 function execute($data, $user, $courseid)
 {
     $finalcourses = array();
     $mycourses = get_my_courses($user->id);
     if (!empty($mycourses)) {
         $finalcourses = array_keys($mycourses);
     }
     return $finalcourses;
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:9,代码来源:plugin.class.php

示例2: definition

 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     // Get customdata
     $action = $this->_customdata['action'];
     $courseid = $this->_customdata['course'];
     $folderid = $this->_customdata['id'];
     /// Print the required moodle fields first
     $mform->addElement('header', 'moodle', get_string('folder', 'block_email_list'));
     $mform->addElement('text', 'name', get_string('namenewfolder', 'block_email_list'));
     $mform->setDefault('name', '');
     $mform->addRule('name', get_string('nofolder', 'block_email_list'), 'required', null, 'client');
     // Get root folders
     $folders = email_get_my_folders($USER->id, $courseid, true, true);
     // Get inbox, there default option on menu
     $inbox = email_get_root_folder($USER->id, EMAIL_INBOX);
     $menu = array();
     // Insert into menu, only name folder
     foreach ($folders as $key => $foldername) {
         $menu[$key] = $foldername;
     }
     if ($parent = email_get_parent_folder($folderid)) {
         $parentid = $parent->id;
     } else {
         $parentid = 0;
     }
     // Select parent folder
     $mform->addElement('select', 'parentfolder', get_string('linkto', 'block_email_list'), $menu);
     $mform->setDefault('parentfolder', $parentid);
     $mform->addElement('hidden', 'gost');
     if ($preference = get_record('email_preference', 'userid', $USER->id)) {
         if ($preference->marriedfolders2courses) {
             // Get my courses
             $mycourses = get_my_courses($USER->id);
             $courses = array();
             // Prepare array
             foreach ($mycourses as $mycourse) {
                 strlen($mycourse->fullname) > 60 ? $course = substr($mycourse->fullname, 0, 60) . ' ...' : ($course = $mycourse->fullname);
                 $courses[$mycourse->id] = $course;
             }
             $mform->addElement('select', 'foldercourse', get_string('course'), $courses);
             $mform->setDefault('foldercourse', $courseid);
         }
     }
     /// Add some extra hidden fields
     $mform->addElement('hidden', 'course', $courseid);
     $mform->addElement('hidden', 'oldname');
     $mform->addElement('hidden', 'id');
     $mform->addElement('hidden', 'action', $action);
     // buttons
     $this->add_action_buttons();
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:53,代码来源:folder_form.php

示例3: email_get_unread_mails

/**
 * This function gets all userid unread mails. It don't read trash, draft and send folders.
 * Only used in the cron.
 *
 * @param int $userid User Id.
 * @return Array All Inbox mails.
 */
function email_get_unread_mails($userid)
{
    global $CFG;
    // Get user courses (don't read hidden courses)
    if ($mycourses = get_my_courses($userid)) {
        $courses = '';
        foreach ($mycourses as $mycourse) {
            $courses .= !empty($courses) ? ', ' . $mycourse->id : $mycourse->id;
        }
        // Get inbox folder
        if ($folder = email_get_root_folder($userid, EMAIL_INBOX)) {
            $foldersid = $folder->id;
            // Get all subfolders
            if ($subfolders = email_get_all_subfolders($folder->id)) {
                foreach ($subfolders as $subfolder) {
                    $foldersid .= ', ' . $subfolder->id;
                }
            }
            $sql = "SELECT *\n\t\t                            FROM {$CFG->prefix}block_email_list_mail m\n\t\t                   LEFT JOIN {$CFG->prefix}block_email_list_send s ON m.id = s.mailid\n\t\t                   LEFT JOIN {$CFG->prefix}block_email_list_foldermail fm ON m.id = fm.mailid ";
            // WHERE principal clause for filter by user and course
            $wheresql = " WHERE s.userid = {$userid}\n\t\t\t\t\t\t  AND s.course IN ( {$courses} )\n\t\t\t\t\t\t  AND fm.folderid IN ( {$foldersid} )\n\t\t\t\t\t\t  AND s.readed = 0\n\t\t\t\t\t\t  AND s.sended = 1";
            return get_records_sql($sql . $wheresql);
        }
    }
    return array();
}
开发者ID:henriquecrang,项目名称:e-UNI,代码行数:33,代码来源:lib.php

示例4: fill_table

 public function fill_table()
 {
     global $CFG, $DB;
     // MDL-11679, only show 'mycourses' instead of all courses
     if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname, showgrades')) {
         $numusers = $this->get_numusers(false);
         foreach ($courses as $course) {
             if (!$course->showgrades) {
                 continue;
             }
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id));
             // Get course grade_item
             $course_item = grade_item::fetch_course_item($course->id);
             // Get the stored grade
             $course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $this->user->id));
             $course_grade->grade_item =& $course_item;
             $finalgrade = $course_grade->finalgrade;
             if (!$canviewhidden and !is_null($finalgrade)) {
                 if ($course_grade->is_hidden()) {
                     $finalgrade = null;
                 } else {
                     // This is a really ugly hack, it will be fixed in 2.0
                     $items = grade_item::fetch_all(array('courseid' => $course->id));
                     $grades = array();
                     $sql = "SELECT g.*\n                                  FROM {grade_grades} g\n                                  JOIN {grade_items} gi ON gi.id = g.itemid\n                                 WHERE g.userid = ? AND gi.courseid = ?";
                     if ($gradesrecords = $DB->get_records_sql($sql, array($this->user->id, $course->id))) {
                         foreach ($gradesrecords as $grade) {
                             $grades[$grade->itemid] = new grade_grade($grade, false);
                         }
                         unset($gradesrecords);
                     }
                     foreach ($items as $itemid => $unused) {
                         if (!isset($grades[$itemid])) {
                             $grade_grade = new grade_grade();
                             $grade_grade->userid = $this->user->id;
                             $grade_grade->itemid = $items[$itemid]->id;
                             $grades[$itemid] = $grade_grade;
                         }
                         $grades[$itemid]->grade_item =& $items[$itemid];
                     }
                     $hiding_affected = grade_grade::get_hiding_affected($grades, $items);
                     if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
                         $finalgrade = $hiding_affected['altered'][$course_item->id];
                     } else {
                         if (!empty($hiding_affected['unknown'][$course_item->id])) {
                             $finalgrade = null;
                         }
                     }
                     unset($hiding_affected);
                     unset($grades);
                     unset($items);
                 }
             }
             $data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
             if (!$this->showrank) {
                 //nothing to do
             } else {
                 if (!is_null($finalgrade)) {
                     /// find the number of users with a higher grade
                     /// please note this can not work if hidden grades involved :-( to be fixed in 2.0
                     $params = array($finalgrade, $course_item->id);
                     $sql = "SELECT COUNT(DISTINCT(userid))\n                              FROM {grade_grades}\n                             WHERE finalgrade IS NOT NULL AND finalgrade > ?\n                                   AND itemid = ?";
                     $rank = $DB->count_records_sql($sql, $params) + 1;
                     $data[] = "{$rank}/{$numusers}";
                 } else {
                     // no grade, no rank
                     $data[] = '-';
                 }
             }
             $this->table->add_data($data);
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:78,代码来源:lib.php

示例5: print_container_start

         print_container_start();
         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
         print_container_end();
         echo '</td>';
     }
     break;
 case 'middle':
     echo '<td valign="top" id="middle-column">';
     print_container_start(TRUE);
     /// The main overview in the middle of the page
     // limits the number of courses showing up
     $courses_limit = 21;
     if (!empty($CFG->mycoursesperpage)) {
         $courses_limit = $CFG->mycoursesperpage;
     }
     $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
     $site = get_site();
     $course = $site;
     //just in case we need the old global $course hack
     if (array_key_exists($site->id, $courses)) {
         unset($courses[$site->id]);
     }
     foreach ($courses as $c) {
         if (isset($USER->lastcourseaccess[$c->id])) {
             $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
         } else {
             $courses[$c->id]->lastaccess = 0;
         }
     }
     if (empty($courses)) {
         print_simple_box(get_string('nocourses', 'my'), 'center');
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:index.php

示例6: calendar_course_filter_selector

function calendar_course_filter_selector($getvars = '')
{
    global $USER, $SESSION;
    if (empty($USER->id) or isguest()) {
        return '';
    }
    if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
        $courses = get_courses('all', 'c.shortname', 'c.id,c.shortname');
    } else {
        $courses = get_my_courses($USER->id, 'shortname');
    }
    unset($courses[SITEID]);
    $courseoptions[SITEID] = get_string('fulllistofcourses');
    foreach ($courses as $course) {
        $courseoptions[$course->id] = format_string($course->shortname);
    }
    if (is_numeric($SESSION->cal_courses_shown)) {
        $selected = $SESSION->cal_courses_shown;
    } else {
        $selected = '';
    }
    return popup_form(CALENDAR_URL . 'set.php?var=setcourse&amp;' . $getvars . '&amp;id=', $courseoptions, 'cal_course_flt', $selected, '', '', '', true);
}
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:23,代码来源:view.php

示例7: unset

        }
        // if no courses pass the filter in that category, delete the current string
        if ($coursecnt == 0) {
            unset($courselist[$catcnt]);
        } else {
            $courselist[$catcnt] .= '</optgroup>';
            $catcnt++;
        }
    }
    // return the html code with categorized courses
    return implode(' ', $courselist);
}
// generate full and selected course lists
$availablecourses = array();
foreach ($SESSION->bulk_users as $user) {
    $usercourses = get_my_courses($user);
    foreach ($usercourses as $key => $junk) {
        if (!in_array($key, $availablecourses)) {
            $availablecourses[] = $key;
        }
    }
}
$unaccessible = array_diff($SESSION->bulk_courses, $availablecourses);
if (!empty($unaccessible)) {
    $SESSION->bulk_courses = array();
}
$coursenames = gen_course_list($searchtext, array_diff($availablecourses, $SESSION->bulk_courses));
$selcoursenames = gen_course_list('', array_intersect($availablecourses, $SESSION->bulk_courses));
// print the page
if ($accept) {
    if (empty($SESSION->bulk_courses)) {
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:index.php

示例8: unset

                    $json_output["enrol"] = true;
                    unset($USER->mycourses);
                } else {
                    $json_output["errors"][] = "Error enrolling student into course.";
                }
            }
        }
    } else {
        $json_output["errors"][] = "Enrolment key is incorrect.";
    }
}
if (isset($_GET['my_courses']) || $update_all) {
    if (!empty($USER->id)) {
        // Return my classes.
        $course_ids = array();
        $courses = get_my_courses($USER->id);
        if ($courses) {
            foreach ($courses as $course) {
                if ($CFG->rolesactive) {
                    $context = get_context_instance(CONTEXT_COURSE, $course->id);
                    $course_ids[$course->id] = array("can_edit" => has_capability('moodle/course:manageactivities', $context));
                } else {
                    if ($course->id != 1) {
                        $course_ids[$course->id] = array("can_edit" => isteacher($course->id, $USER->id, true));
                    }
                }
            }
        }
        /*
        $courses = get_my_remotecourses();
        if($courses) {
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:31,代码来源:main.php

示例9: print_row

}
if ($user->skype && !isset($hiddenfields['skypeid'])) {
    print_row(get_string('skypeid') . ':', '<a href="callto:' . urlencode($user->skype) . '">' . s($user->skype) . ' <img src="http://mystatus.skype.com/smallicon/' . urlencode($user->skype) . '" alt="' . get_string('status') . '" ' . ' /></a>');
}
if ($user->yahoo && !isset($hiddenfields['yahooid'])) {
    print_row(get_string('yahooid') . ':', '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user->yahoo) . '&amp;.src=pg">' . s($user->yahoo) . " <img src=\"http://opi.yahoo.com/online?u=" . urlencode($user->yahoo) . "&m=g&t=0\" alt=\"\"></a>");
}
if ($user->aim && !isset($hiddenfields['aimid'])) {
    print_row(get_string('aimid') . ':', '<a href="aim:goim?screenname=' . s($user->aim) . '">' . s($user->aim) . '</a>');
}
if ($user->msn && !isset($hiddenfields['msnid'])) {
    print_row(get_string('msnid') . ':', s($user->msn));
}
/// Print the Custom User Fields
profile_display_fields($user->id);
if ($mycourses = get_my_courses($user->id, null, null, false, 21)) {
    $shown = 0;
    $courselisting = '';
    foreach ($mycourses as $mycourse) {
        if ($mycourse->category) {
            if ($mycourse->id != $course->id) {
                $class = '';
                if ($mycourse->visible == 0) {
                    // get_my_courses will filter courses $USER cannot see
                    // if we get one with visible 0 it just means it's hidden
                    // ... but not from $USER
                    $class = 'class="dimmed"';
                }
                $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" {$class} >" . format_string($mycourse->fullname) . "</a>, ";
            } else {
                $courselisting .= format_string($mycourse->fullname) . ", ";
开发者ID:r007,项目名称:PMoodle,代码行数:31,代码来源:view.php

示例10: get_string

$straddnewnote = get_string('addnewnote', 'notes');
print_box_start();
if ($courseid != SITEID) {
    //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
    $view = has_capability('moodle/notes:view', $context);
    note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
    note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes . ' (' . $course->fullname . ')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
    note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
} else {
    // Normal course
    //echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
    $view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
    note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
    echo '<a name="coursenotes"></a>';
    if (!empty($userid)) {
        $courses = get_my_courses($userid);
        foreach ($courses as $c) {
            $header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
            if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
                $addid = $c->id;
            } else {
                $addid = 0;
            }
            note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
        }
    }
}
print_box_end();
print_footer($course);
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:31,代码来源:index.php

示例11: foreach

  </li> 


<?php 
// Include HTML based menu from each course, if exists
//include($CFG->dataroot.'/'.$COURSE->id.'/menu.txt');
include $CFG->dataroot . '/1/menu.txt';
?>

  <li><div><a href="<?php 
echo $CFG->wwwroot . '/';
?>
">מרחביי הלימוד שלי</a>
        <ul>
<?php 
if ($courses = get_my_courses($USER->id, 'visible DESC, fullname ASC')) {
    foreach ($courses as $course) {
        if ($course->id == SITEID) {
            continue;
        }
        $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
        echo "<li><a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a></li>";
    }
}
?>
     
	</ul>
</div></li>
</ul>
<div id="top_menu_date">
<a href="<?php 
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:topmenu.php

示例12: message_print_search_results

function message_print_search_results($frm)
{
    global $USER, $CFG;
    echo '<div align="center">';
    /// search for person
    if (!empty($frm->personsubmit) and !empty($frm->name)) {
        if (optional_param('mycourses', 0, PARAM_BOOL)) {
            $users = array();
            $mycourses = get_my_courses($USER->id);
            foreach ($mycourses as $mycourse) {
                if (is_array($susers = message_search_users($mycourse->id, $frm->name))) {
                    foreach ($susers as $suser) {
                        $users[$suser->id] = $suser;
                    }
                }
            }
        } else {
            $users = message_search_users(SITEID, $frm->name);
        }
        if (!empty($users)) {
            echo '<strong>' . get_string('userssearchresults', 'message', count($users)) . '</strong>';
            echo '<table class="message_users">';
            foreach ($users as $user) {
                if ($user->contactlistid) {
                    if ($user->blocked == 0) {
                        /// not blocked
                        $strcontact = message_contact_link($user->id, 'remove', true);
                        $strblock = message_contact_link($user->id, 'block', true);
                    } else {
                        // blocked
                        $strcontact = message_contact_link($user->id, 'add', true);
                        $strblock = message_contact_link($user->id, 'unblock', true);
                    }
                } else {
                    $strcontact = message_contact_link($user->id, 'add', true);
                    $strblock = message_contact_link($user->id, 'block', true);
                }
                $strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
                echo '<tr><td class="pix">';
                print_user_picture($user, SITEID, $user->picture, 20, false, true, 'userwindow');
                echo '</td>';
                echo '<td class="contact">';
                link_to_popup_window("/message/discussion.php?id={$user->id}", "message_{$user->id}", fullname($user), 500, 500, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
                echo '</td>';
                echo '<td class="link">' . $strcontact . '</td>';
                echo '<td class="link">' . $strblock . '</td>';
                echo '<td class="link">' . $strhistory . '</td>';
                echo '</tr>';
            }
            echo '</table>';
        } else {
            notify(get_string('nosearchresults', 'message'));
        }
        /// search messages for keywords
    } else {
        if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) {
            $keywordstring = clean_text(trim($frm->keywords));
            $keywords = explode(' ', $keywordstring);
            $tome = false;
            $fromme = false;
            $courseid = 'none';
            switch ($frm->keywordsoption) {
                case 'tome':
                    $tome = true;
                    break;
                case 'fromme':
                    $fromme = true;
                    break;
                case 'allmine':
                    $tome = true;
                    $fromme = true;
                    break;
                case 'allusers':
                    $courseid = SITEID;
                    break;
                case 'courseusers':
                    $courseid = $frm->courseid;
                    break;
                default:
                    $tome = true;
                    $fromme = true;
            }
            if (($messages = message_search($keywords, $fromme, $tome, $courseid)) !== false) {
                /// get a list of contacts
                if (($contacts = get_records('message_contacts', 'userid', $USER->id, '', 'contactid, blocked')) === false) {
                    $contacts = array();
                }
                /// print heading with number of results
                echo '<p class="heading">' . get_string('keywordssearchresults', 'message', count($messages)) . ' ("' . s($keywordstring) . '")</p>';
                /// print table headings
                echo '<table class="searchresults" cellspacing="0">';
                echo '<tr>';
                echo '<td><strong>' . get_string('from') . '</strong></td>';
                echo '<td><strong>' . get_string('to') . '</strong></td>';
                echo '<td><strong>' . get_string('message', 'message') . '</strong></td>';
                echo '<td><strong>' . get_string('timesent', 'message') . '</strong></td>';
                echo "</tr>\n";
                $blockedcount = 0;
                $dateformat = get_string('strftimedatetimeshort');
                $strcontext = get_string('context', 'message');
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:lib.php

示例13: grade_get_course_grade

/**
 * Returns the aggregated or calculated course grade for the given user(s).
 * @public
 * @param int $userid
 * @param int $courseid optional id of course or array of ids, empty means all uses courses (returns array if not present)
 * @return mixed grade info or grades array including item info, false if error
 */
function grade_get_course_grade($userid, $courseid_or_ids = null)
{
    if (!is_array($courseid_or_ids)) {
        if (empty($courseid_or_ids)) {
            if (!($courses = get_my_courses($userid, $sort = 'visible DESC,sortorder ASC', 'id'))) {
                return false;
            }
            $courseids = array_keys($courses);
            return grade_get_course_grade($userid, $courseids);
        }
        if (!is_numeric($courseid_or_ids)) {
            return false;
        }
        if (!($grades = grade_get_course_grade($userid, array($courseid_or_ids)))) {
            return false;
        } else {
            // only one grade - not array
            $grade = reset($grades);
            return $grade;
        }
    }
    foreach ($courseid_or_ids as $courseid) {
        $grade_item = grade_item::fetch_course_item($courseid);
        $course_items[$grade_item->courseid] = $grade_item;
    }
    $grades = array();
    foreach ($course_items as $grade_item) {
        if ($grade_item->needsupdate) {
            grade_regrade_final_grades($courseid);
        }
        $item = new object();
        $item->scaleid = $grade_item->scaleid;
        $item->name = $grade_item->get_name();
        $item->grademin = $grade_item->grademin;
        $item->grademax = $grade_item->grademax;
        $item->gradepass = $grade_item->gradepass;
        $item->locked = $grade_item->is_locked();
        $item->hidden = $grade_item->is_hidden();
        switch ($grade_item->gradetype) {
            case GRADE_TYPE_NONE:
                continue;
            case GRADE_TYPE_VALUE:
                $item->scaleid = 0;
                break;
            case GRADE_TYPE_TEXT:
                $item->scaleid = 0;
                $item->grademin = 0;
                $item->grademax = 0;
                $item->gradepass = 0;
                break;
        }
        $grade_grade = new grade_grade(array('userid' => $userid, 'itemid' => $grade_item->id));
        $grade_grade->grade_item =& $grade_item;
        $grade = new object();
        $grade->grade = $grade_grade->finalgrade;
        $grade->locked = $grade_grade->is_locked();
        $grade->hidden = $grade_grade->is_hidden();
        $grade->overridden = $grade_grade->overridden;
        $grade->feedback = $grade_grade->feedback;
        $grade->feedbackformat = $grade_grade->feedbackformat;
        $grade->usermodified = $grade_grade->usermodified;
        $grade->dategraded = $grade_grade->get_dategraded();
        $grade->item = $item;
        // create text representation of grade
        if ($grade_item->needsupdate) {
            $grade->grade = false;
            $grade->str_grade = get_string('error');
            $grade->str_long_grade = $grade->str_grade;
        } else {
            if (is_null($grade->grade)) {
                $grade->str_grade = '-';
                $grade->str_long_grade = $grade->str_grade;
            } else {
                $grade->str_grade = grade_format_gradevalue($grade->grade, $grade_item);
                if ($grade_item->gradetype == GRADE_TYPE_SCALE or $grade_item->get_displaytype() != GRADE_DISPLAY_TYPE_REAL) {
                    $grade->str_long_grade = $grade->str_grade;
                } else {
                    $a = new object();
                    $a->grade = $grade->str_grade;
                    $a->max = grade_format_gradevalue($grade_item->grademax, $grade_item);
                    $grade->str_long_grade = get_string('gradelong', 'grades', $a);
                }
            }
        }
        // create html representation of feedback
        if (is_null($grade->feedback)) {
            $grade->str_feedback = '';
        } else {
            $grade->str_feedback = format_text($grade->feedback, $grade->feedbackformat);
        }
        $grades[$grade_item->courseid] = $grade;
    }
    return $grades;
//.........这里部分代码省略.........
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:querylib.php

示例14: confirm_mnet_session


//.........这里部分代码省略.........
                     if (strlen($fetchrequest->response['f1']) > 0) {
                         $imagecontents = base64_decode($fetchrequest->response['f1']);
                         file_put_contents($filename, $imagecontents);
                         $localuser->picture = 1;
                     }
                     if (strlen($fetchrequest->response['f2']) > 0) {
                         $imagecontents = base64_decode($fetchrequest->response['f2']);
                         file_put_contents($dirname . '/f2.jpg', $imagecontents);
                     }
                 }
             }
         }
         if ($key == 'myhosts') {
             $localuser->mnet_foreign_host_array = array();
             foreach ($val as $rhost) {
                 $name = clean_param($rhost['name'], PARAM_ALPHANUM);
                 $url = clean_param($rhost['url'], PARAM_URL);
                 $count = clean_param($rhost['count'], PARAM_INT);
                 $url_is_local = stristr($url, $CFG->wwwroot);
                 if (!empty($name) && !empty($count) && empty($url_is_local)) {
                     $localuser->mnet_foreign_host_array[] = array('name' => $name, 'url' => $url, 'count' => $count);
                 }
             }
         }
         $localuser->{$key} = $val;
     }
     $localuser->mnethostid = $remotepeer->id;
     $DB->update_record('user', $localuser);
     // set up the session
     $mnet_session = $DB->get_record('mnet_session', array('userid' => $localuser->id, 'mnethostid' => $remotepeer->id, 'useragent' => sha1($_SERVER['HTTP_USER_AGENT'])));
     if ($mnet_session == false) {
         $mnet_session = new object();
         $mnet_session->mnethostid = $remotepeer->id;
         $mnet_session->userid = $localuser->id;
         $mnet_session->username = $localuser->username;
         $mnet_session->useragent = sha1($_SERVER['HTTP_USER_AGENT']);
         $mnet_session->token = $token;
         // Needed to support simultaneous sessions
         // and preserving DB rec uniqueness
         $mnet_session->confirm_timeout = time();
         $mnet_session->expires = time() + (int) $session_gc_maxlifetime;
         $mnet_session->session_id = session_id();
         $mnet_session->id = $DB->insert_record('mnet_session', $mnet_session);
     } else {
         $mnet_session->expires = time() + (int) $session_gc_maxlifetime;
         $DB->update_record('mnet_session', $mnet_session);
     }
     if (!$firsttime) {
         // repeat customer! let the IDP know about enrolments
         // we have for this user.
         // set up the RPC request
         $mnetrequest = new mnet_xmlrpc_client();
         $mnetrequest->set_method('auth/mnet/auth.php/update_enrolments');
         // pass username and an assoc array of "my courses"
         // with info so that the IDP can maintain mnet_enrol_assignments
         $mnetrequest->add_param($remoteuser->username);
         $fields = 'id, category, sortorder, fullname, shortname, idnumber, summary,
                    startdate, cost, currency, defaultrole, visible';
         $courses = get_my_courses($localuser->id, 'visible DESC,sortorder ASC', $fields);
         if (is_array($courses) && !empty($courses)) {
             // Second request to do the JOINs that we'd have done
             // inside get_my_courses() if we had been allowed
             $sql = "SELECT c.id,\n                               cc.name AS cat_name, cc.description AS cat_description,\n                               r.shortname as defaultrolename\n                          FROM {course} c\n                          JOIN {course_categories} cc ON c.category = cc.id\n                          LEFT OUTER JOIN {role} r  ON c.defaultrole = r.id\n                         WHERE c.id IN (" . join(',', array_keys($courses)) . ')';
             $extra = $DB->get_records_sql($sql);
             $keys = array_keys($courses);
             $defaultrolename = $DB->get_field('role', 'shortname', array('id' => $CFG->defaultcourseroleid));
             foreach ($keys as $id) {
                 if ($courses[$id]->visible == 0) {
                     unset($courses[$id]);
                     continue;
                 }
                 $courses[$id]->cat_id = $courses[$id]->category;
                 $courses[$id]->defaultroleid = $courses[$id]->defaultrole;
                 unset($courses[$id]->category);
                 unset($courses[$id]->defaultrole);
                 unset($courses[$id]->visible);
                 $courses[$id]->cat_name = $extra[$id]->cat_name;
                 $courses[$id]->cat_description = $extra[$id]->cat_description;
                 if (!empty($extra[$id]->defaultrolename)) {
                     $courses[$id]->defaultrolename = $extra[$id]->defaultrolename;
                 } else {
                     $courses[$id]->defaultrolename = $defaultrolename;
                 }
                 // coerce to array
                 $courses[$id] = (array) $courses[$id];
             }
         } else {
             // if the array is empty, send it anyway
             // we may be clearing out stale entries
             $courses = array();
         }
         $mnetrequest->add_param($courses);
         // Call 0800-RPC Now! -- we don't care too much if it fails
         // as it's just informational.
         if ($mnetrequest->send($remotepeer) === false) {
             // error_log(print_r($mnetrequest->error,1));
         }
     }
     return $localuser;
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:auth.php

示例15: forum_get_readable_forums

/**
 * An array of forum objects that the user is allowed to read/search through.
 * @param $userid
 * @param $courseid - if 0, we look for forums throughout the whole site.
 * @return array of forum objects, or false if no matches
 *         Forum objects have the following attributes:
 *         id, type, course, cmid, cmvisible, cmgroupmode, accessallgroups,
 *         viewhiddentimedposts
 */
function forum_get_readable_forums($userid, $courseid = 0)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/course/lib.php';
    if (!($forummod = get_record('modules', 'name', 'forum'))) {
        error('The forum module is not installed');
    }
    if ($courseid) {
        $courses = get_records('course', 'id', $courseid);
    } else {
        // If no course is specified, then the user can see SITE + his courses.
        // And admins can see all courses, so pass the $doanything flag enabled
        $courses1 = get_records('course', 'id', SITEID);
        $courses2 = get_my_courses($userid, null, null, true);
        $courses = array_merge($courses1, $courses2);
    }
    if (!$courses) {
        return array();
    }
    $readableforums = array();
    foreach ($courses as $course) {
        $modinfo =& get_fast_modinfo($course);
        if (is_null($modinfo->groups)) {
            $modinfo->groups = groups_get_user_groups($course->id, $userid);
        }
        if (empty($modinfo->instances['forum'])) {
            // hmm, no forums?
            continue;
        }
        $courseforums = get_records('forum', 'course', $course->id);
        foreach ($modinfo->instances['forum'] as $forumid => $cm) {
            if (!$cm->uservisible or !isset($courseforums[$forumid])) {
                continue;
            }
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
            $forum = $courseforums[$forumid];
            if (!has_capability('mod/forum:viewdiscussion', $context)) {
                continue;
            }
            /// group access
            if (groups_get_activity_groupmode($cm, $course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                if (is_null($modinfo->groups)) {
                    $modinfo->groups = groups_get_user_groups($course->id, $USER->id);
                }
                if (empty($CFG->enablegroupings)) {
                    $forum->onlygroups = $modinfo->groups[0];
                    $forum->onlygroups[] = -1;
                } else {
                    if (isset($modinfo->groups[$cm->groupingid])) {
                        $forum->onlygroups = $modinfo->groups[$cm->groupingid];
                        $forum->onlygroups[] = -1;
                    } else {
                        $forum->onlygroups = array(-1);
                    }
                }
            }
            /// hidden timed discussions
            $forum->viewhiddentimedposts = true;
            if (!empty($CFG->forum_enabletimedposts)) {
                if (!has_capability('mod/forum:viewhiddentimedposts', $context)) {
                    $forum->viewhiddentimedposts = false;
                }
            }
            /// qanda access
            if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $context)) {
                // We need to check whether the user has posted in the qanda forum.
                $forum->onlydiscussions = array();
                // Holds discussion ids for the discussions
                // the user is allowed to see in this forum.
                if ($discussionspostedin = forum_discussions_user_has_posted_in($forum->id, $USER->id)) {
                    foreach ($discussionspostedin as $d) {
                        $forum->onlydiscussions[] = $d->id;
                    }
                }
            }
            $readableforums[$forum->id] = $forum;
        }
        unset($modinfo);
    }
    // End foreach $courses
    //print_object($courses);
    //print_object($readableforums);
    return $readableforums;
}
开发者ID:r007,项目名称:PMoodle,代码行数:93,代码来源:lib.php


注:本文中的get_my_courses函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。