protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null) { // Standard user fields. $standardfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address')); \core_collator::asort($standardfields); // Custom fields. $customfields = array(); $options = array('context' => \context_course::instance($course->id)); foreach (condition::get_custom_profile_fields() as $field) { $customfields[$field->shortname] = format_string($field->name, true, $options); } \core_collator::asort($customfields); // Make arrays into JavaScript format (non-associative, ordered) and return. return array(self::convert_associative_array_for_js($standardfields, 'field', 'display'), self::convert_associative_array_for_js($customfields, 'field', 'display')); }
/** * This function renders the form elements when adding a customcert element. * * @param mod_customcert_edit_element_form $mform the edit_form instance */ public function render_form_elements($mform) { // Get the user profile fields. $userfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address')); // Get the user custom fields. $arrcustomfields = \availability_profile\condition::get_custom_profile_fields(); $customfields = array(); foreach ($arrcustomfields as $key => $customfield) { $customfields[$customfield->id] = $key; } // Combine the two. $fields = $userfields + $customfields; core_collator::asort($fields); // Create the select box where the user field is selected. $mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $fields); $mform->setType('userfield', PARAM_ALPHANUM); $mform->addHelpButton('userfield', 'userfield', 'customcertelement_userfield'); parent::render_form_elements($mform); }
/** * Add all the user-related columns to the $columns and $headers arrays. * @param table_sql $table the table being constructed. * @param array $columns the list of columns. Added to. * @param array $headers the columns headings. Added to. */ protected function add_user_columns($table, &$columns, &$headers) { global $CFG; if (!$table->is_downloading() && $CFG->grade_report_showuserimage) { $columns[] = 'picture'; $headers[] = ''; } if (!$table->is_downloading()) { $columns[] = 'fullname'; $headers[] = get_string('name'); } else { $columns[] = 'lastname'; $headers[] = get_string('lastname'); $columns[] = 'firstname'; $headers[] = get_string('firstname'); } // When downloading, some extra fields are always displayed (because // there's no space constraint) so do not include in extra-field list. $extrafields = get_extra_user_fields($this->context, $table->is_downloading() ? array('institution', 'department', 'email') : array()); foreach ($extrafields as $field) { $columns[] = $field; $headers[] = get_user_field_name($field); } if ($table->is_downloading()) { $columns[] = 'institution'; $headers[] = get_string('institution'); $columns[] = 'department'; $headers[] = get_string('department'); $columns[] = 'email'; $headers[] = get_string('email'); } }
/** * taskchain_navigation_accesscontrol_form * * @param xxx $course * @param xxx $block_instance */ function taskchain_navigation_accesscontrol_form($course, $block_instance, $action) { global $CFG, $DB, $OUTPUT, $PAGE; // site and system contexts if (class_exists('context')) { $sitecontext = context_course::instance(SITEID); $systemcontext = context_system::instance(); } else { $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID); $systemcontext = get_context_instance(CONTEXT_SYSTEM); } $hassiteconfig = has_capability('moodle/site:config', $systemcontext); // decode block config settings, in case they are needed later $block_instance->config = unserialize(base64_decode($block_instance->configdata)); // we need the DB manager to check which // DB tables and fields are available $dbman = $DB->get_manager(); $plugin = 'block_taskchain_navigation'; $select_size = 5; $cm_namelength = 40; $cm_headlength = 10; $cm_taillength = 10; $section_namelength = 48; $section_headlength = 18; $section_taillength = 18; // get previous or default form values $sections_array = optional_param_array('sections', array(), PARAM_INT); $modules_array = optional_param_array('modules', array(), PARAM_ALPHA); $cmids_array = optional_param_array('cmids', array(), PARAM_INT); $include = optional_param('include', '', PARAM_TEXT); $exclude = optional_param('exclude', '', PARAM_TEXT); $visibility = optional_param('visibility', -1, PARAM_INT); // available from/until dates $time = time(); $fromdisable = optional_param('fromdisable', 0, PARAM_INT); $untildisable = optional_param('untildisable', 0, PARAM_INT); $cutoffdisable = optional_param('cutoffdisable', 0, PARAM_INT); list($availablefrom, $fromdate) = get_timestamp_and_date('from', null, $time, $fromdisable); list($availableuntil, $untildate) = get_timestamp_and_date('until', null, $time, $untildisable); list($availablecutoff, $cutoffdate) = get_timestamp_and_date('cutoff', null, $time, $cutoffdisable); $sortgradeitems = optional_param('sortgradeitems', 0, PARAM_INT); $creategradecats = optional_param('creategradecats', 0, PARAM_INT); $removegradecats = optional_param('removegradecats', 0, PARAM_INT); $rating = optional_param('rating', 0, PARAM_INT); $maxgrade = optional_param('maxgrade', 100, PARAM_INT); $gradepass = optional_param('gradepass', 60, PARAM_INT); $gradecat = optional_param('gradecat', 0, PARAM_INT); $gradeitemhidden = optional_param('gradeitemhidden', 0, PARAM_INT); $extracredit = optional_param('extracredit', 0, PARAM_INT); $regrade = optional_param('regrade', 0, PARAM_INT); $groupmode = optional_param('groupmode', 0, PARAM_INT); $groupingid = optional_param('groupingid', 0, PARAM_INT); $groupmembersonly = optional_param('groupmembersonly', 0, PARAM_INT); $sortactivities = optional_param('sortactivities', 0, PARAM_INT); $visible = optional_param('visible', 1, PARAM_INT); $indent = optional_param('indent', 0, PARAM_INT); $section = optional_param('section', 0, PARAM_INT); $position = optional_param('position', 0, PARAM_INT); $uploadlimit = optional_param('uploadlimit', 0, PARAM_INT); $siteuploadlimit = get_config(null, 'maxbytes'); $courseuploadlimit = $course->maxbytes; $uploadlimitmenu = get_max_upload_sizes($siteuploadlimit, $courseuploadlimit); $removeconditions = optional_param('removeconditions', 0, PARAM_INT); $removecompletion = optional_param('removecompletion', 0, PARAM_INT); $erasecompletion = optional_param('erasecompletion', 0, PARAM_INT); // course_modules_availability OR course_modules.availability $conditiondatedirection = optional_param_array('conditiondatedirection', array(0), PARAM_INT); $conditiongradeitemid = optional_param_array('conditiongradeitemid', array(0), PARAM_INT); $conditiongrademin = optional_param_array('conditiongrademin', array(60), PARAM_INT); $conditiongrademax = optional_param_array('conditiongrademax', array(100), PARAM_INT); $conditionfieldname = optional_param_array('conditionfieldname', array(''), PARAM_ALPHANUM); $conditionfieldoperator = optional_param_array('conditionfieldoperator', array(''), PARAM_ALPHANUM); $conditionfieldvalue = optional_param_array('conditionfieldvalue', array(''), PARAM_ALPHANUM); $conditiongroupid = optional_param_array('conditiongroupid', array(0), PARAM_INT); $conditiongroupingid = optional_param_array('conditiongroupingid', array(0), PARAM_INT); $conditioncmid = optional_param_array('conditioncmid', array(0), PARAM_INT); // may be negative NEXT/PREVIOUS_ANY_COURSE/SECTION $conditioncmungraded = optional_param_array('conditioncmungraded', array(0), PARAM_INT); // 0=skip, 1=include ungraded activities $conditioncmresources = optional_param_array('conditioncmresources', array(0), PARAM_INT); // 0=skip, 1=include resources $conditioncmlabels = optional_param_array('conditioncmlabels', array(0), PARAM_INT); // 0=skip, 1=include labels $conditioncmcompletion = optional_param_array('conditioncmcompletion', array(1), PARAM_INT); // 0=incomplete, 1=complete, 2=pass, 3=fail $conditionaction = optional_param_array('conditionaction', array(1), PARAM_INT); // 0=hide, 1=show(greyed out) // course_modules.xxx $completiontracking = optional_param('completiontracking', 0, PARAM_INT); $completionday = optional_param('completionday', 0, PARAM_INT); $completionmonth = optional_param('completionmonth', 0, PARAM_INT); $completionyear = optional_param('completionyear', 0, PARAM_INT); // there may also be a number of activity-specific completion fields // (e.g. the "completionpass" field used by the Quiz and TaskChain modules) // there may also be a number of fields to enable/disable filters // (e.g. "filterglossary", "filtermediaplugin") // Competency settings $competencyrule = optional_param('competencyrule', 0, PARAM_INT); $conditiondate = array(); $conditiondatetime = array(); foreach ($conditiondatedirection as $i => $d) { switch ($d) { case 1: $d = '>='; break; case 2: $d = '<='; break; default: continue; } list($t, $date) = get_timestamp_and_date('conditiondatetime', $i, $time); $conditiondate[$i] = (object) array('type' => 'date', 'd' => $d, 't' => $t); $conditiondatetime[$i] = $date; } $conditiongrade = array(); foreach ($conditiongradeitemid as $i => $id) { if ($id == 0) { continue; } $conditiongrade[] = (object) array('type' => 'grade', 'id' => $id, 'min' => empty($conditiongrademin[$i]) ? 0 : $conditiongrademin[$i], 'max' => empty($conditiongrademax[$i]) ? 100 : $conditiongrademax[$i]); } $conditionfield = array(); foreach ($conditionfieldname as $i => $name) { if ($name == '') { continue; } $conditionfield[] = (object) array('type' => 'profile', 'sf' => $name, 'op' => empty($conditionfieldoperator[$i]) ? '' : $conditionfieldoperator[$i], 'v' => empty($conditionfieldvalue[$i]) ? '' : $conditionfieldvalue[$i]); } $conditiongroup = array(); foreach ($conditiongroupid as $i => $id) { if ($id == 0) { continue; } $conditiongroup[] = (object) array('type' => 'group', 'id' => $id); } $conditiongrouping = array(); foreach ($conditiongroupingid as $i => $id) { if ($id == 0) { continue; } $conditiongrouping[] = (object) array('type' => 'grouping', 'id' => $id); } $conditioncm = array(); foreach ($conditioncmid as $i => $id) { if ($id == 0) { continue; } $conditioncm[] = (object) array('type' => 'completion', 'cm' => $id, 'e' => isset($conditioncmcompletion[$i]) ? $conditioncmcompletion[$i] : 1, 'ungraded' => empty($conditioncmungraded[$i]) ? 0 : 1, 'resources' => empty($conditioncmresources[$i]) ? 0 : 1, 'labels' => empty($conditioncmlabels[$i]) ? 0 : 1); } if ($completionday && $completionmonth && $completionyear) { $completiondate = make_timestamp($completionyear, $completionmonth, $completionday, 0, 0, 0, 99, false); } else { $completiondate = 0; } // add standard settings $settings = array('availablefrom', 'availableuntil', 'availablecutoff', 'rating', 'maxgrade', 'gradepass', 'gradecat', 'gradeitemhidden', 'extracredit', 'regrade', 'groupmode', 'groupingid', 'groupmembersonly', 'visible', 'indent', 'section', 'uploadlimit'); // add switches to enable/disable filters $filters = filter_get_available_in_context($course->context); foreach (array_keys($filters) as $filter) { $setting = 'filter' . $filter; echo $setting; $settings[] = $setting; ${$setting} = optional_param($setting, null, PARAM_INT); } // add "availability" settings, if enabled if (empty($CFG->enableavailability)) { $enableavailability = false; } else { $enableavailability = true; } if ($enableavailability) { array_push($settings, 'removeconditions', 'conditiondate', 'conditiongrade', 'conditionfield', 'conditiongroup', 'conditiongrouping', 'conditioncm', 'conditionaction'); } // add "completion" settings, if enabled if (empty($CFG->enablecompletion) || empty($course->enablecompletion)) { $enablecompletion = false; } else { $enablecompletion = true; } if ($enablecompletion) { array_push($settings, 'removecompletion', 'erasecompletion', 'completiontracking', 'completiondate'); } // are we using competencies // (available in Moodle >= 3.1) if (get_config('core_competency', 'enabled')) { $enablecompetency = true; } else { $enablecompetency = false; } if ($enablecompetency) { array_push($settings, 'competencyrule'); } // custom html tags that delimit section title in the section summary $sectiontags = $block_instance->config->sectiontitletags; $sectiontags = optional_param('sectiontags', $sectiontags, PARAM_TEXT); // set course section type if ($course->format == 'weeks') { $sectiontype = 'week'; } else { if ($course->format == 'topics') { $sectiontype = 'topic'; } else { $sectiontype = 'section'; } } if (count($sections_array) || count($modules_array) || $include || $exclude || $visibility >= 0 || count($cmids_array)) { $select_defaultvalue = true; } else { $select_defaultvalue = false; } // set date format for course sections $weekdateformat = '%b %d'; // get_string('strftimedateshort'); if ($sortactivities) { $select = 'cm.id, gi.sortorder'; $from = '{grade_items} gi ' . 'JOIN {modules} m ON gi.itemmodule = m.name ' . 'JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = gi.iteminstance'; $where = 'gi.courseid = ? AND gi.itemtype = ?'; $order = 'gi.sortorder'; $params = array($course->id, 'mod'); $items = $DB->get_records_sql("SELECT {$select} FROM {$from} WHERE {$where} ORDER BY {$order}", $params); $select = 'id,sequence,section,summary'; $from = '{course_sections}'; $where = 'course = ? AND sequence IS NOT NULL AND sequence <> ?'; $order = 'section'; $params = array($course->id, ''); $sections = $DB->get_records_sql("SELECT {$select} FROM {$from} WHERE {$where} ORDER BY {$order}", $params); if ($items && $sections) { $modinfo = get_fast_modinfo($course); $rebuild_course_cache = false; foreach (array_keys($sections) as $id) { $sequence = explode(',', $sections[$id]->sequence); $sequence = array_flip($sequence); foreach (array_keys($sequence) as $cmid) { if (array_key_exists($cmid, $items)) { // assign new sortorder to activity $sequence[$cmid] = $items[$cmid]->sortorder; } else { if (isset($modinfo->cms[$cmid])) { // no grade book item (e.g. label) $name = urldecode($modinfo->cms[$cmid]->name); $name = block_taskchain_navigation::filter_text($name); $name = trim(strip_tags($name)); $sequence[$cmid] = $name; unset($modinfo->cms[$cmid]); } else { unset($sequence[$cmid]); // shouldn't happen !! } } } uasort($sequence, 'activity_sequence_uasort'); $sequence = array_keys($sequence); $sequence = implode(',', $sequence); if ($sequence != $sections[$id]->sequence) { $DB->set_field('course_sections', 'sequence', $sequence, array('id' => $id)); $rebuild_course_cache = true; } } if ($rebuild_course_cache) { rebuild_course_cache($course->id); if (class_exists('course_modinfo')) { // Moodle >= 2.4 get_fast_modinfo($course, 0, true); } else { // Moodle <= 2.3 get_fast_modinfo('reset'); } $course = $DB->get_record('course', array('id' => $course->id)); } } unset($items, $sections, $modinfo, $sequence, $name, $cmid, $id); } $cms = array(); $modules = array(); $sections = array(); $filemods = array(); $labelmods = array(); $ratingmods = array(); $resourcemods = array(); $gradingmods = array(); $cutoffdatemods = array(); $completionfields = array(); $durationfields = array('completiontimespent'); $count_cmids = 0; $selected_cmids = array(); $strman = get_string_manager(); // cache of section visibility by sectionnum // Note: could be ommited if we are not bothered about visibility // if ($visibility>=0 || array_key_exists('visible', $selected_settings)) { // } $section_visible = $DB->get_records_menu('course_sections', array('course' => $course->id), 'section', 'section, visible'); $section_visible = array_map('intval', $section_visible); $section_visible[0] = 1; // intro is always visible $modinfo = get_fast_modinfo($course); foreach ($modinfo->sections as $sectionnum => $cmids) { // loop through the course modules foreach ($cmids as $cmid) { if (empty($modinfo->cms[$cmid])) { continue; // shouldn't happen } // shortcut to current course modules $cm = $modinfo->cms[$cmid]; $count_cmids++; $sections[$sectionnum] = true; if (empty($modules[$cm->modname])) { $modules[$cm->modname] = get_string('modulename', $cm->modname); if ($modhaslibfile = file_exists("{$CFG->dirroot}/mod/{$cm->modname}/lib.php")) { $modcompletion = plugin_supports('mod', $cm->modname, FEATURE_COMPLETION_HAS_RULES, false); } else { $modcompletion = false; } // get completion fields if ($enablecompletion) { if ($modcompletion) { $fields = $DB->get_columns($cm->modname); $names = array_keys($fields); $names = preg_grep('/^completion.+$/', $names); $names = array_values($names); // re-index the array } else { $names = array(); // no module-specific fields $fields = array(); } if ($modhaslibfile) { // fields that are common to all modules - see "lib/moodleform_mod.php" if (plugin_supports('mod', $cm->modname, FEATURE_GRADE_HAS_GRADE, false)) { array_unshift($names, 'completiongrade'); } if (plugin_supports('mod', $cm->modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) { array_unshift($names, 'completionview'); } } foreach ($names as $name) { if (empty($completionfields[$name])) { $settings[] = $name; if (isset($_POST[$name]) && is_array($_POST[$name])) { ${$name} = optional_param_array($name, array(), PARAM_INT); ${$name} = array_sum(${$name}); // i.e. same as logical AND } else { ${$name} = optional_param($name, 0, PARAM_INT); } if (in_array($name, $durationfields)) { ${$name} *= optional_param($name . '_unit', 1, PARAM_INT); } $completionfields[$name] = get_completionfield($strman, $plugin, $cm->modname, $name, ${$name}, $fields); } $completionfields[$name]->mods[$cm->modname] = $modules[$cm->modname]; } unset($fields, $names, $name); } // get file sitewide upload limits, if any, for this module switch ($cm->modname) { case 'assign': $filemods[$cm->modname] = get_config('assignsubmission_file', 'maxbytes'); break; case 'assignment': $filemods[$cm->modname] = get_config(null, 'assignment_maxbytes'); break; case 'forum': $filemods[$cm->modname] = get_config(null, 'forum_maxbytes'); break; case 'workshop': $filemods[$cm->modname] = get_config('workshop', 'maxbytes'); break; } if ($modhaslibfile) { $is_label = plugin_supports('mod', $cm->modname, FEATURE_NO_VIEW_LINK, false) == true; $is_resource = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER) == MOD_ARCHETYPE_RESOURCE; $has_rating = plugin_supports('mod', $cm->modname, FEATURE_RATE, false) == true; } else { $is_label = in_array($cm->modname, array('label')); $is_resource = in_array($cm->modname, array('book', 'folder', 'imscp', 'page', 'resource', 'url')); $has_rating = in_array($cm->modname, array('data', 'forum', 'glossary')); } if ($has_grading = defined('FEATURE_ADVANCED_GRADING')) { // Moodle >= 2.2 if ($modhaslibfile) { $has_grading = plugin_supports('mod', $cm->modname, FEATURE_ADVANCED_GRADING, false) == true; } else { $has_grading = in_array($cm->modname, array('assign')); } } if ($is_label) { $labelmods[] = $cm->modname; } else { if ($is_resource) { $resourcemods[] = $cm->modname; } } if ($has_rating) { $ratingmods[$cm->modname] = $modules[$cm->modname]; } // ================================== // disabled until fully functional // ================================== // if ($has_grading) { // $gradingareas[$cm->modname] = grading_manager::available_areas('mod_'.$cm->modname); // if (empty($gradingareas[$cm->modname])) { // unset($gradingareas[$cm->modname]); // } else { // $gradingmods[$cm->modname] = $modules[$cm->modname]; // } // } if (in_array($cm->modname, array('assign'))) { $cutoffdatemods[$cm->modname] = $modules[$cm->modname]; } unset($is_label, $is_resource, $has_rating, $has_grading, $modhaslibfile, $modcompletion); } if (empty($cms[$sectionnum])) { $cms[$sectionnum] = array(); } if (in_array($cmid, $cmids_array)) { $selected = ' selected="selected"'; } else { $selected = ''; } $url = $PAGE->theme->pix_url('icon', $cm->modname)->out(); $style = ' style="background-image: url(' . $url . '); background-repeat: no-repeat; background-position: 1px 2px; min-height: 20px; padding-left: 12px;"'; $name = urldecode($cm->name); $name = block_taskchain_navigation::filter_text($name); $name = trim(strip_tags($name)); $name = block_taskchain_navigation::trim_text($name, $cm_namelength, $cm_headlength, $cm_taillength); $cms[$sectionnum][] = '<option value="' . $cm->id . '"' . $selected . $style . '>' . $name . '</option>'; $select = $select_defaultvalue; if ($select && count($sections_array)) { $select = in_array($cm->sectionnum, $sections_array); } if ($select && count($modules_array)) { $select = in_array($cm->modname, $modules_array); } if ($select && $include) { $select = preg_match('/' . $include . '/', $cm->name); } if ($select && $exclude) { $select = !preg_match('/' . $exclude . '/', $cm->name); } if ($select && $visibility >= 0) { if ($section_visible[$cm->sectionnum]) { $select = $visibility == $cm->visible; } else { // in a hidden section, we need to check the activity module's "visibleold" setting $select = $visibility == $DB->get_field('course_modules', 'visibleold', array('id' => $cm->id)); } } if ($select && count($cmids_array)) { $select = in_array($cm->id, $cmids_array); } if ($select) { $selected_cmids[$cm->id] = $cm; } } } // $completionfields now contains additional "completion" // fields used by activity modules on this Moodle site // these fields have also been added to $settings $selected_settings = array(); if ($action == 'apply') { foreach ($settings as $setting) { $select = 'select_' . $setting; if (optional_param($select, 0, PARAM_INT)) { $selected_settings[] = $setting; } } } $sectionmenu = array(-1 => get_string('currentsection', $plugin), '-' => '-----'); // separator $sectionnums = array_keys($sections); if ($sections = $DB->get_records('course_sections', array('course' => $course->id), 'section', 'section,name,summary')) { foreach ($sections as $sectionnum => $sectioninfo) { // extract section title from section name or summary if ($text = block_taskchain_navigation::filter_text($sectioninfo->name)) { $text = block_taskchain_navigation::trim_text($text, $section_namelength, $section_headlength, $section_taillength); } else { if ($text = block_taskchain_navigation::filter_text($sectioninfo->summary)) { // remove script and style blocks $select = '/\\s*<(script|style)[^>]*>.*?<\\/\\1>\\s*/is'; $text = preg_replace($select, '', $text); if ($tags = $sectiontags) { $tags = preg_split('/[^a-zA-Z0-9]+/', $tags); $tags = array_map('trim', $tags); $tags = array_filter($tags); $tags = implode('|', $tags); if ($tags) { $tags .= '|'; } } $tags .= 'h1|h2|h3|h4|h5|h6'; if (preg_match('/<(' . $tags . ')\\b[^>]*>(.*?)<\\/\\1>/is', $text, $matches)) { $text = $matches[2]; } else { // otherwise, get first line of text $text = preg_split('/<br[^>]*>/', $text); $text = array_map('strip_tags', $text); $text = array_map('trim', $text); $text = array_filter($text); if (empty($text)) { $text = ''; } else { $text = reset($text); } } $text = trim(strip_tags($text)); $text = block_taskchain_navigation::trim_text($text, $section_namelength, $section_taillength, $section_taillength); } } // set default section title, if necessary if ($text == '') { $format = 'format_' . $course->format; switch (true) { case $sectiontype == 'week' && $sectionnum > 0: $date = $course->startdate + 7200 + ($sectionnum - 1) * 604800; $text = userdate($date, $weekdateformat) . ' - ' . userdate($date + 518400, $weekdateformat); break; case $strman->string_exists('section' . $sectionnum . 'name', $format): $text = get_string('section' . $sectionnum . 'name', $format); break; case $strman->string_exists('sectionname', $format): $text = get_string('sectionname', $format) . ' ' . $sectionnum; break; case $strman->string_exists($sectiontype, 'moodle'): $text = get_string('sectionname') . ' ' . $sectionnum; break; default: $text = $sectiontype . ' ' . $sectionnum; } } // assign section title if (in_array($sectionnum, $sectionnums)) { $sections[$sectionnum] = $text; } else { unset($sections[$sectionnum]); } $sectionmenu[$sectionnum] = $text; } } foreach ($cms as $sectionnum => $options) { unset($cms[$sectionnum]); $text = $sections[$sectionnum]; $cms[$text] = '<optgroup label="' . $text . '">' . "\n" . implode("\n", $options) . '</optgroup>'; } $cms = implode("\n", $cms); $cms = '<select id="id_cmids" name="cmids[]" size="' . min($select_size, $count_cmids) . '" multiple="multiple">' . "\n" . $cms . "\n" . '</select>' . "\n"; foreach ($sections as $sectionnum => $text) { if (in_array($sectionnum, $sections_array)) { $selected = ' selected="selected"'; } else { $selected = ''; } $sections[$sectionnum] = '<option value="' . $sectionnum . '"' . $selected . '>' . $text . '</option>'; } $count_sections = count($sections); $sections = implode("\n", $sections); $sections = '<select id="id_sections" name="sections[]" size="' . min($select_size, $count_sections) . '" multiple="multiple">' . "\n" . $sections . "\n" . '</select>' . "\n"; asort($modules); foreach ($modules as $module => $text) { if (in_array($module, $modules_array)) { $selected = ' selected="selected"'; } else { $selected = ''; } if (empty($CFG->modpixpath)) { $style = ''; // shouldn't happen } else { $url = $CFG->modpixpath . '/' . $module . '/icon.gif'; $style = ' style="background-image: url(' . $url . '); background-repeat: no-repeat; background-position: 1px 2px; min-height: 20px; padding-left: 20px;"'; } $modules[$module] = '<option value="' . $module . '"' . $selected . $style . '>' . $text . '</option>'; } $count_modules = count($modules); $modules = implode("\n", $modules); $modules = '<select id="id_modules" name="modules[]" size="' . min($select_size, $count_modules) . '" multiple="multiple">' . "\n" . $modules . "\n" . '</select>' . "\n"; $days = array(); for ($i = 1; $i <= 31; $i++) { $days[$i] = $i; } $months = array(); for ($i = 1; $i <= 12; $i++) { $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), '%B'); } $years = array(); for ($i = 1970; $i <= 2020; $i++) { $years[$i] = $i; } $hours = array(); for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf('%02d', $i); } $minutes = array(); for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf('%02d', $i); } $visibilitymenu = array(-1 => '', 0 => get_string('hidden', 'grades'), 1 => get_string('visible')); $visiblemenu = array(0 => get_string('hide'), 1 => get_string('show')); $ratings = new rating_manager(); $ratings = $ratings->get_aggregate_types(); $gradings = array(); $maxgrades = array(); $gradepassmenu = array(); for ($i = 100; $i >= 1; $i--) { $maxgrades[$i] = $i . '%'; $gradepassmenu[$i] = $i . '%'; } $maxgrades[0] = get_string('nograde'); $gradecategories = grade_get_categories_menu($course->id); $groupmodes = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible')); //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $groupings = array(); if ($records = $DB->get_records('groupings', array('courseid' => $course->id))) { $groupings = array(0 => get_string('none')); foreach ($records as $record) { $groupings[$record->id] = format_string($record->name); } } $indentmenu = array(); for ($i = -5; $i <= 5; $i++) { if ($i == 0) { $indentmenu[$i] = get_string('reset'); } else { $indentmenu[$i] = ($i < 0 ? '-' : '+') . abs($i); } } $positionmenu = array(1 => get_string('startofsection', $plugin), 2 => get_string('endofsection', $plugin)); if ($strman->string_exists('direction_from', 'availability_date')) { // Moodle >= 2.7 $conditiondatedirectionmenu = array(1 => get_string('direction_from', 'availability_date'), 2 => get_string('direction_until', 'availability_date')); } else { // Moodle >= 2.6 $conditiondatedirectionmenu = array(1 => get_string('from'), 2 => get_string('durationuntil', 'calendar')); } $conditiongradeitemidmenu = array(); $conditioncmidmenu = array(); $conditionfieldnamemenu = array(); $conditionfieldoperatormenu = array(); $conditiongroupidmenu = array(); $conditiongroupingidmenu = array(); $conditionactionmenu = array(); $conditioncmcompletionmenu = array(); if ($enableavailability) { $basemenuitems = array('0' => get_string('none', 'moodle'), '00' => '=====', PREVIOUS_ANY_COURSE => get_string('previousanycourse', $plugin), PREVIOUS_ANY_SECTION => get_string('previousanysection', $plugin), PREVIOUS_SAME_COURSE => get_string('previoussamecourse', $plugin), PREVIOUS_SAME_SECTION => get_string('previoussamesection', $plugin), '000' => '=====', NEXT_ANY_COURSE => get_string('nextanycourse', $plugin), NEXT_ANY_SECTION => get_string('nextanysection', $plugin), NEXT_SAME_COURSE => get_string('nextsamecourse', $plugin), NEXT_SAME_SECTION => get_string('nextsamesection', $plugin), '0000' => '====='); $categories = grade_category::fetch_all(array('courseid' => $course->id)); if ($items = grade_item::fetch_all(array('courseid' => $course->id))) { uasort($items, 'grade_items_uasort'); $spaces = ''; $space = '│ '; $ids = array_keys($items); foreach ($ids as $i => $id) { $item = $items[$id]; if ($item->is_course_item()) { $depth = 0; $index = ''; } else { if ($item->is_category_item()) { if ($depth = $DB->get_field('grade_categories', 'depth', array('id' => $item->iteminstance))) { if ($depth > 1) { $depth--; } } $spaces = str_repeat($space, $depth - 1); } else { $spaces = str_repeat($space, $depth); } } $name = $spaces . get_tree_char($depth, $i, $ids, $items, $categories) . $item->get_name(true); $name = block_taskchain_navigation::trim_text($name, $cm_namelength, $cm_headlength + strlen($spaces), $cm_taillength); $items[$id] = $name; } if (count($items)) { $conditiongradeitemidmenu = $basemenuitems + $items; } } if ($enablecompletion) { $items = array(); $modinfo = get_fast_modinfo($course); foreach ($modinfo->cms as $id => $cm) { if ($cm->completion) { $items[$id] = $cm->name; } } if (count($items)) { asort($items); $conditioncmidmenu = $basemenuitems + $items; } } $conditionfieldnamemenu = array('' => get_string('none', 'moodle')); $conditionfieldoperatormenu = array(); $filepath = $CFG->dirroot . '/availability/condition/profile/classes/frontend.php'; if (file_exists($filepath)) { // Moodle >= 2.7 $contents = file_get_contents($filepath); $search = "/'([a-zA-Z0-9]+)' => get_user_field_name\\('\\1'\\)/"; if (preg_match_all($search, $contents, $items)) { foreach ($items[1] as $item) { $conditionfieldnamemenu[$item] = get_user_field_name($item); } } $search = "/(?<=')op_([a-zA-Z0-9]+)(?=')/"; if (preg_match_all($search, $contents, $items)) { foreach ($items[1] as $i => $item) { $conditionfieldoperatormenu[$item] = get_string($items[0][$i], 'availability_profile'); } } require_once $CFG->dirroot . '/user/profile/lib.php'; if ($items = profile_get_custom_fields(true)) { foreach ($items as $item) { $conditionfieldnamemenu[$item->shortname] = $item->name; } } } else { if (method_exists('condition_info', 'get_condition_user_fields')) { // Moodle >= 2.4 if ($items = condition_info::get_condition_user_fields(array('context' => $course->context))) { $conditionfieldnamemenu += $items; } $conditionfieldoperatormenu = condition_info::get_condition_user_field_operators(); } else { // Moodle <= 2.3 doesn't have conditional user fields $conditionfieldnamemenu = array(); } } if ($dbman->field_exists('course_modules', 'availability')) { // Moodle >= 2.7 if ($items = groups_get_all_groups($course->id)) { foreach ($items as $item) { $name = $item->name; $name = block_taskchain_navigation::filter_text($name); $name = block_taskchain_navigation::trim_text($name); $conditiongroupidmenu[$item->id] = $name; } } if ($items = groups_get_all_groupings($course->id)) { foreach ($items as $item) { $name = $item->name; $name = block_taskchain_navigation::filter_text($name); $name = block_taskchain_navigation::trim_text($name); $conditiongroupingidmenu[$item->id] = $name; } } } $str = new stdClass(); if ($strman->string_exists('accessrestrictions', 'availability')) { // Moodle >= 2.7 $str->accessrestrictions = get_string('accessrestrictions', 'availability'); $str->datetitle = get_string('title', 'availability_date'); $str->userfield = get_string('conditiontitle', 'availability_profile'); $str->gradetitle = get_string('title', 'availability_grade'); $str->grademin = get_string('option_min', 'availability_grade'); $str->grademax = get_string('option_max', 'availability_grade'); $str->activitycompletion = get_string('activitycompletion', 'completion'); $conditioncmcompletionmenu = array(COMPLETION_COMPLETE => get_string('option_complete', 'availability_completion'), COMPLETION_INCOMPLETE => get_string('option_incomplete', 'availability_completion'), COMPLETION_COMPLETE_PASS => get_string('option_pass', 'availability_completion'), COMPLETION_COMPLETE_FAIL => get_string('option_fail', 'availability_completion')); $str->showavailability = get_string('display', 'form'); // Note: CONDITION_STUDENTVIEW_xxx constants are not defined in Moodle >= 2.9 $hide = defined('CONDITION_STUDENTVIEW_HIDE') ? CONDITION_STUDENTVIEW_HIDE : 0; $show = defined('CONDITION_STUDENTVIEW_SHOW') ? CONDITION_STUDENTVIEW_SHOW : 1; $conditionactionmenu = array($hide => get_string('hidden_all', 'availability'), $show => get_string('shown_all', 'availability')); } else { // Moodle <= 2.6 $str->accessrestrictions = get_string('availabilityconditions', 'condition'); $str->datetitle = get_string('date'); if ($strman->string_exists('userfield', 'condition')) { // Moodle >= 2.4 $str->userfield = get_string('userfield', 'condition'); } $str->gradetitle = get_string('gradecondition', 'condition'); $str->grademin = get_string('grade_atleast', 'condition'); $str->grademax = get_string('grade_upto', 'condition'); $str->activitycompletion = get_string('completioncondition', 'condition'); $conditioncmcompletionmenu = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition')); $str->showavailability = get_string('showavailability', 'condition'); $conditionactionmenu = array(CONDITION_STUDENTVIEW_HIDE => get_string('showavailability_hide', 'condition'), CONDITION_STUDENTVIEW_SHOW => get_string('showavailability_show', 'condition')); } $icon = new pix_icon('i/hide', ''); $icon = $OUTPUT->render($icon); $str->showavailability = $icon . ' ' . $str->showavailability; if ($enablecompletion) { $str->conditioncmungraded = get_string('conditioncmungraded', $plugin); $str->conditioncmresources = get_string('conditioncmresources', $plugin); $str->conditioncmlabels = get_string('conditioncmlabels', $plugin); } } if ($enablecompletion) { $completiontrackingmenu = array(0 => get_string('completion_none', 'completion'), 1 => get_string('completion_manual', 'completion'), 2 => get_string('completion_automatic', 'completion')); } else { $completiontrackingmenu = array(); } if (class_exists('core_competency\\course_module_competency')) { // Moodle >= 3.1 $competencyrulemenu = \core_competency\course_module_competency::get_ruleoutcome_list(); } else { $competencyrulemenu = array(); } $filtermenu = array(TEXTFILTER_INHERIT => '', TEXTFILTER_OFF => get_string('off', 'filters'), TEXTFILTER_ON => get_string('on', 'filters')); $filterdefaulton = get_string('defaultx', 'filters', $filtermenu[TEXTFILTER_ON]); $filterdefaultoff = get_string('defaultx', 'filters', $filtermenu[TEXTFILTER_OFF]); // initialize state flags $success = null; $started_list = false; $reset_filter_caches = false; $rebuild_course_cache = false; $regrade_course_grades = false; // create grade categories, if necessary if ($creategradecats) { $modinfo = get_fast_modinfo($course); // default aggregate is "simple weighted mean of grades" // TODO: set default aggregate from form $aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2; // get max sortorder from database if ($sortorder = $DB->get_field('grade_items', 'MAX(sortorder)', array('courseid' => $course->id))) { $sortorder++; } else { $sortorder = 1; } // create course grade category - not usually necessary $fullname = '?'; // special name for course grade category $params = array('courseid' => $course->id, 'depth' => 1, 'fullname' => $fullname); if ($course_grade_category_id = $DB->get_field('grade_categories', 'id', $params)) { $DB->set_field('grade_categories', 'aggregation', $aggregation, $params); } else { $course_grade_category_id = create_grade_category($course, $fullname, null, $aggregation, 0.0, $sortorder++, GRADE_DISPLAY_TYPE_PERCENTAGE); } // create/update section grade categories foreach ($sectionmenu as $sectionnum => $sectiontext) { if (empty($modinfo->sections[$sectionnum])) { continue; } $grade_category_id = 0; foreach ($modinfo->sections[$sectionnum] as $cmid) { if (empty($modinfo->cms[$cmid])) { continue; } $params = array('courseid' => $course->id, 'itemtype' => 'mod', 'itemmodule' => $modinfo->cms[$cmid]->modname, 'iteminstance' => $modinfo->cms[$cmid]->instance); if (!($grade_items = $DB->get_records('grade_items', $params))) { continue; } // note that some activities can have more than on grade item per instance // e.g. mod_workshop creates both "submission" and "assessment" grade items foreach ($grade_items as $grade_item) { if ($grade_category_id == 0) { $fullname = $sectiontext; $params = array('courseid' => $course->id, 'depth' => 2, 'fullname' => $fullname); if ($grade_category_id = $DB->get_field('grade_categories', 'id', $params)) { $DB->set_field('grade_categories', 'aggregation', $aggregation, array('id' => $grade_category_id)); } else { $grade_category_id = create_grade_category($course, $fullname, $course_grade_category_id, $aggregation, 0.0, $sortorder++); } } $DB->set_field('grade_items', 'categoryid', $grade_category_id, array('id' => $grade_item->id)); $DB->set_field('grade_items', 'sortorder', $sortorder++, array('id' => $grade_item->id)); } } } $regrade_course_grades = true; } // remove grade categories, if necessary if ($removegradecats) { $select = 'DISTINCT categoryid'; $from = '{grade_items}'; $where = 'courseid = ? AND itemtype <> ? AND itemtype <> ?'; $params = array($course->id, 'course', 'category'); $select = "id IN (SELECT {$select} FROM {$from} WHERE {$where})"; if ($ids = $DB->get_records_select('grade_categories', $select, $params, 'id', 'id,path')) { foreach (array_keys($ids) as $id) { $ids[$id] = trim($ids[$id]->path, '/'); } $ids = array_filter($ids); $ids = implode('/', $ids); $ids = explode('/', $ids); $ids = array_unique($ids); } else { if ($ids = $DB->get_records('grade_categories', array('courseid' => $course->id, 'depth' => 1, 'fullname' => '?'))) { $ids = array(key($ids)); // the course category } } if (empty($ids)) { $ids = ''; $params = array(); } else { list($ids, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_QM, '', false); // i.e. NOT IN } $select = 'courseid = ?' . ($ids == '' ? '' : " AND id {$ids}"); array_unshift($params, $course->id); if ($DB->delete_records_select('grade_categories', $select, $params)) { $regrade_course_grades = true; } $select = 'itemtype = ? AND courseid = ?' . ($ids == '' ? '' : " AND iteminstance {$ids}"); array_unshift($params, 'category'); if ($DB->delete_records_select('grade_items', $select, $params)) { $regrade_course_grades = true; } unset($select, $from, $where, $params, $ids, $id); } // sort grade categories, if necessary if ($sortgradeitems) { $select = 'courseid = ? AND itemtype = ?'; $params = array($course->id, 'mod'); if ($items = $DB->get_records_select('grade_items', $select, $params, 'sortorder')) { $categories = array(); foreach ($items as $item) { $categoryid = $item->categoryid; $cmid = 0; foreach ($modinfo->cms as $cmid => $cm) { if ($item->itemmodule == $cm->modname && $item->iteminstance == $cm->instance) { $cmid = $cm->id; break; } } if ($cmid) { if (empty($categories[$categoryid])) { $categories[$categoryid] = array(); } $categories[$categoryid][$cmid] = $item->sortorder; } } $modinfo_cmids = array_keys($modinfo->cms); foreach (array_keys($categories) as $categoryid) { // get available cm ids and sortorder numbers $cmids = array_keys($categories[$categoryid]); $sortorder = array_values($categories[$categoryid]); // get course page sort order for each cm $cmids = array_flip($cmids); foreach (array_keys($cmids) as $cmid) { $cmids[$cmid] = array_search($cmid, $modinfo_cmids); } // sort cmids according to course page order asort($cmids); // remove course page order info $cmids = array_keys($cmids); // assign an available sort order to each cm's grade item $select = 'courseid = ? AND itemtype = ? AND itemmodule = ? AND iteminstance = ?'; foreach ($cmids as $i => $cmid) { $params = array($course->id, 'mod', $modinfo->cms[$cmid]->modname, $modinfo->cms[$cmid]->instance); $DB->set_field_select('grade_items', 'sortorder', $sortorder[$i], $select, $params); } } } unset($items, $categories, $cmids, $sortorder, $modinfo_cmids); } // update activities, if necessary if (count($selected_cmids) && (count($selected_settings) || $action == 'delete')) { $success = true; $fields = array('assign' => array('availablefrom' => 'allowsubmissionsfromdate', 'availableuntil' => 'duedate', 'maxgrade' => 'grade', 'rating' => ''), 'assignment' => array('availablefrom' => 'timeavailable', 'availableuntil' => 'timedue', 'maxgrade' => 'grade', 'rating' => ''), 'attendance' => array('availablefrom' => '', 'availableuntil' => '', 'maxgrade' => 'grade', 'rating' => ''), 'choice' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => '', 'rating' => ''), 'data' => array('availablefrom' => 'timeavailablefrom', 'availableuntil' => 'timeavailableto', 'maxgrade' => 'scale', 'rating' => 'assessed'), 'feedback' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => '', 'rating' => ''), 'forum' => array('availablefrom' => 'assesstimestart', 'availableuntil' => 'assesstimefinish', 'maxgrade' => 'scale', 'rating' => 'assessed'), 'glossary' => array('availablefrom' => 'assesstimestart', 'availableuntil' => 'assesstimefinish', 'maxgrade' => 'scale', 'rating' => 'assessed'), 'hotpot' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => 'grade', 'rating' => ''), 'lesson' => array('availablefrom' => 'available', 'availableuntil' => 'deadline', 'maxgrade' => 'grade', 'rating' => ''), 'questionnaire' => array('availablefrom' => 'opendate', 'availableuntil' => 'closedate', 'maxgrade' => 'grade', 'rating' => ''), 'quiz' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => 'grade', 'rating' => ''), 'reader' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => 'maxgrade', 'rating' => ''), 'scorm' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => 'maxgrade', 'rating' => ''), 'taskchain' => array('availablefrom' => 'timeopen', 'availableuntil' => 'timeclose', 'maxgrade' => 'gradelimit', 'rating' => ''), 'workshop' => array('availablefrom' => 'assessmentstart', 'availableuntil' => 'assessmentend', 'maxgrade' => 'grade ', 'rating' => '')); $table_columns = array(); // make sure mod pix path is set if (empty($CFG->modpixpath)) { $CFG->modpixpath = $CFG->dirroot . '/mod'; } foreach ($selected_cmids as $cmid => $cm) { $updated = false; $skipped = false; $regrade_item_id = 0; $modhaslibfile = file_exists("{$CFG->dirroot}/mod/{$cm->modname}/lib.php"); // get the $instance of this $cm (include idnumber for grading) $instance = $DB->get_record($cm->modname, array('id' => $cm->instance)); $instance->cmidnumber = $cm->idnumber; // get module context $modulecontext = context_module::instance($cm->id); if ($action == 'delete') { if (function_exists('course_delete_module')) { // Moodle >= 2.5 course_delete_module($cm->id); } else { // Moodle <= 2.4 $filepath = $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; if (!file_exists($filepath)) { $msg = "{$cm->modname} lib.php not found at {$filepath}"; echo $OUTPUT->notification($msg); } require_once $filepath; $deleteinstancefunction = $cm->modname . '_delete_instance'; if (!function_exists($deleteinstancefunction)) { $msg = "{$cm->modname} delete function not found ({$deleteinstancefunction})"; echo $OUTPUT->notification($msg); } // copied from "course/mod.php" if (!$deleteinstancefunction($cm->instance)) { $msg = "Could not delete the {$cm->modname} (instance id={$cm->instance})"; echo $OUTPUT->notification($msg); } if (!delete_course_module($cm->id)) { $msg = "Could not delete the {$cm->modname} (coursemodule, id={$cm->id})"; echo $OUTPUT->notification($msg); } if (!($sectionid = $DB->get_field('course_sections', 'id', array('course' => $cm->course, 'section' => $cm->sectionnum)))) { $msg = "Could not get section id (course id={$cm->course}, section num={$cm->sectionnum})"; echo $OUTPUT->notification($msg); } if (!delete_mod_from_section($cm->id, $sectionid)) { $msg = "Could not delete the {$cm->modname} (id={$cm->id}) from that section (id={$sectionid})"; echo $OUTPUT->notification($msg); } add_to_log($cm->course, 'course', 'delete mod', "view.php?id={$cm->course}", "{$cm->modname} {$cm->instance}", $cm->id); } $rebuild_course_cache = true; $updated = true; } // only check completion/conditions once per $cm $conditions_checked = false; $completion_updated = false; // Note: $selected_settings should only contain anything if $action=='apply' foreach ($selected_settings as $setting) { switch ($setting) { // activity instance settings case 'availablefrom': case 'availableuntil': case 'availablecutoff': case 'maxgrade': case 'rating': if ($cm->modname == 'taskchain') { $table = 'taskchain_chains'; $id = $DB->get_field($table, 'id', array('parenttype' => 0, 'parentid' => $cm->instance)); } else { $table = $cm->modname; $id = $cm->instance; } // get list of fields in this $table if (empty($table_columns[$table])) { $table_columns[$table] = $DB->get_columns($table); foreach (array_keys($table_columns[$table]) as $field) { $table_columns[$table][$field] = true; } } // convert setting name to database field name if (isset($fields[$cm->modname][$setting])) { $field = $fields[$cm->modname][$setting]; } else { if ($setting == 'availablecutoff') { $field = 'cutoffdate'; } else { $field = $setting; } } // update activity instance record, if field exists if (empty($table_columns[$table][$field])) { $skipped = true; } else { if ($DB->set_field($table, $field, ${$setting}, array('id' => $id))) { // $$ is on purpose $updated = true; } else { $success = false; } } break; // course_module settings // course_module settings case 'visible': if ($section_visible[$cm->sectionnum]) { $rebuild_course_cache = true; $field = 'visible'; } else { // hidden section - use "visibleold" field // Note: there is no need to rebuild cache $field = 'visibleold'; } if ($DB->set_field('course_modules', $field, ${$setting}, array('id' => $cm->id))) { $updated = true; } else { $success = false; } break; case 'indent': switch (true) { case $indent == 0: $set = 'indent = 0'; break; case $indent > 0: $set = "indent = (indent + {$indent})"; break; case $indent < 0: $set = "indent = (CASE WHEN indent < ABS({$indent}) THEN 0 ELSE indent - ABS({$indent}) END)"; break; } if ($DB->execute("UPDATE {$CFG->prefix}course_modules SET {$set} WHERE id = {$cm->id}")) { $rebuild_course_cache = true; $updated = true; } else { $success = false; } break; case 'section': if ($cm->sectionnum == $section) { $skipped = true; } else { // remove cm from old section $params = array('course' => $course->id, 'section' => $cm->sectionnum); if ($sectionid = $DB->get_field('course_sections', 'id', $params)) { $sequence = $DB->get_field('course_sections', 'sequence', $params); if (is_string($sequence)) { $sequence = explode(',', $sequence); $sequence = array_filter($sequence); // remove blanks $sequence = preg_grep('/^' . $cm->id . '$/', $sequence, PREG_GREP_INVERT); $sequence = implode(',', $sequence); $DB->set_field('course_sections', 'sequence', $sequence, $params); } // add cm to target $section if ($position == 1) { $add_cm_to_sequence = 'array_unshift'; // prepend to start of section } else { $add_cm_to_sequence = 'array_push'; // append to end of section } $params = array('course' => $course->id, 'section' => $section >= 0 ? $section : $cm->sectionnum); $sectionid = $DB->get_field('course_sections', 'id', $params); $sequence = $DB->get_field('course_sections', 'sequence', $params); if (is_string($sequence)) { $sequence = explode(',', $sequence); $sequence = array_filter($sequence); // remove blanks $sequence = preg_grep('/^' . $cm->id . '$/', $sequence, PREG_GREP_INVERT); } else { $sequence = array(); // shouldn't happen !! } $add_cm_to_sequence($sequence, $cm->id); $sequence = implode(',', $sequence); $DB->set_field('course_sections', 'sequence', $sequence, $params); $DB->set_field('course_modules', 'section', $sectionid, array('id' => $cm->id)); $updated = true; $rebuild_course_cache = true; } } break; // uploadlimit // uploadlimit case 'uploadlimit': switch ($cm->modname) { case 'assign': // Moodle >= 2.3 $table = 'assign_plugin_config'; $params = array('assignment' => $cm->instance, 'subtype' => 'assignsubmission', 'plugin' => 'file', 'name' => 'maxsubmissionsizebytes'); if ($DB->record_exists($table, $params)) { if ($DB->set_field($table, 'value', ${$setting}, $params)) { $updated = true; } else { $success = false; } } else { $params['value'] = ${$setting}; if ($DB->insert_record($table, $params)) { $updated = true; } else { $success = false; } } break; case 'assignment': // Moodle <= 2.2 // Moodle <= 2.2 case 'forum': case 'workshop': if ($DB->set_field($cm->modname, 'maxbytes', ${$setting}, array('id' => $cm->instance))) { $updated = true; } else { $success = false; } break; // skip all other modules // skip all other modules default: $skipped = true; } break; // course module settings // course module settings case 'groupmode': case 'groupingid': case 'groupmembersonly': if ($DB->set_field('course_modules', $setting, ${$setting}, array('id' => $cm->id))) { $updated = true; $rebuild_course_cache = true; } else { $success = false; } break; // gradebook settings // gradebook settings case 'gradecat': case 'gradeitemhidden': case 'gradepass': $select = 'courseid = ? AND itemtype = ? AND itemmodule = ? AND iteminstance = ?'; $params = array($course->id, 'mod', $cm->modname, $cm->instance); switch ($setting) { case 'gradecat': $field = 'categoryid'; break; case 'gradeitemhidden': $field = 'hidden'; break; default: $field = $setting; } if ($DB->set_field_select('grade_items', $field, ${$setting}, $select, $params)) { $updated = true; $regrade_item_id = $DB->get_field_select('grade_items', 'id', $select, $params); } else { $success = false; } break; // extra credit // extra credit case 'extracredit': $skipped = true; $select = 'courseid = ? AND itemtype = ? AND itemmodule = ? AND iteminstance = ?'; $params = array($course->id, 'mod', $cm->modname, $cm->instance); if ($grade_item = $DB->get_record_select('grade_items', $select, $params)) { $select = 'id = ? AND aggregation IN (?, ?, ?)'; $params = array($grade_item->categoryid, GRADE_AGGREGATE_WEIGHTED_MEAN2, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_SUM); if ($grade_category = $DB->get_record_select('grade_categories', $select, $params)) { $skipped = false; if ($DB->set_field('grade_items', 'aggregationcoef', $extracredit, array('id' => $grade_item->id))) { $updated = true; $regrade_item_id = $grade_item->id; } else { $success = false; } } } break; // regrade activity // regrade activity case 'regrade': // Note: the lib.php for this mod was included earlier // if we use just the "update_grades" function, // we cannot know if it is successful or not ... // $update_grades = $cm->modname.'_update_grades'; // ... so we use the following functions instead: $get_user_grades = $cm->modname . '_get_user_grades'; $grade_item_update = $cm->modname . '_grade_item_update'; if (function_exists($get_user_grades) && function_exists($grade_item_update)) { $grades = $get_user_grades($instance); if ($grade_item_update($instance, $grades) == GRADE_UPDATE_OK) { // GRADE_UPDATE_OK = 0 $updated = true; } else { $success = false; } $skipped = false; } else { $skipped = true; } break; case 'removeconditions': if ($removeconditions) { if ($dbman->field_exists('course_modules', 'availability')) { // Moodle >= 2.7 $DB->set_field('course_modules', 'availability', '', array('id' => $cm->id)); $updated = true; } else { // Moodle <= 2.6 if ($dbman->field_exists('course_modules', 'availablefrom')) { $DB->set_field('course_modules', 'availablefrom', 0, array('id' => $cm->id)); $DB->set_field('course_modules', 'availableuntil', 0, array('id' => $cm->id)); $DB->set_field('course_modules', 'showavailability', 0, array('id' => $cm->id)); $updated = true; } if ($dbman->table_exists('course_modules_availability')) { $DB->delete_records('course_modules_availability', array('coursemoduleid' => $cm->id)); $updated = true; } if ($dbman->table_exists('course_modules_avail_fields')) { $DB->delete_records('course_modules_avail_fields', array('coursemoduleid' => $cm->id)); $updated = true; } } $rebuild_course_cache = true; } break; case 'conditiondate': case 'conditiongrade': case 'conditionfield': case 'conditiongroup': case 'conditiongrouping': case 'conditioncm': case 'conditionaction': if ($conditions_checked == false) { $conditions_checked = true; $conditions = array_merge($conditiondate, $conditiongrade, $conditionfield, $conditiongroup, $conditiongrouping, $conditioncm); update_course_module_availability($labelmods, $resourcemods, $course, $cm, $conditions, $conditionaction, $updated, $skipped); if ($updated) { $rebuild_course_cache = true; } } break; case 'removecompletion': if ($removecompletion) { $table = 'course_modules'; $params = array('id' => $cm->id); $names = array('completion' => 0, 'completionview' => 0, 'completionexpected' => 0, 'completiongradeitemnumber' => null); foreach ($names as $name => $disabled) { $value = $DB->get_field($table, $name, $params); if (isset($value)) { $value = intval($value); } if ($value === $disabled) { $skipped = true; } else { $updated = $DB->set_field($table, $name, $disabled, $params); } } $params = array('id' => $cm->instance); foreach ($completionfields as $name => $field) { if ($field->cmfield) { continue; // e.g. completionview/grade } if (array_key_exists($cm->modname, $field->mods)) { if ($DB->get_field($cm->modname, $name, $params)) { $updated = $DB->set_field($cm->modname, $name, 0, $params); } else { $skipped = true; } } } if ($updated) { $completion_updated = true; } } break; case 'erasecompletion': if ($erasecompletion) { $completion_updated = true; $updated = true; } else { $skipped = true; } break; case 'completiontracking': update_course_module_completion('course_modules', $cm->id, 'completion', $completiontracking, $updated, $skipped, $completion_updated); break; case 'completiondate': update_course_module_completion('course_modules', $cm->id, $setting, $completiondate, $updated, $skipped, $completion_updated); break; case 'completionview': if (array_key_exists($cm->modname, $completionfields[$setting]->mods)) { update_course_module_completion('course_modules', $cm->id, $setting, $completionview, $updated, $skipped, $completion_updated); } break; case 'completiongrade': if (array_key_exists($cm->modname, $completionfields[$setting]->mods)) { // course_modules.completiongradeitemnumber // see "set_moduleinfo_defaults()" in "course/modlib.php" // null=disabled, 0=enabled (i.e. require grade) $completiongradeitemnumber = $completiongrade ? 0 : null; update_course_module_completion('course_modules', $cm->id, 'completiongradeitemnumber', $completiongradeitemnumber, $updated, $skipped, $completion_updated); } break; case 'competencyrule': $data = (object) array('coursemodule' => $cm->id, 'competencies' => array(), 'competency_rule' => $competencyrule); // see "admin/tool/lp/lib.php" $data = tool_lp_coursemodule_edit_post_actions($data, $course); $updated = true; break; default: if (array_key_exists($setting, $completionfields)) { $field = $completionfields[$setting]; if (array_key_exists($cm->modname, $field->mods)) { update_course_module_completion($cm->modname, $cm->instance, $setting, ${$setting}, $updated, $skipped, $completion_updated); } } else { if (substr($setting, 0, 6) == 'filter') { $filter = substr($setting, 6); if (in_array(${$setting}, array(TEXTFILTER_ON, TEXTFILTER_OFF, TEXTFILTER_INHERIT))) { filter_set_local_state($filter, $modulecontext->id, ${$setting}); $reset_filter_caches = true; $updated = true; } else { $skipped = true; } } else { // unexpected setting - shouldn't happen !! echo 'Unknown setting, ' . $setting . ', not processed' . html_writer::empty_tag('br'); } } } // end switch } // end foreach $selected_settings if ($completion_updated) { $completion = $completiontracking; // if automatic completion (=2) is requested, // check that some completion conditions are set if ($completion == 2) { $completion = 0; $table = 'course_modules'; $params = array('id' => $cm->id); $names = array('completionview' => 0, 'completionexpected' => 0, 'completiongradeitemnumber' => null); foreach ($names as $name => $disabled) { $value = $DB->get_field($table, $name, $params); if (isset($value)) { $value = intval($value); } if ($value !== $disabled) { $completion = $completiontracking; } } foreach ($completionfields as $field) { $name = $field->name; if (property_exists($instance, $name) && $instance->{$name}) { $completion = $completiontracking; } } } // force completion to be something sensible update_course_module_completion('course_modules', $cm->id, 'completion', $completion, $updated, $skipped, $completion_updated); // get full $cm record if (method_exists($cm, 'get_course_module_record')) { // Moodle >= 2.7 $cm = $cm->get_course_module_record(true); } else { // Moodle <= 2.6 $cm = get_coursemodule_from_id($cm->modname, $cm->id, $cm->course, true); } // prevent "Cannot find grade item" error in "lib/completionlib.php" $params = array('courseid' => $cm->course, 'itemtype' => 'mod', 'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance); if (!grade_item::fetch($params)) { $cm->completiongradeitemnumber = null; // disable grade completion } $completion = new completion_info($course); $completion->reset_all_state($cm); $rebuild_course_cache = true; } if ($regrade_item_id) { $regrade_course_grades = true; $DB->set_field('grade_items', 'needsupdate', 1, array('id' => $regrade_item_id)); $DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $course->id, 'itemtype' => 'course')); } if ($started_list == false) { $started_list = true; echo '<table border="0" cellpadding="4" cellspacing="4" class="selectedactivitylist"><tbody>' . "\n"; echo '<tr><th colspan="2">' . get_string('settingsselected', $plugin) . '</th></tr>' . "\n"; foreach ($selected_settings as $setting) { list($name, $value) = format_setting($setting, ${$setting}, $ratings, $gradecategories, $groupmodes, $groupings, $indentmenu, $sectionmenu, $positionmenu, $uploadlimitmenu, $conditiongradeitemidmenu, $conditioncmidmenu, $conditioncmcompletionmenu, $conditionfieldnamemenu, $conditionfieldoperatormenu, $conditiongroupidmenu, $conditiongroupingidmenu, $conditionactionmenu, $completiontrackingmenu, $completionfields, $competencyrulemenu, $filters, $filtermenu, $filterdefaulton, $filterdefaultoff); echo '<tr><td class="itemname">' . $name . ':</td><td class="itemvalue">' . $value . '</td></tr>' . "\n"; } echo '<tr><th colspan="2">' . get_string('activitiesselected', $plugin) . '</th></tr>' . "\n"; } echo '<tr><td class="itemname">'; if ($updated) { echo '<span class="updated">' . get_string('updated', 'moodle', $cm->modname) . '</span>'; } else { if ($skipped) { echo '<span class="skipped">' . get_string('skipped') . ' ' . $cm->modname . '</span>'; } else { echo '<span class="failure">' . get_string('fail', 'install') . ' ' . $cm->modname . '</span>'; } } echo '</td><td class="itemvalue">'; $url = $PAGE->theme->pix_url('icon', $cm->modname)->out(); echo '<img src="' . $url . '" class="icon" title="' . s(get_string('modulename', $cm->modname)) . '"></img> '; $name = urldecode($cm->name); $name = block_taskchain_navigation::filter_text($name); $name = trim(strip_tags($name)); $name = block_taskchain_navigation::trim_text($name, $cm_namelength, $cm_headlength, $cm_taillength); echo $name; echo '</td></tr>' . "\n"; } } if ($sortgradeitems || $creategradecats || $removegradecats || $reset_filter_caches || $rebuild_course_cache || $regrade_course_grades || isset($success)) { if ($started_list == false) { $started_list = true; echo '<table border="0" cellpadding="4" cellspacing="4" class="selectedactivitylist"><tbody>' . "\n"; } if ($sortgradeitems) { echo '<tr><td class="notifymessage" colspan="2">'; $msg = get_string('sortedgradeitems', $plugin); echo $OUTPUT->notification($msg, 'notifysuccess'); echo '</td></tr>' . "\n"; } if ($creategradecats) { echo '<tr><td class="notifymessage" colspan="2">'; $msg = get_string('createdgradecategories', $plugin); echo $OUTPUT->notification($msg, 'notifysuccess'); echo '</td></tr>' . "\n"; } if ($removegradecats) { echo '<tr><td class="notifymessage" colspan="2">'; $msg = get_string('removedgradecategories', $plugin); echo $OUTPUT->notification($msg, 'notifysuccess'); echo '</td></tr>' . "\n"; } if ($reset_filter_caches) { echo '<tr><td class="notifymessage" colspan="2">'; echo get_string('resettingfiltercache', $plugin) . ' ... '; filter_manager::reset_caches(); //unset($FILTERLIB_PRIVATE->active[$context->id]); echo get_string('ok') . '</td></tr>' . "\n"; } if ($rebuild_course_cache) { echo '<tr><td class="notifymessage" colspan="2">'; echo get_string('rebuildingcoursecache', $plugin) . ' ... '; rebuild_course_cache($course->id); echo get_string('ok') . '</td></tr>' . "\n"; } if ($regrade_course_grades) { echo '<tr><td class="notifymessage" colspan="2">'; echo get_string('recalculatingcoursegrades', $plugin) . ' ... '; grade_regrade_final_grades($course->id); echo get_string('ok') . '</td></tr>' . "\n"; } if ($success === true) { echo '<tr><td class="notifymessage" colspan="2">'; $msg = get_string('success'); echo $OUTPUT->notification($msg, 'notifysuccess'); echo '</td></tr>' . "\n"; } if ($success === false) { echo '<tr><td class="notifymessage" colspan="2">'; $msg = get_string('activityupdatefailure', $plugin); echo $OUTPUT->notification($msg, 'notifyproblem'); echo '</td></tr>' . "\n"; } } if ($started_list) { $started_list = false; echo '</tbody></table>' . "\n"; } echo '<script type="text/javascript">' . "\n"; echo "//<![CDATA[\n"; echo "function reset_all_in(elTagName, elNamePrefix, parentTagName, parentClass, parentId, resetValues) {\n"; echo " var obj = document.getElementsByTagName(elTagName);\n"; echo " obj = filterByParent(obj, function(el) {return findParentNode(el, parentTagName, parentClass, parentId);});\n"; echo " for (var i=0; i<obj.length; i++) {\n"; echo " var elName = obj[i].name;\n"; echo " if (elName && (elNamePrefix=='' || elName.substr(0, elNamePrefix.length)==elNamePrefix)) {\n"; echo " switch (obj[i].type) {\n"; echo " case 'checkbox':\n"; echo " case 'radio':\n"; echo " if (typeof(resetValues)=='string') {\n"; echo " obj[i].checked = (resetValues=='all' ? true : false);\n"; echo " } else {\n"; echo " obj[i].checked = (resetValues[elName] ? true : false);\n"; echo " }\n"; echo " if (obj[i].onclick) {\n"; echo " obj[i].onclick()\n"; echo " }\n"; echo " break;\n"; echo " case 'select':\n"; echo " case 'select-multiple':\n"; echo " for (var ii=0; ii<obj[i].options.length; ii++) {\n"; echo " if (typeof(resetValues)=='string') {\n"; echo " obj[i].options[ii].selected = (resetValues=='all' ? true : false);\n"; echo " } else {\n"; echo " var elValue = obj[i].options[ii].value;\n"; echo " obj[i].options[ii].selected = (resetValues[elValue] ? true : false);\n"; echo " }\n"; echo " }\n"; echo " break;\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo "}\n"; echo "function set_disabled(frm, names, value, sync_checkbox) {\n"; echo " var fixed_color = false;\n"; echo " if (frm) {\n"; echo " var i_max = names.length;\n"; echo " for (var i=0; i<i_max; i++) {\n"; echo " if (frm.elements[names[i]]) {\n"; echo " frm.elements[names[i]].disabled = value;\n"; echo " if (sync_checkbox) {\n"; echo " if (frm.elements[names[i]].type=='checkbox') {\n"; echo " frm.elements[names[i]].checked = (! value);\n"; echo " }\n"; echo " }\n"; echo " if (fixed_color==false) {\n"; echo " fixed_color = true;\n"; echo " var obj = frm.elements[names[i]].parentNode;\n"; echo " if (obj) {\n"; echo " obj.style.color = (value ? '#999999' : 'inherit');\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " return true;\n"; echo "}\n"; echo "function init_disabled(frm, names, value) {\n"; echo " var obj = document.getElementsByTagName('input');\n"; echo " if (obj) {\n"; echo " var i_max = obj.length;\n"; echo " for (var i=0; i<i_max; i++) {\n"; echo " if (obj[i].name && obj[i].name.substr(0, 7)=='select_' && obj[i].onclick) {\n"; echo " obj[i].id = 'id_' + obj[i].name;\n"; echo " obj[i].onclick();\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " return true;\n"; echo "}\n"; echo "function confirm_action(msg, checksettings) {\n"; echo " var ok = false;\n"; echo " var obj = null;\n"; echo " if (obj = document.getElementById('id_sections')) {\n"; echo " if (obj.selectedIndex >= 0) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (obj = document.getElementById('id_modules')) {\n"; echo " if (obj.selectedIndex >= 0) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (obj = document.getElementById('id_include')) {\n"; echo " if (obj.value) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (obj = document.getElementById('id_exclude')) {\n"; echo " if (obj.value) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (obj = document.getElementById('menuvisibility')) {\n"; echo " if (obj.selectedIndex >= 1) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (obj = document.getElementById('id_cmids')) {\n"; echo " if (obj.selectedIndex >= 0) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " if (ok==false) {\n"; echo " alert('" . js(get_string('noactivitiesselected', $plugin)) . "');\n"; echo " return ok;\n"; echo " }\n"; echo " if (checksettings) {\n"; echo " ok = false;\n"; echo " var settings = new Array('id_select_" . implode("', 'id_select_", $settings) . "');\n"; echo " for (var i=0; i<settings.length; i++) {\n"; echo " if (obj = document.getElementById(settings[i])) {\n"; echo " if (obj.checked) {\n"; echo " ok = true;\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " }\n"; echo " if (ok==false) {\n"; echo " alert('" . js(get_string('nosettingsselected', $plugin)) . "');\n"; echo " return ok;\n"; echo " }\n"; echo " return confirm(msg);\n"; echo "}\n"; echo "if (window.addEventListener) {\n"; echo " window.addEventListener('load', init_disabled, false);\n"; echo "} else if (window.attachEvent) {\n"; echo " window.attachEvent('onload', init_disabled)\n"; echo "} else {\n"; echo " window.onload = init_disabled;\n"; echo "}\n"; echo "//]]>\n"; echo '</script>' . "\n"; echo '<form method="post" action="accesscontrol.php" enctype="multipart/form-data">' . "\n"; echo '<table border="0" cellpadding="4" cellspacing="4" width="720" style="margin: auto;" class="blockconfigtable">' . "\n"; echo '<tr>' . "\n"; echo '<td colspan="2" class="blockdescription">' . nl2br(get_string('accesspagedescription', $plugin)) . '</td>' . "\n"; echo '<td class="itemselect">'; echo get_string('select') . ' '; echo $OUTPUT->help_icon('selectsettings', $plugin); echo '<br />'; echo '<a href="' . "javascript:reset_all_in('INPUT','select_','TD','itemselect',null,'all');" . '">' . get_string('all') . '</a>'; echo ' / '; echo '<a href="' . "javascript:reset_all_in('INPUT','select_','TD','itemselect',null,'none');" . '">' . get_string('none') . '</a>'; echo '</td>' . "\n"; echo '</tr>' . "\n"; // ============================ // Activity filters // ============================ // print_sectionheading(get_string('activityfilters', $plugin), 'activityfilters', false); echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('sectiontags', $plugin) . ':</td>'; echo '<td class="itemvalue">'; echo '<input id="id_sectiontags" type="text" name="sectiontags" size="15" value="' . $sectiontags . '" />'; echo ' ' . $OUTPUT->help_icon('sectiontitletags', $plugin); echo '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('sections', $plugin) . ':'; echo '<div class="smalltext">'; echo '<a href="' . "javascript:reset_all_in('SELECT','sections','','',null,'all');" . '">' . get_string('all') . '</a>'; echo ' / '; echo '<a href="' . "javascript:reset_all_in('SELECT','sections','','',null,'none');" . '">' . get_string('none') . '</a>'; echo '</div>'; echo '</td>' . "\n"; echo '<td class="itemvalue">' . $sections . '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('activitytypes', $plugin) . ':'; echo '<div class="smalltext">'; echo '<a href="' . "javascript:reset_all_in('SELECT','modules','','',null,'all');" . '">' . get_string('all') . '</a>'; echo ' / '; echo '<a href="' . "javascript:reset_all_in('SELECT','modules','','',null,'none');" . '">' . get_string('none') . '</a>'; echo '</div>'; echo '</td>' . "\n"; echo '<td class="itemvalue">' . $modules . '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('activitynamefilters', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo ' <div class="subitem">'; echo ' <div class="subname">' . get_string('include', $plugin) . ':</div>'; echo ' <input id="id_include" type="text" name="include" size="15" value="' . $include . '" />'; echo ' </div>'; echo ' <div class="subitem">'; echo ' <div class="subname">' . get_string('exclude', $plugin) . ':</div>'; echo ' <input id="id_exclude" type="text" name="exclude" size="15" value="' . $exclude . '" />'; echo ' </div>'; echo '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('visibility', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($visibilitymenu, 'visibility', $visibility, ''); echo '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('activityids', $plugin) . ':'; echo '<div class="smalltext">'; echo '<a href="' . "javascript:reset_all_in('SELECT','cmids','','',null,'all');" . '">' . get_string('all') . '</a>'; echo ' / '; echo '<a href="' . "javascript:reset_all_in('SELECT','cmids','','',null,'none');" . '">' . get_string('none') . '</a>'; echo '</div>'; echo '</td>' . "\n"; echo '<td class="itemvalue">' . $cms . '</td>' . "\n"; echo '<td class="itemselect"> </td>' . "\n"; echo '</tr>' . "\n"; // ============================ // Availability dates // ============================ // print_sectionheading(get_string('dates', $plugin), 'dates', true); echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('availablefrom', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; $fromdate['minutes'] = intval($fromdate['minutes']) - intval($fromdate['minutes']) % 5; echo html_writer::select($days, 'fromday', intval($fromdate['mday']), '') . ' '; echo html_writer::select($months, 'frommonth', intval($fromdate['mon']), '') . ' '; echo html_writer::select($years, 'fromyear', intval($fromdate['year']), '') . ' '; echo html_writer::select($hours, 'fromhours', intval($fromdate['hours']), '') . ' '; echo html_writer::select($minutes, 'fromminutes', intval($fromdate['minutes']), '') . ' '; $names = "'menufromday', 'menufrommonth', 'menufromyear', 'menufromhours', 'menufromminutes'"; $script = "return set_disabled(this.form, new Array({$names}), (this.disabled || this.checked))"; echo html_writer::checkbox('fromdisable', '1', $fromdisable, get_string('disable'), array('onclick' => $script)); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('fromdisable'), (! this.checked)) && this.form.fromdisable.onclick()"; $checked = optional_param('select_availablefrom', 0, PARAM_INT); echo html_writer::checkbox('select_availablefrom', 1, $checked, '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('availableuntil', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; $untildate['minutes'] = intval($untildate['minutes']) - intval($untildate['minutes']) % 5; echo html_writer::select($days, 'untilday', intval($untildate['mday']), '') . ' '; echo html_writer::select($months, 'untilmonth', intval($untildate['mon']), '') . ' '; echo html_writer::select($years, 'untilyear', intval($untildate['year']), '') . ' '; echo html_writer::select($hours, 'untilhours', intval($untildate['hours']), '') . ' '; echo html_writer::select($minutes, 'untilminutes', intval($untildate['minutes']), '') . ' '; $names = "'menuuntilday', 'menuuntilmonth', 'menuuntilyear', 'menuuntilhours', 'menuuntilminutes'"; $script = "return set_disabled(this.form, new Array({$names}), (this.disabled || this.checked))"; echo html_writer::checkbox('untildisable', '1', $untildisable, get_string('disable'), array('onclick' => $script)); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('untildisable'), (! this.checked)) && this.form.untildisable.onclick()"; $checked = optional_param('select_availableuntil', 0, PARAM_INT); echo html_writer::checkbox('select_availableuntil', 1, $checked, '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; if ($modnames = implode(', ', $cutoffdatemods)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('cutoffdate', 'assign') . ':</td>' . "\n"; echo '<td class="itemvalue">'; $cutoffdate['minutes'] = intval($cutoffdate['minutes']) - intval($cutoffdate['minutes']) % 5; echo html_writer::select($days, 'cutoffday', intval($cutoffdate['mday']), '') . ' '; echo html_writer::select($months, 'cutoffmonth', intval($cutoffdate['mon']), '') . ' '; echo html_writer::select($years, 'cutoffyear', intval($cutoffdate['year']), '') . ' '; echo html_writer::select($hours, 'cutoffhours', intval($cutoffdate['hours']), '') . ' '; echo html_writer::select($minutes, 'cutoffminutes', intval($cutoffdate['minutes']), '') . ' '; $names = "'menucutoffday', 'menucutoffmonth', 'menucutoffyear', 'menucutoffhours', 'menucutoffminutes'"; $script = "return set_disabled(this.form, new Array({$names}), (this.disabled || this.checked))"; echo html_writer::checkbox('cutoffdisable', '1', $cutoffdisable, get_string('disable'), array('onclick' => $script)); echo html_writer::empty_tag('br') . '(' . get_string('completionfieldactivities', $plugin, $modnames) . ')'; echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('cutoffdisable'), (! this.checked)) && this.form.cutoffdisable.onclick()"; $checked = optional_param('select_availablecutoff', 0, PARAM_INT); echo html_writer::checkbox('select_availablecutoff', 1, $checked, '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ============================ // Grades // ============================ // echo '<tr class="sectionheading" id="id_section_dates">' . "\n"; echo '<th colspan="2">'; echo get_string('grades'); echo ' <span class="sortgradeitems">'; if ($sortgradeitems) { echo ' ' . get_string('sortedgradeitems', $plugin); } else { $href = $CFG->wwwroot . '/blocks/taskchain_navigation/accesscontrol.php?id=' . $block_instance->id . '&sortgradeitems=1&sesskey=' . sesskey(); $onclick = 'return confirm("' . js(get_string('confirmsortgradeitems', $plugin)) . '")'; echo '<a href="' . s($href) . '" onclick="' . s($onclick) . '">' . get_string('sortgradeitems', $plugin) . '</a> '; echo $OUTPUT->help_icon('sortgradeitems', $plugin); } echo '</span>'; echo ' <span class="creategradecategories">'; if ($creategradecats) { echo ' ' . get_string('createdgradecategories', $plugin); } else { $href = $CFG->wwwroot . '/blocks/taskchain_navigation/accesscontrol.php?id=' . $block_instance->id . '&creategradecats=1&sesskey=' . sesskey(); $onclick = 'return confirm("' . js(get_string('confirmcreategradecategories', $plugin)) . '")'; echo '<a href="' . s($href) . '" onclick="' . s($onclick) . '">' . get_string('creategradecategories', $plugin) . '</a> '; echo $OUTPUT->help_icon('creategradecategories', $plugin); } echo '</span>'; echo ' <span class="removegradecategories">'; if ($removegradecats) { echo ' ' . get_string('removedgradecategories', $plugin); } else { $href = $CFG->wwwroot . '/blocks/taskchain_navigation/accesscontrol.php?id=' . $block_instance->id . '&removegradecats=1&sesskey=' . sesskey(); $onclick = 'return confirm("' . js(get_string('confirmremovegradecategories', $plugin)) . '")'; echo '<a href="' . s($href) . '" onclick="' . s($onclick) . '">' . get_string('removegradecategories', $plugin) . '</a> '; echo $OUTPUT->help_icon('removegradecategories', $plugin); } echo '</span>'; echo '</th>' . "\n"; echo '<th class="toggle"></th>' . "\n"; echo '</tr>' . "\n"; if ($modnames = implode(', ', $ratingmods)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('rating', 'rating') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($ratings, 'rating', $rating, '') . ' '; echo '(' . get_string('completionfieldactivities', $plugin, $modnames) . ')'; echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('rating'), (! this.checked))"; echo html_writer::checkbox('select_rating', 1, optional_param('select_rating', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } if ($modnames = implode(', ', $gradingmods)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('grade') . ':</td>' . "\n"; echo '<td class="itemvalue">'; foreach ($gradingmods as $modname => $modtext) { echo "<p>{$modname} - {$modtext}<br />"; foreach ($gradingareas[$modname] as $areaname => $areatext) { echo " == {$areaname} - {$areatext}<br />"; } echo "</p>\n"; } echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('grading'), (! this.checked))"; echo html_writer::checkbox('select_grading', 1, optional_param('select_grading', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('maximumgrade', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($maxgrades, 'maxgrade', $maxgrade, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('maxgrade'), (! this.checked))"; echo html_writer::checkbox('select_maxgrade', 1, optional_param('select_maxgrade', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('gradepass', 'grades') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($gradepassmenu, 'gradepass', $gradepass, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('gradepass'), (! this.checked))"; echo html_writer::checkbox('select_gradepass', 1, optional_param('select_gradepass', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('gradecategory', 'grades') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($gradecategories, 'gradecat', $gradecat, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('gradecat'), (! this.checked))"; echo html_writer::checkbox('select_gradecat', 1, optional_param('select_gradecat', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('gradeitemhidden', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select_yes_no('gradeitemhidden', $gradeitemhidden); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('gradeitemhidden'), (! this.checked))"; echo html_writer::checkbox('select_gradeitemhidden', 1, optional_param('select_gradeitemhidden', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('aggregationcoefextra', 'grades') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select_yes_no('extracredit', $extracredit); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('extracredit'), (! this.checked))"; echo html_writer::checkbox('select_extracredit', 1, optional_param('select_extracredit', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('regrade', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select_yes_no('regrade', $regrade); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('regrade'), (! this.checked))"; echo html_writer::checkbox('select_regrade', 1, optional_param('select_regrade', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ============================ // Groups // ============================ // print_sectionheading(get_string('groups'), 'groups', true); echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('groupmode') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($groupmodes, 'groupmode', $groupmode, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('groupmode'), (! this.checked))"; echo html_writer::checkbox('select_groupmode', 1, optional_param('select_groupmode', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; if (count($groupings)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('grouping', 'group') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($groupings, 'groupingid', $groupingid, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('groupingid'), (! this.checked))"; echo html_writer::checkbox('select_groupingid', 1, optional_param('select_groupingid', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; if ($strman->string_exists('groupmembersonly', 'group')) { echo '<tr>' . "\n"; echo '<td class="itemname groupmembersonly">' . get_string('groupmembersonly', 'group') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::checkbox('groupmembersonly', 1, $groupmembersonly); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('groupmembersonly'), (! this.checked))"; echo html_writer::checkbox('select_groupmembersonly', 1, optional_param('select_groupmembersonly', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } } // ============================ // Course page // ============================ // echo '<tr class="sectionheading" id="id_section_coursepage">' . "\n"; echo '<th colspan="2">'; echo get_string('coursepage', $plugin); echo ' <span class="sortgradeitems">'; if ($sortactivities) { echo ' ' . get_string('sortedactivities', $plugin); } else { $href = $CFG->wwwroot . '/blocks/taskchain_navigation/accesscontrol.php?id=' . $block_instance->id . '&sortactivities=1&sesskey=' . sesskey(); $onclick = 'return confirm("' . get_string('confirmsortactivities', $plugin) . '")'; echo '<a href="' . s($href) . '" onclick="' . js($onclick) . '">' . get_string('sortactivities', $plugin) . '</a> '; echo $OUTPUT->help_icon('sortactivities', $plugin); } echo '</span>'; echo '</th>' . "\n"; echo '<th class="toggle"></th>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('visible') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($visiblemenu, 'visible', $visible, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('visible'), (! this.checked))"; echo html_writer::checkbox('select_visible', 1, optional_param('select_visible', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('indent', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($indentmenu, 'indent', $indent, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('indent'), (! this.checked))"; echo html_writer::checkbox('select_indent', 1, optional_param('select_indent', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; if ($strman->string_exists('moveto', 'question')) { // Moodle >= 2.2 $moveto = get_string('moveto', 'question'); } else { // Moodle <= 2.1 $moveto = get_string('movehere'); } echo '<tr>' . "\n"; echo '<td class="itemname">' . $moveto . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($sectionmenu, 'section', $section, ''); echo ' '; echo html_writer::select($positionmenu, 'position', $position, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('section', 'position'), (! this.checked))"; echo html_writer::checkbox('select_section', 1, optional_param('select_section', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ============================ // Files and uploads // ============================ // if (count($filemods)) { print_sectionheading(get_string('fileuploads', 'install'), 'files', true); $href = 'http://php.net/manual/' . substr(current_language(), 0, 2) . '/ini.core.php'; $icon = html_writer::empty_tag('img', array('src' => $PAGE->theme->pix_url('i/info', ''), 'title' => get_string('info'))); $params = array('onclick' => 'this.target="_blank"'); echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('phpuploadlimit', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; if ($limit = ini_get('upload_max_filesize')) { $limit = display_size(get_real_size($limit)) . ' upload_max_filesize '; echo html_writer::tag('span', $limit, array('class' => 'uploadlimit')); echo html_writer::link($href . '#ini.upload-max-filesize', $icon, $params); echo html_writer::empty_tag('br'); } if ($limit = ini_get('post_max_size')) { $limit = display_size(get_real_size($limit)) . ' post_max_size '; echo html_writer::tag('span', $limit, array('class' => 'uploadlimit')); echo html_writer::link($href . '#ini.post-max-size', $icon, $params); } echo '</td>' . "\n"; echo '<td class="itemselect"></td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('siteuploadlimit', $plugin) . ':' . '</td>' . "\n"; echo '<td class="itemvalue">'; // Site administration -> Security -> Site policies: Maximum uploaded file size if ($siteuploadlimit) { $limit = display_size($siteuploadlimit); } else { $limit = get_string('phpuploadlimit', $plugin); $limit = get_string('sameas', $plugin, $limit); $limit = html_writer::tag('i', $limit); } echo html_writer::tag('span', $limit, array('class' => 'uploadlimit')); if (has_capability('moodle/course:update', $sitecontext)) { $href = new moodle_url('/admin/settings.php', array('section' => 'sitepolicies')); $icon = html_writer::empty_tag('img', array('src' => $PAGE->theme->pix_url('i/settings', ''), 'title' => get_string('update'))); echo html_writer::link($href, $icon, array('onclick' => 'this.target="_blank"')); } echo '</td>' . "\n"; echo '<td class="itemselect"></td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('courseuploadlimit', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; if ($courseuploadlimit) { $limit = display_size($courseuploadlimit); } else { $limit = get_string('siteuploadlimit', $plugin); $limit = get_string('sameas', $plugin, $limit); $limit = html_writer::tag('i', $limit); } echo html_writer::tag('span', $limit, array('class' => 'uploadlimit')); if (has_capability('moodle/course:update', $course->context)) { $href = new moodle_url('/course/edit.php', array('id' => $course->id)); $icon = html_writer::empty_tag('img', array('src' => $PAGE->theme->pix_url('i/settings', ''), 'title' => get_string('update'))); echo html_writer::link($href, $icon, array('onclick' => 'this.target="_blank"')); } echo '</td>' . "\n"; echo '<td class="itemselect"></td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('pluginuploadlimits', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; foreach ($filemods as $name => $limit) { if ($limit) { $limit = display_size($limit); } else { $limit = get_string('courseuploadlimit', $plugin); $limit = get_string('sameas', $plugin, $limit); $limit = html_writer::tag('i', $limit); } $limit .= ': ' . get_string('pluginname', $name); echo html_writer::tag('span', $limit, array('class' => 'uploadlimit')); if ($hassiteconfig) { if ($name == 'assign') { $href = $name . 'submission_file'; } else { $href = 'modsetting' . $name; } $href = new moodle_url('/admin/settings.php', array('section' => $href)); $icon = html_writer::empty_tag('img', array('src' => $PAGE->theme->pix_url('i/settings', ''), 'title' => get_string('update'))); echo html_writer::link($href, $icon, array('onclick' => 'this.target="_blank"')); } echo html_writer::empty_tag('br'); } echo '</td>' . "\n"; echo '<td class="itemselect"></td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('activityuploadlimit', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($uploadlimitmenu, 'uploadlimit', $uploadlimit, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('uploadlimit'), (! this.checked))"; echo html_writer::checkbox('select_uploadlimit', 1, optional_param('select_uploadlimit', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ============================ // Active filters // ============================ // if (count($filters)) { print_sectionheading(get_string('actfilterhdr', 'filters'), 'filters', true); foreach ($filters as $filter => $filterinfo) { if ($filterinfo->inheritedstate == TEXTFILTER_ON) { $filtermenu[TEXTFILTER_INHERIT] = $filterdefaulton; } else { $filtermenu[TEXTFILTER_INHERIT] = $filterdefaultoff; } $setting = 'filter' . $filter; echo '<tr>' . "\n"; echo '<td class="itemname">' . filter_get_name($filter) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($filtermenu, $setting, ${$setting}, ''); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$setting}'), (! this.checked))"; echo html_writer::checkbox('select_' . $setting, 1, optional_param('select_' . $setting, 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } } // ============================ // Access restrictions (Moodle >= 2.7) // Restrict access (Moodle <= 2.6) // ============================ // if ($enableavailability) { echo '<tr class="sectionheading" id ="id_section_availability">' . "\n"; echo '<th colspan="2">' . $str->accessrestrictions . '</th>' . "\n"; echo '<th class="toggle"></th>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname removeconditions">' . get_string('removeconditions', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::checkbox('removeconditions', 1, $removeconditions, get_string('removeconditions_help', $plugin)); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('removeconditions'), (! this.checked), true)"; echo html_writer::checkbox('select_removeconditions', 1, optional_param('select_removeconditions', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ===================== // condition dates // ===================== // echo '<tr>' . "\n"; echo '<td class="itemname">' . $str->datetitle . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditiondatedirection); for ($i = 0; $i < $i_max; $i++) { $conditiondatetime[$i]['minutes'] = intval($conditiondatetime[$i]['minutes']) - intval($conditiondatetime[$i]['minutes']) % 5; echo html_writer::start_tag('p'); echo html_writer::select($conditiondatedirectionmenu, "conditiondatedirection[{$i}]", $conditiondatedirection[$i], '') . ' '; echo html_writer::select($days, "conditiondatetimeday[{$i}]", intval($conditiondatetime[$i]['mday']), '') . ' '; echo html_writer::select($months, "conditiondatetimemonth[{$i}]", intval($conditiondatetime[$i]['mon']), '') . ' '; echo html_writer::select($years, "conditiondatetimeyear[{$i}]", intval($conditiondatetime[$i]['year']), '') . ' '; echo html_writer::select($hours, "conditiondatetimehours[{$i}]", intval($conditiondatetime[$i]['hours']), '') . ' '; echo html_writer::select($minutes, "conditiondatetimeminutes[{$i}]", intval($conditiondatetime[$i]['minutes']), '') . ' '; echo html_writer::end_tag('p'); $names[] = "conditiondatedirection[{$i}]"; $names[] = "conditiondatetimeday[{$i}]"; $names[] = "conditiondatetimemonth[{$i}]"; $names[] = "conditiondatetimeyear[{$i}]"; $names[] = "conditiondatetimehours[{$i}]"; $names[] = "conditiondatetimeminutes[{$i}]"; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditiondate', 1, optional_param('select_conditiondate', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ===================== // condition grades // ===================== // if (count($conditiongradeitemidmenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . $str->gradetitle . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditiongradeitemid); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditiongradeitemidmenu, 'conditiongradeitemid[' . $i . ']', $conditiongradeitemid[$i], '', array('class' => 'conditiongradeitemid')) . ' '; echo html_writer::empty_tag('br'); echo $str->grademin . ' '; echo ' <input id="id_conditiongrademin[' . $i . ']" type="text" name="conditiongrademin[' . $i . ']" size="3" value="' . $conditiongrademin[$i] . '" />% '; echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('spacer'), 'class' => 'spacer', 'width' => '30px')); echo $str->grademax . ' '; echo ' <input id="id_conditiongrademax[' . $i . ']" type="text" name="conditiongrademax[' . $i . ']" size="3" value="' . $conditiongrademax[$i] . '" />% '; echo html_writer::end_tag('p'); $names[] = 'conditiongradeitemid[' . $i . ']'; $names[] = 'conditiongrademin[' . $i . ']'; $names[] = 'conditiongrademax[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditiongrade', 1, optional_param('select_conditiongrade', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ===================== // condition userfields // ===================== // if (count($conditionfieldnamemenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . $str->userfield . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditionfieldname); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditionfieldnamemenu, 'conditionfieldname[' . $i . ']', $conditionfieldname[$i], '', array('class' => 'conditionfieldname')) . ' '; echo html_writer::select($conditionfieldoperatormenu, 'conditionfieldoperator[' . $i . ']', $conditionfieldoperator[$i], '', array('class' => 'conditionfieldoperator')), ' '; echo '<input id="id_conditionfieldvalue[' . $i . ']" type="text" name="conditionfieldvalue[' . $i . ']" size="15" value="' . $conditionfieldvalue[$i] . '" />'; echo html_writer::end_tag('p'); $names[] = 'conditionfieldname[' . $i . ']'; $names[] = 'conditionfieldoperator[' . $i . ']'; $names[] = 'conditionfieldvalue[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditionfield', 1, optional_param('select_conditionfield', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ===================== // condition groups // ===================== // if (count($conditiongroupidmenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('group') . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditiongroupid); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditiongroupidmenu, 'conditiongroupid[' . $i . ']', $conditiongroupid[$i], '', array('class' => 'conditiongroupid')); echo html_writer::end_tag('p'); $names[] = 'conditiongroupid[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditiongroup', 1, optional_param('select_conditiongroup', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ===================== // condition groupings // ===================== // if (count($conditiongroupingidmenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('grouping', 'group') . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditiongroupingid); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditiongroupingidmenu, 'conditiongroupingid[' . $i . ']', $conditiongroupingid[$i], '', array('class' => 'conditiongroupingid')); echo html_writer::end_tag('p'); $names[] = 'conditiongroupingid[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditiongrouping', 1, optional_param('select_conditiongrouping', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ===================== // conditions completion // of other activities // ===================== // if (count($conditioncmidmenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . $str->activitycompletion . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditioncmid); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditioncmidmenu, 'conditioncmid[' . $i . ']', $conditioncmid[$i], '', array('class' => 'conditioncmid')); echo html_writer::empty_tag('br'); echo html_writer::checkbox('conditioncmungraded[' . $i . ']', 1, $conditioncmungraded[$i], $str->conditioncmungraded, array('class' => 'conditioncmungraded')); echo html_writer::empty_tag('br'); echo html_writer::checkbox('conditioncmresources[' . $i . ']', 1, $conditioncmresources[$i], $str->conditioncmresources, array('class' => 'conditioncmresources')); echo html_writer::empty_tag('br'); echo html_writer::checkbox('conditioncmlabels[' . $i . ']', 1, $conditioncmlabels[$i], $str->conditioncmlabels, array('class' => 'conditioncmlabels')); echo html_writer::empty_tag('br'); echo html_writer::select($conditioncmcompletionmenu, 'conditioncmcompletion[' . $i . ']', $conditioncmcompletion[$i], '', array('class' => 'conditioncmcompletion')); echo html_writer::end_tag('p'); $names[] = 'conditioncmid[' . $i . ']'; $names[] = 'conditioncmungraded[' . $i . ']'; $names[] = 'conditioncmresources[' . $i . ']'; $names[] = 'conditioncmlabels[' . $i . ']'; $names[] = 'conditioncmcompletion[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditioncm', 1, optional_param('select_conditioncm', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ===================== // conditions actions // ===================== // if (count($conditionactionmenu)) { echo '<tr>' . "\n"; echo '<td class="itemname">' . $str->showavailability . ':</td>' . "\n"; echo '<td class="itemvalue">'; $names = array(); $i_max = count($conditionaction); for ($i = 0; $i < $i_max; $i++) { echo html_writer::start_tag('p'); echo html_writer::select($conditionactionmenu, 'conditionaction[' . $i . ']', $conditionaction[$i], '', array('class' => 'conditionaction')); echo html_writer::end_tag('p'); $names[] = 'conditionaction[' . $i . ']'; } $names = implode("', '", $names); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('{$names}'), (! this.checked))"; echo html_writer::checkbox('select_conditionaction', 1, optional_param('select_conditionaction', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } } // ============================ // Activity completion // ============================ // if ($enablecompletion) { print_sectionheading(get_string('activitycompletion', 'completion'), 'completion', true); echo '<tr>' . "\n"; echo '<td class="itemname removecompletion">' . get_string('removecompletion', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::checkbox('removecompletion', 1, $removecompletion, get_string('removecompletion_help', $plugin)); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('removecompletion'), (! this.checked), true)"; echo html_writer::checkbox('select_removecompletion', 1, optional_param('select_removecompletion', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo '<td class="itemname erasecompletion">' . get_string('erasecompletion', $plugin) . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::checkbox('erasecompletion', 1, $erasecompletion, get_string('erasecompletion_help', $plugin)); echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('erasecompletion'), (! this.checked), true)"; echo html_writer::checkbox('select_erasecompletion', 1, optional_param('select_erasecompletion', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ===================== // completion type // none/manual/automatic // ===================== // echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('completion', 'completion') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($completiontrackingmenu, 'completiontracking', $completiontracking, ''); echo html_writer::empty_tag('br') . '(' . get_string('usedbyall', $plugin) . ')'; echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('completiontracking'), (! this.checked))"; echo html_writer::checkbox('select_completiontracking', 1, optional_param('select_completiontracking', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ===================== // require view // ===================== // //echo '<tr>'."\n"; //echo '<td class="itemname">'.get_string('completionview', 'completion').':</td>'."\n"; //echo '<td class="itemvalue">'; //echo html_writer::checkbox('completionview', 1, $completionview, get_string('completionview_desc', 'completion')); //echo '</td>'."\n"; //echo '<td class="itemselect">'; //$script = "return set_disabled(this.form, new Array('completionview'), (! this.checked), true)"; //echo html_writer::checkbox('select_completionview', 1, optional_param('select_completionview', 0, PARAM_INT), '', array('onclick' => $script)); //echo '</td>'."\n"; //echo '</tr>'."\n"; // ===================== // require grade // ===================== // //echo '<tr>'."\n"; //echo '<td class="itemname">'.get_string('completionusegrade', 'completion').':</td>'."\n"; //echo '<td class="itemvalue">'; //echo html_writer::checkbox('completiongrade', 1, $completiongrade, get_string('completionusegrade_desc', 'completion')); //echo '</td>'."\n"; //echo '<td class="itemselect">'; //$script = "return set_disabled(this.form, new Array('completiongrade'), (! this.checked), true)"; //echo html_writer::checkbox('select_completiongrade', 1, optional_param('select_completiongrade', 0, PARAM_INT), '', array('onclick' => $script)); //echo '</td>'."\n"; //echo '</tr>'."\n"; // ===================== // completion date // ===================== // echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('completionexpected', 'completion') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select_time('days', 'completionday', $completiondate, 1) . ' '; echo html_writer::select_time('months', 'completionmonth', $completiondate, 1) . ' '; echo html_writer::select_time('years', 'completionyear', $completiondate, 1); echo html_writer::empty_tag('br') . '(' . get_string('usedbyall', $plugin) . ')'; echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('completionday', 'completionmonth', 'completionyear'), (! this.checked))"; echo html_writer::checkbox('select_completiondate', 1, optional_param('select_completiondate', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; // ===================== // activity-specific // completion settings // ===================== // foreach ($completionfields as $name => $field) { $text = $field->text; $desc = $field->desc; $type = $field->type; if ($text == $desc) { $desc = ''; } if (empty($field->params['name'])) { $fieldname = $name; } else { $fieldname = $field->params['name']; } if ($modnames = implode(', ', $field->mods)) { $modnames = get_string('completionfieldactivities', $plugin, $modnames); $modnames = html_writer::tag('span', "({$modnames})", array('class' => 'completionfieldmodnames')); if ($desc) { $modnames = html_writer::empty_tag('br') . $modnames; } } echo '<tr>' . "\n"; echo '<td class="itemname">' . $text . ':</td>' . "\n"; echo '<td class="itemvalue">'; switch ($type) { case 'checkbox': echo html_writer::checkbox($name, 1, ${$name}, ' ' . $desc . $modnames, $field->params); break; case 'duration': $options = implode('', $field->options); echo $desc . ' ' . html_writer::empty_tag('input', $field->params['number']) . ' ' . html_writer::tag('select', $options, $field->params['unit']) . ' ' . $modnames; break; case 'select': $options = implode('', $field->options); echo $desc . ' ' . html_writer::tag('select', $options, $field->params) . $modnames; break; case 'textbox': echo $desc . ' ' . html_writer::empty_tag('input', $field->params) . ' ' . $modnames; break; } echo '</td>' . "\n"; echo '<td class="itemselect">'; $fieldnames = "'{$fieldname}'"; if ($type == 'duration') { $fieldnames .= ",'" . $fieldname . "_unit'"; } $script = $type == 'checkbox' ? 'true' : 'false'; // sync_checkbox $script = "return set_disabled(this.form, new Array({$fieldnames}), (! this.checked), {$script})"; echo html_writer::checkbox('select_' . $name, 1, optional_param('select_' . $name, 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } } // ============================ // Activity competency // ============================ // if ($enablecompetency) { print_sectionheading(get_string('competencies', 'competency'), 'competency', true); echo '<tr>' . "\n"; echo '<td class="itemname">' . get_string('uponcoursemodulecompletion', 'tool_lp') . ':</td>' . "\n"; echo '<td class="itemvalue">'; echo html_writer::select($competencyrulemenu, 'competencyrule', $competencyrule, ''); echo html_writer::empty_tag('br') . '(' . get_string('usedbyall', $plugin) . ')'; echo '</td>' . "\n"; echo '<td class="itemselect">'; $script = "return set_disabled(this.form, new Array('competencyrule'), (! this.checked))"; echo html_writer::checkbox('select_competencyrule', 1, optional_param('select_competencyrule', 0, PARAM_INT), '', array('onclick' => $script)); echo '</td>' . "\n"; echo '</tr>' . "\n"; } // ============================ // Actions // ============================ // print_sectionheading(get_string('actions'), 'actions', false); echo '<tr>' . "\n"; echo '<td class="itemname"> </td>' . "\n"; echo '<td class="itemvalue">' . "\n"; $btn = get_string('applysettings', $plugin); $msg = js(get_string('confirmapply', $plugin)); echo '<input type="submit" name="apply" value="' . $btn . '" onclick="return confirm_action(' . "'{$msg}'" . ', true)" />' . "\n"; echo ' ' . "\n"; echo '<input type="submit" name="cancel" value="' . get_string('cancel') . '" />' . "\n"; echo ' ' . "\n"; $btn = get_string('delete'); $msg = js(get_string('confirmdelete', $plugin)); echo '<input type="submit" name="delete" value="' . $btn . '" onclick="return confirm_action(' . "'{$msg}'" . ')" />' . "\n"; echo '<input type="hidden" name="id" value="' . $block_instance->id . '" />' . "\n"; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . "\n"; echo '</td><td></td>' . "\n"; echo '</tr>' . "\n"; echo '</table>' . "\n"; echo '</form>' . "\n"; }
/** * overridden constructor keeps a reference to the assignment class that is displaying this table * * @param assign $assignment The assignment class * @param int $perpage how many per page * @param string $filter The current filter * @param int $rowoffset For showing a subsequent page of results * @param bool $quickgrading Is this table wrapped in a quickgrading form? * @param string $downloadfilename */ public function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgrading, $downloadfilename = null) { global $CFG, $PAGE, $DB, $USER; parent::__construct('mod_assign_grading'); $this->is_persistent(true); $this->assignment = $assignment; // Check permissions up front. $this->hasgrantextension = has_capability('mod/assign:grantextension', $this->assignment->get_context()); $this->hasgrade = $this->assignment->can_grade(); // Check if we have the elevated view capablities to see the blind details. $this->hasviewblind = has_capability('mod/assign:viewblinddetails', $this->assignment->get_context()); foreach ($assignment->get_feedback_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_grading_batch_operations() as $action => $description) { if (empty($this->plugingradingbatchoperations)) { $this->plugingradingbatchoperations[$plugin->get_type()] = array(); } $this->plugingradingbatchoperations[$plugin->get_type()][$action] = $description; } } } $this->perpage = $perpage; $this->quickgrading = $quickgrading && $this->hasgrade; $this->output = $PAGE->get_renderer('mod_assign'); $urlparams = array('action' => 'grading', 'id' => $assignment->get_course_module()->id); $url = new moodle_url($CFG->wwwroot . '/mod/assign/view.php', $urlparams); $this->define_baseurl($url); // Do some business - then set the sql. $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); if ($rowoffset) { $this->rownum = $rowoffset - 1; } $users = array_keys($assignment->list_participants($currentgroup, true)); if (count($users) == 0) { // Insert a record that will never match to the sql is still valid. $users[] = -1; } $params = array(); $params['assignmentid1'] = (int) $this->assignment->get_instance()->id; $params['assignmentid2'] = (int) $this->assignment->get_instance()->id; $params['assignmentid3'] = (int) $this->assignment->get_instance()->id; $extrauserfields = get_extra_user_fields($this->assignment->get_context()); $fields = user_picture::fields('u', $extrauserfields) . ', '; $fields .= 'u.id as userid, '; $fields .= 's.status as status, '; $fields .= 's.id as submissionid, '; $fields .= 's.timecreated as firstsubmission, '; $fields .= 's.timemodified as timesubmitted, '; $fields .= 's.attemptnumber as attemptnumber, '; $fields .= 'g.id as gradeid, '; $fields .= 'g.grade as grade, '; $fields .= 'g.timemodified as timemarked, '; $fields .= 'g.timecreated as firstmarked, '; $fields .= 'uf.mailed as mailed, '; $fields .= 'uf.locked as locked, '; $fields .= 'uf.extensionduedate as extensionduedate, '; $fields .= 'uf.workflowstate as workflowstate, '; $fields .= 'uf.allocatedmarker as allocatedmarker '; $from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = :assignmentid1 AND s.latest = 1 LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignmentid2 '; // For group submissions we don't immediately create an entry in the assign_submission table for each user, // instead the userid is set to 0. In this case we use a different query to retrieve the grade for the user. if ($this->assignment->get_instance()->teamsubmission) { $params['assignmentid4'] = (int) $this->assignment->get_instance()->id; $grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt FROM {assign_grades} mxg WHERE mxg.assignment = :assignmentid4 GROUP BY mxg.userid'; $from .= 'LEFT JOIN (' . $grademaxattempt . ') gmx ON u.id = gmx.userid AND g.attemptnumber = gmx.maxattempt '; } else { $from .= 'AND g.attemptnumber = s.attemptnumber '; } $from .= 'LEFT JOIN {assign_user_flags} uf ON u.id = uf.userid AND uf.assignment = :assignmentid3'; $userparams = array(); $userindex = 0; list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user'); $where = 'u.id ' . $userwhere; $params = array_merge($params, $userparams); // The filters do not make sense when there are no submissions, so do not apply them. if ($this->assignment->is_any_submission_plugin_enabled()) { if ($filter == ASSIGN_FILTER_SUBMITTED) { $where .= ' AND (s.timemodified IS NOT NULL AND s.status = :submitted) '; $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else { if ($filter == ASSIGN_FILTER_NOT_SUBMITTED) { $where .= ' AND (s.timemodified IS NULL OR s.status != :submitted) '; $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else { if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) { $where .= ' AND (s.timemodified IS NOT NULL AND s.status = :submitted AND (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL))'; $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else { if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) { $userfilter = (int) array_pop(explode('=', $filter)); $where .= ' AND (u.id = :userid)'; $params['userid'] = $userfilter; } } } } } if ($this->assignment->get_instance()->markingworkflow && $this->assignment->get_instance()->markingallocation) { if (has_capability('mod/assign:manageallocations', $this->assignment->get_context())) { // Check to see if marker filter is set. $markerfilter = (int) get_user_preferences('assign_markerfilter', ''); if (!empty($markerfilter)) { if ($markerfilter == ASSIGN_MARKER_FILTER_NO_MARKER) { $where .= ' AND (uf.allocatedmarker IS NULL OR uf.allocatedmarker = 0)'; } else { $where .= ' AND uf.allocatedmarker = :markerid'; $params['markerid'] = $markerfilter; } } } else { // Only show users allocated to this marker. $where .= ' AND uf.allocatedmarker = :markerid'; $params['markerid'] = $USER->id; } } if ($this->assignment->get_instance()->markingworkflow) { $workflowstates = $this->assignment->get_marking_workflow_states_for_current_user(); if (!empty($workflowstates)) { $workflowfilter = get_user_preferences('assign_workflowfilter', ''); if ($workflowfilter == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED) { $where .= ' AND (uf.workflowstate = :workflowstate OR uf.workflowstate IS NULL OR ' . $DB->sql_isempty('assign_user_flags', 'workflowstate', true, true) . ')'; $params['workflowstate'] = $workflowfilter; } else { if (array_key_exists($workflowfilter, $workflowstates)) { $where .= ' AND uf.workflowstate = :workflowstate'; $params['workflowstate'] = $workflowfilter; } } } } $this->set_sql($fields, $from, $where, $params); if ($downloadfilename) { $this->is_downloading('csv', $downloadfilename); } $columns = array(); $headers = array(); // Select. if (!$this->is_downloading() && $this->hasgrade) { $columns[] = 'select'; $headers[] = get_string('select') . '<div class="selectall"><label class="accesshide" for="selectall">' . get_string('selectall') . '</label> <input type="checkbox" id="selectall" name="selectall" title="' . get_string('selectall') . '"/></div>'; } // User picture. if ($this->hasviewblind || !$this->assignment->is_blind_marking()) { if (!$this->is_downloading()) { $columns[] = 'picture'; $headers[] = get_string('pictureofuser'); } else { $columns[] = 'recordid'; $headers[] = get_string('recordid', 'assign'); } // Fullname. $columns[] = 'fullname'; $headers[] = get_string('fullname'); foreach ($extrauserfields as $extrafield) { $columns[] = $extrafield; $headers[] = get_user_field_name($extrafield); } } else { // Record ID. $columns[] = 'recordid'; $headers[] = get_string('recordid', 'assign'); } // Submission status. $columns[] = 'status'; $headers[] = get_string('status', 'assign'); // Team submission columns. if ($assignment->get_instance()->teamsubmission) { $columns[] = 'team'; $headers[] = get_string('submissionteam', 'assign'); } // Allocated marker. if ($this->assignment->get_instance()->markingworkflow && $this->assignment->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->assignment->get_context())) { // Add a column for the allocated marker. $columns[] = 'allocatedmarker'; $headers[] = get_string('marker', 'assign'); } // Grade. $columns[] = 'grade'; $headers[] = get_string('grade'); if ($this->is_downloading()) { if ($this->assignment->get_instance()->grade >= 0) { $columns[] = 'grademax'; $headers[] = get_string('maxgrade', 'assign'); } else { // This is a custom scale. $columns[] = 'scale'; $headers[] = get_string('scale', 'assign'); } if ($this->assignment->get_instance()->markingworkflow) { // Add a column for the marking workflow state. $columns[] = 'workflowstate'; $headers[] = get_string('markingworkflowstate', 'assign'); } // Add a column for the list of valid marking workflow states. $columns[] = 'gradecanbechanged'; $headers[] = get_string('gradecanbechanged', 'assign'); } if (!$this->is_downloading() && $this->hasgrade) { // We have to call this column userid so we can use userid as a default sortable column. $columns[] = 'userid'; $headers[] = get_string('edit'); } // Submission plugins. if ($assignment->is_any_submission_plugin_enabled()) { $columns[] = 'timesubmitted'; $headers[] = get_string('lastmodifiedsubmission', 'assign'); foreach ($this->assignment->get_submission_plugins() as $plugin) { if ($this->is_downloading()) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_editor_fields() as $field => $description) { $index = 'plugin' . count($this->plugincache); $this->plugincache[$index] = array($plugin, $field); $columns[] = $index; $headers[] = $plugin->get_name(); } } } else { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) { $index = 'plugin' . count($this->plugincache); $this->plugincache[$index] = array($plugin); $columns[] = $index; $headers[] = $plugin->get_name(); } } } } // Time marked. $columns[] = 'timemarked'; $headers[] = get_string('lastmodifiedgrade', 'assign'); // Feedback plugins. foreach ($this->assignment->get_feedback_plugins() as $plugin) { if ($this->is_downloading()) { if ($plugin->is_visible() && $plugin->is_enabled()) { foreach ($plugin->get_editor_fields() as $field => $description) { $index = 'plugin' . count($this->plugincache); $this->plugincache[$index] = array($plugin, $field); $columns[] = $index; $headers[] = $description; } } } else { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) { $index = 'plugin' . count($this->plugincache); $this->plugincache[$index] = array($plugin); $columns[] = $index; $headers[] = $plugin->get_name(); } } } // Exclude 'Final grade' column in downloaded grading worksheets. if (!$this->is_downloading()) { // Final grade. $columns[] = 'finalgrade'; $headers[] = get_string('finalgrade', 'grades'); } // Load the grading info for all users. $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users); if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) { $columns[] = 'outcomes'; $headers[] = get_string('outcomes', 'grades'); } // Set the columns. $this->define_columns($columns); $this->define_headers($headers); foreach ($extrauserfields as $extrafield) { $this->column_class($extrafield, $extrafield); } $this->no_sorting('recordid'); $this->no_sorting('finalgrade'); $this->no_sorting('userid'); $this->no_sorting('select'); $this->no_sorting('outcomes'); if ($assignment->get_instance()->teamsubmission) { $this->no_sorting('team'); } $plugincolumnindex = 0; foreach ($this->assignment->get_submission_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) { $submissionpluginindex = 'plugin' . $plugincolumnindex++; $this->no_sorting($submissionpluginindex); } } foreach ($this->assignment->get_feedback_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) { $feedbackpluginindex = 'plugin' . $plugincolumnindex++; $this->no_sorting($feedbackpluginindex); } } // When there is no data we still want the column headers printed in the csv file. if ($this->is_downloading()) { $this->start_output(); } }
get_string('lastname').'</a>'; } else { print "<a href=\"./?course={$course->id}&sort=firstname{$sistring}\">". get_string('firstname').'</a> / '. get_string('lastname'); } print '</th>'; // Print user identity columns foreach ($extrafields as $field) { echo '<th scope="col" class="completion-identifyfield">' . get_user_field_name($field) . '</th>'; } } else { foreach ($extrafields as $field) { echo $sep . csv_quote(get_user_field_name($field)); } } // Activities foreach($activities as $activity) { $activity->datepassed = $activity->completionexpected && $activity->completionexpected <= time(); $activity->datepassedclass=$activity->datepassed ? 'completion-expired' : ''; if ($activity->completionexpected) { $datetext=userdate($activity->completionexpected,get_string('strftimedate','langconfig')); } else { $datetext=''; } // Some names (labels) come URL-encoded and can be very long, so shorten them
if (!empty($user->role)) { $row->cells[1]->text .= get_string('role').get_string('labelsep', 'langconfig').$user->role.'<br />'; } if ($user->maildisplay == 1 or ($user->maildisplay == 2 and ($course->id != SITEID) and !isguestuser()) or has_capability('moodle/course:viewhiddenuserfields', $context) or in_array('email', $extrafields)) { $row->cells[1]->text .= get_string('email').get_string('labelsep', 'langconfig').html_writer::link("mailto:$user->email", $user->email) . '<br />'; } foreach ($extrafields as $field) { if ($field === 'email') { // Skip email because it was displayed with different // logic above (because this page is intended for // students too) continue; } $row->cells[1]->text .= get_user_field_name($field) . get_string('labelsep', 'langconfig') . s($user->{$field}) . '<br />'; } if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) { $row->cells[1]->text .= get_string('city').get_string('labelsep', 'langconfig'); if ($user->city && !isset($hiddenfields['city'])) { $row->cells[1]->text .= $user->city; } if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) { if ($user->city && !isset($hiddenfields['city'])) { $row->cells[1]->text .= ', '; } $row->cells[1]->text .= $countries[$user->country]; } $row->cells[1]->text .= '<br />'; }
/** * displays the full report * @param \stdClass $scorm full SCORM object * @param \stdClass $cm - full course_module object * @param \stdClass $course - full course object * @param string $download - type of download being requested */ public function display($scorm, $cm, $course, $download) { global $CFG, $DB, $OUTPUT, $PAGE; $contextmodule = \context_module::instance($cm->id); $action = optional_param('action', '', PARAM_ALPHA); $attemptids = optional_param_array('attemptid', array(), PARAM_RAW); $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT); $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses. echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); } } // Find out current groups mode. $currentgroup = groups_get_activity_group($cm, true); // Detailed report. $mform = new \mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $pagesize = $fromform->pagesize; $showobjectivescore = $fromform->objectivescore; set_user_preference('scorm_report_pagesize', $pagesize); set_user_preference('scorm_report_objectives_score', $showobjectivescore); } else { $pagesize = get_user_preferences('scorm_report_pagesize', 0); $showobjectivescore = get_user_preferences('scorm_report_objectives_score', 0); } if ($pagesize < 1) { $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE; } // Select group menu. $displayoptions = array(); $displayoptions['attemptsmode'] = $attemptsmode; $displayoptions['objectivescore'] = $showobjectivescore; $mform->set_data($displayoptions + array('pagesize' => $pagesize)); if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. if (!$download) { groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions)); } } $formattextoptions = array('context' => \context_course::instance($course->id)); // We only want to show the checkbox to delete attempts // if the user has permissions and if the report mode is showing attempts. $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule) && $attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO; // Select the students. $nostudents = false; if (empty($currentgroup)) { // All users who can attempt scoes. if (!($students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false))) { echo $OUTPUT->notification(get_string('nostudentsyet')); $nostudents = true; $allowedlist = ''; } else { $allowedlist = array_keys($students); } unset($students); } else { // All users who can attempt scoes and who are in the currently selected group. $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $currentgroup, '', false); if (!$groupstudents) { echo $OUTPUT->notification(get_string('nostudentsingroup')); $nostudents = true; $groupstudents = array(); } $allowedlist = array_keys($groupstudents); unset($groupstudents); } if (!$nostudents) { // Now check if asked download of data. $coursecontext = \context_course::instance($course->id); if ($download) { $filename = clean_filename("{$course->shortname} " . format_string($scorm->name, true, $formattextoptions)); } // Define table columns. $columns = array(); $headers = array(); if (!$download && $candelete) { $columns[] = 'checkbox'; $headers[] = null; } if (!$download && $CFG->grade_report_showuserimage) { $columns[] = 'picture'; $headers[] = ''; } $columns[] = 'fullname'; $headers[] = get_string('name'); $extrafields = get_extra_user_fields($coursecontext); foreach ($extrafields as $field) { $columns[] = $field; $headers[] = get_user_field_name($field); } $columns[] = 'attempt'; $headers[] = get_string('attempt', 'scorm'); $columns[] = 'start'; $headers[] = get_string('started', 'scorm'); $columns[] = 'finish'; $headers[] = get_string('last', 'scorm'); $columns[] = 'score'; $headers[] = get_string('score', 'scorm'); $scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id'); foreach ($scoes as $sco) { if ($sco->launch != '') { $columns[] = 'scograde' . $sco->id; $headers[] = format_string($sco->title, '', $formattextoptions); } } $params = array(); list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED); // Construct the SQL. $select = 'SELECT DISTINCT ' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' '; // This part is the same for all cases - join users and scorm_scoes_track tables. $from = 'FROM {user} u '; $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = ' . $scorm->id; switch ($attemptsmode) { case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts. $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NOT NULL'; break; case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts. $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NULL'; break; case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts. $where = ' WHERE u.id ' . $usql . ' AND (st.userid IS NOT NULL OR st.userid IS NULL)'; break; } $countsql = 'SELECT COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ')) AS nbresults, '; $countsql .= 'COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'st.attempt') . ')) AS nbattempts, '; $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers '; $countsql .= $from . $where; $nbmaincolumns = count($columns); // Get number of main columns used. $objectives = get_scorm_objectives($scorm->id); $nosort = array(); foreach ($objectives as $scoid => $sco) { foreach ($sco as $id => $objectivename) { $colid = $scoid . 'objectivestatus' . $id; $columns[] = $colid; $nosort[] = $colid; if (!$displayoptions['objectivescore']) { // Display the objective name only. $headers[] = $objectivename; } else { // Display the objective status header with a "status" suffix to avoid confusion. $headers[] = $objectivename . ' ' . get_string('status', 'scormreport_objectives'); // Now print objective score headers. $colid = $scoid . 'objectivescore' . $id; $columns[] = $colid; $nosort[] = $colid; $headers[] = $objectivename . ' ' . get_string('score', 'scormreport_objectives'); } } } $emptycell = ''; // Used when an empty cell is being printed - in html we add a space. if (!$download) { $emptycell = ' '; $table = new \flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl($PAGE->url); $table->sortable(true); $table->collapsible(true); // This is done to prevent redundant data, when a user has multiple attempts. $table->column_suppress('picture'); $table->column_suppress('fullname'); foreach ($extrafields as $field) { $table->column_suppress($field); } foreach ($nosort as $field) { $table->no_sorting($field); } $table->no_sorting('start'); $table->no_sorting('finish'); $table->no_sorting('score'); $table->no_sorting('checkbox'); $table->no_sorting('picture'); foreach ($scoes as $sco) { if ($sco->launch != '') { $table->no_sorting('scograde' . $sco->id); } } $table->column_class('picture', 'picture'); $table->column_class('fullname', 'bold'); $table->column_class('score', 'bold'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over. $table->setup(); } else { if ($download == 'ODS') { require_once "{$CFG->libdir}/odslib.class.php"; $filename .= ".ods"; // Creating a workbook. $workbook = new \MoodleODSWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. $sheettitle = get_string('report', 'scorm'); $myxls = $workbook->add_worksheet($sheettitle); // Format types. $format = $workbook->add_format(); $format->set_bold(0); $formatbc = $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb = $workbook->add_format(); $formatb->set_bold(1); $formaty = $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc = $workbook->add_format(); $formatc->set_align('center'); $formatr = $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg = $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); // Here starts workshhet headers. $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else { if ($download == 'Excel') { require_once "{$CFG->libdir}/excellib.class.php"; $filename .= ".xls"; // Creating a workbook. $workbook = new \MoodleExcelWorkbook("-"); // Sending HTTP headers. $workbook->send($filename); // Creating the first worksheet. $sheettitle = get_string('report', 'scorm'); $myxls = $workbook->add_worksheet($sheettitle); // Format types. $format = $workbook->add_format(); $format->set_bold(0); $formatbc = $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb = $workbook->add_format(); $formatb->set_bold(1); $formaty = $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc = $workbook->add_format(); $formatc->set_align('center'); $formatr = $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg = $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else { if ($download == 'CSV') { $csvexport = new \csv_export_writer("tab"); $csvexport->set_filename($filename, ".txt"); $csvexport->add_data($headers); } } } } if (!$download) { $sort = $table->get_sql_sort(); } else { $sort = ''; } // Fix some wired sorting. if (empty($sort)) { $sort = ' ORDER BY uniqueid'; } else { $sort = ' ORDER BY ' . $sort; } if (!$download) { // Add extra limits due to initials bar. list($twhere, $tparams) = $table->get_sql_where(); if ($twhere) { $where .= ' AND ' . $twhere; // Initial bar. $params = array_merge($params, $tparams); } if (!empty($countsql)) { $count = $DB->get_record_sql($countsql, $params); $totalinitials = $count->nbresults; if ($twhere) { $countsql .= ' AND ' . $twhere; } $count = $DB->get_record_sql($countsql, $params); $total = $count->nbresults; } $table->pagesize($pagesize, $total); echo \html_writer::start_div('scormattemptcounts'); if ($count->nbresults == $count->nbattempts) { echo get_string('reportcountattempts', 'scorm', $count); } else { if ($count->nbattempts > 0) { echo get_string('reportcountallattempts', 'scorm', $count); } else { echo $count->nbusers . ' ' . get_string('users'); } } echo \html_writer::end_div(); } // Fetch the attempts. if (!$download) { $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size()); echo \html_writer::start_div('', array('id' => 'scormtablecontainer')); if ($candelete) { // Start form. $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm')); echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post', 'action' => $PAGE->url->out(false), 'onsubmit' => 'return confirm("' . $strreallydel . '");')); echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete')); echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); echo \html_writer::start_div('', array('style' => 'display: none;')); echo \html_writer::input_hidden_params($PAGE->url); echo \html_writer::end_div(); echo \html_writer::start_div(); } $table->initialbars($totalinitials > 20); // Build table rows. } else { $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params); } if ($attempts) { foreach ($attempts as $scouser) { $row = array(); if (!empty($scouser->attempt)) { $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt); } else { $timetracks = ''; } if (in_array('checkbox', $columns)) { if ($candelete && !empty($timetracks->start)) { $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false); } else { if ($candelete) { $row[] = ''; } } } if (in_array('picture', $columns)) { $user = new \stdClass(); $additionalfields = explode(',', \user_picture::fields()); $user = username_load_fields_from_object($user, $scouser, null, $additionalfields); $user->id = $scouser->userid; $row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id)); } if (!$download) { $url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id)); $row[] = \html_writer::link($url, fullname($scouser)); } else { $row[] = fullname($scouser); } foreach ($extrafields as $field) { $row[] = s($scouser->{$field}); } if (empty($timetracks->start)) { $row[] = '-'; $row[] = '-'; $row[] = '-'; $row[] = '-'; } else { if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); $row[] = \html_writer::link($url, $scouser->attempt); } else { $row[] = $scouser->attempt; } if ($download == 'ODS' || $download == 'Excel') { $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig")); } else { $row[] = userdate($timetracks->start); } if ($download == 'ODS' || $download == 'Excel') { $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig')); } else { $row[] = userdate($timetracks->finish); } $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt); } // Print out all scores of attempt. foreach ($scoes as $sco) { if ($sco->launch != '') { if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) { if ($trackdata->status == '') { $trackdata->status = 'notattempted'; } $strstatus = get_string($trackdata->status, 'scorm'); if ($trackdata->score_raw != '') { // If raw score exists, print it. $score = $trackdata->score_raw; // Add max score if it exists. if (isset($trackdata->score_max)) { $score .= '/' . $trackdata->score_max; } } else { // ...else print out status. $score = $strstatus; } if (!$download) { $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt)); $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm'))); } else { $row[] = $score; } // Iterate over tracks and match objective id against values. $scorm2004 = false; if (scorm_version_check($scorm->version, SCORM_13)) { $scorm2004 = true; $objectiveprefix = "cmi.objectives."; } else { $objectiveprefix = "cmi.objectives_"; } $keywords = array(".id", $objectiveprefix); $objectivestatus = array(); $objectivescore = array(); foreach ($trackdata as $name => $value) { if (strpos($name, $objectiveprefix) === 0 && strrpos($name, '.id') !== false) { $num = trim(str_ireplace($keywords, '', $name)); if (is_numeric($num)) { if ($scorm2004) { $element = $objectiveprefix . $num . '.completion_status'; } else { $element = $objectiveprefix . $num . '.status'; } if (isset($trackdata->{$element})) { $objectivestatus[$value] = $trackdata->{$element}; } else { $objectivestatus[$value] = ''; } if ($displayoptions['objectivescore']) { $element = $objectiveprefix . $num . '.score.raw'; if (isset($trackdata->{$element})) { $objectivescore[$value] = $trackdata->{$element}; } else { $objectivescore[$value] = ''; } } } } } // Interaction data. if (!empty($objectives[$trackdata->scoid])) { foreach ($objectives[$trackdata->scoid] as $name) { if (isset($objectivestatus[$name])) { $row[] = s($objectivestatus[$name]); } else { $row[] = $emptycell; } if ($displayoptions['objectivescore']) { if (isset($objectivescore[$name])) { $row[] = s($objectivescore[$name]); } else { $row[] = $emptycell; } } } } // End of interaction data. } else { // If we don't have track data, we haven't attempted yet. $strstatus = get_string('notattempted', 'scorm'); if (!$download) { $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . $strstatus; } else { $row[] = $strstatus; } // Complete the empty cells. for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) { $row[] = $emptycell; } } } } if (!$download) { $table->add_data($row); } else { if ($download == 'Excel' or $download == 'ODS') { $colnum = 0; foreach ($row as $item) { $myxls->write($rownum, $colnum, $item, $format); $colnum++; } $rownum++; } else { if ($download == 'CSV') { $csvexport->add_data($row); } } } } if (!$download) { $table->finish_output(); if ($candelete) { echo \html_writer::start_tag('table', array('id' => 'commands')); echo \html_writer::start_tag('tr') . \html_writer::start_tag('td'); echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')) . ' / '; echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm')); echo ' '; echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'scorm'), 'class' => 'btn btn-secondary')); echo \html_writer::end_tag('td') . \html_writer::end_tag('tr') . \html_writer::end_tag('table'); // Close form. echo \html_writer::end_tag('div'); echo \html_writer::end_tag('form'); } echo \html_writer::end_div(); if (!empty($attempts)) { echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')) . \html_writer::start_tag('tr'); echo \html_writer::start_tag('td'); echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods'), 'post', ['class' => 'm-t-1']); echo \html_writer::end_tag('td'); echo \html_writer::start_tag('td'); echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel'), 'post', ['class' => 'm-t-1']); echo \html_writer::end_tag('td'); echo \html_writer::start_tag('td'); echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext'), 'post', ['class' => 'm-t-1']); echo \html_writer::end_tag('td'); echo \html_writer::start_tag('td'); echo \html_writer::end_tag('td'); echo \html_writer::end_tag('tr') . \html_writer::end_tag('table'); } } } else { if ($candelete && !$download) { echo \html_writer::end_div(); echo \html_writer::end_tag('form'); $table->finish_output(); } echo \html_writer::end_div(); } // Show preferences form irrespective of attempts are there to report or not. if (!$download) { $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode')); $mform->display(); } if ($download == 'Excel' or $download == 'ODS') { $workbook->close(); exit; } else { if ($download == 'CSV') { $csvexport->download_file(); exit; } } } else { echo $OUTPUT->notification(get_string('noactivity', 'scorm')); } }
/** * Determines whether this particular item is currently available * according to these criteria. * * - This does not include the 'visible' setting (i.e. this might return * true even if visible is false); visible is handled independently. * - This does not take account of the viewhiddenactivities capability. * That should apply later. * * @uses COMPLETION_COMPLETE * @uses COMPLETION_COMPLETE_FAIL * @uses COMPLETION_COMPLETE_PASS * @param string $information If the item has availability restrictions, * a string that describes the conditions will be stored in this variable; * if this variable is set blank, that means don't display anything * @param bool $grabthelot Performance hint: if true, caches information * required for all course-modules, to make the front page and similar * pages work more quickly (works only for current user) * @param int $userid If set, specifies a different user ID to check availability for * @param course_modinfo|null $modinfo Usually leave as null for default. Specify when * calling recursively from inside get_fast_modinfo() * @return bool True if this item is available to the user, false otherwise */ public function is_available(&$information, $grabthelot = false, $userid = 0, $modinfo = null) { $this->require_data(); $available = true; $information = ''; // Check each completion condition if (count($this->item->conditionscompletion) > 0) { if (!$modinfo) { $modinfo = get_fast_modinfo($this->item->course); } $completion = new completion_info($modinfo->get_course()); foreach ($this->item->conditionscompletion as $cmid => $expectedcompletion) { // If this depends on a deleted module, handle that situation // gracefully. if (empty($modinfo->cms[$cmid])) { global $PAGE; if (isset($PAGE) && strpos($PAGE->pagetype, 'course-view-') === 0) { debugging("Warning: activity {$this->item->id} '{$this->item->name}' has condition " . "on deleted activity {$cmid} (to get rid of this message, edit the named activity)"); } continue; } // The completion system caches its own data $completiondata = $completion->get_data((object) array('id' => $cmid), $grabthelot, $userid, $modinfo); $thisisok = true; if ($expectedcompletion == COMPLETION_COMPLETE) { // 'Complete' also allows the pass, fail states switch ($completiondata->completionstate) { case COMPLETION_COMPLETE: case COMPLETION_COMPLETE_FAIL: case COMPLETION_COMPLETE_PASS: break; default: $thisisok = false; } } else { // Other values require exact match if ($completiondata->completionstate != $expectedcompletion) { $thisisok = false; } } if (!$thisisok) { $available = false; $information .= html_writer::start_tag('li'); $information .= get_string('requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name) . ' '; $information .= html_writer::end_tag('li'); } } } // Check each grade condition if (count($this->item->conditionsgrade) > 0) { foreach ($this->item->conditionsgrade as $gradeitemid => $minmax) { $score = $this->get_cached_grade_score($gradeitemid, $grabthelot, $userid); if ($score === false || !is_null($minmax->min) && $score < $minmax->min || !is_null($minmax->max) && $score >= $minmax->max) { // Grade fail $available = false; // String depends on type of requirement. We are coy about // the actual numbers, in case grades aren't released to // students. if (is_null($minmax->min) && is_null($minmax->max)) { $string = 'any'; } else { if (is_null($minmax->max)) { $string = 'min'; } else { if (is_null($minmax->min)) { $string = 'max'; } else { $string = 'range'; } } } $information .= html_writer::start_tag('li'); $information .= get_string('requires_grade_' . $string, 'condition', $minmax->name) . ' '; $information .= html_writer::end_tag('li'); } } } // Check if user field condition if (count($this->item->conditionsfield) > 0) { $context = $this->get_context(); foreach ($this->item->conditionsfield as $field => $details) { $uservalue = $this->get_cached_user_profile_field($userid, $field); if (!$this->is_field_condition_met($details->operator, $uservalue, $details->value)) { // Set available to false $available = false; // Display the fieldname into current lang. if (is_numeric($field)) { // Is a custom profile field (will use multilang). $translatedfieldname = $details->fieldname; } else { $translatedfieldname = get_user_field_name($details->fieldname); } $a = new stdClass(); $a->field = format_string($translatedfieldname, true, array('context' => $context)); $a->value = s($details->value); $information .= html_writer::start_tag('li'); $information .= get_string('requires_user_field_' . $details->operator, 'condition', $a) . ' '; $information .= html_writer::end_tag('li'); } } } // Test dates if ($this->item->availablefrom) { if (time() < $this->item->availablefrom) { $available = false; $information .= html_writer::start_tag('li'); $information .= get_string('requires_date', 'condition', self::show_time($this->item->availablefrom, self::is_midnight($this->item->availablefrom))); $information .= html_writer::end_tag('li'); } } if ($this->item->availableuntil) { if (time() >= $this->item->availableuntil) { $available = false; // But we don't display any information about this case. This is // because the only reason to set a 'disappear' date is usually // to get rid of outdated information/clutter in which case there // is no point in showing it... // Note it would be nice if we could make it so that the 'until' // date appears below the item while the item is still accessible, // unfortunately this is not possible in the current system. Maybe // later, or if somebody else wants to add it. } } // If the item is marked as 'not visible' then we don't change the available // flag (visible/available are treated distinctly), but we remove any // availability info. If the item is hidden with the eye icon, it doesn't // make sense to show 'Available from <date>' or similar, because even // when that date arrives it will still not be available unless somebody // toggles the eye icon. if (!$this->item->visible) { $information = ''; } // The information is in <li> tags, but to avoid taking up more space // if there is only a single item, we strip out the list tags so that it // is plain text in that case. if (!empty($information)) { $li = strpos($information, '<li>', 4); if ($li === false) { $information = preg_replace('~^\\s*<li>(.*)</li>\\s*$~s', '$1', $information); } else { $information = html_writer::tag('ul', $information); } $information = trim($information); } return $available; }
/** * fills workbook (either XLSX or ODS) with data * * @param MoodleExcelWorkbook $workbook workbook to put data into * @param stdClass[] $data userdata with headline at index 0 * @param stdClass[] $orderby current sort-array * @param string[] $collapsed current collapsed columns */ private function userlist_fill_workbook(&$workbook, $data = array(), $orderby = array(), $collapsed = array()) { global $SESSION, $CFG; $orientation = optional_param('orientation', 0, PARAM_BOOL); if (count($data) > 0) { if (count($data) > 1) { // General information? unused at the moment! $worksheet = $workbook->add_worksheet(get_string('all')); if (is_a($worksheet, 'Moodle_Excel_Worksheet')) { if ($orientation) { $worksheet->pear_excel_worksheet->setLandscape(); } else { $worksheet->pear_excel_worksheet->setPortrait(); } } } // Prepare formats! $headlineprop = array('size' => 12, 'bold' => 1, 'HAlign' => 'center', 'bottom' => 2, 'VAlign' => 'vcenter'); $headlineformat = $workbook->add_format($headlineprop); $headlineformat->set_right(1); $headlineformat->set_align('center'); $headlineformat->set_align('vcenter'); $headlinelast = $workbook->add_format($headlineprop); $headlinelast->set_align('center'); $headlinelast->set_align('vcenter'); $headlinelast->set_left(1); $headlinenb = $workbook->add_format($headlineprop); $headlinenb->set_align('center'); $headlinenb->set_align('vcenter'); unset($headlineprop['bottom']); $headlinenbb = $workbook->add_format($headlineprop); $headlinenbb->set_align('center'); $headlinenbb->set_align('vcenter'); $regentryprop = array('size' => 10, 'align' => 'left'); $queueentryprop = $regentryprop; $queueentryprop['italic'] = true; $queueentryprop['color'] = 'grey'; $regentryformat = $workbook->add_format($regentryprop); $regentryformat->set_right(1); $regentryformat->set_align('vcenter'); $regentrylast = $workbook->add_format($regentryprop); $regentrylast->set_align('vcenter'); $noregentriesformat = $workbook->add_format($regentryprop); $noregentriesformat->set_align('center'); $noregentriesformat->set_align('vcenter'); $noregentriesformat->set_right(1); $queueentryformat = $workbook->add_format($queueentryprop); $queueentryformat->set_right(1); $queueentryformat->set_align('vcenter'); $queueentrylast = $workbook->add_format($queueentryprop); $queueentrylast->set_align('vcenter'); $noqueueentriesformat = $workbook->add_format($queueentryprop); $noqueueentriesformat->set_align('center'); $noqueueentriesformat->set_align('vcenter'); // Start row for groups general sheet! $j = 0; // We create a dummy user-object to get the fullname-format! $dummy = new stdClass(); $namefields = get_all_user_name_fields(); foreach ($namefields as $namefield) { $dummy->{$namefield} = $namefield; } $fullnameformat = fullname($dummy); // Now get the ones used in fullname in the correct order! $namefields = order_in_string($namefields, $fullnameformat); $columnwidth = array(0 => 26, 'fullname' => 26, 'firstname' => 20, 'surname' => 20, 'email' => 35, 'registrations' => 47, 'queues_rank' => 7.5, 'queues_grp' => 47); // Unit: mm! foreach ($data as $key => $user) { if ($key == 0) { // Headline! $k = 0; // First we output every namefield from used by fullname in exact the defined order! foreach ($namefields as $namefield) { $worksheet->write_string($j, $k, get_user_field_name($namefield), $headlineformat); $worksheet->write_blank($j + 1, $k, $headlineformat); $worksheet->merge_cells($j, $k, $j + 1, $k); $hidden = in_array($namefield, $collapsed) ? true : false; $columnwidth[$namefield] = empty($columnwidth[$namefield]) ? $columnwidth[0] : $columnwidth[$namefield]; $worksheet->set_column($k, $k, $columnwidth[$namefield], null, $hidden); $k++; } // ...k = n! if (!empty($CFG->showuseridentity)) { $fields = explode(',', $CFG->showuseridentity); foreach ($fields as $field) { $worksheet->write_string($j, $k, get_user_field_name($field), $headlineformat); $worksheet->write_blank($j + 1, $k, $headlineformat); $hidden = in_array($field, $collapsed) ? true : false; $columnwidth[$field] = empty($columnwidth[$field]) ? $columnwidth[0] : $columnwidth[$field]; $worksheet->set_column($k, $k, $columnwidth[$field], null, $hidden); $worksheet->merge_cells($j, $k, $j + 1, $k); $k++; // ...k = n+x! } } else { $worksheet->write_string($j, $k, get_user_field_name('idnumber'), $headlineformat); $worksheet->write_blank($j + 1, $k, $headlineformat); $hidden = in_array('idnumber', $collapsed) ? true : false; $columnwidth['idnumber'] = empty($columnwidth['idnumber']) ? $columnwidth[0] : $columnwidth['idnumber']; $worksheet->set_column($k, $k, $columnwidth['idnumber'], null, $hidden); $worksheet->merge_cells($j, $k, $j + 1, $k); $k++; // ...k = n+1! $worksheet->write_string($j, $k, get_user_field_name('email'), $headlineformat); $worksheet->write_blank($j + 1, $k, $headlineformat); $hidden = in_array('email', $collapsed) ? true : false; $columnwidth['email'] = empty($columnwidth['email']) ? $columnwidth[0] : $columnwidth['email']; $worksheet->set_column($k, $k, $columnwidth['email'], null, $hidden); $worksheet->merge_cells($j, $k, $j + 1, $k); $k++; // ...k = n+2! } $worksheet->write_string($j, $k, $user['registrations'], $headlineformat); $worksheet->write_blank($j + 1, $k, $headlineformat); $hidden = in_array('registrations', $collapsed) ? true : false; $columnwidth['registrations'] = empty($columnwidth['registrations']) ? $columnwidth[0] : $columnwidth['registrations']; $worksheet->set_column($k, $k, $columnwidth['registrations'], null, $hidden); $worksheet->merge_cells($j, $k, $j + 1, $k); $k++; // ...k = n+3! $worksheet->write_string($j, $k, $user['queues'], $headlinenbb); $worksheet->write_blank($j, $k + 1, $headlinenbb); $hidden = in_array('queues', $collapsed) ? true : false; $columnwidth['queues_rank'] = empty($columnwidth['queues_rank']) ? $columnwidth[0] : $columnwidth['queues_rank']; $worksheet->set_column($k, $k, $columnwidth['queues_rank'], null, $hidden); $columnwidth['queues_grp'] = empty($columnwidth['queues_grp']) ? $columnwidth[0] : $columnwidth['queues_grp']; $worksheet->set_column($k + 1, $k + 1, $columnwidth['queues_grp'], null, $hidden); $worksheet->merge_cells($j, $k, $j, $k + 1); $worksheet->write_string($j + 1, $k, get_string('rank', 'grouptool'), $headlinelast); $worksheet->write_string($j + 1, $k + 1, get_string('group', 'group'), $headlinenb); $k += 2; // ...k = n+5! $rows = 2; } else { $k = 0; $rows = max(array(1, count($user['registrations']), count($user['queues']))); // First we output every namefield from used by fullname in exact the defined order! foreach ($namefields as $namefield) { if (empty($user[$namefield])) { $user[$namefield] = ''; } $worksheet->write_string($j, $k, $user[$namefield], $regentryformat); if ($rows > 1) { $worksheet->merge_cells($j, $k, $j + $rows - 1, $k); } $k++; } // ...k = n! if (!empty($CFG->showuseridentity)) { $fields = explode(',', $CFG->showuseridentity); foreach ($fields as $field) { if (empty($user[$field])) { $worksheet->write_blank($j, $k, $regentryformat); } else { $worksheet->write_string($j, $k, $user[$field], $regentryformat); } if ($rows > 1) { $worksheet->merge_cells($j, $k, $j + $rows - 1, $k); } $k++; // ...k = n+x! } } else { $worksheet->write_string($j, $k, $user['idnumber'], $regentryformat); if ($rows > 1) { $worksheet->merge_cells($j, $k, $j + $rows - 1, $k); } $k++; // ...k = n+1! $worksheet->write_string($j, $k, $user['email'], $regentryformat); if ($rows > 1) { $worksheet->merge_cells($j, $k, $j + $rows - 1, $k); } $k++; // ...k = n+2! } for ($i = 0; $i < $rows; $i++) { if ($i != 0) { for ($m = 0; $m < $k; $m++) { // Write all the empty cells! $worksheet->write_blank($j + $i, $m, $regentryformat); } } if (count($user['registrations']) == 0 && $i == 0) { $worksheet->write_string($j, $k, get_string('no_registrations', 'grouptool'), $noregentriesformat); if ($rows > 1) { $worksheet->merge_cells($j, $k, $j + $rows - 1, $k); } } else { if (key_exists($i, $user['registrations'])) { $worksheet->write_string($j + $i, $k, $user['registrations'][$i], $regentryformat); } else { $worksheet->write_blank($j + $i, $k, $regentryformat); } } if (count($user['queues']) == 0 && $i == 0) { $worksheet->write_string($j, $k + 1, get_string('nowhere_queued', 'grouptool'), $noqueueentriesformat); $worksheet->merge_cells($j, $k + 1, $j + $rows - 1, $k + 2); } else { if (key_exists($i, $user['queues'])) { $worksheet->write_number($j + $i, $k + 1, $user['queues'][$i]['rank'], $queueentrylast); $worksheet->write_string($j + $i, $k + 2, $user['queues'][$i]['name'], $queueentrylast); } else { $worksheet->write_blank($j + $i, $k + 1, $queueentrylast); $worksheet->write_blank($j + $i, $k + 2, $queueentrylast); } } } $k += 3; } $j += $rows; // We use 1 row space between groups! } } }
/** * overridden constructor keeps a reference to the assignment class that is displaying this table * * @param assign $assignment The assignment class * @param int $perpage how many per page * @param string $filter The current filter * @param int $rowoffset For showing a subsequent page of results * @param bool $quickgrading Is this table wrapped in a quickgrading form? */ function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgrading) { global $CFG, $PAGE, $DB; parent::__construct('mod_assign_grading'); $this->assignment = $assignment; $this->perpage = $perpage; $this->quickgrading = $quickgrading; $this->output = $PAGE->get_renderer('mod_assign'); $this->define_baseurl(new moodle_url($CFG->wwwroot . '/mod/assign/view.php', array('action'=>'grading', 'id'=>$assignment->get_course_module()->id))); // do some business - then set the sql $currentgroup = groups_get_activity_group($assignment->get_course_module(), true); if ($rowoffset) { $this->rownum = $rowoffset - 1; } $users = array_keys( $assignment->list_participants($currentgroup, true)); if (count($users) == 0) { // insert a record that will never match to the sql is still valid. $users[] = -1; } $params = array(); $params['assignmentid1'] = (int)$this->assignment->get_instance()->id; $params['assignmentid2'] = (int)$this->assignment->get_instance()->id; $extrauserfields = get_extra_user_fields($this->assignment->get_context()); $fields = user_picture::fields('u', $extrauserfields) . ', u.id as userid, '; $fields .= 's.status as status, s.id as submissionid, s.timecreated as firstsubmission, s.timemodified as timesubmitted, '; $fields .= 'g.id as gradeid, g.grade as grade, g.timemodified as timemarked, g.timecreated as firstmarked, g.mailed as mailed, g.locked as locked'; $from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = :assignmentid1' . ' LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignmentid2'; $userparams = array(); $userindex = 0; list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user'); $where = 'u.id ' . $userwhere; $params = array_merge($params, $userparams); // The filters do not make sense when there are no submissions, so do not apply them. if ($this->assignment->is_any_submission_plugin_enabled()) { if ($filter == ASSIGN_FILTER_SUBMITTED) { $where .= ' AND (s.timemodified IS NOT NULL AND s.status = :submitted) '; $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) { $where .= ' AND (s.timemodified IS NOT NULL AND s.status = :submitted AND (s.timemodified > g.timemodified OR g.timemodified IS NULL))'; $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) { $userfilter = (int) array_pop(explode('=', $filter)); $where .= ' AND (u.id = :userid)'; $params['userid'] = $userfilter; } } $this->set_sql($fields, $from, $where, $params); $columns = array(); $headers = array(); // Select if (!$this->is_downloading()) { $columns[] = 'select'; $headers[] = get_string('select') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>'; } // User picture $columns[] = 'picture'; $headers[] = get_string('pictureofuser'); // Fullname $columns[] = 'fullname'; $headers[] = get_string('fullname'); foreach ($extrauserfields as $extrafield) { $columns[] = $extrafield; $headers[] = get_user_field_name($extrafield); } // Submission status if ($assignment->is_any_submission_plugin_enabled()) { $columns[] = 'status'; $headers[] = get_string('status'); } // Grade $columns[] = 'grade'; $headers[] = get_string('grade'); if (!$this->is_downloading()) { // We have to call this column userid so we can use userid as a default sortable column. $columns[] = 'userid'; $headers[] = get_string('edit'); } // Submission plugins if ($assignment->is_any_submission_plugin_enabled()) { $columns[] = 'timesubmitted'; $headers[] = get_string('lastmodifiedsubmission', 'assign'); foreach ($this->assignment->get_submission_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { $columns[] = 'assignsubmission_' . $plugin->get_type(); $headers[] = $plugin->get_name(); } } } // time marked $columns[] = 'timemarked'; $headers[] = get_string('lastmodifiedgrade', 'assign'); // Feedback plugins foreach ($this->assignment->get_feedback_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { $columns[] = 'assignfeedback_' . $plugin->get_type(); $headers[] = $plugin->get_name(); } } // final grade $columns[] = 'finalgrade'; $headers[] = get_string('finalgrade', 'grades'); // load the grading info for all users $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users); if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) { $columns[] = 'outcomes'; $headers[] = get_string('outcomes', 'grades'); } // set the columns $this->define_columns($columns); $this->define_headers($headers); foreach ($extrauserfields as $extrafield) { $this->column_class($extrafield, $extrafield); } // We require at least one unique column for the sort. $this->sortable(true, 'userid'); $this->no_sorting('finalgrade'); $this->no_sorting('userid'); $this->no_sorting('select'); $this->no_sorting('outcomes'); foreach ($this->assignment->get_submission_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { $this->no_sorting('assignsubmission_' . $plugin->get_type()); } } foreach ($this->assignment->get_feedback_plugins() as $plugin) { if ($plugin->is_visible() && $plugin->is_enabled()) { $this->no_sorting('assignfeedback_' . $plugin->get_type()); } } }
function geogebra_view_results($geogebra, $context, $cm, $course, $action) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; if ($action == 'submitgrade') { // Upgrade submitted grade $grade = optional_param('grade', '', PARAM_INT); $gradecomment = optional_param_array('comment_editor', '', PARAM_RAW); $attemptid = optional_param('attemptid', '', PARAM_INT); $attempt = geogebra_get_attempt($attemptid); parse_str($attempt->vars, $parsedvars); $parsedvars['grade'] = $grade; $attempt->vars = http_build_query($parsedvars, '', '&'); geogebra_update_attempt($attemptid, $attempt->vars, GEOGEBRA_UPDATE_TEACHER, $gradecomment['text']); } // Show students list with their results require_once $CFG->libdir . '/gradelib.php'; $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; $page = optional_param('page', 0, PARAM_INT); // Find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); // Get all ppl that are allowed to submit geogebra list($esql, $params) = get_enrolled_sql($context, 'mod/geogebra:submit', $currentgroup); $sql = "SELECT u.id FROM {user} u " . "LEFT JOIN ({$esql}) eu ON eu.id=u.id " . "WHERE u.deleted = 0 AND eu.id=u.id "; $users = $DB->get_records_sql($sql, $params); if (!empty($users)) { $users = array_keys($users); } // If groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } // TODO: Review to show all users information if (!empty($users)) { // Create results table $extrafields = get_extra_user_fields($context); $tablecolumns = array_merge(array('picture', 'fullname'), $extrafields, array('attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status')); $extrafieldnames = array(); foreach ($extrafields as $field) { $extrafieldnames[] = get_user_field_name($field); } $tableheaders = array_merge(array('', get_string('fullnameuser')), $extrafieldnames, array(get_string('attempts', 'geogebra'), get_string('duration', 'geogebra'), get_string('grade'), get_string('comment', 'geogebra'), get_string('lastmodifiedsubmission', 'geogebra'), get_string('lastmodifiedgrade', 'geogebra'), get_string('status', 'geogebra'))); require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-geogebra-results'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/geogebra/report.php?id=' . $cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); // Sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); foreach ($extrafields as $field) { $table->column_class($field, $field); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'results generaltable generalbox'); $table->set_attribute('width', '100%'); $table->no_sorting('attempts'); $table->no_sorting('duration'); $table->no_sorting('grade'); $table->no_sorting('comment'); $table->no_sorting('datestudent'); $table->no_sorting('dateteacher'); $table->no_sorting('status'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); // Construct the SQL list($where, $params) = $table->get_sql_where(); if ($where) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $ufields = user_picture::fields('u', $extrafields); $select = "SELECT {$ufields} "; $sql = 'FROM {user} u WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size()); $table->pagesize($perpage, count($users)); $offset = $page * $perpage; // Offset used to calculate index of student in that particular query, needed for the pop up to know who's next if ($ausers !== false) { // $grading_info = grade_get_grades($course->id, 'mod', 'geogebra', $geogebra->id, array_keys($ausers)); foreach ($ausers as $auser) { $picture = $OUTPUT->user_picture($auser); $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>'; $row = array($picture, $userlink); $extradata = array(); foreach ($extrafields as $field) { $extradata[] = $auser->{$field}; } $row += $extradata; // Attempts summary $attempts = geogebra_get_user_attempts($geogebra->id, $auser->id); $attemptssummary = geogebra_get_user_grades($geogebra, $auser->id); if ($attemptssummary) { $row[] = $attemptssummary->attempts; $row[] = geogebra_time2str($attemptssummary->duration); $row[] = $attemptssummary->grade; $rowclass = $attemptssummary->attempts > 0 ? 'summary-row' : ""; } else { $row[] = ""; $row[] = ""; $row[] = ""; $rowclass = ""; } $row[] = ""; $row[] = ""; $row[] = ""; $row[] = ""; $table->add_data($row, $rowclass); // Show attempts information foreach ($attempts as $attempt) { $row = array(); // In the attempts row, show only the summary of the attempt (it's not necessary to repeat user information) for ($i = 0; $i < count($extradata) + 2; $i++) { array_push($row, ''); } // Attempt information $row = geogebra_get_attempt_row($geogebra, $attempt, $auser, $cm, $context, $row); /*array_push($row, $attempt->duration); array_push($row, $attempt->grade); array_push($row, $attempt->comment);*/ $table->add_data($row); } } } $table->print_html(); // Print the whole table } else { echo $OUTPUT->notification(get_string('msg_nosessions', 'geogebra'), 'notifymessage'); } }
/** * Get criteria details for displaying to users * * @return string */ public function get_details($short = '') { global $DB, $OUTPUT; $output = array(); foreach ($this->params as $p) { if (is_numeric($p['field'])) { $str = $DB->get_field('user_info_field', 'name', array('id' => $p['field'])); } else { $str = get_user_field_name($p['field']); } if (!$str) { $output[] = $OUTPUT->error_text(get_string('error:nosuchfield', 'badges')); } else { $output[] = $str; } } if ($short) { return implode(', ', $output); } else { return html_writer::alist($output, array(), 'ul'); } }
/** * Refactored function for generating HTML of sorting links with matching arrows. * Returns an array with 'studentname' and 'idnumber' as keys, with HTML ready * to inject into a table header cell. * @param array $extrafields Array of extra fields being displayed, such as * user idnumber * @return array An associative array of HTML sorting links+arrows */ public function get_sort_arrows(array $extrafields = array()) { global $OUTPUT; $arrows = array(); $strsortasc = $this->get_lang_string('sortasc', 'grades'); $strsortdesc = $this->get_lang_string('sortdesc', 'grades'); $strfirstname = $this->get_lang_string('firstname'); $strlastname = $this->get_lang_string('lastname'); $iconasc = $OUTPUT->pix_icon('t/sort_asc', $strsortasc, '', array('class' => 'iconsmall sorticon')); $icondesc = $OUTPUT->pix_icon('t/sort_desc', $strsortdesc, '', array('class' => 'iconsmall sorticon')); $firstlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid' => 'firstname')), $strfirstname); $lastlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid' => 'lastname')), $strlastname); $arrows['studentname'] = $lastlink; if ($this->sortitemid === 'lastname') { if ($this->sortorder == 'ASC') { $arrows['studentname'] .= $iconasc; } else { $arrows['studentname'] .= $icondesc; } } $arrows['studentname'] .= ' ' . $firstlink; if ($this->sortitemid === 'firstname') { if ($this->sortorder == 'ASC') { $arrows['studentname'] .= $iconasc; } else { $arrows['studentname'] .= $icondesc; } } foreach ($extrafields as $field) { $fieldlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid' => $field)), get_user_field_name($field)); $arrows[$field] = $fieldlink; if ($field == $this->sortitemid) { if ($this->sortorder == 'ASC') { $arrows[$field] .= $iconasc; } else { $arrows[$field] .= $icondesc; } } } return $arrows; }
echo certificate_get_grade($certificate, $course, $user->id) . "\t"; echo $user->code . "\n"; $row++; } } exit; } $usercount = count(certificate_get_issues($certificate->id, $DB->sql_fullname(), $groupmode, $cm)); // Create the table for the users $table = new html_table(); $table->width = "95%"; $table->tablealign = "center"; $table->head = array($strto); $table->align = array('left'); foreach ($extrafields as $field) { $table->head[] = get_user_field_name($field); $table->align[] = 'left'; } $table->head = array_merge($table->head, array($strdate, $strgrade, $strcode)); $table->align = array_merge($table->align, array('left', 'center', 'center')); foreach ($users as $user) { $name = $OUTPUT->user_picture($user) . fullname($user); $date = userdate($user->timecreated) . certificate_print_user_files($certificate, $user->id, $context->id); $code = $user->code; $data = array(); $data[] = $name; foreach ($extrafields as $field) { $data[] = $user->{$field}; } $data = array_merge($data, array($date, certificate_get_grade($certificate, $course, $user->id), $code)); $table->data[] = $data;
print $iconlink ? '</a>' : ''; print '</th>'; } // Overall course completion status print '<th class="criteriaicon">'; print '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="' . get_string('course') . '" title="' . get_string('coursecomplete', 'completion') . '" />'; print '</th>'; print '</tr></thead>'; echo '<tbody>'; } else { // The CSV headers $row = array(); $row[] = get_string('id', 'report_completion'); $row[] = get_string('name', 'report_completion'); foreach ($extrafields as $field) { $row[] = get_user_field_name($field); } // Add activity headers foreach ($criteria as $criterion) { // Handle activity completion differently if ($criterion->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) { // Load activity $mod = $criterion->get_mod_instance(); $row[] = $mod->name; $row[] = $mod->name . ' - ' . get_string('completiondate', 'report_completion'); } else { // Handle all other criteria $row[] = strip_tags($criterion->get_title_detailed()); } } $row[] = get_string('coursecomplete', 'completion');
// if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } // Create results table if (function_exists('get_extra_user_fields')) { $extrafields = get_extra_user_fields($context); } else { $extrafields = array(); } $tablecolumns = array_merge(array('picture', 'fullname'), $extrafields, array('starttime', 'attempts', 'solveddone', 'totaltime', 'grade')); $extrafieldnames = array(); foreach ($extrafields as $field) { $extrafieldnames[] = get_user_field_name($field); } $strstarttime = $mode == 'details' ? get_string('starttime', 'jclic') : get_string('lastaccess', 'jclic'); $tableheaders = array_merge(array('', get_string('fullnameuser')), $extrafieldnames, array($strstarttime, get_string('attempts', 'jclic'), get_string('solveddone', 'jclic'), get_string('totaltime', 'jclic'), get_string('grade'))); require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-jclic-results'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/jclic/report.php?id=' . $cm->id . '¤tgroup=' . $currentgroup . '&mode=' . $mode); $table->sortable(true, 'lastname'); // Sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture');
public function get_description($full, $not, \core_availability\info $info) { $course = $info->get_course(); // Display the fieldname into current lang. if ($this->customfield) { // Is a custom profile field (will use multilang). $customfields = self::get_custom_profile_fields(); if (array_key_exists($this->customfield, $customfields)) { $translatedfieldname = $customfields[$this->customfield]->name; } else { $translatedfieldname = get_string('missing', 'availability_profile', $this->customfield); } } else { $translatedfieldname = get_user_field_name($this->standardfield); } $context = \context_course::instance($course->id); $a = new \stdClass(); $a->field = format_string($translatedfieldname, true, array('context' => $context)); $a->value = s($this->value); if ($not) { // When doing NOT strings, we replace the operator with its inverse. // Some of them don't have inverses, so for those we use a new // identifier which is only used for this lang string. switch ($this->operator) { case self::OP_CONTAINS: $opname = self::OP_DOES_NOT_CONTAIN; break; case self::OP_DOES_NOT_CONTAIN: $opname = self::OP_CONTAINS; break; case self::OP_ENDS_WITH: $opname = 'notendswith'; break; case self::OP_IS_EMPTY: $opname = self::OP_IS_NOT_EMPTY; break; case self::OP_IS_EQUAL_TO: $opname = 'notisequalto'; break; case self::OP_IS_NOT_EMPTY: $opname = self::OP_IS_EMPTY; break; case self::OP_STARTS_WITH: $opname = 'notstartswith'; break; default: throw new \coding_exception('Unexpected operator: ' . $this->operator); } } else { $opname = $this->operator; } return get_string('requires_' . $opname, 'availability_profile', $a); }
/** * Initialises table */ protected function init() { $tablecolumns = array('userpic', 'fullname'); $tableheaders = array(get_string('userpic'), get_string('fullnameuser')); $extrafields = get_extra_user_fields($this->get_context()); $ufields = user_picture::fields('u', $extrafields, $this->useridfield); $fields = 'c.id, c.timemodified as completed_timemodified, c.courseid, ' . $ufields; $from = '{feedback_completed} c ' . 'JOIN {user} u ON u.id = c.userid AND u.deleted = :notdeleted'; $where = 'c.anonymous_response = :anon AND c.feedback = :instance'; if ($this->feedbackstructure->get_courseid()) { $where .= ' AND c.courseid = :courseid'; } if ($this->is_downloading()) { // When downloading data: // Remove 'userpic' from downloaded data. array_shift($tablecolumns); array_shift($tableheaders); // Add all identity fields as separate columns. foreach ($extrafields as $field) { $fields .= ", u.{$field}"; $tablecolumns[] = $field; $tableheaders[] = get_user_field_name($field); } } if ($this->feedbackstructure->get_feedback()->course == SITEID && !$this->feedbackstructure->get_courseid()) { $tablecolumns[] = 'courseid'; $tableheaders[] = get_string('course'); } $tablecolumns[] = 'completed_timemodified'; $tableheaders[] = get_string('date'); $this->define_columns($tablecolumns); $this->define_headers($tableheaders); $this->sortable(true, 'lastname', SORT_ASC); $this->collapsible(true); $this->set_attribute('id', 'showentrytable'); $params = array(); $params['anon'] = FEEDBACK_ANONYMOUS_NO; $params['instance'] = $this->feedbackstructure->get_feedback()->id; $params['notdeleted'] = 0; $params['courseid'] = $this->feedbackstructure->get_courseid(); $group = groups_get_activity_group($this->feedbackstructure->get_cm(), true); if ($group) { $where .= ' AND c.userid IN (SELECT g.userid FROM {groups_members} g WHERE g.groupid = :group)'; $params['group'] = $group; } $this->set_sql($fields, $from, $where, $params); $this->set_count_sql("SELECT COUNT(c.id) FROM {$from} WHERE {$where}", $params); }
/** * displays the full report * @param stdClass $scorm full SCORM object * @param stdClass $cm - full course_module object * @param stdClass $course - full course object * @param string $download - type of download being requested */ function display($scorm, $cm, $course, $download) { global $CFG, $DB, $OUTPUT, $PAGE; $contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id); $action = optional_param('action', '', PARAM_ALPHA); $attemptids = optional_param_array('attemptid', array(), PARAM_RAW); $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT); $PAGE->set_url(new moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode))); if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm)) { //delete responses. add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id); echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); } } // find out current groups mode $currentgroup = groups_get_activity_group($cm, true); // detailed report $mform = new mod_scorm_report_interactions_settings($PAGE->url, compact('currentgroup')); if ($fromform = $mform->get_data()) { $pagesize = $fromform->pagesize; $includeqtext = $fromform->qtext; $includeresp = $fromform->resp; $includeright = $fromform->right; set_user_preference('scorm_report_pagesize', $pagesize); set_user_preference('scorm_report_interactions_qtext', $includeqtext); set_user_preference('scorm_report_interactions_resp', $includeresp); set_user_preference('scorm_report_interactions_right', $includeright); } else { $pagesize = get_user_preferences('scorm_report_pagesize', 0); $includeqtext = get_user_preferences('scorm_report_interactions_qtext', 0); $includeresp = get_user_preferences('scorm_report_interactions_resp', 1); $includeright = get_user_preferences('scorm_report_interactions_right', 0); } if ($pagesize < 1) { $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE; } // select group menu $displayoptions = array(); $displayoptions['attemptsmode'] = $attemptsmode; $displayoptions['qtext'] = $includeqtext; $displayoptions['resp'] = $includeresp; $displayoptions['right'] = $includeright; $mform->set_data($displayoptions + array('pagesize' => $pagesize)); if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$download) { groups_print_activity_menu($cm, new moodle_url($PAGE->url, $displayoptions)); } } $formattextoptions = array('context' => get_context_instance(CONTEXT_COURSE, $course->id)); // We only want to show the checkbox to delete attempts // if the user has permissions and if the report mode is showing attempts. $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule) && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO); // select the students $nostudents = false; if (empty($currentgroup)) { // all users who can attempt scoes if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', '', '', '', '', '', '', false)) { echo $OUTPUT->notification(get_string('nostudentsyet')); $nostudents = true; $allowedlist = ''; } else { $allowedlist = array_keys($students); } } else { // all users who can attempt scoes and who are in the currently selected group if (!$groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', '', '', '', '', $currentgroup, '', false)) { echo $OUTPUT->notification(get_string('nostudentsingroup')); $nostudents = true; $groupstudents = array(); } $allowedlist = array_keys($groupstudents); } if ( !$nostudents ) { // Now check if asked download of data $coursecontext = context_course::instance($course->id); if ($download) { $filename = clean_filename("$course->shortname ".format_string($scorm->name, true,$formattextoptions)); } // Define table columns $columns = array(); $headers = array(); if (!$download && $candelete) { $columns[] = 'checkbox'; $headers[] = null; } if (!$download && $CFG->grade_report_showuserimage) { $columns[] = 'picture'; $headers[] = ''; } $columns[] = 'fullname'; $headers[] = get_string('name'); $extrafields = get_extra_user_fields($coursecontext); foreach ($extrafields as $field) { $columns[] = $field; $headers[] = get_user_field_name($field); } $columns[] = 'attempt'; $headers[] = get_string('attempt', 'scorm'); $columns[] = 'start'; $headers[] = get_string('started', 'scorm'); $columns[] = 'finish'; $headers[] = get_string('last', 'scorm'); $columns[] = 'score'; $headers[] = get_string('score', 'scorm'); $scoes = $DB->get_records('scorm_scoes', array("scorm"=>$scorm->id), 'id'); foreach ($scoes as $sco) { if ($sco->launch != '') { $columns[] = 'scograde'.$sco->id; $headers[] = format_string($sco->title,'',$formattextoptions); } } $params = array(); list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED); // Construct the SQL $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email'. get_extra_user_fields_sql($coursecontext, 'u', '', array('idnumber')) . ' '; // This part is the same for all cases - join users and scorm_scoes_track tables $from = 'FROM {user} u '; $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id; switch ($attemptsmode) { case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL'; break; case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL'; break; case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)'; break; } $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, '; $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'st.attempt').')) AS nbattempts, '; $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers '; $countsql .= $from.$where; $attempts = $DB->get_records_sql($select.$from.$where, $params); $questioncount = get_scorm_question_count($scorm->id); for($id = 0; $id < $questioncount; $id++) { if ($displayoptions['qtext']) { $columns[] = 'question' . $id; $headers[] = get_string('questionx', 'scormreport_interactions', $id); } if ($displayoptions['resp']) { $columns[] = 'response' . $id; $headers[] = get_string('responsex', 'scormreport_interactions', $id); } if ($displayoptions['right']) { $columns[] = 'right' . $id; $headers[] = get_string('rightanswerx', 'scormreport_interactions', $id); } } if (!$download) { $table = new flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl($PAGE->url); $table->sortable(true); $table->collapsible(true); // This is done to prevent redundant data, when a user has multiple attempts $table->column_suppress('picture'); $table->column_suppress('fullname'); foreach ($extrafields as $field) { $table->column_suppress($field); } $table->no_sorting('start'); $table->no_sorting('finish'); $table->no_sorting('score'); foreach ($scoes as $sco) { if ($sco->launch != '') { $table->no_sorting('scograde'.$sco->id); } } $table->column_class('picture', 'picture'); $table->column_class('fullname', 'bold'); $table->column_class('score', 'bold'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); } else if ($download == 'ODS') { require_once("$CFG->libdir/odslib.class.php"); $filename .= ".ods"; // Creating a workbook $workbook = new MoodleODSWorkbook("-"); // Sending HTTP headers $workbook->send($filename); // Creating the first worksheet $sheettitle = get_string('report', 'scorm'); $myxls =& $workbook->add_worksheet($sheettitle); // format types $format =& $workbook->add_format(); $format->set_bold(0); $formatbc =& $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb =& $workbook->add_format(); $formatb->set_bold(1); $formaty =& $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc =& $workbook->add_format(); $formatc->set_align('center'); $formatr =& $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg =& $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); // Here starts workshhet headers $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else if ($download =='Excel') { require_once("$CFG->libdir/excellib.class.php"); $filename .= ".xls"; // Creating a workbook $workbook = new MoodleExcelWorkbook("-"); // Sending HTTP headers $workbook->send($filename); // Creating the first worksheet $sheettitle = get_string('report', 'scorm'); $myxls =& $workbook->add_worksheet($sheettitle); // format types $format =& $workbook->add_format(); $format->set_bold(0); $formatbc =& $workbook->add_format(); $formatbc->set_bold(1); $formatbc->set_align('center'); $formatb =& $workbook->add_format(); $formatb->set_bold(1); $formaty =& $workbook->add_format(); $formaty->set_bg_color('yellow'); $formatc =& $workbook->add_format(); $formatc->set_align('center'); $formatr =& $workbook->add_format(); $formatr->set_bold(1); $formatr->set_color('red'); $formatr->set_align('center'); $formatg =& $workbook->add_format(); $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); $colnum = 0; foreach ($headers as $item) { $myxls->write(0, $colnum, $item, $formatbc); $colnum++; } $rownum = 1; } else if ($download == 'CSV') { $filename .= ".txt"; header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Expires: 0"); header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Pragma: public"); echo implode("\t", $headers)." \n"; } if (!$download) { $sort = $table->get_sql_sort(); } else { $sort = ''; } // Fix some wired sorting if (empty($sort)) { $sort = ' ORDER BY uniqueid'; } else { $sort = ' ORDER BY '.$sort; } if (!$download) { // Add extra limits due to initials bar list($twhere, $tparams) = $table->get_sql_where(); if ($twhere) { $where .= ' AND '.$twhere; //initial bar $params = array_merge($params, $tparams); } if (!empty($countsql)) { $count = $DB->get_record_sql($countsql,$params); $totalinitials = $count->nbresults; if ($twhere) { $countsql .= ' AND '.$twhere; } $count = $DB->get_record_sql($countsql, $params); $total = $count->nbresults; } $table->pagesize($pagesize, $total); echo '<div class="quizattemptcounts">'; if ( $count->nbresults == $count->nbattempts ) { echo get_string('reportcountattempts', 'scorm', $count); } else if ( $count->nbattempts>0 ) { echo get_string('reportcountallattempts', 'scorm', $count); } else { echo $count->nbusers.' '.get_string('users'); } echo '</div>'; } // Fetch the attempts if (!$download) { $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params, $table->get_page_start(), $table->get_page_size()); echo '<div id="scormtablecontainer">'; if ($candelete) { // Start form $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm')); echo '<form id="attemptsform" method="post" action="' . $PAGE->url->out(false) . '" onsubmit="return confirm(\''.$strreallydel.'\');">'; echo '<input type="hidden" name="action" value="delete"/>'; echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; echo '<div style="display: none;">'; echo html_writer::input_hidden_params($PAGE->url); echo '</div>'; echo '<div>'; } $table->initialbars($totalinitials>20); // Build table rows } else { $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params); } if ($attempts) { foreach ($attempts as $scouser) { $row = array(); if (!empty($scouser->attempt)) { $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt); } else { $timetracks = ''; } if (in_array('checkbox', $columns)) { if ($candelete && !empty($timetracks->start)) { $row[] = '<input type="checkbox" name="attemptid[]" value="'. $scouser->userid . ':' . $scouser->attempt . '" />'; } else if ($candelete) { $row[] = ''; } } if (in_array('picture', $columns)) { $user = (object)array( 'id'=>$scouser->userid, 'picture'=>$scouser->picture, 'imagealt'=>$scouser->imagealt, 'email'=>$scouser->email, 'firstname'=>$scouser->firstname, 'lastname'=>$scouser->lastname); $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id)); } if (!$download) { $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&course='.$course->id.'">'.fullname($scouser).'</a>'; } else { $row[] = fullname($scouser); } foreach ($extrafields as $field) { $row[] = s($scouser->{$field}); } if (empty($timetracks->start)) { $row[] = '-'; $row[] = '-'; $row[] = '-'; $row[] = '-'; } else { if (!$download) { $row[] = '<a href="userreport.php?a='.$scorm->id.'&user='******'&attempt='.$scouser->attempt.'">'.$scouser->attempt.'</a>'; } else { $row[] = $scouser->attempt; } if ($download =='ODS' || $download =='Excel' ) { $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig")); } else { $row[] = userdate($timetracks->start); } if ($download =='ODS' || $download =='Excel' ) { $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig')); } else { $row[] = userdate($timetracks->finish); } $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt); } // print out all scores of attempt foreach ($scoes as $sco) { if ($sco->launch != '') { if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) { if ($trackdata->status == '') { $trackdata->status = 'notattempted'; } $strstatus = get_string($trackdata->status, 'scorm'); // if raw score exists, print it if ($trackdata->score_raw != '') { $score = $trackdata->score_raw; // add max score if it exists if ($scorm->version == 'SCORM_1.3') { $maxkey = 'cmi.score.max'; } else { $maxkey = 'cmi.core.score.max'; } if (isset($trackdata->$maxkey)) { $score .= '/'.$trackdata->$maxkey; } // else print out status } else { $score = $strstatus; } if (!$download) { $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/> <a href="userreport.php?b='.$sco->id.'&user='******'&attempt='.$scouser->attempt. '" title="'.get_string('details', 'scorm').'">'.$score.'</a>'; } else { $row[] = $score; } // interaction data $i=0; $element='cmi.interactions_'.$i.'.id'; while(isset($trackdata->$element)) { if ($displayoptions['qtext']) { $element='cmi.interactions_'.$i.'.id'; if (isset($trackdata->$element)) { $row[] = s($trackdata->$element); } else { $row[] = ' '; } } if ($displayoptions['resp']) { $element='cmi.interactions_'.$i.'.student_response'; if (isset($trackdata->$element)) { $row[] = s($trackdata->$element); } else { $row[] = ' '; } } if ($displayoptions['right']) { $j=0; $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern'; $rightans = ''; if (isset($trackdata->$element)) { while(isset($trackdata->$element)) { if($j>0) { $rightans .= ','; } $rightans .= s($trackdata->$element); $j++; $element = 'cmi.interactions_'.$i.'.correct_responses_'.$j.'.pattern'; } $row[] = $rightans; } else { $row[] = ' '; } } $i++; $element = 'cmi.interactions_'.$i.'.id'; } //---end of interaction data*/ } else { // if we don't have track data, we haven't attempted yet $strstatus = get_string('notattempted', 'scorm'); if (!$download) { $row[] = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" /><br/>'.$strstatus; } else { $row[] = $strstatus; } } } } if (!$download) { $table->add_data($row); } else if ($download == 'Excel' or $download == 'ODS') { $colnum = 0; foreach ($row as $item) { $myxls->write($rownum, $colnum, $item, $format); $colnum++; } $rownum++; } else if ($download == 'CSV') { $text = implode("\t", $row); echo $text." \n"; } } if (!$download) { $table->finish_output(); if ($candelete) { echo '<table id="commands">'; echo '<tr><td>'; echo '<a href="javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');">'. get_string('selectall', 'scorm').'</a> / '; echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');">'. get_string('selectnone', 'scorm').'</a> '; echo ' '; echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>'; echo '</td></tr></table>'; // Close form echo '</div>'; echo '</form>'; } echo '</div>'; if (!empty($attempts)) { echo '<table class="boxaligncenter"><tr>'; echo '<td>'; echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('download'=>'ODS') + $displayoptions), get_string('downloadods')); echo "</td>\n"; echo '<td>'; echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('download'=>'Excel') + $displayoptions), get_string('downloadexcel')); echo "</td>\n"; echo '<td>'; echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('download'=>'CSV') + $displayoptions), get_string('downloadtext')); echo "</td>\n"; echo "<td>"; echo "</td>\n"; echo '</tr></table>'; } } } else { if ($candelete && !$download) { echo '</div>'; echo '</form>'; $table->finish_output(); } echo '</div>'; } // Show preferences form irrespective of attempts are there to report or not if (!$download) { $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode')); $mform->display(); } if ($download == 'Excel' or $download == 'ODS') { $workbook->close(); exit; } else if ($download == 'CSV') { exit; } } else { echo $OUTPUT->notification(get_string('noactivity', 'scorm')); } }// function ends
if ($firstnamesort) { print get_string('firstname')." / <a href=\"./?course={$course->id}{$sistring}\">". get_string('lastname').'</a>'; } else { print "<a href=\"./?course={$course->id}&sort=firstname{$sistring}\">". get_string('firstname').'</a> / '. get_string('lastname'); } print '</th>'; // Print user identity columns foreach ($extrafields as $field) { echo '<th scope="col" class="completion-identifyfield">' . get_user_field_name($field) . '</th>'; } /// /// Print criteria icons /// foreach ($criteria as $criterion) { // Generate icon details $icon = ''; $iconlink = ''; $icontitle = ''; // Required if $iconlink set $iconalt = ''; // Required switch ($criterion->criteriatype) { case COMPLETION_CRITERIA_TYPE_ACTIVITY:
/** * Display all the submissions ready for grading * * @global object * @global object * @global object * @global object * @param string $message * @return bool|void */ function display_submissions($message = '') { global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ $filters = array(self::FILTER_ALL => get_string('all'), self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment')); $updatepref = optional_param('updatepref', 0, PARAM_BOOL); if ($updatepref) { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; $filter = optional_param('filter', 0, PARAM_INT); set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); set_user_preference('assignment_filter', $filter); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('assignment_perpage', 10); $quickgrade = get_user_preferences('assignment_quickgrade', 0) && $this->quickgrade_mode_allowed(); $filter = get_user_preferences('assignment_filter', 0); $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; } else { $uses_outcomes = false; } $page = optional_param('page', 0, PARAM_INT); $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); /// Some shortcuts to make the code read better $course = $this->course; $assignment = $this->assignment; $cm = $this->cm; $hassubmission = false; // reset filter to all for offline assignment only. if ($assignment->assignmenttype == 'offline') { if ($filter == self::FILTER_SUBMITTED) { $filter = self::FILTER_ALL; } } else { $filters[self::FILTER_SUBMITTED] = get_string('submitted', 'assignment'); } $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->cm->id, $this->assignment->id, $this->cm->id); $PAGE->set_title(format_string($this->assignment->name, true)); $PAGE->set_heading($this->course->fullname); echo $OUTPUT->header(); echo '<div class="usersubmissions">'; //hook to allow plagiarism plugins to update status/print links. echo plagiarism_update_status($this->course, $this->cm); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>'; } if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// Check to see if groups are being used in this assignment /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id); /// Print quickgrade form around the table if ($quickgrade) { $formattrs = array(); $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php'); $formattrs['id'] = 'fastg'; $formattrs['method'] = 'post'; echo html_writer::start_tag('form', $formattrs); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $this->cm->id)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'mode', 'value' => 'fastgrade')); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $page)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); } /// Get all ppl that are allowed to submit assignments list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:submit', $currentgroup); if ($filter == self::FILTER_ALL) { $sql = "SELECT u.id FROM {user} u " . "LEFT JOIN ({$esql}) eu ON eu.id=u.id " . "WHERE u.deleted = 0 AND eu.id=u.id "; } else { $wherefilter = ' AND s.assignment = ' . $this->assignment->id; $assignmentsubmission = "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) "; if ($filter == self::FILTER_SUBMITTED) { $wherefilter .= ' AND s.timemodified > 0 '; } else { if ($filter == self::FILTER_REQUIRE_GRADING && $assignment->assignmenttype != 'offline') { $wherefilter .= ' AND s.timemarked < s.timemodified '; } else { // require grading for offline assignment $assignmentsubmission = ""; $wherefilter = ""; } } $sql = "SELECT u.id FROM {user} u " . "LEFT JOIN ({$esql}) eu ON eu.id=u.id " . $assignmentsubmission . "WHERE u.deleted = 0 AND eu.id=u.id " . $wherefilter; } $users = $DB->get_records_sql($sql, $params); if (!empty($users)) { if ($assignment->assignmenttype == 'offline' && $filter == self::FILTER_REQUIRE_GRADING) { //remove users who has submitted their assignment foreach ($this->get_submissions() as $submission) { if (array_key_exists($submission->userid, $users)) { unset($users[$submission->userid]); } } } $users = array_keys($users); } // if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } $extrafields = get_extra_user_fields($context); $tablecolumns = array_merge(array('picture', 'fullname'), $extrafields, array('grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade')); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $extrafieldnames = array(); foreach ($extrafields as $field) { $extrafieldnames[] = get_user_field_name($field); } $tableheaders = array_merge(array('', get_string('fullnameuser')), $extrafieldnames, array(get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . get_string('submission', 'assignment') . ')', get_string('lastmodified') . ' (' . get_string('grade') . ')', get_string('status'), get_string('finalgrade', 'grades'))); if ($uses_outcomes) { $tableheaders[] = get_string('outcome', 'grades'); } require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-assignment-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); //sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); foreach ($extrafields as $field) { $table->column_class($field, $field); } $table->column_class('grade', 'grade'); $table->column_class('submissioncomment', 'comment'); $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); $table->column_class('finalgrade', 'finalgrade'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '100%'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); $table->text_sorting('submissioncomment'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); /// Construct the SQL list($where, $params) = $table->get_sql_where(); if ($where) { $where .= ' AND '; } if ($filter == self::FILTER_SUBMITTED) { $where .= 's.timemodified > 0 AND '; } else { if ($filter == self::FILTER_REQUIRE_GRADING) { $where = ''; if ($assignment->assignmenttype != 'offline') { $where .= 's.timemarked < s.timemodified AND '; } } } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $ufields = user_picture::fields('u', $extrafields); if (!empty($users)) { $select = "SELECT {$ufields},\n s.id AS submissionid, s.grade, s.submissioncomment,\n s.timemodified, s.timemarked,\n CASE WHEN s.timemarked > 0 AND s.timemarked >= s.timemodified THEN 1\n ELSE 0 END AS status "; $sql = 'FROM {user} u ' . 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $ausers = $DB->get_records_sql($select . $sql . $sort, $params, $table->get_page_start(), $table->get_page_size()); $table->pagesize($perpage, count($users)); ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next $offset = $page * $perpage; $strupdate = get_string('update'); $strgrade = get_string('grade'); $strview = get_string('view'); $grademenu = make_grades_menu($this->assignment->grade); if ($ausers !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); $endposition = $offset + $perpage; $currentposition = 0; foreach ($ausers as $auser) { if ($currentposition == $offset && $offset < $endposition) { $rowclass = null; $final_grade = $grading_info->items[0]->grades[$auser->id]; $grademax = $grading_info->items[0]->grademax; $final_grade->formatted_grade = round($final_grade->grade, 2) . ' / ' . round($grademax, 2); $locked_overridden = 'locked'; if ($final_grade->overridden) { $locked_overridden = 'overridden'; } // TODO add here code if advanced grading grade must be reviewed => $auser->status=0 $picture = $OUTPUT->user_picture($auser); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { $hassubmission = true; ///Prints student answer and student modified date ///attach file or print link to student answer, depending on the type of the assignment. ///Refer to print_student_answer in inherited classes. if ($auser->timemodified > 0) { $studentmodifiedcontent = $this->print_student_answer($auser->id) . userdate($auser->timemodified); if ($assignment->timedue && $auser->timemodified > $assignment->timedue && $this->supports_lateness()) { $studentmodifiedcontent .= $this->display_lateness($auser->timemodified); $rowclass = 'late'; } } else { $studentmodifiedcontent = ' '; } $studentmodified = html_writer::tag('div', $studentmodifiedcontent, array('id' => 'ts' . $auser->id)); ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::label(get_string('assignment:grade', 'assignment'), 'menumenu' . $auser->id, false, array('class' => 'accesshide')); $menu .= html_writer::select(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, array(-1 => get_string('nograde')), $attributes); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } else { $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::label(get_string('assignment:grade', 'assignment'), 'menumenu' . $auser->id, false, array('class' => 'accesshide')); $menu .= html_writer::select(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, array(-1 => get_string('nograde')), $attributes); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } ///Print Comment if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>'; } } } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; $status = '<div id="st' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->formatted_grade . '</div>'; $hassubmission = true; } else { if ($quickgrade) { // allow editing $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::label(get_string('assignment:grade', 'assignment'), 'menumenu' . $auser->id, false, array('class' => 'accesshide')); $menu .= html_writer::select(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, array(-1 => get_string('nograde')), $attributes); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; $hassubmission = true; } else { $grade = '<div id="g' . $auser->id . '">-</div>'; } } if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '"> </div>'; } } } if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 $auser->status = 0; } else { $auser->status = 1; } $buttontext = $auser->status == 1 ? $strupdate : $strgrade; if ($final_grade->locked or $final_grade->overridden) { $buttontext = $strview; } ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&filter=' . $filter . '&offset=' . $offset++; $button = $OUTPUT->action_link($popup_url, $buttontext); $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>'; $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>'; $outcomes = ''; if ($uses_outcomes) { foreach ($grading_info->outcomes as $n => $outcome) { $outcomes .= '<div class="outcome"><label for="' . 'outcome_' . $n . '_' . $auser->id . '">' . $outcome->name . '</label>'; $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$auser->id]->locked or !$quickgrade) { $options[0] = get_string('nooutcome', 'grades'); $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>'; } else { $attributes = array(); $attributes['tabindex'] = $tabindex++; $attributes['id'] = 'outcome_' . $n . '_' . $auser->id; $outcomes .= ' ' . html_writer::select($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, array(0 => get_string('nooutcome', 'grades')), $attributes); } $outcomes .= '</div>'; } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>'; $extradata = array(); foreach ($extrafields as $field) { $extradata[] = $auser->{$field}; } $row = array_merge(array($picture, $userlink), $extradata, array($grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade)); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row, $rowclass); } $currentposition++; } if ($hassubmission && method_exists($this, 'download_submissions')) { echo html_writer::start_tag('div', array('class' => 'mod-assignment-download-link')); echo html_writer::link(new moodle_url('/mod/assignment/submissions.php', array('id' => $this->cm->id, 'download' => 'zip')), get_string('downloadall', 'assignment')); echo html_writer::end_tag('div'); } $table->print_html(); /// Print the whole table } else { if ($filter == self::FILTER_SUBMITTED) { echo html_writer::tag('div', get_string('nosubmisson', 'assignment'), array('class' => 'nosubmisson')); } else { if ($filter == self::FILTER_REQUIRE_GRADING) { echo html_writer::tag('div', get_string('norequiregrading', 'assignment'), array('class' => 'norequiregrading')); } } } } /// Print quickgrade form around the table if ($quickgrade && $table->started_output && !empty($users)) { $mailinfopref = false; if (get_user_preferences('assignment_mailinfo', 1)) { $mailinfopref = true; } $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enablenotification', 'assignment')); $emailnotification .= $OUTPUT->help_icon('enablenotification', 'assignment'); echo html_writer::tag('div', $emailnotification, array('class' => 'emailnotification')); $savefeedback = html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'fastg', 'value' => get_string('saveallfeedback', 'assignment'))); echo html_writer::tag('div', $savefeedback, array('class' => 'fastgbutton')); echo html_writer::end_tag('form'); } else { if ($quickgrade) { echo html_writer::end_tag('form'); } } echo '</div>'; /// End of fast grading form /// Mini form for setting user preference $formaction = new moodle_url('/mod/assignment/submissions.php', array('id' => $this->cm->id)); $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class' => 'optionspref')); $mform->addElement('hidden', 'updatepref'); $mform->setDefault('updatepref', 1); $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment')); $mform->addElement('select', 'filter', get_string('show'), $filters); $mform->setDefault('filter', $filter); $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size' => 1)); $mform->setDefault('perpage', $perpage); if ($this->quickgrade_mode_allowed()) { $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'assignment')); $mform->setDefault('quickgrade', $quickgrade); $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment'); } $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); $mform->display(); echo $OUTPUT->footer(); }
/** * The user fields we can compare * * @global moodle_database $DB * @return array Associative array from user field constants to display name */ public static function get_condition_user_fields() { global $DB; $userfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'interests' => get_user_field_name('interests'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address')); // Go through the custom profile fields now if ($user_info_fields = $DB->get_records('user_info_field')) { foreach ($user_info_fields as $field) { $userfields[$field->id] = $field->name; } } return $userfields; }
$renderer = $PAGE->get_renderer('local_help_desk'); $lib_help_desk = new help_desk(); $hierarchy = new hierarchy(); $ufiltering = new user_filtering_accounts(); //Tab tree (current tab) $tab = 'accounts'; $serialkey_form = new accounts_serialkey_form(NULL, array('skid' => $skid)); echo $OUTPUT->header(); $lib_help_desk->createtabview($tab); //Tab tree $extracolumns = get_extra_user_fields($systemcontext); $ufiltering = new user_filtering_accounts(); $allusernamefields = get_all_user_name_fields(false, null, null, null, true); $columns = array_merge($allusernamefields, $extracolumns, array('city', 'country', 'lastaccess')); foreach ($columns as $column) { $string[$column] = get_user_field_name($column); if ($sort != $column) { $columnicon = ""; if ($column == "lastaccess") { $columndir = "DESC"; } else { $columndir = "ASC"; } } else { $columndir = $dir == "ASC" ? "DESC" : "ASC"; if ($column == "lastaccess") { $columnicon = $dir == "ASC" ? "sort_desc" : "sort_asc"; } else { $columnicon = $dir == "ASC" ? "sort_asc" : "sort_desc"; } $columnicon = "<img class='iconsort' src=\"" . $OUTPUT->pix_url('t/' . $columnicon) . "\" alt=\"\" />";
$a = new stdClass(); $a->firstname = 'firstname'; $a->lastname = 'lastname'; // Getting the fullname display will ensure that the order in the language file is maintained. $usernameheader = explode(' ', get_string('fullnamedisplay', null, $a)); } else { // If everything is as expected then put them in the order specified by the alternative full name format setting. $usernameheader = order_in_string($allusernames, $fullusernames); } // Loop through each name and return the language string. foreach ($usernameheader as $key => $username) { $userdetails[$username] = get_string($username); } $extrafields = get_extra_user_fields($context); foreach ($extrafields as $field) { $userdetails[$field] = get_user_field_name($field); } $fields = array('userdetails' => $userdetails, 'lastcourseaccess' => get_string('lastcourseaccess'), 'role' => get_string('roles', 'role'), 'group' => get_string('groups', 'group'), 'enrol' => get_string('enrolmentinstances', 'enrol')); // Remove hidden fields if the user has no access if (!has_capability('moodle/course:viewhiddenuserfields', $context)) { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); if (isset($hiddenfields['lastaccess'])) { unset($fields['lastcourseaccess']); } if (isset($hiddenfields['groups'])) { unset($fields['group']); } } $filterform = new enrol_users_filter_form('users.php', array('manager' => $manager, 'id' => $id, 'newcourse' => $newcourse), 'get', '', array('id' => 'filterform')); $filterform->set_data(array('search' => $search, 'ifilter' => $filter, 'role' => $role, 'filtergroup' => $fgroup, 'status' => $status)); $table->set_fields($fields, $renderer);
$row->cells[1]->attributes['class'] = 'content'; $row->cells[1]->text = $OUTPUT->container(fullname($user, has_capability('moodle/site:viewfullnames', $context)), 'username'); $row->cells[1]->text .= $OUTPUT->container_start('info'); if (!empty($user->role)) { $row->cells[1]->text .= get_string('role') . get_string('labelsep', 'langconfig') . $user->role . '<br />'; } if ($user->maildisplay == 1 or $user->maildisplay == 2 and $course->id != SITEID and !isguestuser() or has_capability('moodle/course:viewhiddenuserfields', $context) or in_array('email', $extrafields) or $user->id == $USER->id) { $row->cells[1]->text .= get_string('email') . get_string('labelsep', 'langconfig') . html_writer::link("mailto:{$user->email}", $user->email) . '<br />'; } foreach ($extrafields as $field) { if ($field === 'email') { // Skip email because it was displayed with different logic above // because this page is intended for students too. continue; } $row->cells[1]->text .= get_user_field_name($field) . get_string('labelsep', 'langconfig') . s($user->{$field}) . '<br />'; } if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) { $row->cells[1]->text .= get_string('city') . get_string('labelsep', 'langconfig'); if ($user->city && !isset($hiddenfields['city'])) { $row->cells[1]->text .= $user->city; } if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) { if ($user->city && !isset($hiddenfields['city'])) { $row->cells[1]->text .= ', '; } $row->cells[1]->text .= $countries[$user->country]; } $row->cells[1]->text .= '<br />'; } if (!isset($hiddenfields['lastaccess'])) {
print '</th></tr>'; } // Print user heading and icons print '<tr>'; // User heading / sort option print '<th scope="col" class="completion-sortchoice" style="clear: both;">'; $sistring = "&silast={$silast}&sifirst={$sifirst}"; if ($firstnamesort) { print get_string('firstname') . " / <a href=\"./?course={$course->id}{$sistring}\">" . get_string('lastname') . '</a>'; } else { print "<a href=\"./?course={$course->id}&sort=firstname{$sistring}\">" . get_string('firstname') . '</a> / ' . get_string('lastname'); } print '</th>'; // Print user identity columns foreach ($extrafields as $field) { echo '<th scope="col" class="completion-identifyfield">' . get_user_field_name($field) . '</th>'; } /// /// Print criteria icons /// foreach ($criteria as $criterion) { // Generate icon details $icon = ''; $iconlink = ''; $icontitle = ''; // Required if $iconlink set $iconalt = ''; // Required switch ($criterion->criteriatype) { case COMPLETION_CRITERIA_TYPE_ACTIVITY: // Display icon