本文整理汇总了PHP中student::find方法的典型用法代码示例。如果您正苦于以下问题:PHP student::find方法的具体用法?PHP student::find怎么用?PHP student::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student
的用法示例。
在下文中一共展示了student::find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_enrolled_course_user_syncstoclass
/**
* Validate that the sync from course role assignment to class instance enrolment works
*/
public function test_enrolled_course_user_syncstoclass()
{
global $CFG, $DB;
require_once elispm::lib('lib.php');
// Set up import data.
$this->load_csv_data();
// Make sure the context is set up.
$crsctx = context_course::instance(100);
// Set up our test role.
$roleid = create_role('gradedrole', 'gradedrole', 'gradedrole');
set_config('gradebookroles', $roleid);
// Create role assignments.
role_assign($roleid, 100, $crsctx->id);
// Attempt the sync.
$sync = new \local_elisprogram\moodle\synchronize();
$sync->synchronize_moodle_class_grades();
// Make sure the student record was created.
$student = student::find();
$this->assertTrue($student->valid());
// Make sure the student has the right class id.
$student = $student->current();
$this->assertEquals(100, $student->classid);
}
示例2: data_enrol_students
/**
* Enrol the students associated with the class into the attached Moodle
* course.
*
* @param none
* @return bool True on success, False otherwise.
*/
function data_enrol_students()
{
if (empty($this->classid) || empty($this->moodlecourseid) || !empty($this->siteconfig) && !file_exists($this->siteconfig)) {
return false;
}
$students = student::find(new field_filter('classid', $this->classid));
if ($students->valid()) {
/// At this point we must switch over the other Moodle site's DB config, if needed
if (!empty($this->siteconfig)) {
// TBD: implement this in the future if needed in v2
//$cfgbak = moodle_load_config($this->siteconfig);
}
/// This has to be put here in case we have a site config reload.
$CFG = $GLOBALS['CFG'];
if (!($context = context_course::instance($this->moodlecourseid))) {
return false;
}
$plugin = enrol_get_plugin('elis');
$enrol = $plugin->get_or_create_instance($this->_db->get_record('course', array('id' => $this->moodlecourseid)));
foreach ($students as $student) {
/// Make sure that a Moodle account exists for this user already.
$user = $student->users;
if (!($muser = $user->get_moodleuser())) {
if (!($muserid = $user->synchronize_moodle_user(true, true))) {
throw new Exception(get_string('errorsynchronizeuser', self::LANG_FILE));
}
} else {
$muserid = $muser->id;
}
if (!is_enrolled($context, $muserid)) {
$plugin->enrol_user($enrol, $muserid, $enrol->roleid, $student->enrolmenttime, $student->endtime);
}
}
/// Reset $CFG object.
if (!empty($this->siteconfig)) {
// TBD: implement this in the future if needed in v2
//moodle_load_config($cfgbak->dirroot . '/config.php');
}
}
$students->close();
return true;
}
示例3: update_enrolment_status
/**
* Update enrolment status of users enroled in the current class, completing and locking
* records where applicable based on class grade and required completion elements
*
* @param int $pmuserid optional userid to update, default(0) updates all users
*/
function update_enrolment_status($pmuserid = 0)
{
//information about which course this belongs to may not have been
//loaded due to lazy-loading
$this->load();
// if (isset($this->course) && (get_class($this->course) == 'course')) {
if (isset($this->courseid)) {
$course = new course($this->courseid);
$elements = $course->get_completion_elements();
} else {
$elements = false;
}
$timenow = time();
if (!empty($elements) && $elements->valid() === true) {
// for each student, find out how many required completion elements are
// incomplete, and when the last completion element was graded
$sql = 'SELECT s.*, grades.incomplete, grades.maxtime
FROM {' . student::TABLE . '} s
JOIN (SELECT s.userid, COUNT(CASE WHEN grades.id IS NULL AND cc.required = 1 THEN 1
ELSE NULL END) AS incomplete,
MAX(timegraded) AS maxtime
FROM {' . student::TABLE . '} s
JOIN {' . coursecompletion::TABLE . '} cc
ON cc.courseid = :courseid
LEFT JOIN {' . student_grade::TABLE . '} grades
ON grades.userid = s.userid
AND grades.completionid = cc.id
AND grades.classid = :joinclassid
AND grades.grade >= cc.completion_grade
WHERE s.classid = :innerclassid AND s.locked = 0
GROUP BY s.userid
) grades ON grades.userid = s.userid
WHERE s.classid = :outerclassid AND s.locked = 0';
$params = array('courseid' => $this->courseid, 'joinclassid' => $this->id, 'innerclassid' => $this->id, 'outerclassid' => $this->id);
if ($pmuserid) {
$sql .= ' AND s.userid = :userid';
$params['userid'] = $pmuserid;
}
$rs = $this->_db->get_recordset_sql($sql, $params);
foreach ($rs as $rec) {
if ($rec->incomplete == 0 && $rec->grade > 0 && $rec->grade >= $this->course->completion_grade) {
$student = new student($rec);
$student->completestatusid = STUSTATUS_PASSED;
$student->completetime = $rec->maxtime;
$student->credits = $this->course->credits;
$student->locked = 1;
$student->complete();
}
}
} else {
/// We have no completion elements so just make sure the user's grade is at least the
/// minimum value required for the course.
/// Get all unlocked enrolments
$stufilters = array(new field_filter('classid', $this->id), new field_filter('locked', 0));
if ($pmuserid) {
$stufilters[] = new field_filter('userid', $pmuserid);
}
$rs = student::find($stufilters);
foreach ($rs as $rec) {
if ($rec->grade > 0 && $rec->grade >= $this->course->completion_grade) {
$rec->completestatusid = STUSTATUS_PASSED;
$rec->completetime = $timenow;
$rec->credits = $this->course->credits;
$rec->locked = 1;
$rec->complete();
}
}
}
unset($elements);
}