本文整理汇总了PHP中grade_tree类的典型用法代码示例。如果您正苦于以下问题:PHP grade_tree类的具体用法?PHP grade_tree怎么用?PHP grade_tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了grade_tree类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: grade_regrade_final_grades
$data->aggregation = $aggregationtype;
grade_category::set_properties($grade_category, $data);
$grade_category->update();
grade_regrade_final_grades($courseid);
}
//first make sure we have proper final grades - we need it for locking changes
$normalisationmessage = null;
$originalweights = grade_helper::fetch_all_natural_weights_for_course($courseid);
grade_regrade_final_grades($courseid);
$alteredweights = grade_helper::fetch_all_natural_weights_for_course($courseid);
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') {
示例2: inject_colspans
/**
* Static recursive helper - add colspan information into categories
*
* @param array &$element The seed of the recursion
*
* @return int
*/
public function inject_colspans(&$element)
{
if (empty($element['children'])) {
return 1;
}
$count = 0;
foreach ($element['children'] as $key => $child) {
$count += grade_tree::inject_colspans($element['children'][$key]);
}
$element['colspan'] = $count;
return $count;
}
示例3: inject_colspans
/**
* Static recursive helper - add colspan information into categories
*
* @param array &$element The seed of the recursion
*
* @return int
*/
public function inject_colspans(&$element)
{
if (empty($element['children'])) {
return 1;
}
$count = 0;
foreach ($element['children'] as $key => $child) {
if (!self::can_output_item($child)) {
continue;
}
$count += grade_tree::inject_colspans($element['children'][$key]);
}
$element['colspan'] = $count;
return $count;
}
示例4: required_param
require_once $CFG->dirroot . '/grade/lib.php';
$courseid = required_param('id', PARAM_INT);
$action = required_param('action', PARAM_ALPHA);
$eid = required_param('eid', PARAM_ALPHANUM);
$PAGE->set_url('/grade/edit/tree/action.php', array('id' => $courseid, 'action' => $action, 'eid' => $eid));
/// Make sure they can even access this course
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
print_error('nocourseid');
}
require_login($course);
$context = context_course::instance($course->id);
// default return url
$gpr = new grade_plugin_return();
$returnurl = $gpr->get_return_url($CFG->wwwroot . '/grade/edit/tree/index.php?id=' . $course->id);
// get the grading tree object
$gtree = new grade_tree($courseid, false, false);
// what are we working with?
if (!($element = $gtree->locate_element($eid))) {
print_error('invalidelementid', '', $returnurl);
}
$object = $element['object'];
$type = $element['type'];
switch ($action) {
case 'hide':
if ($eid and confirm_sesskey()) {
if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) {
print_error('nopermissiontohide', '', $returnurl);
}
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
示例5: optional_param
$eid = optional_param('eid', 0, PARAM_ALPHANUM);
/// Make sure they can even access this course
if (!($course = get_record('course', 'id', $courseid))) {
print_error('nocourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
/// return tracking object
$gpr = new grade_plugin_return(array('type' => 'edit', 'plugin' => 'tree', 'courseid' => $courseid));
$returnurl = $gpr->get_return_url(null);
//first make sure we have proper final grades - we need it for locking changes
grade_regrade_final_grades($courseid);
// 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))) {
error('Incorrect element id!', $returnurl);
}
$object = $element['object'];
}
$switch = grade_report::get_pref('aggregationposition');
$strgrades = get_string('grades');
$strgraderreport = get_string('graderreport', 'grades');
$strcategoriesedit = get_string('categoriesedit', 'grades');
$strcategoriesanditems = get_string('categoriesanditems', 'grades');
$navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid));
示例6: get_right_rows
/**
* Builds and returns the rows that will make up the right part of the grader report
* @param boolean $displayaverages whether to display average rows in the table
* @return array Array of html_table_row objects
*/
public function get_right_rows($displayaverages)
{
global $CFG, $USER, $OUTPUT, $DB, $PAGE;
$rows = array();
$this->rowcount = 0;
$numrows = count($this->gtree->get_levels());
$numusers = count($this->users);
$gradetabindex = 1;
$columnstounset = array();
$strgrade = $this->get_lang_string('grade');
$strfeedback = $this->get_lang_string("feedback");
$arrows = $this->get_sort_arrows();
$jsarguments = array('cfg' => array('ajaxenabled' => false), 'items' => array(), 'users' => array(), 'feedback' => array(), 'grades' => array());
$jsscales = array();
// Get preferences once.
$showactivityicons = $this->get_pref('showactivityicons');
$quickgrading = $this->get_pref('quickgrading');
$showquickfeedback = $this->get_pref('showquickfeedback');
$enableajax = $this->get_pref('enableajax');
$showanalysisicon = $this->get_pref('showanalysisicon');
// Get strings which are re-used inside the loop.
$strftimedatetimeshort = get_string('strftimedatetimeshort');
$strexcludedgrades = get_string('excluded', 'grades');
$strerror = get_string('error');
foreach ($this->gtree->get_levels() as $key => $row) {
$headingrow = new html_table_row();
$headingrow->attributes['class'] = 'heading_name_row';
foreach ($row as $columnkey => $element) {
$sortlink = clone $this->baseurl;
if (isset($element['object']->id)) {
$sortlink->param('sortitemid', $element['object']->id);
}
$eid = $element['eid'];
$object = $element['object'];
$type = $element['type'];
$categorystate = @$element['categorystate'];
if (!empty($element['colspan'])) {
$colspan = $element['colspan'];
} else {
$colspan = 1;
}
if (!empty($element['depth'])) {
$catlevel = 'catlevel' . $element['depth'];
} else {
$catlevel = '';
}
// Element is a filler
if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') {
$fillercell = new html_table_cell();
$fillercell->attributes['class'] = $type . ' ' . $catlevel;
$fillercell->colspan = $colspan;
$fillercell->text = ' ';
// This is a filler cell; don't use a <th>, it'll confuse screen readers.
$fillercell->header = false;
$headingrow->cells[] = $fillercell;
} else {
if ($type == 'category') {
// Make sure the grade category has a grade total or at least has child grade items.
if (grade_tree::can_output_item($element)) {
// Element is a category.
$categorycell = new html_table_cell();
$categorycell->attributes['class'] = 'category ' . $catlevel;
$categorycell->colspan = $colspan;
$categorycell->text = $this->get_course_header($element);
$categorycell->header = true;
$categorycell->scope = 'col';
// Print icons.
if ($USER->gradeediting[$this->courseid]) {
$categorycell->text .= $this->get_icons($element);
}
$headingrow->cells[] = $categorycell;
}
} else {
// Element is a grade_item
if ($element['object']->id == $this->sortitemid) {
if ($this->sortorder == 'ASC') {
$arrow = $this->get_sort_arrow('up', $sortlink);
} else {
$arrow = $this->get_sort_arrow('down', $sortlink);
}
} else {
$arrow = $this->get_sort_arrow('move', $sortlink);
}
$headerlink = $this->gtree->get_element_header($element, true, $showactivityicons, false, false, true);
$itemcell = new html_table_cell();
$itemcell->attributes['class'] = $type . ' ' . $catlevel . ' highlightable' . ' i' . $element['object']->id;
$itemcell->attributes['data-itemid'] = $element['object']->id;
if ($element['object']->is_hidden()) {
$itemcell->attributes['class'] .= ' dimmed_text';
}
$singleview = '';
// FIXME: MDL-52678 This is extremely hacky we should have an API for inserting grade column links.
if (get_capability_info('gradereport/singleview:view')) {
if (has_all_capabilities(array('gradereport/singleview:view', 'moodle/grade:viewall', 'moodle/grade:edit'), $this->context)) {
$url = new moodle_url('/grade/report/singleview/index.php', array('id' => $this->course->id, 'item' => 'grade', 'itemid' => $element['object']->id));
//.........这里部分代码省略.........
示例7: generate_jwc_xml
function generate_jwc_xml($jwc_courses, $export_users, $include_cats = false, $dryrun = true)
{
global $course, $output, $jwc, $DB, $USER, $nonexist_users;
if ($include_cats) {
$heading = '导出分项成绩及总分到教务处';
} else {
$heading = '导出总分到教务处';
}
if ($dryrun) {
$heading .= '(模拟)';
} else {
$heading .= '(正式)';
}
echo $output->heading($heading);
//first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades($course->id);
// 获得成绩类别和项信息
$tree = new grade_tree($course->id, true, true);
$levels = $tree->get_levels();
// 总分
$total_item = normalize_grade_item($levels[0][0]['object']->grade_item);
$sub_items = array();
$extra_items = array();
$items = array();
// 顶级成绩分类和项
if (array_key_exists(1, $levels) && $include_cats) {
foreach ($levels[1] as $element) {
if ($element['type'] == 'item') {
$grade_item = normalize_grade_item($element['object']);
} else {
if ($element['type'] == 'category') {
$tmp = array_pop($element['children']);
$grade_item = normalize_grade_item($tmp['object']);
//用类别名做成绩名
$grade_item->itemname = $element['object']->fullname;
} else {
// ignore unused fillers
continue;
}
}
if ($grade_item->grademax <= 0) {
// 不计分成绩项/类别
continue;
}
if ($grade_item->aggregationcoef) {
// 额外加分
$extra_items[$grade_item->id] = $grade_item;
} else {
$sub_items[$grade_item->id] = $grade_item;
}
}
}
/// 验证成绩项是否符合教务处要求
$result = true;
// 总成绩满分必须是100分
if ($total_item->grademax != MAX_TOTAL_GRADE) {
echo $output->require_max_total_grade($total_item->grademax);
$result = false;
}
if ($include_cats) {
// 总成绩算法必须是“简单加权平均分”
$total_aggregation = $levels[0][0]['object']->aggregation;
if ($total_aggregation != GRADE_AGGREGATE_WEIGHTED_MEAN2 and $total_aggregation != GRADE_AGGREGATE_SUM) {
echo $output->require_aggregation($total_aggregation);
$result = false;
}
// 子成绩项权重和必须为100
// 所有非加分的分项相加为100,才合法,除非不包含子类别
$weight_sum = 0;
foreach ($sub_items as $item) {
$weight_sum += $item->grademax;
}
if ($include_cats and $weight_sum != MAX_TOTAL_GRADE) {
echo $output->require_100_weight($weight_sum);
$result = false;
}
// 子成绩项数量不能超过8
if (count($sub_items) > MAX_SUB_GRADE_COUNT) {
echo $output->require_max_subitems(count($sub_items));
$result = false;
}
// 加分成绩项数量不能超过2
if (count($extra_items) > MAX_EXTRA_SUB_GRADE_COUNT) {
echo $output->require_max_extraitems(count($extra_items));
$result = false;
}
}
if (!$result) {
echo $output->modify_items_link();
return false;
}
$xml = new gradebook_xml();
if ($dryrun) {
echo $output->box_start();
echo $output->heading('可导出成绩项', 3);
}
$itemtable = new html_table();
$itemtable->head = array('成绩分项名称', '权重', '加分');
foreach ($sub_items as $item) {
$itemtable->data[] = new html_table_row(array($item->itemname, $item->grademax . '%', '否'));
//.........这里部分代码省略.........
示例8: test_can_output_item
/**
* Test can_output_item.
*/
public function test_can_output_item()
{
$this->resetAfterTest();
$generator = $this->getDataGenerator();
// Course level grade category.
$course = $generator->create_course();
// Grade tree looks something like:
// - Test course (Rendered).
$gradetree = grade_category::fetch_course_tree($course->id);
$this->assertTrue(grade_tree::can_output_item($gradetree));
// Add a grade category with default settings.
$generator->create_grade_category(array('courseid' => $course->id));
// Grade tree now looks something like:
// - Test course n (Rendered).
// -- Grade category n (Rendered).
$gradetree = grade_category::fetch_course_tree($course->id);
$this->assertNotEmpty($gradetree['children']);
foreach ($gradetree['children'] as $child) {
$this->assertTrue(grade_tree::can_output_item($child));
}
// Add a grade category with grade type = None.
$nototalcategory = 'No total category';
$nototalparams = ['courseid' => $course->id, 'fullname' => $nototalcategory, 'aggregation' => GRADE_AGGREGATE_WEIGHTED_MEAN];
$nototal = $generator->create_grade_category($nototalparams);
$catnototal = grade_category::fetch(array('id' => $nototal->id));
// Set the grade type of the grade item associated to the grade category.
$catitemnototal = $catnototal->load_grade_item();
$catitemnototal->gradetype = GRADE_TYPE_NONE;
$catitemnototal->update();
// Grade tree looks something like:
// - Test course n (Rendered).
// -- Grade category n (Rendered).
// -- No total category (Not rendered).
$gradetree = grade_category::fetch_course_tree($course->id);
foreach ($gradetree['children'] as $child) {
if ($child['object']->fullname == $nototalcategory) {
$this->assertFalse(grade_tree::can_output_item($child));
} else {
$this->assertTrue(grade_tree::can_output_item($child));
}
}
// Add another grade category with default settings under 'No total category'.
$normalinnototalparams = ['courseid' => $course->id, 'fullname' => 'Normal category in no total category', 'parent' => $nototal->id];
$generator->create_grade_category($normalinnototalparams);
// Grade tree looks something like:
// - Test course n (Rendered).
// -- Grade category n (Rendered).
// -- No total category (Rendered).
// --- Normal category in no total category (Rendered).
$gradetree = grade_category::fetch_course_tree($course->id);
foreach ($gradetree['children'] as $child) {
// All children are now visible.
$this->assertTrue(grade_tree::can_output_item($child));
if (!empty($child['children'])) {
foreach ($child['children'] as $grandchild) {
$this->assertTrue(grade_tree::can_output_item($grandchild));
}
}
}
// Add a grade category with grade type = None.
$nototalcategory2 = 'No total category 2';
$nototal2params = ['courseid' => $course->id, 'fullname' => $nototalcategory2, 'aggregation' => GRADE_AGGREGATE_WEIGHTED_MEAN];
$nototal2 = $generator->create_grade_category($nototal2params);
$catnototal2 = grade_category::fetch(array('id' => $nototal2->id));
// Set the grade type of the grade item associated to the grade category.
$catitemnototal2 = $catnototal2->load_grade_item();
$catitemnototal2->gradetype = GRADE_TYPE_NONE;
$catitemnototal2->update();
// Add a category with no total under 'No total category'.
$nototalinnototalcategory = 'Category with no total in no total category';
$nototalinnototalparams = ['courseid' => $course->id, 'fullname' => $nototalinnototalcategory, 'aggregation' => GRADE_AGGREGATE_WEIGHTED_MEAN, 'parent' => $nototal2->id];
$nototalinnototal = $generator->create_grade_category($nototalinnototalparams);
$catnototalinnototal = grade_category::fetch(array('id' => $nototalinnototal->id));
// Set the grade type of the grade item associated to the grade category.
$catitemnototalinnototal = $catnototalinnototal->load_grade_item();
$catitemnototalinnototal->gradetype = GRADE_TYPE_NONE;
$catitemnototalinnototal->update();
// Grade tree looks something like:
// - Test course n (Rendered).
// -- Grade category n (Rendered).
// -- No total category (Rendered).
// --- Normal category in no total category (Rendered).
// -- No total category 2 (Not rendered).
// --- Category with no total in no total category (Not rendered).
$gradetree = grade_category::fetch_course_tree($course->id);
foreach ($gradetree['children'] as $child) {
if ($child['object']->fullname == $nototalcategory2) {
$this->assertFalse(grade_tree::can_output_item($child));
} else {
$this->assertTrue(grade_tree::can_output_item($child));
}
if (!empty($child['children'])) {
foreach ($child['children'] as $grandchild) {
if ($grandchild['object']->fullname == $nototalinnototalcategory) {
$this->assertFalse(grade_tree::can_output_item($grandchild));
} else {
$this->assertTrue(grade_tree::can_output_item($grandchild));
//.........这里部分代码省略.........
示例9: sort_gradebook
/**
* Re-sorts the gradebook to put all MTG grade items first.
*
* Gets all of the grade items for the specifed course. Iterates over the array
* of items and moves the MTG items to the front of the array. Then does a
* second pass to renumber all the sortorders to make the items sequential from
* 2 upwards (1 will be the course item).
*
* @param object $course Database record for course, containing the id.
*/
function sort_gradebook($course)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/grade/lib.php';
require_once $CFG->dirroot . '/grade/edit/tree/lib.php';
$gtree = new \grade_tree($course->id, false, false);
$fields = array('alis_avgcse', 'alis_alisnum', 'alis_alis', 'alis_mtg', 'alis_cpg');
$params = array($course->id);
list($in_sql, $in_params) = $DB->get_in_or_equal($params);
$params = \array_merge($params, $in_params);
$where = 'courseid = ? AND idnumber ' . $in_sql;
$gradeitems = $DB->get_records_select('grade_items', $where, $params, 'itemnumber DESC');
$courseitem = $DB->get_record('grade_items', array('courseid' => $course->id, 'itemtype' => 'course'));
//$mtgitems = count_records_select('grade_items', $where);
// First, move the MTG grade items to the front
$offset = 0;
foreach ($gradeitems as $item) {
if (!($element = $gtree->locate_element('i' . $item->id))) {
\print_error('invalidelementid');
}
$object = $element['object'];
$moveafter = 'c' . $courseitem->iteminstance;
$first = 1;
// If First is set to 1, it means the target is the first child of the category $moveafter
if (!($after_el = $gtree->locate_element($moveafter))) {
\print_error('invalidelementid');
}
$after = $after_el['object'];
$sortorder = $after->get_sortorder();
if (!$first) {
$parent = $after->get_parent_category();
$object->set_parent($parent->id);
} else {
$object->set_parent($after->id);
}
$object->move_after_sortorder($sortorder);
}
}
示例10: array
/**
* Given the grade tree and an array of element ids (e.g. c15, i42), and expecting the 'moveafter' URL param,
* moves the selected items to the requested location. Then redirects the user to the given $returnurl
*
* @param object $gtree The grade tree (a recursive representation of the grade categories and grade items)
* @param array $eids
* @param string $returnurl
*/
function move_elements($eids, $returnurl)
{
$moveafter = required_param('moveafter', PARAM_INT);
if (!is_array($eids)) {
$eids = array($eids);
}
if (!($after_el = $this->gtree->locate_element("cg{$moveafter}"))) {
print_error('invalidelementid', '', $returnurl);
}
$after = $after_el['object'];
$parent = $after;
$sortorder = $after->get_sortorder();
foreach ($eids as $eid) {
if (!($element = $this->gtree->locate_element($eid))) {
print_error('invalidelementid', '', $returnurl);
}
$object = $element['object'];
$object->set_parent($parent->id);
$object->move_after_sortorder($sortorder);
$sortorder++;
}
redirect($returnurl, '', 0);
}
示例11: fill_table_recursive
private function fill_table_recursive(&$element)
{
global $DB, $CFG;
$type = $element['type'];
$depth = $element['depth'];
$grade_object = $element['object'];
$eid = $grade_object->id;
$element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, true, true);
$data = array();
$hidden = '';
$excluded = '';
$class = '';
$classfeedback = '';
// If this is a hidden grade category, hide it completely from the user
if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil())) {
return false;
}
if ($type == 'category') {
$this->evenodd[$depth] = ($this->evenodd[$depth] + 1) % 2;
}
$alter = $this->evenodd[$depth] == 0 ? 'even' : 'odd';
/// Process those items that have scores associated
if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
$header_row = "row_{$eid}_{$this->user->id}";
$header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";
if (!($grade_grade = grade_grade::fetch(array('itemid' => $grade_object->id, 'userid' => $this->user->id)))) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $grade_object->id;
}
$grade_grade->load_grade_item();
/// Hidden Items
if ($grade_grade->grade_item->is_hidden()) {
$hidden = ' dimmed_text';
}
$hide = false;
// If this is a hidden grade item, hide it completely from the user.
if ($grade_grade->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil())) {
$hide = true;
} else {
if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
// The grade object can be marked visible but still be hidden if
// the student cannot see the activity due to conditional access
// and it's set to be hidden entirely.
$instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance];
if (!$cm->uservisible) {
// If there is 'availableinfo' text then it is only greyed
// out and not entirely hidden.
if (!$cm->availableinfo) {
$hide = true;
}
}
}
}
}
if (!$hide) {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' [' . get_string('excluded', 'grades') . ']';
$excluded = ' excluded';
}
/// Other class information
$class = "{$hidden} {$excluded}";
if ($this->switch) {
// alter style based on whether aggregation is first or last
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggt b2b" : " item b1b";
} else {
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggb" : " item b1b";
}
if ($type == 'categoryitem' or $type == 'courseitem') {
$header_cat = "cat_{$grade_object->iteminstance}_{$this->user->id}";
}
/// Name
$data['itemname']['content'] = $fullname;
$data['itemname']['class'] = $class;
$data['itemname']['colspan'] = $this->maxdepth - $depth;
$data['itemname']['celltype'] = 'th';
$data['itemname']['id'] = $header_row;
/// Actual Grade
$gradeval = $grade_grade->finalgrade;
if (!$this->canviewhidden) {
/// Virtual Grade (may be calculated excluding hidden items etc).
$adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($this->courseid, $grade_grade->grade_item, $gradeval);
$gradeval = $adjustedgrade['grade'];
// We temporarily adjust the view of this grade item - because the min and
// max are affected by the hidden values in the aggregation.
$grade_grade->grade_item->grademax = $adjustedgrade['grademax'];
$grade_grade->grade_item->grademin = $adjustedgrade['grademin'];
}
if ($this->showfeedback) {
// Copy $class before appending itemcenter as feedback should not be centered
$classfeedback = $class;
}
$class .= " itemcenter ";
if ($this->showweight) {
$data['weight']['class'] = $class;
$data['weight']['content'] = '-';
//.........这里部分代码省略.........
示例12: fill_table_recursive
private function fill_table_recursive(&$element)
{
global $DB, $CFG;
$type = $element['type'];
$depth = $element['depth'];
$grade_object = $element['object'];
$eid = $grade_object->id;
$element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, false, true);
$data = array();
$hidden = '';
$excluded = '';
$class = '';
$classfeedback = '';
$row_class = '';
$activity_start_date = '';
// If this is a hidden grade category, hide it completely from the user
if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_MARKSHEET_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_MARKSHEET_HIDE_UNTIL && !$grade_object->is_hiddenuntil())) {
return false;
}
if ($type == 'category') {
$this->evenodd[$depth] = ($this->evenodd[$depth] + 1) % 2;
}
$alter = $this->evenodd[$depth] == 0 ? 'even' : 'odd';
if ($type == 'item') {
$cat_id = $grade_object->categoryid;
} else {
$cat_id = ' ';
}
/// Process those items that have scores associated
if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
//&& ($depth == 2)) {
$header_row = "row_{$eid}_{$this->user->id}";
$header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";
if (!($grade_grade = grade_grade::fetch(array('itemid' => $grade_object->id, 'userid' => $this->user->id)))) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $grade_object->id;
}
$grade_grade->load_grade_item();
$hide = false;
// If this is a hidden grade item, hide it completely from the user.
if ($grade_grade->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_MARKSHEET_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_MARKSHEET_HIDE_UNTIL && !$grade_grade->is_hiddenuntil())) {
$hide = true;
} else {
if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
// The grade object can be marked visible but still be hidden if...
// 1) "enablegroupmembersonly" is on and the activity is assigned to a grouping the user is not in.
// 2) the student cannot see the activity due to conditional access and its set to be hidden entirely.
$instances = $this->gtree->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance];
if (!$cm->uservisible) {
// Further checks are required to determine whether the activity is entirely hidden or just greyed out.
if ($cm->is_user_access_restricted_by_group() || $cm->is_user_access_restricted_by_conditional_access() || $cm->is_user_access_restricted_by_capability()) {
$hide = true;
}
}
}
}
}
if ($grade_grade->grade_item->is_hidden() && !$this->showhiddenactivity) {
$hide = true;
}
//set start dates by category
$categoryid = $grade_grade->grade_item->categoryid;
if ($type == 'item' && isset($cm)) {
$this->grade_category_modids[$categoryid][] = $cm->id;
}
/// Hidden Items
if ($grade_grade->grade_item->is_hidden()) {
$hidden = ' hidden';
}
if (!$hide) {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' [' . get_string('excluded', 'grades') . ']';
$excluded = ' excluded';
}
if (isset($grade_grade->grade_item->itemmodule)) {
$modname = $grade_grade->grade_item->itemmodule;
}
if (isset($cm)) {
$modid = $cm->id;
}
if ($type == "categoryitem") {
// print_r($grade_grade);
// $timemodified = $grade_grade->grade_item->timemodified;
// $activity_start_date = new DateTime('@'.$timemodified);
// print_r($activity_start_date);
echo "<br>";
}
/// Other class information
if (isset($modname) && isset($modid)) {
$modaction = "view";
$course = $this->course;
$user = $this->user->id;
$activity_start_date = get_activity_start_date($course, $user, $modname, $modaction, $modid);
}
if ($type == 'item') {
//.........这里部分代码省略.........
示例13: fill_table_recursive
private function fill_table_recursive(&$element)
{
global $DB, $CFG;
$type = $element['type'];
$depth = $element['depth'];
$grade_object = $element['object'];
$eid = $grade_object->id;
$element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, true, true);
$data = array();
$hidden = '';
$excluded = '';
$class = '';
// If this is a hidden grade category, hide it completely from the user
if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil())) {
return false;
}
if ($type == 'category') {
$this->evenodd[$depth] = ($this->evenodd[$depth] + 1) % 2;
}
$alter = $this->evenodd[$depth] == 0 ? 'even' : 'odd';
/// Process those items that have scores associated
if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
if (!($grade_grade = grade_grade::fetch(array('itemid' => $grade_object->id, 'userid' => $this->user->id)))) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $grade_object->id;
}
$grade_grade->load_grade_item();
/// Hidden Items
if ($grade_grade->grade_item->is_hidden()) {
$hidden = ' hidden';
}
// If this is a hidden grade item, hide it completely from the user.
if ($grade_grade->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil())) {
// return false;
} else {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' [' . get_string('excluded', 'grades') . ']';
$excluded = ' excluded';
}
/// Other class information
$class = "{$hidden} {$excluded}";
if ($this->switch) {
// alter style based on whether aggregation is first or last
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggt b2b" : " item b1b";
} else {
$class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggb" : " item b1b";
}
/// Name
$data['itemname']['content'] = $fullname;
$data['itemname']['class'] = $class;
$data['itemname']['colspan'] = $this->maxdepth - $depth;
/// Actual Grade
$gradeval = $grade_grade->finalgrade;
$class .= " itemcenter ";
if ($this->showweight) {
$data['weight']['class'] = $class;
$data['weight']['content'] = '-';
// has a weight assigned, might be extra credit
if ($grade_object->aggregationcoef > 0 && $type != 'courseitem') {
$data['weight']['content'] = number_format($grade_object->aggregationcoef, 2) . '%';
}
}
if ($this->showgrade) {
if ($grade_grade->grade_item->needsupdate) {
$data['grade']['class'] = $class . ' gradingerror';
$data['grade']['content'] = get_string('error');
} else {
if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$this->canviewhidden and $grade_grade->is_hidden() and !$grade_grade->grade_item->is_category_item() and !$grade_grade->grade_item->is_course_item()) {
// the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
$class .= ' datesubmitted';
$data['grade']['class'] = $class;
$data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));
} elseif ($grade_grade->is_hidden()) {
$data['grade']['class'] = $class . ' hidden';
$data['grade']['content'] = '-';
} else {
$data['grade']['class'] = $class;
$gradeval = $this->blank_hidden_total($this->courseid, $grade_grade->grade_item, $gradeval);
$data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true);
}
}
}
// Range
if ($this->showrange) {
$data['range']['class'] = $class;
$data['range']['content'] = $grade_grade->grade_item->get_formatted_range(GRADE_DISPLAY_TYPE_REAL, $this->rangedecimals);
}
// Percentage
if ($this->showpercentage) {
if ($grade_grade->grade_item->needsupdate) {
$data['percentage']['class'] = $class . ' gradingerror';
$data['percentage']['content'] = get_string('error');
} else {
if ($grade_grade->is_hidden()) {
$data['percentage']['class'] = $class . ' hidden';
$data['percentage']['content'] = '-';
} else {
//.........这里部分代码省略.........
示例14: fill_table_recursive
/**
* Fill the table with data.
*
* @param $element - An array containing the table data for the current row.
*/
private function fill_table_recursive(&$element) {
global $DB, $CFG;
$type = $element['type'];
$depth = $element['depth'];
$grade_object = $element['object'];
$eid = $grade_object->id;
$element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, true, true, true, true);
$data = array();
$hidden = '';
$excluded = '';
$itemlevel = ($type == 'categoryitem' || $type == 'category' || $type == 'courseitem') ? $depth : ($depth + 1);
$class = 'level' . $itemlevel . ' level' . ($itemlevel % 2 ? 'odd' : 'even');
$classfeedback = '';
// If this is a hidden grade category, hide it completely from the user
if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && (
$this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil()))) {
return false;
}
if ($type == 'category') {
$this->evenodd[$depth] = (($this->evenodd[$depth] + 1) % 2);
}
$alter = ($this->evenodd[$depth] == 0) ? 'even' : 'odd';
/// Process those items that have scores associated
if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
$header_row = "row_{$eid}_{$this->user->id}";
$header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";
if (! $grade_grade = grade_grade::fetch(array('itemid'=>$grade_object->id,'userid'=>$this->user->id))) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $grade_object->id;
}
$grade_grade->load_grade_item();
/// Hidden Items
if ($grade_grade->grade_item->is_hidden()) {
$hidden = ' dimmed_text';
}
$hide = false;
// If this is a hidden grade item, hide it completely from the user.
if ($grade_grade->is_hidden() && !$this->canviewhidden && (
$this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
$hide = true;
} else if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
// The grade object can be marked visible but still be hidden if
// the student cannot see the activity due to conditional access
// and it's set to be hidden entirely.
$instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance];
if (!$cm->uservisible) {
// If there is 'availableinfo' text then it is only greyed
// out and not entirely hidden.
if (!$cm->availableinfo) {
$hide = true;
}
}
}
}
// Actual Grade - We need to calculate this whether the row is hidden or not.
$gradeval = $grade_grade->finalgrade;
$hint = $grade_grade->get_aggregation_hint();
if (!$this->canviewhidden) {
/// Virtual Grade (may be calculated excluding hidden items etc).
$adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($this->courseid,
$grade_grade->grade_item,
$gradeval);
$gradeval = $adjustedgrade['grade'];
// We temporarily adjust the view of this grade item - because the min and
// max are affected by the hidden values in the aggregation.
$grade_grade->grade_item->grademax = $adjustedgrade['grademax'];
$grade_grade->grade_item->grademin = $adjustedgrade['grademin'];
$hint['status'] = $adjustedgrade['aggregationstatus'];
$hint['weight'] = $adjustedgrade['aggregationweight'];
} else {
// The max and min for an aggregation may be different to the grade_item.
if (!is_null($gradeval)) {
$grade_grade->grade_item->grademax = $grade_grade->rawgrademax;
$grade_grade->grade_item->grademin = $grade_grade->rawgrademin;
}
}
//.........这里部分代码省略.........