Beispiel #1
0
 /**
  * Set up for every test
  */
 public function setUp()
 {
     global $DB;
     $this->resetAfterTest(true);
     $s1grade1 = 80;
     $s1grade2 = 40;
     $s2grade = 60;
     $this->course1 = $this->getDataGenerator()->create_course();
     $this->course2 = $this->getDataGenerator()->create_course();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
     $this->student1 = $this->getDataGenerator()->create_user();
     $this->teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course1->id, $teacherrole->id);
     $this->getDataGenerator()->enrol_user($this->student1->id, $this->course1->id, $studentrole->id);
     $this->getDataGenerator()->enrol_user($this->student1->id, $this->course2->id, $studentrole->id);
     $this->student2 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($this->student2->id, $this->course1->id, $studentrole->id);
     $this->getDataGenerator()->enrol_user($this->student2->id, $this->course2->id, $studentrole->id);
     $assignment1 = $this->getDataGenerator()->create_module('assign', array('name' => "Test assign", 'course' => $this->course1->id));
     $assignment2 = $this->getDataGenerator()->create_module('assign', array('name' => "Test assign", 'course' => $this->course2->id));
     $modcontext1 = get_coursemodule_from_instance('assign', $assignment1->id, $this->course1->id);
     $modcontext2 = get_coursemodule_from_instance('assign', $assignment2->id, $this->course2->id);
     $assignment1->cmidnumber = $modcontext1->id;
     $assignment2->cmidnumber = $modcontext2->id;
     $this->student1grade1 = array('userid' => $this->student1->id, 'rawgrade' => $s1grade1);
     $this->student1grade2 = array('userid' => $this->student1->id, 'rawgrade' => $s1grade2);
     $this->student2grade = array('userid' => $this->student2->id, 'rawgrade' => $s2grade);
     $studentgrades = array($this->student1->id => $this->student1grade1, $this->student2->id => $this->student2grade);
     assign_grade_item_update($assignment1, $studentgrades);
     $studentgrades = array($this->student1->id => $this->student1grade2);
     assign_grade_item_update($assignment2, $studentgrades);
     grade_get_setting($this->course1->id, 'report_overview_showrank', 1);
 }
Beispiel #2
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $userid The id of the user
  */
 function grade_report_user($courseid, $gpr, $context, $userid)
 {
     global $CFG;
     parent::grade_report($courseid, $gpr, $context);
     $this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
     $this->showpercentage = grade_get_setting($this->courseid, 'report_user_showpercentage', $CFG->grade_report_user_showpercentage);
     $this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
     $this->showrange = true;
     $this->switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, false, $this->switch, false, !$CFG->enableoutcomes);
     // Determine the number of rows and indentation
     $this->maxdepth = 1;
     $this->inject_rowspans($this->gtree->top_element);
     $this->maxdepth++;
     // Need to account for the lead column that spans all children
     for ($i = 1; $i <= $this->maxdepth; $i++) {
         $this->evenodd[$i] = 0;
     }
     $this->tabledata = array();
     $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->courseid));
     // get the user (for full name)
     $this->user = get_record('user', 'id', $userid);
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/report?id=' . $courseid . '&amp;userid=' . $userid;
     $this->pbarurl = $this->baseurl;
     // no groups on this report - rank is from all course users
     $this->setup_table();
 }
Beispiel #3
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $userid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  */
 public function __construct($userid, $gpr, $context)
 {
     global $CFG, $COURSE, $DB;
     parent::__construct($COURSE->id, $gpr, $context);
     // Get the user (for full name).
     $this->user = $DB->get_record('user', array('id' => $userid));
     // Load the user's courses.
     $this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
     $this->showrank = array();
     $this->showrank['any'] = false;
     $this->showtotalsifcontainhidden = array();
     if ($this->courses) {
         foreach ($this->courses as $course) {
             $this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
             if ($this->showrank[$course->id]) {
                 $this->showrank['any'] = true;
             }
             $this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
         }
     }
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
     $this->pbarurl = $this->baseurl;
     $this->setup_table();
 }
Beispiel #4
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $userid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  */
 public function __construct($userid, $gpr, $context)
 {
     global $CFG, $COURSE, $DB;
     parent::__construct($COURSE->id, $gpr, $context);
     $this->showrank = grade_get_setting($this->courseid, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
     // get the user (for full name)
     $this->user = $DB->get_record('user', array('id' => $userid));
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
     $this->pbarurl = $this->baseurl;
     $this->setup_table();
 }
Beispiel #5
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $userid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  */
 function grade_report_overview($userid, $gpr, $context)
 {
     global $CFG, $COURSE;
     parent::grade_report($COURSE->id, $gpr, $context);
     $this->showrank = grade_get_setting($this->courseid, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
     $this->showtotalsifcontainhidden = grade_get_setting($this->courseid, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
     // get the user (for full name)
     $this->user = get_record('user', 'id', $userid);
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
     $this->pbarurl = $this->baseurl;
     $this->setup_table();
 }
Beispiel #6
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $userid The id of the user
  */
 function grade_report_user($courseid, $gpr, $context, $userid)
 {
     global $CFG;
     parent::grade_report($courseid, $gpr, $context);
     $this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
     $this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
     $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     // Grab the grade_seq for this course
     $this->gseq = new grade_seq($this->courseid, $switch);
     // get the user (for full name)
     $this->user = get_record('user', 'id', $userid);
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/report?id=' . $courseid . '&amp;userid=' . $userid;
     $this->pbarurl = $this->baseurl;
     // no groups on this report - rank is from all course users
     $this->setup_table();
 }
Beispiel #7
0
 /**
  * Returns the minimum and maximum number of points this grade is graded with respect to.
  *
  * @since  Moodle 2.8.7, 2.9.1
  * @return array A list containing, in order, the minimum and maximum number of points.
  */
 protected function get_grade_min_and_max()
 {
     global $CFG;
     $this->load_grade_item();
     // When the following setting is turned on we use the grade_grade raw min and max values.
     $minmaxtouse = grade_get_setting($this->grade_item->courseid, 'minmaxtouse', $CFG->grade_minmaxtouse);
     // Only aggregate items use separate min grades.
     if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE || $this->grade_item->is_aggregate_item()) {
         return array($this->rawgrademin, $this->rawgrademax);
     } else {
         return array($this->grade_item->grademin, $this->grade_item->grademax);
     }
 }
Beispiel #8
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $page The current page being viewed (when report is paged)
  * @param int $sortitemid The id of the grade_item by which to sort the table
  */
 function grade_report_grader($courseid, $gpr, $context, $page = null, $sortitemid = null)
 {
     global $CFG;
     parent::grade_report($courseid, $gpr, $context, $page);
     $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
     // load collapsed settings for this report
     if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) {
         $this->collapsed = unserialize($collapsed);
     } else {
         $this->collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
     }
     if (empty($CFG->enableoutcomes)) {
         $nooutcomes = false;
     } else {
         $nooutcomes = get_user_preferences('grade_report_shownooutcomes');
     }
     // if user report preference set or site report setting set use it, otherwise use course or site setting
     $switch = $this->get_pref('aggregationposition');
     if ($switch == '') {
         $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     }
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, true, $switch, $this->collapsed, $nooutcomes);
     $this->sortitemid = $sortitemid;
     // base url for sorting by first/last name
     $studentsperpage = $this->get_pref('studentsperpage');
     $perpage = '';
     $curpage = '';
     if (!empty($studentsperpage)) {
         $perpage = '&amp;perpage=' . $studentsperpage;
         $curpage = '&amp;page=' . $this->page;
     }
     $this->baseurl = 'index.php?id=' . $this->courseid . $perpage . $curpage . '&amp;';
     $this->pbarurl = 'index.php?id=' . $this->courseid . $perpage . '&amp;';
     $this->setup_groups();
     $this->setup_sortitemid();
 }
 /**
  * Test upgrade minmaxgrade step.
  */
 public function test_upgrade_minmaxgrade()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/gradelib.php';
     $initialminmax = $CFG->grade_minmaxtouse;
     $this->resetAfterTest();
     $c1 = $this->getDataGenerator()->create_course();
     $c2 = $this->getDataGenerator()->create_course();
     $c3 = $this->getDataGenerator()->create_course();
     $u1 = $this->getDataGenerator()->create_user();
     $a1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1, 'grade' => 100));
     $a2 = $this->getDataGenerator()->create_module('assign', array('course' => $c2, 'grade' => 100));
     $a3 = $this->getDataGenerator()->create_module('assign', array('course' => $c3, 'grade' => 100));
     $cm1 = get_coursemodule_from_instance('assign', $a1->id);
     $ctx1 = context_module::instance($cm1->id);
     $assign1 = new assign($ctx1, $cm1, $c1);
     $cm2 = get_coursemodule_from_instance('assign', $a2->id);
     $ctx2 = context_module::instance($cm2->id);
     $assign2 = new assign($ctx2, $cm2, $c2);
     $cm3 = get_coursemodule_from_instance('assign', $a3->id);
     $ctx3 = context_module::instance($cm3->id);
     $assign3 = new assign($ctx3, $cm3, $c3);
     // Give a grade to the student.
     $ug = $assign1->get_user_grade($u1->id, true);
     $ug->grade = 10;
     $assign1->update_grade($ug);
     $ug = $assign2->get_user_grade($u1->id, true);
     $ug->grade = 20;
     $assign2->update_grade($ug);
     $ug = $assign3->get_user_grade($u1->id, true);
     $ug->grade = 30;
     $assign3->update_grade($ug);
     // Run the upgrade.
     upgrade_minmaxgrade();
     // Nothing has happened.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
     $this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
     $this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Create inconsistency in c1 and c2.
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a1->id, 'courseid' => $c1->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademin = 5;
     $gi->update();
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a2->id, 'courseid' => $c2->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademax = 50;
     $gi->update();
     // C1 and C2 should be updated, but the course setting should not be set.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C1 and C2 were partially updated.
     $this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
     $this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     $this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
     $this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
     $this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     $this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Course setting should not be set on a course that has the setting already.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($c1->id, 'minmaxtouse', -1);
     // Sets different value than constant to check that it remained the same.
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C2 was updated.
     $this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     // Nothing has happened for C1.
     $this->assertSame('-1', grade_get_setting($c1->id, 'minmaxtouse', false, true));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Final check, this time we'll unset the default config.
     unset($CFG->grade_minmaxtouse);
     grade_set_setting($c1->id, 'minmaxtouse', null);
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C1 was updated.
     $this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Restore value.
     $CFG->grade_minmaxtouse = $initialminmax;
 }
Beispiel #10
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $page The current page being viewed (when report is paged)
  * @param int $sortitemid The id of the grade_item by which to sort the table
  */
 public function __construct($courseid, $gpr, $context, $page = null, $sortitemid = null)
 {
     global $CFG;
     parent::__construct($courseid, $gpr, $context, $page);
     $this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->course->id));
     // load collapsed settings for this report
     $this->collapsed = static::get_collapsed_preferences($this->course->id);
     if (empty($CFG->enableoutcomes)) {
         $nooutcomes = false;
     } else {
         $nooutcomes = get_user_preferences('grade_report_shownooutcomes');
     }
     // if user report preference set or site report setting set use it, otherwise use course or site setting
     $switch = $this->get_pref('aggregationposition');
     if ($switch == '') {
         $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     }
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, true, $switch, $this->collapsed, $nooutcomes);
     $this->sortitemid = $sortitemid;
     // base url for sorting by first/last name
     $this->baseurl = new moodle_url('index.php', array('id' => $this->courseid));
     $studentsperpage = $this->get_students_per_page();
     if (!empty($this->page) && !empty($studentsperpage)) {
         $this->baseurl->params(array('perpage' => $studentsperpage, 'page' => $this->page));
     }
     $this->pbarurl = new moodle_url('/grade/report/grader/index.php', array('id' => $this->courseid));
     $this->setup_groups();
     $this->setup_users();
     $this->setup_sortitemid();
     $this->overridecat = (bool) get_config('moodle', 'grade_overridecat');
 }
 public function __construct(attendance $att)
 {
     global $CFG;
     $this->perm = $att->perm;
     $currenttime = time();
     if ($att->pageparams->view == ATT_VIEW_NOTPRESENT) {
         $att->pageparams->enddate = $currenttime;
     }
     $this->pageparams = $att->pageparams;
     $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
     if (isset($att->pageparams->userids)) {
         foreach ($this->users as $key => $user) {
             if (!in_array($user->id, $att->pageparams->userids)) {
                 unset($this->users[$key]);
             }
         }
     }
     $this->groups = groups_get_all_groups($att->course->id);
     $this->sessions = $att->get_filtered_sessions();
     $this->statuses = $att->get_statuses(true, true);
     $this->allstatuses = $att->get_statuses(false, true);
     $this->gradable = $att->grade > 0;
     if (!($this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints'))) {
         $this->decimalpoints = $CFG->grade_decimalpoints;
     }
     $maxgrade = att_get_user_max_grade(count($this->sessions), $this->statuses);
     foreach ($this->users as $key => $user) {
         $grade = 0;
         if ($this->gradable) {
             $grade = $att->get_user_grade($user->id, array('enddate' => $currenttime));
             $totalgrade = $att->get_user_grade($user->id);
         }
         if ($att->pageparams->view != ATT_VIEW_NOTPRESENT || $grade < $maxgrade) {
             $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id);
             $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id);
             $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id);
             if ($this->gradable) {
                 $this->grades[$user->id] = $totalgrade;
                 $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);
             }
         } else {
             unset($this->users[$key]);
         }
     }
     $this->att = $att;
 }
Beispiel #12
0
/**
 * Add, update or delete a course gradebook setting
 *
 * @param int $courseid The course ID
 * @param string $name Name of the setting
 * @param string $value Value of the setting. NULL means delete the setting.
 */
function grade_set_setting($courseid, $name, $value)
{
    global $DB;
    if (is_null($value)) {
        $DB->delete_records('grade_settings', array('courseid' => $courseid, 'name' => $name));
    } else {
        if (!($existing = $DB->get_record('grade_settings', array('courseid' => $courseid, 'name' => $name)))) {
            $data = new stdClass();
            $data->courseid = $courseid;
            $data->name = $name;
            $data->value = $value;
            $DB->insert_record('grade_settings', $data);
        } else {
            $data = new stdClass();
            $data->id = $existing->id;
            $data->value = $value;
            $DB->update_record('grade_settings', $data);
        }
    }
    grade_get_setting($courseid, null, null, true);
    // reset the cache
}
Beispiel #13
0
 /**
  * Returns the value of the decimals field. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.
  * @return int Decimals (0 - 5)
  */
 function get_decimals()
 {
     global $CFG;
     if (is_null($this->decimals)) {
         return grade_get_setting($this->courseid, 'decimalpoints', $CFG->grade_decimalpoints);
     } else {
         return $this->decimals;
     }
 }
Beispiel #14
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $userid The id of the user
  * @param boolean $hidereport Hide all report only show assessments
  */
 public function __construct($courseid, $gpr, $context, $userid, $hidereport)
 {
     global $DB, $CFG;
     parent::__construct($courseid, $gpr, $context);
     if (isset($hidereport)) {
         $this->hidereport = $hidereport;
     }
     $this->showhiddenactivity = grade_get_setting($this->courseid, 'report_marksheet_showhiddenactivity', $CFG->grade_report_marksheet_showhiddenactivity);
     $this->showrank = grade_get_setting($this->courseid, 'report_marksheet_showrank', $CFG->grade_report_marksheet_showrank);
     $this->showpercentage = grade_get_setting($this->courseid, 'report_marksheet_showpercentage', $CFG->grade_report_marksheet_showpercentage);
     $this->showhiddenitems = grade_get_setting($this->courseid, 'report_marksheet_showhiddenitems', $CFG->grade_report_marksheet_showhiddenitems);
     $this->showtotalsifcontainhidden = array($this->courseid => grade_get_setting($this->courseid, 'report_marksheet_showtotalsifcontainhidden', $CFG->grade_report_marksheet_showtotalsifcontainhidden));
     $this->showgrade = grade_get_setting($this->courseid, 'report_marksheet_showgrade', !empty($CFG->grade_report_marksheet_showgrade));
     $this->showrange = grade_get_setting($this->courseid, 'report_marksheet_showrange', !empty($CFG->grade_report_marksheet_showrange));
     $this->showfeedback = grade_get_setting($this->courseid, 'report_marksheet_showfeedback', !empty($CFG->grade_report_marksheet_showfeedback));
     $this->showweight = grade_get_setting($this->courseid, 'report_marksheet_showweight', !empty($CFG->grade_report_marksheet_showweight));
     $this->showlettergrade = grade_get_setting($this->courseid, 'report_marksheet_showlettergrade', !empty($CFG->grade_report_marksheet_showlettergrade));
     $this->showaverage = grade_get_setting($this->courseid, 'report_marksheet_showaverage', !empty($CFG->grade_report_marksheet_showaverage));
     $this->showtimeupdate = grade_get_setting($this->courseid, 'report_marksheet_showtimeupdate', !empty($CFG->grade_report_marksheet_showtimeupdate));
     $this->showstartdate = grade_get_setting($this->courseid, 'report_marksheet_showstartdate', !empty($CFG->grade_report_marksheet_showstartdate));
     $this->grade_category_modids = array();
     $this->grade_category_start_dates = array();
     // The default grade decimals is 2
     $defaultdecimals = 2;
     date_default_timezone_set('Australia/Victoria');
     if (property_exists($CFG, 'grade_decimalpoints')) {
         $defaultdecimals = $CFG->grade_decimalpoints;
     }
     $this->decimals = grade_get_setting($this->courseid, 'decimalpoints', $defaultdecimals);
     // The default range decimals is 0
     $defaultrangedecimals = 0;
     if (property_exists($CFG, 'grade_report_marksheet_rangedecimals')) {
         $defaultrangedecimals = $CFG->grade_report_marksheet_rangedecimals;
     }
     $this->rangedecimals = grade_get_setting($this->courseid, 'report_marksheet_rangedecimals', $defaultrangedecimals);
     $this->switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, false, $this->switch, null, !$CFG->enableoutcomes);
     // Determine the number of rows and indentation
     $this->maxdepth = 1;
     $this->inject_rowspans($this->gtree->top_element);
     $this->maxdepth++;
     // Need to account for the lead column that spans all children
     for ($i = 1; $i <= $this->maxdepth; $i++) {
         $this->evenodd[$i] = 0;
     }
     $this->tabledata = array();
     $this->canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($this->courseid));
     // get the user (for full name)
     $this->user = $DB->get_record('user', array('id' => $userid));
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/report?id=' . $courseid . '&amp;userid=' . $userid;
     $this->pbarurl = $this->baseurl;
     // no groups on this report - rank is from all course users
     $this->setup_table();
     //optionally calculate grade item averages
     $this->calculate_averages();
     // //Set Marksheet Categoryid
     // $cat = grade_category::fetch(array('courseid'=>$this->courseid,'fullname'=>'Marksheet'));
     // if (isset($cat)) {
     //     $this->marksheet_category_id = $cat->id;
     // }else
     // {
     //     $this->marksheet_category_id = nil;
     // }
 }
Beispiel #15
0
/**
 * Add/update course gradebook setting
 * @param int $courseid
 * @param string $name of setting
 * @param string value, NULL means no setting==remove
 * @return void
 */
function grade_set_setting($courseid, $name, $value)
{
    if (is_null($value)) {
        delete_records('grade_settings', 'courseid', $courseid, 'name', addslashes($name));
    } else {
        if (!($existing = get_record('grade_settings', 'courseid', $courseid, 'name', addslashes($name)))) {
            $data = new object();
            $data->courseid = $courseid;
            $data->name = addslashes($name);
            $data->value = addslashes($value);
            insert_record('grade_settings', $data);
        } else {
            $data = new object();
            $data->id = $existing->id;
            $data->value = addslashes($value);
            update_record('grade_settings', $data);
        }
    }
    grade_get_setting($courseid, null, null, true);
    // reset the cache
}
Beispiel #16
0
 function definition()
 {
     global $CFG, $COURSE, $DB, $OUTPUT;
     $mform =& $this->_form;
     $category = $this->_customdata['current'];
     $this->aggregation_options = grade_helper::get_aggregation_strings();
     // visible elements
     $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
     $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
     $mform->setType('fullname', PARAM_TEXT);
     $mform->addRule('fullname', null, 'required', null, 'client');
     $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
     $mform->addHelpButton('aggregation', 'aggregation', 'grades');
     if ((int) $CFG->grade_aggregation_flag & 2) {
         $mform->setAdvanced('aggregation');
     }
     $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
     $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades');
     if ((int) $CFG->grade_aggregateonlygraded_flag & 2) {
         $mform->setAdvanced('aggregateonlygraded');
     }
     if (empty($CFG->enableoutcomes)) {
         $mform->addElement('hidden', 'aggregateoutcomes');
         $mform->setType('aggregateoutcomes', PARAM_INT);
     } else {
         $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
         $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades');
         if ((int) $CFG->grade_aggregateoutcomes_flag & 2) {
             $mform->setAdvanced('aggregateoutcomes');
         }
     }
     $mform->addElement('text', 'keephigh', get_string('keephigh', 'grades'), 'size="3"');
     $mform->setType('keephigh', PARAM_INT);
     $mform->addHelpButton('keephigh', 'keephigh', 'grades');
     if ((int) $CFG->grade_keephigh_flag & 2) {
         $mform->setAdvanced('keephigh');
     }
     $mform->addElement('text', 'droplow', get_string('droplow', 'grades'), 'size="3"');
     $mform->setType('droplow', PARAM_INT);
     $mform->addHelpButton('droplow', 'droplow', 'grades');
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     if ((int) $CFG->grade_droplow_flag & 2) {
         $mform->setAdvanced('droplow');
     }
     $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     // Grade item settings
     // Displayed as Category total to avoid confusion between grade items requiring marking and category totals
     $mform->addElement('header', 'general', get_string('categorytotal', 'grades'));
     $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades'));
     $mform->setType('grade_item_itemname', PARAM_TEXT);
     $mform->setAdvanced('grade_item_itemname');
     $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades'));
     $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades');
     $mform->setType('grade_item_iteminfo', PARAM_TEXT);
     $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod'));
     $mform->addHelpButton('grade_item_idnumber', 'idnumbermod');
     $mform->setType('grade_item_idnumber', PARAM_RAW);
     if (!empty($category->id)) {
         $gradecategory = grade_category::fetch(array('id' => $category->id));
         $gradeitem = $gradecategory->load_grade_item();
         // If grades exist set a message so the user knows why they can not alter the grade type or scale.
         // We could never change the grade type for external items, so only need to show this for manual grade items.
         if ($gradeitem->has_overridden_grades()) {
             // Set a message so the user knows why the can not alter the grade type or scale.
             if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
                 $gradesexistmsg = get_string('modgradecategorycantchangegradetyporscalemsg', 'grades');
             } else {
                 $gradesexistmsg = get_string('modgradecategorycantchangegradetypemsg', 'grades');
             }
             $notification = new \core\output\notification($gradesexistmsg, \core\output\notification::NOTIFY_INFO);
             $notification->set_show_closebutton(false);
             $mform->addElement('static', 'gradesexistmsg', '', $OUTPUT->render($notification));
         }
     }
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options);
     $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades');
     $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possible to use custom scale from other courses :-(
     if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $category->grade_item_scaleid))) {
             $options[$scale->id] = $scale->get_name() . ' ' . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options);
     $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades');
     $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $choices = array();
     $choices[''] = get_string('choose');
     $choices['no'] = get_string('no');
     $choices['yes'] = get_string('yes');
     $mform->addElement('select', 'grade_item_rescalegrades', get_string('modgradecategoryrescalegrades', 'grades'), $choices);
     $mform->addHelpButton('grade_item_rescalegrades', 'modgradecategoryrescalegrades', 'grades');
     $mform->disabledIf('grade_item_rescalegrades', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades'));
     $mform->setType('grade_item_grademax', PARAM_RAW);
     $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades');
     $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     if ((bool) get_config('moodle', 'grade_report_showmin')) {
         $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades'));
         $mform->setType('grade_item_grademin', PARAM_RAW);
         $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades');
         $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
         $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     }
     $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades'));
     $mform->setType('grade_item_gradepass', PARAM_RAW);
     $mform->addHelpButton('grade_item_gradepass', 'gradepass', 'grades');
     $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_TEXT);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'));
     asort($options);
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     $mform->addElement('select', 'grade_item_display', get_string('gradedisplaytype', 'grades'), $options);
     $mform->addHelpButton('grade_item_display', 'gradedisplaytype', 'grades');
     $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
     $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'grade_item_decimals', get_string('decimalpoints', 'grades'), $options);
     $mform->addHelpButton('grade_item_decimals', 'decimalpoints', 'grades');
     $mform->setDefault('grade_item_decimals', -1);
     $mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     /// hiding
     // advcheckbox is not compatible with disabledIf!
     $mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades'));
     $mform->addHelpButton('grade_item_hidden', 'hidden', 'grades');
     $mform->addElement('date_time_selector', 'grade_item_hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true));
     $mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked');
     /// locking
     $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades'));
     $mform->addHelpButton('grade_item_locked', 'locked', 'grades');
     $mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional' => true));
     $mform->disabledIf('grade_item_locktime', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
     $mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades');
     $mform->addElement('text', 'grade_item_aggregationcoef2', get_string('weight', 'grades'));
     $mform->addHelpButton('grade_item_aggregationcoef2', 'weight', 'grades');
     $mform->setType('grade_item_aggregationcoef2', PARAM_RAW);
     $mform->disabledIf('grade_item_aggregationcoef2', 'grade_item_weightoverride');
     $options = array();
     $default = -1;
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
         $options[$cat->id] = $cat->get_name();
         if ($cat->is_course_category()) {
             $default = $cat->id;
         }
     }
     if (count($categories) > 1) {
         $mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
         $mform->setDefault('parentcategory', $default);
         $mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades'));
     }
     // hidden params
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid', 0);
     $mform->setType('courseid', PARAM_INT);
     /// add return tracking info
     $gpr = $this->_customdata['gpr'];
     $gpr->add_mform_elements($mform);
     /// mark advanced according to site settings
     if (isset($CFG->grade_item_advanced)) {
         $advanced = explode(',', $CFG->grade_item_advanced);
         foreach ($advanced as $el) {
             $el = 'grade_item_' . $el;
             if ($mform->elementExists($el)) {
                 $mform->setAdvanced($el);
             }
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
     //-------------------------------------------------------------------------------
     $this->set_data($category);
 }
Beispiel #17
0
 function definition()
 {
     global $CFG, $COURSE, $DB;
     $mform =& $this->_form;
     $category = $this->_customdata['current'];
     $this->aggregation_options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'), GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'), GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
     // visible elements
     $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades'));
     $mform->addElement('text', 'fullname', get_string('categoryname', 'grades'));
     $mform->addRule('fullname', null, 'required', null, 'client');
     $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options);
     $mform->addHelpButton('aggregation', 'aggregation', 'grades');
     if ((int) $CFG->grade_aggregation_flag & 2) {
         $mform->setAdvanced('aggregation');
     }
     $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
     $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades');
     $mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     if ((int) $CFG->grade_aggregateonlygraded_flag & 2) {
         $mform->setAdvanced('aggregateonlygraded');
     }
     if (empty($CFG->enableoutcomes)) {
         $mform->addElement('hidden', 'aggregateoutcomes');
         $mform->setType('aggregateoutcomes', PARAM_INT);
     } else {
         $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
         $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades');
         if ((int) $CFG->grade_aggregateoutcomes_flag & 2) {
             $mform->setAdvanced('aggregateoutcomes');
         }
     }
     $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades'));
     $mform->addHelpButton('aggregatesubcats', 'aggregatesubcats', 'grades');
     if ((int) $CFG->grade_aggregatesubcats_flag & 2) {
         $mform->setAdvanced('aggregatesubcats');
     }
     $options = array(0 => get_string('none'));
     for ($i = 1; $i <= 20; $i++) {
         $options[$i] = $i;
     }
     $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options);
     $mform->addHelpButton('keephigh', 'keephigh', 'grades');
     if ((int) $CFG->grade_keephigh_flag & 2) {
         $mform->setAdvanced('keephigh');
     }
     $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options);
     $mform->addHelpButton('droplow', 'droplow', 'grades');
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     if ((int) $CFG->grade_droplow_flag & 2) {
         $mform->setAdvanced('droplow');
     }
     $mform->disabledIf('keephigh', 'droplow', 'noteq', 0);
     $mform->disabledIf('droplow', 'keephigh', 'noteq', 0);
     // Grade item settings
     // Displayed as Category total to avoid confusion between grade items requiring marking and category totals
     $mform->addElement('header', 'general', get_string('categorytotal', 'grades'));
     $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades'));
     $mform->setAdvanced('grade_item_itemname');
     $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades'));
     $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades');
     $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod'));
     $mform->addHelpButton('grade_item_idnumber', 'idnumbermod');
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options);
     $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades');
     $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possible to use custom scale from other courses :-(
     if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $category->grade_item_scaleid))) {
             $options[$scale->id] = $scale->get_name() . ' ' . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options);
     $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades');
     $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades'));
     $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades');
     $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades'));
     $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades');
     $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
     $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades'));
     $mform->addHelpButton('grade_item_gradepass', 'gradepass', 'grades');
     $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_TEXT);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'));
     asort($options);
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     $mform->addElement('select', 'grade_item_display', get_string('gradedisplaytype', 'grades'), $options);
     $mform->addHelpButton('grade_item_display', 'gradedisplaytype', 'grades');
     $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
     $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'grade_item_decimals', get_string('decimalpoints', 'grades'), $options);
     $mform->addHelpButton('grade_item_decimals', 'decimalpoints', 'grades');
     $mform->setDefault('grade_item_decimals', -1);
     $mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     /// hiding
     // advcheckbox is not compatible with disabledIf!
     $mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades'));
     $mform->addHelpButton('grade_item_hidden', 'hidden', 'grades');
     $mform->addElement('date_time_selector', 'grade_item_hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true));
     $mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked');
     /// locking
     $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades'));
     $mform->addHelpButton('grade_item_locked', 'locked', 'grades');
     $mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional' => true));
     $mform->disabledIf('grade_item_locktime', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $options = array();
     $default = '';
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
         $options[$cat->id] = $cat->get_name();
         if ($cat->is_course_category()) {
             $default = $cat->id;
         }
     }
     if (count($categories) > 1) {
         $mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options);
         $mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades'));
     }
     // hidden params
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid', 0);
     $mform->setType('courseid', PARAM_INT);
     /// add return tracking info
     $gpr = $this->_customdata['gpr'];
     $gpr->add_mform_elements($mform);
     /// mark advanced according to site settings
     if (isset($CFG->grade_item_advanced)) {
         $advanced = explode(',', $CFG->grade_item_advanced);
         foreach ($advanced as $el) {
             $el = 'grade_item_' . $el;
             if ($mform->elementExists($el)) {
                 $mform->setAdvanced($el);
             }
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
     //-------------------------------------------------------------------------------
     $this->set_data($category);
 }
Beispiel #18
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $userid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  */
 public function __construct($userid, $gpr, $context)
 {
     global $CFG, $COURSE, $DB;
     parent::__construct($COURSE->id, $gpr, $context);
     // Get the user (for full name).
     $this->user = $DB->get_record('user', array('id' => $userid));
     // Load the user's courses.
     $this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
     $this->showrank = array();
     $this->showrank['any'] = false;
     $this->showtotalsifcontainhidden = array();
     $this->studentcourseids = array();
     $this->teachercourses = array();
     $roleids = explode(',', get_config('moodle', 'gradebookroles'));
     if ($this->courses) {
         foreach ($this->courses as $course) {
             $this->showrank[$course->id] = grade_get_setting($course->id, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
             if ($this->showrank[$course->id]) {
                 $this->showrank['any'] = true;
             }
             $this->showtotalsifcontainhidden[$course->id] = grade_get_setting($course->id, 'report_overview_showtotalsifcontainhidden', $CFG->grade_report_overview_showtotalsifcontainhidden);
             $coursecontext = context_course::instance($course->id);
             foreach ($roleids as $roleid) {
                 if (user_has_role_assignment($userid, $roleid, $coursecontext->id)) {
                     $this->studentcourseids[$course->id] = $course->id;
                     // We only need to check if one of the roleids has been assigned.
                     break;
                 }
             }
             if (has_capability('moodle/grade:viewall', $coursecontext, $userid)) {
                 $this->teachercourses[$course->id] = $course;
             }
         }
     }
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/overview/index.php?id=' . $userid;
     $this->pbarurl = $this->baseurl;
     $this->setup_table();
 }
 function definition()
 {
     global $CFG, $COURSE, $USER, $DB;
     $mform =& $this->_form;
     if (isset($this->_customdata)) {
         // hardcoding plugin names here is hacky
         $features = $this->_customdata;
     } else {
         $features = array();
     }
     $mform->addElement('header', 'options', get_string('options', 'grades'));
     $mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
     $mform->setDefault('export_feedback', 0);
     $coursecontext = context_course::instance($COURSE->id);
     if (has_capability('moodle/course:viewsuspendedusers', $coursecontext)) {
         $mform->addElement('advcheckbox', 'export_onlyactive', get_string('exportonlyactive', 'grades'));
         $mform->setType('export_onlyactive', PARAM_BOOL);
         $mform->setDefault('export_onlyactive', 1);
         $mform->addHelpButton('export_onlyactive', 'exportonlyactive', 'grades');
     } else {
         $mform->addElement('hidden', 'export_onlyactive', 1);
         $mform->setType('export_onlyactive', PARAM_BOOL);
         $mform->setConstant('export_onlyactive', 1);
     }
     $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
     if (!empty($features['updategradesonly'])) {
         $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
     }
     /// selections for decimal points and format, MDL-11667, defaults to site settings, if set
     //$default_gradedisplaytype = $CFG->grade_export_displaytype;
     $options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
     /*
     foreach ($options as $key=>$option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     */
     $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
     $mform->setDefault('display', $CFG->grade_export_displaytype);
     //$default_gradedecimals = $CFG->grade_export_decimalpoints;
     $options = array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
     $mform->setDefault('decimals', $CFG->grade_export_decimalpoints);
     $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     /*
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     */
     if (!empty($features['includeseparator'])) {
         $radio = array();
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
         $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
         $mform->setDefault('separator', 'comma');
     }
     if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
         $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
         $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
         $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?", array($COURSE->id, $USER->id));
         if ($keys) {
             foreach ($keys as $key) {
                 $options[$key->value] = $key->value;
                 // TODO: add more details - ip restriction, valid until ??
             }
         }
         $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
         $mform->addHelpButton('key', 'userkey', 'userkey');
         $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'), '<a href="' . $CFG->wwwroot . '/grade/export/keymanager.php?id=' . $COURSE->id . '">' . get_string('keymanager', 'userkey') . '</a>');
         $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size' => 80));
         $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
         $mform->setDefault('iprestriction', getremoteaddr());
         // own IP - just in case somebody does not know what user key is
         $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional' => true));
         $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
         $mform->setDefault('validuntil', time() + 3600 * 24 * 7);
         // only 1 week default duration - just in case somebody does not know what user key is
         $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
         $mform->disabledIf('validuntil', 'key', 'noteq', 1);
     }
     $mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
     $switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
     // Grab the grade_seq for this course
     $gseq = new grade_seq($COURSE->id, $switch);
     if ($grade_items = $gseq->items) {
         $needs_multiselect = false;
         $canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
         foreach ($grade_items as $grade_item) {
             // Is the grade_item hidden? If so, can the user see hidden grade_items?
             if ($grade_item->is_hidden() && !$canviewhidden) {
                 continue;
             }
             if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
                 $mform->addElement('advcheckbox', 'itemids[' . $grade_item->id . ']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
                 $mform->hardFreeze('itemids[' . $grade_item->id . ']');
             } else {
                 $mform->addElement('advcheckbox', 'itemids[' . $grade_item->id . ']', $grade_item->get_name(), null, array('group' => 1));
                 $mform->setDefault('itemids[' . $grade_item->id . ']', 1);
                 $needs_multiselect = true;
             }
         }
         if ($needs_multiselect) {
             $this->add_checkbox_controller(1, null, null, 1);
             // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
         }
     }
     $mform->addElement('hidden', 'id', $COURSE->id);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(false, get_string('submit'));
 }
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $page The current page being viewed (when report is paged)
  * @param int $sortitemid The id of the grade_item by which to sort the table
  */
 function grade_report_laegrader($courseid, $gpr, $context, $page = null, $sortitemid = null)
 {
     global $CFG;
     parent::grade_report($courseid, $gpr, $context, $page);
     $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
     $this->accuratetotals = ($temp = grade_get_setting($this->courseid, 'report_laegrader_accuratetotals', $CFG->grade_report_laegrader_accuratetotals)) ? $temp : 0;
     // need this array, even tho its useless in the laegrader report or we'll generate warnings
     $this->collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
     if (empty($CFG->enableoutcomes)) {
         $nooutcomes = false;
     } else {
         $nooutcomes = get_user_preferences('grade_report_shownooutcomes');
     }
     // force category_last to true
     $switch = true;
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, false, $switch, null, $nooutcomes);
     // Fill items with parent information needed later
     $this->gtree->parents = array();
     fill_parents($this->gtree->parents, $this->gtree->items, $this->gtree->top_element, $this->gtree->top_element['object']->grade_item->id, $this->accuratetotals);
     //        fill_parents($this->gtree->items, $this->gtree->top_element,$this->gtree->top_element['object']->id,$this->gtree->top_element['object']->aggregation);
     $this->sortitemid = $sortitemid;
     // base url for sorting by first/last name
     $studentsperpage = 0;
     //$this->get_pref('studentsperpage');
     $perpage = '';
     $curpage = '';
     $this->baseurl = 'index.php?id=' . $this->courseid . $perpage . $curpage . '&amp;';
     $this->pbarurl = 'index.php?id=' . $this->courseid . $perpage . '&amp;';
     $this->setup_groups();
     $this->setup_sortitemid();
 }
Beispiel #21
0
 function definition()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $item = $this->_customdata['current'];
     /// visible elements
     $mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
     $mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
     $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
     $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true);
     $mform->addElement('text', 'idnumber', get_string('idnumbermod'));
     $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true);
     $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades'));
     $mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
     $mform->setHelpButton('gradetype', array('gradetype', get_string('gradetype', 'grades'), 'grade'), true);
     $mform->setDefault('gradetype', GRADE_TYPE_VALUE);
     //$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $options = array(0 => get_string('usenoscale', 'grades'));
     if ($scales = grade_scale::fetch_all_local($COURSE->id)) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     if ($scales = grade_scale::fetch_all_global()) {
         foreach ($scales as $scale) {
             $options[$scale->id] = $scale->get_name();
         }
     }
     // ugly BC hack - it was possbile to use custom scale from other courses :-(
     if (!empty($item->scaleid) and !isset($options[$item->scaleid])) {
         if ($scale = grade_scale::fetch(array('id' => $item->scaleid))) {
             $options[$scale->id] = $scale->get_name() . get_string('incorrectcustomscale', 'grades');
         }
     }
     $mform->addElement('select', 'scaleid', get_string('scale'), $options);
     $mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true);
     $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
     $mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
     $mform->setHelpButton('grademax', array('grademax', get_string('grademax', 'grades'), 'grade'), true);
     $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'grademin', get_string('grademin', 'grades'));
     $mform->setHelpButton('grademin', array('grademin', get_string('grademin', 'grades'), 'grade'), true);
     $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
     $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
     $mform->setHelpButton('gradepass', array('gradepass', get_string('gradepass', 'grades'), 'grade'), true);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades'));
     $mform->setHelpButton('multfactor', array('multfactor', get_string('multfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('multfactor');
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades'));
     $mform->setHelpButton('plusfactor', array('plusfactor', get_string('plusfactor', 'grades'), 'grade'), true);
     $mform->setAdvanced('plusfactor');
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
     $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
     /// grade display prefs
     $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
     $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades'));
     asort($options);
     foreach ($options as $key => $option) {
         if ($key == $default_gradedisplaytype) {
             $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
             break;
         }
     }
     $mform->addElement('select', 'display', get_string('gradedisplaytype', 'grades'), $options);
     $mform->setHelpButton('display', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'), true);
     $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints);
     $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
     $mform->addElement('select', 'decimals', get_string('decimalpoints', 'grades'), $options);
     $mform->setHelpButton('decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true);
     $mform->setDefault('decimals', -1);
     $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
     if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
         $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
     }
     /// hiding
     // advcheckbox is not compatible with disabledIf!
     $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
     $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true));
     $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
     $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
     /// locking
     $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
     $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
     $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true));
     $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade'));
     $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
     /// parent category related settings
     $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
     $options = array();
     $coefstring = '';
     $categories = grade_category::fetch_all(array('courseid' => $COURSE->id));
     foreach ($categories as $cat) {
         $cat->apply_forced_settings();
         $options[$cat->id] = $cat->get_name();
     }
     if (count($categories) > 1) {
         $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
     }
     /// hidden params
     $mform->addElement('hidden', 'id', 0);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid', $COURSE->id);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'itemtype', 'manual');
     // all new items are manual only
     $mform->setType('itemtype', PARAM_ALPHA);
     /// add return tracking info
     $gpr = $this->_customdata['gpr'];
     $gpr->add_mform_elements($mform);
     /// mark advanced according to site settings
     if (isset($CFG->grade_item_advanced)) {
         $advanced = explode(',', $CFG->grade_item_advanced);
         foreach ($advanced as $el) {
             if ($mform->elementExists($el)) {
                 $mform->setAdvanced($el);
             }
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
     //-------------------------------------------------------------------------------
     $this->set_data($item);
 }
Beispiel #22
0
 /**
  * Constructor. Sets local copies of user preferences and initialises grade_tree.
  * @param int $courseid
  * @param object $gpr grade plugin return tracking object
  * @param string $context
  * @param int $userid The id of the user
  * @param bool $viewasuser Set this to true when the current user is a mentor/parent of the targetted user.
  */
 public function __construct($courseid, $gpr, $context, $userid, $viewasuser = null)
 {
     global $DB, $CFG;
     parent::__construct($courseid, $gpr, $context);
     $this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank);
     $this->showpercentage = grade_get_setting($this->courseid, 'report_user_showpercentage', $CFG->grade_report_user_showpercentage);
     $this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems);
     $this->showtotalsifcontainhidden = array($this->courseid => grade_get_setting($this->courseid, 'report_user_showtotalsifcontainhidden', $CFG->grade_report_user_showtotalsifcontainhidden));
     $this->showgrade = grade_get_setting($this->courseid, 'report_user_showgrade', !empty($CFG->grade_report_user_showgrade));
     $this->showrange = grade_get_setting($this->courseid, 'report_user_showrange', !empty($CFG->grade_report_user_showrange));
     $this->showfeedback = grade_get_setting($this->courseid, 'report_user_showfeedback', !empty($CFG->grade_report_user_showfeedback));
     $this->showweight = grade_get_setting($this->courseid, 'report_user_showweight', !empty($CFG->grade_report_user_showweight));
     $this->showlettergrade = grade_get_setting($this->courseid, 'report_user_showlettergrade', !empty($CFG->grade_report_user_showlettergrade));
     $this->showaverage = grade_get_setting($this->courseid, 'report_user_showaverage', !empty($CFG->grade_report_user_showaverage));
     $this->viewasuser = $viewasuser;
     // The default grade decimals is 2
     $defaultdecimals = 2;
     if (property_exists($CFG, 'grade_decimalpoints')) {
         $defaultdecimals = $CFG->grade_decimalpoints;
     }
     $this->decimals = grade_get_setting($this->courseid, 'decimalpoints', $defaultdecimals);
     // The default range decimals is 0
     $defaultrangedecimals = 0;
     if (property_exists($CFG, 'grade_report_user_rangedecimals')) {
         $defaultrangedecimals = $CFG->grade_report_user_rangedecimals;
     }
     $this->rangedecimals = grade_get_setting($this->courseid, 'report_user_rangedecimals', $defaultrangedecimals);
     $this->switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
     // Grab the grade_tree for this course
     $this->gtree = new grade_tree($this->courseid, false, $this->switch, null, !$CFG->enableoutcomes);
     // Get the user (for full name).
     $this->user = $DB->get_record('user', array('id' => $userid));
     // What user are we viewing this as?
     $coursecontext = context_course::instance($this->courseid);
     if ($viewasuser) {
         $this->modinfo = new course_modinfo($this->course, $this->user->id);
         $this->canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext, $this->user->id);
     } else {
         $this->modinfo = $this->gtree->modinfo;
         $this->canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
     }
     // Determine the number of rows and indentation.
     $this->maxdepth = 1;
     $this->inject_rowspans($this->gtree->top_element);
     $this->maxdepth++;
     // Need to account for the lead column that spans all children.
     for ($i = 1; $i <= $this->maxdepth; $i++) {
         $this->evenodd[$i] = 0;
     }
     $this->tabledata = array();
     // base url for sorting by first/last name
     $this->baseurl = $CFG->wwwroot . '/grade/report?id=' . $courseid . '&amp;userid=' . $userid;
     $this->pbarurl = $this->baseurl;
     // no groups on this report - rank is from all course users
     $this->setup_table();
     //optionally calculate grade item averages
     $this->calculate_averages();
 }
Beispiel #23
0
/**
 * Print warning about changed grades during upgrade to 2.8.
 *
 * @param int $courseid The current course id.
 * @param context $context The course context.
 * @param string $thispage The relative path for the current page. E.g. /grade/report/user/index.php
 * @param boolean $return return as string
 *
 * @return nothing or string if $return true
 */
function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage, $return = false)
{
    global $CFG, $OUTPUT;
    $html = '';
    // Do not do anything if they cannot manage the grades of this course.
    if (!has_capability('moodle/grade:manage', $context)) {
        return $html;
    }
    $hidesubcatswarning = optional_param('seenaggregatesubcatsupgradedgrades', false, PARAM_BOOL) && confirm_sesskey();
    $showsubcatswarning = get_config('core', 'show_aggregatesubcats_upgrade_' . $courseid);
    $hidenaturalwarning = optional_param('seensumofgradesupgradedgrades', false, PARAM_BOOL) && confirm_sesskey();
    $shownaturalwarning = get_config('core', 'show_sumofgrades_upgrade_' . $courseid);
    $hideminmaxwarning = optional_param('seenminmaxupgradedgrades', false, PARAM_BOOL) && confirm_sesskey();
    $showminmaxwarning = get_config('core', 'show_min_max_grades_changed_' . $courseid);
    $useminmaxfromgradeitem = optional_param('useminmaxfromgradeitem', false, PARAM_BOOL) && confirm_sesskey();
    $useminmaxfromgradegrade = optional_param('useminmaxfromgradegrade', false, PARAM_BOOL) && confirm_sesskey();
    $minmaxtouse = grade_get_setting($courseid, 'minmaxtouse', $CFG->grade_minmaxtouse);
    $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $courseid);
    $acceptgradebookchanges = optional_param('acceptgradebookchanges', false, PARAM_BOOL) && confirm_sesskey();
    // Hide the warning if the user told it to go away.
    if ($hidenaturalwarning) {
        hide_natural_aggregation_upgrade_notice($courseid);
    }
    // Hide the warning if the user told it to go away.
    if ($hidesubcatswarning) {
        hide_aggregatesubcats_upgrade_notice($courseid);
    }
    // Hide the min/max warning if the user told it to go away.
    if ($hideminmaxwarning) {
        grade_hide_min_max_grade_upgrade_notice($courseid);
        $showminmaxwarning = false;
    }
    if ($useminmaxfromgradegrade) {
        // Revert to the new behaviour, we now use the grade_grade for min/max.
        grade_upgrade_use_min_max_from_grade_grade($courseid);
        grade_hide_min_max_grade_upgrade_notice($courseid);
        $showminmaxwarning = false;
    } else {
        if ($useminmaxfromgradeitem) {
            // Apply the new logic, we now use the grade_item for min/max.
            grade_upgrade_use_min_max_from_grade_item($courseid);
            grade_hide_min_max_grade_upgrade_notice($courseid);
            $showminmaxwarning = false;
        }
    }
    if (!$hidenaturalwarning && $shownaturalwarning) {
        $message = get_string('sumofgradesupgradedgrades', 'grades');
        $hidemessage = get_string('upgradedgradeshidemessage', 'grades');
        $urlparams = array('id' => $courseid, 'seensumofgradesupgradedgrades' => true, 'sesskey' => sesskey());
        $goawayurl = new moodle_url($thispage, $urlparams);
        $goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get');
        $html .= $OUTPUT->notification($message, 'notifysuccess');
        $html .= $goawaybutton;
    }
    if (!$hidesubcatswarning && $showsubcatswarning) {
        $message = get_string('aggregatesubcatsupgradedgrades', 'grades');
        $hidemessage = get_string('upgradedgradeshidemessage', 'grades');
        $urlparams = array('id' => $courseid, 'seenaggregatesubcatsupgradedgrades' => true, 'sesskey' => sesskey());
        $goawayurl = new moodle_url($thispage, $urlparams);
        $goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get');
        $html .= $OUTPUT->notification($message, 'notifysuccess');
        $html .= $goawaybutton;
    }
    if ($showminmaxwarning) {
        $hidemessage = get_string('upgradedgradeshidemessage', 'grades');
        $urlparams = array('id' => $courseid, 'seenminmaxupgradedgrades' => true, 'sesskey' => sesskey());
        $goawayurl = new moodle_url($thispage, $urlparams);
        $hideminmaxbutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get');
        $moreinfo = html_writer::link(get_docs_url(get_string('minmaxtouse_link', 'grades')), get_string('moreinfo'), array('target' => '_blank'));
        if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_ITEM) {
            // Show the message that there were min/max issues that have been resolved.
            $message = get_string('minmaxupgradedgrades', 'grades') . ' ' . $moreinfo;
            $revertmessage = get_string('upgradedminmaxrevertmessage', 'grades');
            $urlparams = array('id' => $courseid, 'useminmaxfromgradegrade' => true, 'sesskey' => sesskey());
            $reverturl = new moodle_url($thispage, $urlparams);
            $revertbutton = $OUTPUT->single_button($reverturl, $revertmessage, 'get');
            $html .= $OUTPUT->notification($message);
            $html .= $revertbutton . $hideminmaxbutton;
        } else {
            if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) {
                // Show the warning that there are min/max issues that have not be resolved.
                $message = get_string('minmaxupgradewarning', 'grades') . ' ' . $moreinfo;
                $fixmessage = get_string('minmaxupgradefixbutton', 'grades');
                $urlparams = array('id' => $courseid, 'useminmaxfromgradeitem' => true, 'sesskey' => sesskey());
                $fixurl = new moodle_url($thispage, $urlparams);
                $fixbutton = $OUTPUT->single_button($fixurl, $fixmessage, 'get');
                $html .= $OUTPUT->notification($message);
                $html .= $fixbutton . $hideminmaxbutton;
            }
        }
    }
    if ($gradebookcalculationsfreeze) {
        if ($acceptgradebookchanges) {
            // Accept potential changes in grades caused by extra credit bug MDL-49257.
            hide_gradebook_calculations_freeze_notice($courseid);
            $courseitem = grade_item::fetch_course_item($courseid);
            $courseitem->force_regrading();
            grade_regrade_final_grades($courseid);
            $html .= $OUTPUT->notification(get_string('gradebookcalculationsuptodate', 'grades'), 'notifysuccess');
        } else {
            // Show the warning that there may be extra credit weights problems.
            $a = new stdClass();
            $a->gradebookversion = $gradebookcalculationsfreeze;
            if (preg_match('/(\\d{8,})/', $CFG->release, $matches)) {
                $a->currentversion = $matches[1];
            } else {
                $a->currentversion = $CFG->release;
            }
            $a->url = get_docs_url('Gradebook_calculation_changes');
            $message = get_string('gradebookcalculationswarning', 'grades', $a);
            $fixmessage = get_string('gradebookcalculationsfixbutton', 'grades');
            $urlparams = array('id' => $courseid, 'acceptgradebookchanges' => true, 'sesskey' => sesskey());
            $fixurl = new moodle_url($thispage, $urlparams);
            $fixbutton = $OUTPUT->single_button($fixurl, $fixmessage, 'get');
            $html .= $OUTPUT->notification($message);
            $html .= $fixbutton;
        }
    }
    if (!empty($html)) {
        $html = html_writer::tag('div', $html, array('class' => 'core_grades_notices'));
    }
    if ($return) {
        return $html;
    } else {
        echo $html;
    }
}
 /**
  * Return criteria progress details for display in reports
  *
  * @param completion_completion $completion The user's completion record
  * @return array An array with the following keys:
  *     type, criteria, requirement, status
  */
 public function get_details($completion)
 {
     global $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     $decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);
     $details = array();
     $details['type'] = get_string('coursegrade', 'completion');
     $details['criteria'] = get_string('graderequired', 'completion');
     $details['requirement'] = format_float($this->gradepass, $decimalpoints);
     $details['status'] = '';
     $grade = format_float($this->get_grade($completion), $decimalpoints);
     if ($grade) {
         $details['status'] = $grade;
     }
     return $details;
 }
Beispiel #25
0
 /**
  * Recursive function for building the table holding the grade categories and items,
  * with CSS indentation and styles.
  *
  * @param array   $element The current tree element being rendered
  * @param boolean $totals Whether or not to print category grade items (category totals)
  * @param array   $parents An array of parent categories for the current element (used for indentation and row classes)
  *
  * @return string HTML
  */
 public function build_html_tree($element, $totals, $parents, $level, &$row_count)
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $object = $element['object'];
     $eid = $element['eid'];
     $object->name = $this->gtree->get_element_header($element, true, true, true, true, true);
     $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
     $is_category_item = false;
     if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
         $is_category_item = true;
     }
     $rowclasses = array();
     foreach ($parents as $parent_eid) {
         $rowclasses[] = $parent_eid;
     }
     $moveaction = '';
     $actionsmenu = new action_menu();
     $actionsmenu->set_menu_trigger(get_string('edit'));
     $actionsmenu->set_owner_selector('grade-item-' . $eid);
     $actionsmenu->set_alignment(action_menu::TL, action_menu::BL);
     if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
         $actionsmenu->add($icon);
     }
     // MDL-49281 if grade_item already has calculation, it should be editable even if global setting is off.
     $type = $element['type'];
     $iscalculated = ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') && $object->is_calculated();
     $icon = $this->gtree->get_calculation_icon($element, $this->gpr, true);
     if ($iscalculated || $this->show_calculations && $icon) {
         $actionsmenu->add($icon);
     }
     if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
         if ($this->element_deletable($element)) {
             $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
             $icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
             $actionsmenu->add($icon);
         }
         $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
         $moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
     }
     if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     $actions = $OUTPUT->render($actionsmenu);
     $returnrows = array();
     $root = false;
     $id = required_param('id', PARAM_INT);
     /// prepare move target if needed
     $last = '';
     /// print the list items now
     if ($this->moving == $eid) {
         // do not diplay children
         $cell = new html_table_cell();
         $cell->colspan = 12;
         $cell->attributes['class'] = $element['type'] . ' moving column-name level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
         $cell->text = $object->name . ' (' . get_string('move') . ')';
         return array(new html_table_row(array($cell)));
     }
     if ($element['type'] == 'category') {
         $level++;
         $this->categories[$object->id] = $object->stripped_name;
         $category = grade_category::fetch(array('id' => $object->id));
         $item = $category->get_grade_item();
         // Add aggregation coef input if not a course item and if parent category has correct aggregation type
         $dimmed = $item->is_hidden() ? 'dimmed_text' : '';
         // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
         $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
         $category_total_data = null;
         // Used if aggregationposition is set to "last", so we can print it last
         $html_children = array();
         $row_count = 0;
         foreach ($element['children'] as $child_el) {
             $moveto = null;
             if (empty($child_el['object']->itemtype)) {
                 $child_el['object']->itemtype = false;
             }
             if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
                 continue;
             }
             $child_eid = $child_el['eid'];
             $first = '';
             if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 $first = array('first' => 1);
                 $child_eid = $eid;
             }
             if ($this->moving && $this->moving != $child_eid) {
                 $strmove = get_string('move');
                 $strmovehere = get_string('movehere');
                 $actions = $moveaction = '';
                 // no action icons when moving
                 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
                 if ($first) {
                     $aurl->params($first);
                 }
                 $cell = new html_table_cell();
                 $cell->colspan = 12;
                 $cell->attributes['class'] = 'movehere level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
                 $icon = new pix_icon('movehere', $strmovehere, null, array('class' => 'movetarget'));
                 $cell->text = $OUTPUT->action_icon($aurl, $icon);
                 $moveto = new html_table_row(array($cell));
             }
             $newparents = $parents;
             $newparents[] = $eid;
             $row_count++;
             $child_row_count = 0;
             // If moving, do not print course and category totals, but still print the moveto target box
             if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
                 $html_children[] = $moveto;
             } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
                 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count);
                 if (!$aggregation_position) {
                     $html_children = array_merge($html_children, $category_total_item);
                 }
             } else {
                 $html_children = array_merge($html_children, $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count));
                 if (!empty($moveto)) {
                     $html_children[] = $moveto;
                 }
                 if ($this->moving) {
                     $row_count++;
                 }
             }
             $row_count += $child_row_count;
             // If the child is a category, increment row_count by one more (for the extra coloured row)
             if ($child_el['type'] == 'category') {
                 $row_count++;
             }
         }
         // Print category total at the end if aggregation position is "last" (1)
         if (!empty($category_total_item) && $aggregation_position) {
             $html_children = array_merge($html_children, $category_total_item);
         }
         // Determine if we are at the root
         if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) {
             $root = true;
         }
         $levelclass = "level{$level} level" . ($level % 2 ? 'odd' : 'even');
         $courseclass = '';
         if ($level == 1) {
             $courseclass = 'coursecategory';
         }
         $row = new html_table_row();
         $row->id = 'grade-item-' . $eid;
         $row->attributes['class'] = $courseclass . ' category ' . $dimmed;
         $row->attributes['data-category'] = $eid;
         $row->attributes['data-itemid'] = $category->get_grade_item()->id;
         foreach ($rowclasses as $class) {
             $row->attributes['class'] .= ' ' . $class;
         }
         $headercell = new html_table_cell();
         $headercell->header = true;
         $headercell->scope = 'row';
         $headercell->attributes['title'] = $object->stripped_name;
         $headercell->attributes['class'] = 'cell column-rowspan rowspan ' . $levelclass;
         $headercell->rowspan = $row_count + 1;
         $row->cells[] = $headercell;
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $row->cells[] = $column->get_category_cell($category, $levelclass, ['id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'moveaction' => $moveaction, 'eid' => $eid]);
             }
         }
         $returnrows[] = $row;
         $returnrows = array_merge($returnrows, $html_children);
         // Print a coloured row to show the end of the category across the table
         $endcell = new html_table_cell();
         $endcell->colspan = 19 - $level;
         $endcell->attributes['class'] = 'emptyrow colspan ' . $levelclass;
         $returnrows[] = new html_table_row(array($endcell));
     } else {
         // Dealing with a grade item
         $item = grade_item::fetch(array('id' => $object->id));
         $element['type'] = 'item';
         $element['object'] = $item;
         $categoryitemclass = '';
         if ($item->itemtype == 'category') {
             $categoryitemclass = 'categoryitem';
         }
         if ($item->itemtype == 'course') {
             $categoryitemclass = 'courseitem';
         }
         $dimmed = $item->is_hidden() ? "dimmed_text" : "";
         $gradeitemrow = new html_table_row();
         $gradeitemrow->id = 'grade-item-' . $eid;
         $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
         $gradeitemrow->attributes['data-itemid'] = $object->id;
         foreach ($rowclasses as $class) {
             $gradeitemrow->attributes['class'] .= ' ' . $class;
         }
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'element' => $element, 'eid' => $eid, 'moveaction' => $moveaction, 'itemtype' => $object->itemtype));
             }
         }
         $returnrows[] = $gradeitemrow;
     }
     return $returnrows;
 }
Beispiel #26
0
 /**
  * Returns the minimum and maximum number of points this grade is graded with respect to.
  *
  * @since  Moodle 2.8.7, 2.9.1
  * @return array A list containing, in order, the minimum and maximum number of points.
  */
 protected function get_grade_min_and_max()
 {
     global $CFG;
     $this->load_grade_item();
     // When the following setting is turned on we use the grade_grade raw min and max values.
     $minmaxtouse = grade_get_setting($this->grade_item->courseid, 'minmaxtouse', $CFG->grade_minmaxtouse);
     // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
     // wish to update the grades.
     $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->grade_item->courseid);
     // Gradebook is frozen, run through old code.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Only aggregate items use separate min grades.
         if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE || $this->grade_item->is_aggregate_item()) {
             return array($this->rawgrademin, $this->rawgrademax);
         } else {
             return array($this->grade_item->grademin, $this->grade_item->grademax);
         }
     } else {
         // Only aggregate items use separate min grades, unless they are calculated grade items.
         if ($this->grade_item->is_aggregate_item() && !$this->grade_item->is_calculated() || $minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) {
             return array($this->rawgrademin, $this->rawgrademax);
         } else {
             return array($this->grade_item->grademin, $this->grade_item->grademax);
         }
     }
 }
Beispiel #27
0
function construct_local_full_user_stat_html_table($attendance, $course, $user) {
    global $CFG;
    $gradeable = $attendance->grade > 0;
    $statuses = local_att_get_statuses($attendance->id);
    $userstatusesstat = local_att_get_user_statuses_stat($attendance->id, $course->startdate, $user->id);
    $stat['completed'] = local_att_get_user_taken_sessions_count($attendance->id, $course->startdate, $user->id);
    $stat['statuses'] = $userstatusesstat;
    if ($gradeable) {
        $grade = local_att_get_user_grade($userstatusesstat, $statuses);
        $maxgrade = local_att_get_user_max_grade(local_att_get_user_taken_sessions_count($attendance->id, $course->startdate,
                                                                             $user->id), $statuses);
        if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
            $decimalpoints = $CFG->grade_decimalpoints;
        }
    } else {
        $grade = 0;
        $maxgrade = 0;
        $decimalpoints = 0;
    }

    return construct_user_data_stat($stat, $statuses,
                $gradeable, $grade, $maxgrade, $decimalpoints);
}
Beispiel #28
0
 function definition()
 {
     global $USER, $CFG;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $context = context_course::instance($course->id);
     $canviewhidden = has_capability('moodle/grade:viewhidden', $context);
     $checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', 0 => get_string('no'), 1 => get_string('yes'));
     $advanced = array();
     /// form definition with preferences defaults
     //--------------------------------------------------------------------------------
     $preferences = array();
     // Initialise the preferences arrays with grade:manage capabilities
     if (has_capability('moodle/grade:manage', $context)) {
         $preferences['prefshow'] = array();
         $preferences['prefshow']['showcalculations'] = $checkbox_default;
         $preferences['prefshow']['showeyecons'] = $checkbox_default;
         if ($canviewhidden) {
             $preferences['prefshow']['showaverages'] = $checkbox_default;
         }
         $preferences['prefshow']['showlocks'] = $checkbox_default;
         $preferences['prefrows'] = array('rangesdisplaytype' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')), 'rangesdecimalpoints' => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5));
         $advanced = array_merge($advanced, array('rangesdisplaytype', 'rangesdecimalpoints'));
         if ($canviewhidden) {
             $preferences['prefrows']['averagesdisplaytype'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
             $preferences['prefrows']['averagesdecimalpoints'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
             $preferences['prefrows']['meanselection'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'), GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades'));
             $advanced = array_merge($advanced, array('averagesdisplaytype', 'averagesdecimalpoints'));
         }
     }
     // quickgrading and showquickfeedback are conditional on grade:edit capability
     if (has_capability('moodle/grade:edit', $context)) {
         $preferences['prefgeneral']['quickgrading'] = $checkbox_default;
         $preferences['prefgeneral']['showquickfeedback'] = $checkbox_default;
     }
     // View capability is the lowest permission. Users with grade:manage or grade:edit must also have grader:view
     if (has_capability('gradereport/grader:view', $context)) {
         $preferences['prefgeneral']['studentsperpage'] = 'text';
         $preferences['prefgeneral']['aggregationposition'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'), GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
         $preferences['prefgeneral']['enableajax'] = $checkbox_default;
         $preferences['prefshow']['showuserimage'] = $checkbox_default;
         $preferences['prefshow']['showactivityicons'] = $checkbox_default;
         $preferences['prefshow']['showranges'] = $checkbox_default;
         $preferences['prefshow']['showanalysisicon'] = $checkbox_default;
         if ($canviewhidden) {
             $preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
         }
         $advanced = array_merge($advanced, array('aggregationposition'));
     }
     foreach ($preferences as $group => $prefs) {
         $mform->addElement('header', $group, get_string($group, 'grades'));
         foreach ($prefs as $pref => $type) {
             // Detect and process dynamically numbered preferences
             if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
                 $lang_string = $matches[1];
                 $number = ' ' . $matches[2];
             } else {
                 $lang_string = $pref;
                 $number = null;
             }
             $full_pref = 'grade_report_' . $pref;
             $pref_value = get_user_preferences($full_pref);
             $options = null;
             if (is_array($type)) {
                 $options = $type;
                 $type = 'select';
                 // MDL-11478
                 // get default aggregationposition from grade_settings
                 $course_value = null;
                 if (!empty($CFG->{$full_pref})) {
                     $course_value = grade_get_setting($course->id, $pref, $CFG->{$full_pref});
                 }
                 if ($pref == 'aggregationposition') {
                     if (!empty($options[$course_value])) {
                         $default = $options[$course_value];
                     } else {
                         $default = $options[$CFG->grade_aggregationposition];
                     }
                 } elseif (isset($options[$CFG->{$full_pref}])) {
                     $default = $options[$CFG->{$full_pref}];
                 } else {
                     $default = '';
                 }
             } else {
                 $default = $CFG->{$full_pref};
             }
             // Replace the '*default*' value with the site default language string - 'default' might collide with custom language packs
             if (!is_null($options) and isset($options[GRADE_REPORT_PREFERENCE_DEFAULT]) && $options[GRADE_REPORT_PREFERENCE_DEFAULT] == '*default*') {
                 $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('reportdefault', 'grades', $default);
             }
             $label = get_string($lang_string, 'grades') . $number;
             $mform->addElement($type, $full_pref, $label, $options);
             if ($lang_string != 'showuserimage') {
                 $mform->addHelpButton($full_pref, $lang_string, 'grades');
             }
             $mform->setDefault($full_pref, $pref_value);
             $mform->setType($full_pref, PARAM_ALPHANUM);
         }
     }
     foreach ($advanced as $name) {
         $mform->setAdvanced('grade_report_' . $name);
     }
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->setDefault('id', $course->id);
     $this->add_action_buttons();
 }
Beispiel #29
0
if (array_diff($originalweights, $alteredweights)) {
    $normalisationmessage = get_string('weightsadjusted', 'grades');
}
// get the grading tree object
// note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
$gtree = new grade_tree($courseid, false, false);
if (empty($eid)) {
    $element = null;
    $object = null;
} else {
    if (!($element = $gtree->locate_element($eid))) {
        print_error('invalidelementid', '', $returnurl);
    }
    $object = $element['object'];
}
$switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition);
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
$moving = false;
$movingeid = false;
if ($action == 'moveselect') {
    if ($eid and confirm_sesskey()) {
        $movingeid = $eid;
        $moving = true;
    }
}
$grade_edit_tree = new grade_edit_tree($gtree, $movingeid, $gpr);
switch ($action) {
    case 'delete':
        if ($eid && confirm_sesskey()) {
            if (!$grade_edit_tree->element_deletable($element)) {
 public function __construct(attendance $att)
 {
     global $CFG;
     $this->perm = $att->perm;
     $this->pageparams = $att->pageparams;
     $this->users = $att->get_users($att->pageparams->group, $att->pageparams->page);
     $this->groups = groups_get_all_groups($att->course->id);
     $this->sessions = $att->get_filtered_sessions();
     $this->statuses = $att->get_statuses();
     $this->allstatuses = $att->get_statuses(false);
     $this->gradable = $att->grade > 0;
     if (!($this->decimalpoints = grade_get_setting($att->course->id, 'decimalpoints'))) {
         $this->decimalpoints = $CFG->grade_decimalpoints;
     }
     foreach ($this->users as $user) {
         $this->usersgroups[$user->id] = groups_get_all_groups($att->course->id, $user->id);
         $this->sessionslog[$user->id] = $att->get_user_filtered_sessions_log($user->id);
         $this->usersstats[$user->id] = $att->get_user_statuses_stat($user->id);
         if ($this->gradable) {
             $this->grades[$user->id] = $att->get_user_grade($user->id);
             $this->maxgrades[$user->id] = $att->get_user_max_grade($user->id);
         }
     }
     $this->att = $att;
 }