本文整理汇总了PHP中grade_outcome类的典型用法代码示例。如果您正苦于以下问题:PHP grade_outcome类的具体用法?PHP grade_outcome怎么用?PHP grade_outcome使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了grade_outcome类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition_after_data
function definition_after_data()
{
global $CFG;
$mform =& $this->_form;
// first load proper scales
if ($courseid = $mform->getElementValue('courseid')) {
$options = array();
if ($scales = grade_scale::fetch_all_local($courseid)) {
$options[-1] = '--' . get_string('scalescustom');
foreach ($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
if ($scales = grade_scale::fetch_all_global()) {
$options[-2] = '--' . get_string('scalesstandard');
foreach ($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
$scale_el =& $mform->getElement('scaleid');
$scale_el->load($options);
} else {
$options = array();
if ($scales = grade_scale::fetch_all_global()) {
foreach ($scales as $scale) {
$options[$scale->id] = $scale->get_name();
}
}
$scale_el =& $mform->getElement('scaleid');
$scale_el->load($options);
}
if ($id = $mform->getElementValue('id')) {
$outcome = grade_outcome::fetch(array('id' => $id));
$itemcount = $outcome->get_item_uses_count();
$coursecount = $outcome->get_course_uses_count();
if ($itemcount) {
$mform->hardFreeze('scaleid');
}
if (empty($courseid)) {
$mform->hardFreeze('standard');
} else {
if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
} else {
if ($coursecount and empty($outcome->courseid)) {
$mform->hardFreeze('standard');
}
}
}
} else {
if (empty($courseid) or !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
$mform->hardFreeze('standard');
}
}
}
示例2: emarking_copy_course_outcomes
/**
* Copies the outcomes (and associates to course if necessary) from
* a source emarking activity to a destination one
*
* @param unknown $emarkingsrc
* @param unknown $emarkingdst
* @return boolean
*/
function emarking_copy_course_outcomes($emarkingsrc, $emarkingdst)
{
global $DB, $CFG;
require_once $CFG->libdir . "/gradelib.php";
require_once $CFG->libdir . "/grade/grade_outcome.php";
if (!($coursesrc = $DB->get_record('course', array('id' => $emarkingsrc->course)))) {
return false;
}
if (!($coursedst = $DB->get_record('course', array('id' => $emarkingdst->course)))) {
return false;
}
$params = array($coursesrc->id, $emarkingsrc->id);
$sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'";
$tocopy = $DB->get_records_sql($sql, $params);
$outcomesready = array();
foreach ($tocopy as $outcomeused) {
$outcomesready[] = $outcomeused->outcomeid;
}
$params = array($coursedst->id, $emarkingdst->id);
$sql = "SELECT outcomeid, itemnumber\n FROM {grade_items}\n WHERE courseid=? AND outcomeid IS NOT NULL\n AND itemmodule = 'emarking' AND iteminstance = ?\n AND itemtype = 'mod'";
$realused = $DB->get_records_sql($sql, $params);
$maxitemnumber = 999;
foreach ($realused as $outcomeused) {
if (array_search($outcomeused->outcomeid, $outcomesready)) {
array_remove_by_value($outcomesready, $outcomeused->outcomeid);
}
if ($outcomeused->itemnumber > $maxitemnumber) {
$maxitemnumber = $outcomeused->itemnumber;
}
}
$outcomesdst = grade_outcome::fetch_all_available($emarkingdst->course);
$outcomesavailable = array();
foreach ($outcomesdst as $outcomedst) {
$outcomesavailable[] = $outcomedst->id;
}
if ($maxitemnumber < 1000) {
$maxitemnumber = 1000;
}
foreach ($outcomesready as $outcometocopy) {
$outcome = grade_outcome::fetch(array('id' => $outcometocopy));
if (!array_search($outcometocopy, $outcomesavailable)) {
$outcome->use_in($emarkingdst->course);
}
$outcomeitem = new grade_item();
$outcomeitem->courseid = $emarkingdst->course;
$outcomeitem->itemtype = 'mod';
$outcomeitem->itemmodule = 'emarking';
$outcomeitem->iteminstance = $emarkingdst->id;
$outcomeitem->itemnumber = $maxitemnumber;
$outcomeitem->itemname = $outcome->fullname;
$outcomeitem->outcomeid = $outcome->id;
$outcomeitem->gradetype = GRADE_TYPE_SCALE;
$outcomeitem->scaleid = $outcome->scaleid;
$outcomeitem->insert();
$maxitemnumber++;
}
return true;
}
示例3: grade_scale
} else {
$scale_data['courseid'] = 0;
// 'global' : scale use '0', outcomes use null
}
$scale = new grade_scale($scale_data);
$scale_id = $scale->insert();
}
}
// add outcome
$outcome_data = array('shortname' => $csv_data[$imported_headers['outcome_shortname']], 'fullname' => $csv_data[$imported_headers['outcome_name']], 'scaleid' => $scale_id, 'description' => $csv_data[$imported_headers['outcome_description']], 'usermodified' => $USER->id);
if ($local_scope) {
$outcome_data['courseid'] = $courseid;
} else {
$outcome_data['courseid'] = null;
// 'global' : scale use '0', outcomes use null
}
$outcome = new grade_outcome($outcome_data);
$outcome_id = $outcome->insert();
$outcome_success_strings = new StdClass();
$outcome_success_strings->name = $outcome_data['fullname'];
$outcome_success_strings->id = $outcome_id;
echo $OUTPUT->box(get_string('importoutcomesuccess', 'grades', $outcome_success_strings));
}
} else {
echo $OUTPUT->box(get_string('importoutcomenofile', 'grades', 0));
}
// finish
fclose($handle);
// delete temp file
unlink($imported_file);
echo $OUTPUT->footer();
示例4: standard_coursemodule_elements
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
*/
function standard_coursemodule_elements()
{
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
$this->_outcomesused = false;
if ($this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$this->_outcomesused = true;
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
foreach ($outcomes as $outcome) {
$mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
}
}
}
if ($this->_features->rating) {
require_once $CFG->dirroot . '/rating/lib.php';
$rm = new rating_manager();
$mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
$permission = CAP_ALLOW;
$rolenamestring = null;
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
$rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
$rolenamestring = implode(', ', $rolenames);
} else {
$rolenamestring = get_string('capabilitychecknotavailable', 'rating');
}
$mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
$mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
$mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
$mform->setDefault('assessed', 0);
$mform->addHelpButton('assessed', 'aggregatetype', 'rating');
$mform->addElement('modgrade', 'scale', get_string('scale'), false);
$mform->disabledIf('scale', 'assessed', 'eq', 0);
$mform->addHelpButton('scale', 'modgrade', 'grades');
$mform->setDefault('scale', $CFG->gradepointdefault);
$mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
$mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
$mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
$mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimestart', 'ratingtime');
$mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
$mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimefinish', 'ratingtime');
}
//doing this here means splitting up the grade related settings on the lesson settings page
//$this->standard_grading_coursemodule_elements();
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
$mform->addElement('modvisible', 'visible', get_string('visible'));
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
if (!has_capability('moodle/course:activityvisibility', $context)) {
$mform->hardFreeze('visible');
}
}
if ($this->_features->idnumber) {
$mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
$mform->setType('cmidnumber', PARAM_RAW);
$mform->addHelpButton('cmidnumber', 'idnumbermod');
}
if ($this->_features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
$mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
$mform->addHelpButton('groupmode', 'groupmode', 'group');
}
if ($this->_features->groupings) {
// Groupings selector - used to select grouping for groups in activity.
$options = array();
if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
}
core_collator::asort($options);
$options = array(0 => get_string('none')) + $options;
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
$mform->addHelpButton('groupingid', 'grouping', 'group');
}
if (!empty($CFG->enableavailability)) {
// Add special button to end of previous section if groups/groupings
// are enabled.
if ($this->_features->groups || $this->_features->groupings) {
$mform->addElement('static', 'restrictgroupbutton', '', html_writer::tag('button', get_string('restrictbygroup', 'availability'), array('id' => 'restrictbygroup', 'disabled' => 'disabled')));
}
// Availability field. This is just a textarea; the user interface
// interaction is all implemented in JavaScript.
$mform->addElement('header', 'availabilityconditionsheader', get_string('restrictaccess', 'availability'));
// Note: This field cannot be named 'availability' because that
// conflicts with fields in existing modules (such as assign).
// So it uses a long name that will not conflict.
$mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability'));
// The _cm variable may not be a proper cm_info, so get one from modinfo.
if ($this->_cm) {
$modinfo = get_fast_modinfo($COURSE);
$cm = $modinfo->get_cm($this->_cm->id);
} else {
$cm = null;
//.........这里部分代码省略.........
示例5: remove_course_grades
/**
* Remove all grade related course data
* Grade history is kept
*
* @param int $courseid The course ID
* @param bool $showfeedback If true success notifications will be displayed
*/
function remove_course_grades($courseid, $showfeedback)
{
global $DB, $OUTPUT;
$fs = get_file_storage();
$strdeleted = get_string('deleted');
$course_category = grade_category::fetch_course_category($courseid);
$course_category->delete('coursedelete');
$fs->delete_area_files(get_context_instance(CONTEXT_COURSE, $courseid)->id, 'grade', 'feedback');
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . ' - ' . get_string('grades', 'grades') . ', ' . get_string('items', 'grades') . ', ' . get_string('categories', 'grades'), 'notifysuccess');
}
if ($outcomes = grade_outcome::fetch_all(array('courseid' => $courseid))) {
foreach ($outcomes as $outcome) {
$outcome->delete('coursedelete');
}
}
$DB->delete_records('grade_outcomes_courses', array('courseid' => $courseid));
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . ' - ' . get_string('outcomes', 'grades'), 'notifysuccess');
}
if ($scales = grade_scale::fetch_all(array('courseid' => $courseid))) {
foreach ($scales as $scale) {
$scale->delete('coursedelete');
}
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . ' - ' . get_string('scales'), 'notifysuccess');
}
$DB->delete_records('grade_settings', array('courseid' => $courseid));
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . ' - ' . get_string('settings', 'grades'), 'notifysuccess');
}
}
示例6: fetch_all_local
/**
* Static function returning all local course outcomes
* @static
* @param int $courseid
* @return object
*/
function fetch_all_local($courseid)
{
if (!($outcomes = grade_outcome::fetch_all(array('courseid' => $courseid)))) {
$outcomes = array();
}
return $outcomes;
}
示例7: load_outcome
/**
* Instantiates a grade_outcome object whose data is retrieved from the DB,
* if this item's outcomeid variable is set.
* @return object grade_outcome
*/
function load_outcome()
{
if (!empty($this->outcomeid)) {
$this->outcome = grade_outcome::fetch(array('id' => $this->outcomeid));
}
return $this->outcome;
}
示例8: standard_coursemodule_elements
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
*/
function standard_coursemodule_elements()
{
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
$this->_outcomesused = false;
if ($this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$this->_outcomesused = true;
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
foreach ($outcomes as $outcome) {
$mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
}
}
}
if ($this->_features->rating) {
require_once $CFG->dirroot . '/rating/lib.php';
$rm = new rating_manager();
$mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
$permission = CAP_ALLOW;
$rolenamestring = null;
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
$rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
$rolenamestring = implode(', ', $rolenames);
} else {
$rolenamestring = get_string('capabilitychecknotavailable', 'rating');
}
$mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
$mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
$mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
$mform->setDefault('assessed', 0);
$mform->addHelpButton('assessed', 'aggregatetype', 'rating');
$mform->addElement('modgrade', 'scale', get_string('scale'), false);
$mform->disabledIf('scale', 'assessed', 'eq', 0);
$mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
$mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
$mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
$mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimestart', 'ratingtime');
$mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
$mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimefinish', 'ratingtime');
}
//doing this here means splitting up the grade related settings on the lesson settings page
//$this->standard_grading_coursemodule_elements();
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($this->_features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
$mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
$mform->addHelpButton('groupmode', 'groupmode', 'group');
}
if ($this->_features->groupings or $this->_features->groupmembersonly) {
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
$options = array();
$options[0] = get_string('none');
if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
}
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
$mform->addHelpButton('groupingid', 'grouping', 'group');
$mform->setAdvanced('groupingid');
}
if ($this->_features->groupmembersonly) {
$mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
$mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group');
$mform->setAdvanced('groupmembersonly');
}
$mform->addElement('modvisible', 'visible', get_string('visible'));
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
if (!has_capability('moodle/course:activityvisibility', $context)) {
$mform->hardFreeze('visible');
}
}
if ($this->_features->idnumber) {
$mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
$mform->addHelpButton('cmidnumber', 'idnumbermod');
}
if (!empty($CFG->enableavailability)) {
// String used by conditions
$strnone = get_string('none', 'condition');
// Conditional availability
// Available from/to defaults to midnight because then the display
// will be nicer where it tells users when they can access it (it
// shows only the date and not time).
$date = usergetdate(time());
$midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
// From/until controls
$mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
$mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
$mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
$mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
// Conditions based on grades
$gradeoptions = array();
$items = grade_item::fetch_all(array('courseid' => $COURSE->id));
//.........这里部分代码省略.........
示例9: require_login
require_login();
require_capability('moodle/grade:manage', $systemcontext);
}
}
// default return url
$gpr = new grade_plugin_return();
$returnurl = $gpr->get_return_url('index.php?id=' . $courseid);
$mform = new edit_outcome_form(null, array('gpr' => $gpr));
$mform->set_data($outcome_rec);
if ($mform->is_cancelled()) {
redirect($returnurl);
} else {
if ($data = $mform->get_data(false)) {
$outcome = new grade_outcome(array('id' => $id));
$data->usermodified = $USER->id;
grade_outcome::set_properties($outcome, $data);
if (empty($outcome->id)) {
if (!has_capability('moodle/grade:manage', $systemcontext)) {
$data->standard = 0;
}
$outcome->courseid = !empty($data->standard) ? null : $courseid;
if (empty($outcome->courseid)) {
$outcome->courseid = null;
}
$outcome->insert();
} else {
if (isset($data->standard)) {
$outcome->courseid = !empty($data->standard) ? null : $courseid;
} else {
unset($outcome->couseid);
// keep previous
示例10: test_get_course_module
/**
* Test get_course_module
*/
public function test_get_course_module()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
$course = self::getDataGenerator()->create_course();
$record = array('course' => $course->id, 'name' => 'First Assignment');
$options = array('idnumber' => 'ABC', 'visible' => 0);
// Hidden activity.
$assign = self::getDataGenerator()->create_module('assign', $record, $options);
$outcomescale = 'Distinction, Very Good, Good, Pass, Fail';
// Insert a custom grade scale to be used by an outcome.
$gradescale = new grade_scale();
$gradescale->name = 'gettcoursemodulescale';
$gradescale->courseid = $course->id;
$gradescale->userid = 0;
$gradescale->scale = $outcomescale;
$gradescale->description = 'This scale is used to mark standard assignments.';
$gradescale->insert();
// Insert an outcome.
$data = new stdClass();
$data->courseid = $course->id;
$data->fullname = 'Team work';
$data->shortname = 'Team work';
$data->scaleid = $gradescale->id;
$outcome = new grade_outcome($data, false);
$outcome->insert();
$outcomegradeitem = new grade_item();
$outcomegradeitem->itemname = $outcome->shortname;
$outcomegradeitem->itemtype = 'mod';
$outcomegradeitem->itemmodule = 'assign';
$outcomegradeitem->iteminstance = $assign->id;
$outcomegradeitem->outcomeid = $outcome->id;
$outcomegradeitem->cmid = 0;
$outcomegradeitem->courseid = $course->id;
$outcomegradeitem->aggregationcoef = 0;
$outcomegradeitem->itemnumber = 1;
// The activity's original grade item will be 0.
$outcomegradeitem->gradetype = GRADE_TYPE_SCALE;
$outcomegradeitem->scaleid = $outcome->scaleid;
$outcomegradeitem->insert();
$assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assign->id, 'itemnumber' => 0, 'courseid' => $course->id));
$outcomegradeitem->set_parent($assignmentgradeitem->categoryid);
$outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder);
// Test admin user can see the complete hidden activity.
$result = core_course_external::get_course_module($assign->cmid);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
$this->assertCount(0, $result['warnings']);
// Test we retrieve all the fields.
$this->assertCount(27, $result['cm']);
$this->assertEquals($record['name'], $result['cm']['name']);
$this->assertEquals($options['idnumber'], $result['cm']['idnumber']);
$this->assertEquals(100, $result['cm']['grade']);
$this->assertEquals(0.0, $result['cm']['gradepass']);
$this->assertEquals('submissions', $result['cm']['advancedgrading'][0]['area']);
$this->assertEmpty($result['cm']['advancedgrading'][0]['method']);
$this->assertEquals($outcomescale, $result['cm']['outcomes'][0]['scale']);
$student = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
self::getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id);
$this->setUser($student);
// The user shouldn't be able to see the activity.
try {
core_course_external::get_course_module($assign->cmid);
$this->fail('Exception expected due to invalid permissions.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Make module visible.
set_coursemodule_visible($assign->cmid, 1);
// Test student user.
$result = core_course_external::get_course_module($assign->cmid);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
$this->assertCount(0, $result['warnings']);
// Test we retrieve only the few files we can see.
$this->assertCount(11, $result['cm']);
$this->assertEquals($assign->cmid, $result['cm']['id']);
$this->assertEquals($course->id, $result['cm']['course']);
$this->assertEquals('assign', $result['cm']['modname']);
$this->assertEquals($assign->id, $result['cm']['instance']);
}
示例11: RWSUQGrades
function RWSUQGrades($r_qiz)
{
$r_gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'itemnumber' => 0, 'courseid' => $r_qiz->course));
if ($r_gi && $r_gi->idnumber != $r_qiz->cmidnumber) {
$r_gi->idnumber = $r_qiz->cmidnumber;
$r_gi->update();
}
$r_its = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'courseid' => $r_qiz->course));
if ($r_its && isset($r_qiz->gradecat)) {
if ($r_qiz->gradecat == -1) {
$r_gcat = new grade_category();
$r_gcat->courseid = $r_qiz->course;
$r_gcat->fullname = $r_qiz->name;
$r_gcat->insert();
if ($r_gi) {
$r_par = $r_gi->get_parent_category();
$r_gcat->set_parent($r_par->id);
}
$r_qiz->gradecat = $r_gcat->id;
}
foreach ($r_its as $r_iti => $r_un) {
$r_its[$r_iti]->set_parent($r_qiz->gradecat);
if ($r_iti == $r_gi->id) {
$r_gi = $r_its[$r_iti];
}
}
}
if ($r_ocs = grade_outcome::fetch_all_available($r_qiz->course)) {
$r_gis = array();
$r_mit = 999;
if ($r_its) {
foreach ($r_its as $r_it) {
if ($r_it->itemnumber > $r_mit) {
$r_mit = $r_it->itemnumber;
}
}
}
foreach ($r_ocs as $r_oc) {
$r_eln = 'outcome_' . $r_oc->id;
if (property_exists($r_qiz, $r_eln) and $r_qiz->{$r_eln}) {
if ($r_its) {
foreach ($r_its as $r_it) {
if ($r_it->outcomeid == $r_oc->id) {
continue 2;
}
}
}
$r_mit++;
$r_oi = new grade_item();
$r_oi->courseid = $r_qiz->course;
$r_oi->itemtype = 'mod';
$r_oi->itemmodule = $r_qiz->modulename;
$r_oi->iteminstance = $r_qiz->instance;
$r_oi->itemnumber = $r_mit;
$r_oi->itemname = $r_oc->fullname;
$r_oi->outcomeid = $r_oc->id;
$r_oi->gradetype = GRADE_TYPE_SCALE;
$r_oi->scaleid = $r_oc->scaleid;
$r_oi->insert();
if ($r_gi) {
$r_oi->set_parent($r_gi->categoryid);
$r_oi->move_after_sortorder($r_gi->sortorder);
} else {
if (isset($r_qiz->gradecat)) {
$r_oi->set_parent($r_qiz->gradecat);
}
}
}
}
}
}
示例12: standard_coursemodule_elements
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
*
* @param mixed array or object describing supported features - groups, groupings, groupmembersonly
*/
function standard_coursemodule_elements($features = null)
{
global $COURSE, $CFG;
$mform =& $this->_form;
// deal with legacy $supportgroups param
if ($features === true or $features === false) {
$groupmode = $features;
$features = new object();
$features->groups = $groupmode;
} else {
if (is_array($features)) {
$features = (object) $features;
} else {
if (empty($features)) {
$features = new object();
}
}
}
if (!isset($features->groups)) {
$features->groups = true;
}
if (!isset($features->groupings)) {
$features->groupings = false;
}
if (!isset($features->groupmembersonly)) {
$features->groupmembersonly = false;
}
if (!empty($CFG->enableoutcomes)) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
foreach ($outcomes as $outcome) {
$mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
}
}
}
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
// if no other elements will be shown, this header should be removed
$showHeader = false;
if ($features->groups) {
$mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
$showHeader = true;
}
if (!empty($CFG->enablegroupings)) {
if ($features->groupings or $features->groupmembersonly) {
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
$options = array();
$options[0] = get_string('none');
if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
}
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
$mform->setAdvanced('groupingid');
$showHeader = true;
}
if ($features->groupmembersonly) {
$mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
$mform->setAdvanced('groupmembersonly');
$showHeader = true;
}
}
if (!$showHeader) {
$mform->removeElement('modstandardelshdr');
}
// kowy - this parameter is too dificult to leave setting to a teacher
//$mform->addElement('modvisible', 'visible', get_string('visible'));
//$mform->addElement('text', 'cmidnumber', get_string('idnumber'));
$this->standard_hidden_coursemodule_elements();
}
示例13: foreach
foreach ($items as $item) {
if (empty($item->outcomeid)) {
continue;
}
if ($item->itemnumber > $max) {
$max = $item->itemnumber;
}
}
$grade_item->itemnumber = $max + 1;
}
} else {
$grade_item->itemnumber = 1000;
}
}
// fix scale used
$outcome = grade_outcome::fetch(array('id' => $data->outcomeid));
$grade_item->gradetype = GRADE_TYPE_SCALE;
$grade_item->scaleid = $outcome->scaleid;
//TODO: we might recalculate existing outcome grades when changing scale
if (empty($grade_item->id)) {
$grade_item->insert();
// move next to activity if adding linked outcome
if ($grade_item->itemtype == 'mod') {
if ($item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $grade_item->itemmodule, 'iteminstance' => $grade_item->iteminstance, 'itemnumber' => 0, 'courseid' => $COURSE->id))) {
$grade_item->set_parent($item->categoryid);
$grade_item->move_after_sortorder($item->sortorder);
}
}
} else {
$grade_item->update();
}
示例14: foreach
if ($grade_item) {
$parent = $grade_item->get_parent_category();
$grade_category->set_parent($parent->id);
}
$fromform->gradecat = $grade_category->id;
}
foreach ($items as $itemid => $unused) {
$items[$itemid]->set_parent($fromform->gradecat);
if ($itemid == $grade_item->id) {
// use updated grade_item
$grade_item = $items[$itemid];
}
}
}
// add outcomes if requested
if ($outcomes = grade_outcome::fetch_all_available($course->id)) {
$grade_items = array();
// Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes
$max_itemnumber = 999;
if ($items) {
foreach ($items as $item) {
if ($item->itemnumber > $max_itemnumber) {
$max_itemnumber = $item->itemnumber;
}
}
}
foreach ($outcomes as $outcome) {
$elname = 'outcome_' . $outcome->id;
if (property_exists($fromform, $elname) and $fromform->{$elname}) {
// so we have a request for new outcome grade item?
if ($items) {
示例15: standard_coursemodule_elements
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
*/
function standard_coursemodule_elements()
{
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
$outcomesused = false;
if ($this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$outcomesused = true;
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
foreach ($outcomes as $outcome) {
$mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
}
}
}
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($this->_features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
$mform->addElement('select', 'groupmode', get_string('groupmode'), $options, NOGROUPS);
$mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')));
}
if (!empty($CFG->enablegroupings)) {
if ($this->_features->groupings or $this->_features->groupmembersonly) {
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
$options = array();
$options[0] = get_string('none');
if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
}
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
$mform->setHelpButton('groupingid', array('grouping', get_string('grouping', 'group')));
$mform->setAdvanced('groupingid');
}
if ($this->_features->groupmembersonly) {
$mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
$mform->setHelpButton('groupmembersonly', array('groupmembersonly', get_string('groupmembersonly', 'group')));
$mform->setAdvanced('groupmembersonly');
}
}
$mform->addElement('modvisible', 'visible', get_string('visible'));
if ($this->_features->idnumber) {
$mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
$mform->setHelpButton('cmidnumber', array('cmidnumber', get_string('idnumbermod')), true);
}
if ($this->_features->gradecat) {
$categories = grade_get_categories_menu($COURSE->id, $outcomesused);
$mform->addElement('select', 'gradecat', get_string('gradecategory', 'grades'), $categories);
}
if (!empty($CFG->enableavailability)) {
// Conditional availability
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
$mform->addElement('date_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true));
$mform->setHelpButton('availablefrom', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition'));
$mform->addElement('date_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true));
$mform->setHelpButton('availableuntil', array('conditiondates', get_string('help_conditiondates', 'condition'), 'condition'));
// Conditions based on grades
$gradeoptions = array();
$items = grade_item::fetch_all(array('courseid' => $COURSE->id));
$items = $items ? $items : array();
foreach ($items as $id => $item) {
// Do not include grades for current item
if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
continue;
}
$gradeoptions[$id] = $item->get_name();
}
asort($gradeoptions);
$gradeoptions = array(0 => get_string('none', 'condition')) + $gradeoptions;
$grouparray = array();
$grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
$grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
$grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
$grouparray[] =& $mform->createElement('static', '', '', '%');
$mform->setType('conditiongrademin', PARAM_FLOAT);
$mform->setType('conditiongrademax', PARAM_FLOAT);
$group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
// Get version with condition info and store it so we don't ask
// twice
if (!empty($this->_cm)) {
$ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
$this->_cm = $ci->get_full_course_module();
$count = count($this->_cm->conditionsgrade) + 1;
} else {
$count = 1;
}
$this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
$mform->setHelpButton('conditiongradegroup[0]', array('gradecondition', get_string('help_gradecondition', 'condition'), 'condition'));
// Conditions based on completion
$completion = new completion_info($COURSE);
if ($completion->is_enabled()) {
$completionoptions = array();
$modinfo = get_fast_modinfo($COURSE);
foreach ($modinfo->cms as $id => $cm) {
// Add each course-module if it:
//.........这里部分代码省略.........