protected function readquestions($lines) { // For this class the method has been simplified as // there can never be more than one question for a // multianswer import $questions = array(); $questiontext = array(); $questiontext['text'] = implode('', $lines); $questiontext['format'] = 0; $questiontext['itemid'] = ''; $question = qtype_multianswer_extract_question($questiontext); $question->questiontext = $question->questiontext['text']; $question->questiontextformat = 0; $question->qtype = MULTIANSWER; $question->generalfeedback = ''; $question->course = $this->course; if (!empty($question)) { $name = html_to_text(implode(' ', $lines)); $name = preg_replace('/{[^}]*}/', '', $name); $name = trim($name); if ($name) { $question->name = shorten_text($name, 45); } else { // We need some name, so use the current time, since that will be // reasonably unique. $question->name = userdate(time()); } $questions[] = $question; } return $questions; }
protected function get_other_values(renderer_base $output) { $contextcache = array(); $competencies = array(); foreach ($this->related['competencies'] as $competency) { if (!isset($contextcache[$competency->get_competencyframeworkid()])) { $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context(); } $context = $contextcache[$competency->get_competencyframeworkid()]; $compexporter = new competency_exporter($competency, array('context' => $context)); $competencies[] = $compexporter->export($output); } $urlshort = ''; $url = $this->persistent->get_url(); if (!empty($url)) { $murl = new moodle_url($url); $shorturl = preg_replace('@^https?://(www\\.)?@', '', $murl->out(false)); $urlshort = shorten_text($shorturl, 30, true); } $files = array(); $storedfiles = $this->persistent->get_files(); if (!empty($storedfiles)) { foreach ($storedfiles as $storedfile) { $fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context'])); $files[] = $fileexporter->export($output); } } $values = array('canmanage' => $this->persistent->can_manage(), 'competencycount' => count($competencies), 'competencies' => $competencies, 'filecount' => count($files), 'files' => $files, 'hasurlorfiles' => !empty($files) || !empty($url), 'urlshort' => $urlshort); return $values; }
/** * Generate options array for hierselect form element * * Creates a list of discussions. * * @return array */ public function get_discussion_options() { $options = array(0 => get_string('all', 'hsuforum')); $rs = hsuforum_get_discussions($this->_customdata->cm, 'd.name'); foreach ($rs as $discussion) { $options[$discussion->discussion] = shorten_text(format_string($discussion->name)); } $rs->close(); return $options; }
/** * Displaying search results. * * @param \core_search\document Containing a single search response to be displayed.a * @return string HTML */ public function render_result(\core_search\document $doc) { $docdata = $doc->export_for_template($this); // Limit text fields size. $docdata['title'] = shorten_text($docdata['title'], static::SEARCH_RESULT_STRING_SIZE, true); $docdata['content'] = $docdata['content'] ? shorten_text($docdata['content'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; $docdata['description1'] = $docdata['description1'] ? shorten_text($docdata['description1'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; $docdata['description2'] = $docdata['description2'] ? shorten_text($docdata['description2'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; return $this->output->render_from_template('core_search/result', $docdata); }
/** * Prevent name from exceeding 255 chars. */ public static function shorten_post_name($name) { $strre = get_string('re', 'hsuforum'); if (\core_text::strlen($name) > 255) { $shortened = shorten_text($name, 255); if (trim(str_ireplace($strre, '', $shortened)) === '...' || \core_text::strlen($shortened) > 255) { // Make a 2nd pass with the 'exact' param true, as shortening on word boundary failed or exceeded 255 chars. $shortened = shorten_text($name, 255, true); } $name = $shortened; } return $name; }
protected function get_other_values(renderer_base $output) { $filename = $this->file->get_filename(); $filenameshort = $filename; if (core_text::strlen($filename) > 25) { $filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..'); $filenameshort .= substr($filename, -4); } $icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file); $iconurl = $output->pix_url($icon, 'core'); $url = moodle_url::make_pluginfile_url($this->file->get_contextid(), $this->file->get_component(), $this->file->get_filearea(), $this->file->get_itemid(), $this->file->get_filepath(), $this->file->get_filename(), true); return array('filenameshort' => $filenameshort, 'filesizeformatted' => display_size((int) $this->file->get_filesize()), 'icon' => $icon, 'iconurl' => $iconurl->out(false), 'url' => $url->out(false), 'timecreatedformatted' => userdate($this->file->get_timecreated()), 'timemodifiedformatted' => userdate($this->file->get_timemodified())); }
public function edit_form_add(&$mform) { global $COURSE, $CFG; require_once $CFG->dirroot . '/course/lib.php'; get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesusesd); $modinfo = unserialize((string) $COURSE->modinfo); $modules = array(); foreach ($mods as $mod) { $instancename = urldecode($modinfo[$mod->id]->name); $instancename = format_string($instancename, true, $COURSE->id); $modules[$mod->id] = shorten_text($mod->modfullname . ': ' . $instancename, 28); } natcasesort($modules); // Add our choose option to the front $options = array(0 => get_string('choose', 'pagemenu')) + $modules; $mform->addElement('select', 'moduleid', get_string('addmodule', 'pagemenu'), $options); $mform->setType('moduleid', PARAM_INT); }
/** * @param object $resource * @uses $CFG */ function get_text_for_indexing_txt(&$resource, $directfile = '') { global $CFG; // SECURITY : do not allow non admin execute anything on system !! if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { return; } // just try to get text empirically from ppt binary flow if ($directfile == '') { $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); } else { $text = implode('', file("{$CFG->dataroot}/{$directfile}")); } if (!empty($CFG->block_search_limit_index_body)) { $text = shorten_text($text, $CFG->block_search_limit_index_body); } return $text; }
protected function get_other_values(renderer_base $output) { $urlshort = ''; $url = $this->persistent->get_url(); if (!empty($url)) { $murl = new moodle_url($url); $shorturl = preg_replace('@^https?://(www\\.)?@', '', $murl->out(false)); $urlshort = shorten_text($shorturl, 30, true); } $files = array(); $storedfiles = $this->persistent->get_files(); if (!empty($storedfiles)) { foreach ($storedfiles as $storedfile) { $fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context'])); $files[] = $fileexporter->export($output); } } $userevidencecompetencies = array(); $frameworks = array(); $scales = array(); $usercompetencies = $this->persistent->get_user_competencies(); foreach ($usercompetencies as $usercompetency) { $competency = $usercompetency->get_competency(); // Get the framework. if (!isset($frameworks[$competency->get_competencyframeworkid()])) { $frameworks[$competency->get_competencyframeworkid()] = $competency->get_framework(); } $framework = $frameworks[$competency->get_competencyframeworkid()]; // Get the scale. $scaleid = $competency->get_scaleid(); if ($scaleid === null) { $scaleid = $framework->get_scaleid(); } if (!isset($scales[$framework->get_scaleid()])) { $scales[$framework->get_scaleid()] = $framework->get_scale(); } $scale = $scales[$framework->get_scaleid()]; $related = array('competency' => $competency, 'usercompetency' => $usercompetency, 'scale' => $scale, 'context' => $framework->get_context()); $userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related); $userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output); } $values = array('canmanage' => $this->persistent->can_manage(), 'filecount' => count($files), 'files' => $files, 'userhasplan' => $this->persistent->user_has_plan(), 'hasurlorfiles' => !empty($files) || !empty($url), 'urlshort' => $urlshort, 'competencycount' => count($userevidencecompetencies), 'usercompetencies' => $userevidencecompetencies); return $values; }
/** * @param object $resource * @uses $CFG */ function get_text_for_indexing_xml(&$resource, $directfile = '') { global $CFG; // SECURITY : do not allow non admin execute anything on system !! if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { return; } // just get text if ($directfile == '') { $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); } else { $text = implode('', file("{$CFG->dataroot}/{$directfile}")); } // filter out all xml tags $text = preg_replace("/<[^>]*>/", ' ', $text); if (!empty($CFG->block_search_limit_index_body)) { $text = shorten_text($text, $CFG->block_search_limit_index_body); } return $text; }
/** * @param object $resource * @uses $CFG */ function get_text_for_indexing_htm(&$resource, $directfile = '') { global $CFG; // SECURITY : do not allow non admin execute anything on system !! if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { return; } // just get text if ($directfile == '') { $text = implode('', file("{$CFG->dataroot}/{$resource->course}/{$resource->reference}")); } else { $text = implode('', file("{$CFG->dataroot}/{$directfile}")); } // extract keywords and other interesting meta information and put it back as real content for indexing if (preg_match('/(.*)<meta ([^>]*)>(.*)/is', $text, $matches)) { $prefix = $matches[1]; $meta_attributes = $matches[2]; $suffix = $matches[3]; if (preg_match('/name="(keywords|description)"/i', $meta_attributes)) { preg_match('/content="([^"]+)"/i', $meta_attributes, $matches); $text = $prefix . ' ' . $matches[1] . ' ' . $suffix; } } // brutally filters all html tags $text = preg_replace("/<[^>]*>/", '', $text); $text = preg_replace("/<!--[^>]*-->/", '', $text); $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); $text = mb_convert_encoding($text, 'UTF-8', 'auto'); /* * debug code for tracing input echo "<hr/>"; $FILE = fopen("filetrace.log", 'w'); fwrite($FILE, $text); fclose($FILE); echo "<hr/>"; */ if (!empty($CFG->block_search_limit_index_body)) { $text = shorten_text($text, $CFG->block_search_limit_index_body); } return $text; }
public function export_for_template(\renderer_base $output) { global $USER; $context = clone $this->notification; if ($context->useridto == $USER->id && $context->timeusertodeleted) { $context->deleted = true; } else { $context->deleted = false; } $context->timecreatedpretty = get_string('ago', 'message', format_time(time() - $context->timecreated)); $context->text = message_format_message_text($context); $context->read = $context->timeread ? true : false; $context->shortenedsubject = shorten_text($context->subject, 125); if (!empty($context->component) && substr($context->component, 0, 4) == 'mod_') { $iconurl = $output->pix_url('icon', $context->component); } else { $iconurl = $output->pix_url('i/marker', 'core'); } $context->iconurl = $iconurl->out(); return $context; }
public function readquestions($lines) { question_bank::get_qtype('multianswer'); // Ensure the multianswer code is loaded. // For this class the method has been simplified as // there can never be more than one question for a // multianswer import. $questions = array(); $questiontext = array(); $questiontext['text'] = implode('', $lines); $questiontext['format'] = FORMAT_MOODLE; $questiontext['itemid'] = ''; $question = qtype_multianswer_extract_question($questiontext); $question->questiontext = $question->questiontext['text']; $question->questiontextformat = 0; $question->qtype = 'multianswer'; $question->generalfeedback = ''; $question->generalfeedbackformat = FORMAT_MOODLE; $question->length = 1; $question->penalty = 0.3333333; if (!empty($question)) { $name = html_to_text(implode(' ', $lines)); $name = preg_replace('/{[^}]*}/', '', $name); $name = trim($name); if ($name) { $question->name = shorten_text($name, 45); } else { // We need some name, so use the current time, since that will be // reasonably unique. $question->name = userdate(time()); } $questions[] = $question; } return $questions; }
public function edit_form_add(&$mform) { global $COURSE, $CFG; require_once $CFG->dirroot . '/course/lib.php'; $modinfo = get_fast_modinfo($COURSE); $modules = array(); foreach ($modinfo->cms as $cm) { $modules[$cm->modplural][$cm->id] = shorten_text(format_string($cm->name, true, $COURSE->id), 28); } // Fix the sorting $options = array(); $modnames = array_keys($modules); natcasesort($modnames); foreach ($modnames as $modname) { $mods = $modules[$modname]; natcasesort($mods); $options[$modname] = $mods; } // Add our choose option to the front $options = array('' => array(0 => get_string('choose', 'pagemenu'))) + $options; $mform->addElement('selectgroups', 'moduleid', get_string('addmodule', 'pagemenu'), $options); $mform->setType('moduleid', PARAM_INT); }
public function comment_on_datasetitems($qtypeobj, $questionid, $questiontext, $answers, $data, $number) { global $DB; $comment = new stdClass(); $comment->stranswers = array(); $comment->outsidelimit = false; $comment->answers = array(); // Find a default unit. if (!empty($questionid) && ($unit = $DB->get_record('question_numerical_units', array('question' => $questionid, 'multiplier' => 1.0)))) { $unit = $unit->unit; } else { $unit = ''; } $answers = fullclone($answers); $delimiter = ': '; $virtualqtype = $qtypeobj->get_virtual_qtype(); foreach ($answers as $key => $answer) { $error = qtype_calculated_find_formula_errors($answer->answer); if ($error) { $comment->stranswers[$key] = $error; continue; } $formula = $this->substitute_variables($answer->answer, $data); $formattedanswer = qtype_calculated_calculate_answer($answer->answer, $data, $answer->tolerance, $answer->tolerancetype, $answer->correctanswerlength, $answer->correctanswerformat, $unit); if ($formula === '*') { $answer->min = ' '; $formattedanswer->answer = $answer->answer; } else { eval('$ansvalue = ' . $formula . ';'); $ans = new qtype_numerical_answer(0, $ansvalue, 0, '', 0, $answer->tolerance); $ans->tolerancetype = $answer->tolerancetype; list($answer->min, $answer->max) = $ans->get_tolerance_interval($answer); } if ($answer->min === '') { // This should mean that something is wrong. $comment->stranswers[$key] = " {$formattedanswer->answer}" . '<br/><br/>'; } else { if ($formula === '*') { $comment->stranswers[$key] = $formula . ' = ' . get_string('anyvalue', 'qtype_calculated') . '<br/><br/><br/>'; } else { $formula = shorten_text($formula, 57, true); $comment->stranswers[$key] = $formula . ' = ' . $formattedanswer->answer . '<br/>'; $correcttrue = new stdClass(); $correcttrue->correct = $formattedanswer->answer; $correcttrue->true = ''; if ($formattedanswer->answer < $answer->min || $formattedanswer->answer > $answer->max) { $comment->outsidelimit = true; $comment->answers[$key] = $key; $comment->stranswers[$key] .= get_string('trueansweroutsidelimits', 'qtype_calculated', $correcttrue); } else { $comment->stranswers[$key] .= get_string('trueanswerinsidelimits', 'qtype_calculated', $correcttrue); } $comment->stranswers[$key] .= '<br/>'; $comment->stranswers[$key] .= get_string('min', 'qtype_calculated') . $delimiter . $answer->min . ' --- '; $comment->stranswers[$key] .= get_string('max', 'qtype_calculated') . $delimiter . $answer->max; } } } return fullclone($comment); }
public function test_shorten_text_multilang() { // This is not necessaryily specific to multilang. The issue is really // tags with attributes, where before we were generating invalid HTML // output like shorten_text('<span id="x" class="y">A</span> B', 1) // returning '<span id="x" ...</span>'. It is just that multilang // requires the sort of HTML that is quite likely to trigger this. // ........................................1... $text = '<span lang="en" class="multilang">A</span>' . '<span lang="fr" class="multilang">B</span>'; $this->assertSame('<span lang="en" class="multilang">...</span>', shorten_text($text, 1)); }
/** * 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_SUBMITTED => get_string('submitted', 'assignment'), self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment')); $updatepref = optional_param('updatepref', 0, PARAM_INT); if (isset($_POST['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); $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; $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. plagiarism_update_status($this->course, $this->cm); /// 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())); } $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); /// Get all ppl that are allowed to submit assignments list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $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 = ''; if($filter == self::FILTER_SUBMITTED) { $wherefilter = ' AND s.timemodified > 0'; } else if($filter == self::FILTER_REQUIRE_GRADING) { $wherefilter = ' AND s.timemarked < s.timemodified '; } $sql = "SELECT u.id FROM {user} u ". "LEFT JOIN ($esql) eu ON eu.id=u.id ". "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " . "WHERE u.deleted = 0 AND eu.id=u.id ". 'AND s.assignment = '. $this->assignment->id . $wherefilter; } $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)); } } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), 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'); $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->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); if (empty($users)) { echo $OUTPUT->heading(get_string('nosubmitusers','assignment')); echo '</div>'; return true; } if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak) echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&download=zip">'.get_string('downloadall', 'assignment').'</a></div>'; } /// 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 .= 's.timemarked < s.timemodified AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY '.$sort; } $ufields = user_picture::fields('u'); $select = "SELECT $ufields, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) 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'); $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) { $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'; } /// Calculate user status $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified); $picture = $OUTPUT->user_picture($auser); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///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) { $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id) . userdate($auser->timemodified).'</div>'; } else { $studentmodified = '<div id="ts'.$auser->id.'"> </div>'; } ///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::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::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>'; } else if ($quickgrade) { // allow editing $attributes = array(); $attributes['tabindex'] = $tabindex++; $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.'">-</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; ///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>'.$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>'; $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } $currentposition++; } } $table->print_html(); /// Print the whole table /// Print quickgrade form around the table if ($quickgrade && $table->started_output){ $mailinfopref = false; if (get_user_preferences('assignment_mailinfo', 1)) { $mailinfopref = true; } $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment')); $emailnotification .= $OUTPUT->help_icon('enableemailnotification', '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); $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(); }
/** * Display all the submissions ready for grading */ function display_submissions($message = '') { global $CFG, $db, $USER; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ if (isset($_POST['updatepref'])) { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); } /* 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); $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; } $teacherattempts = true; /// Temporary measure $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; $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $navlinks = array(); $navlinks[] = array('name' => $this->strassignments, 'link' => "index.php?id={$course->id}", 'type' => 'activity'); $navlinks[] = array('name' => format_string($this->assignment->name, true), 'link' => "view.php?a={$this->assignment->id}", 'type' => 'activityinstance'); $navlinks[] = array('name' => $this->strsubmissions, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit assignments $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false); $users = array_keys($users); if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id'); $users = array_intersect($users, array_keys($groupingusers)); } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', 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'); $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', '90%'); //$table->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); /// Check to see if groups are being used in this assignment if (!$teacherattempts) { $teachers = get_course_teachers($course->id); if (!empty($teachers)) { $keys = array_keys($teachers); } foreach ($keys as $key) { unset($users[$key]); } } if (empty($users)) { print_heading(get_string('noattempts', 'assignment')); return true; } /// Construct the SQL if ($where = $table->get_sql_where()) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status '; $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $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'); $grademenu = make_grades_menu($this->assignment->grade); if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); foreach ($ausers as $auser) { $final_grade = $grading_info->items[0]->grades[$auser->id]; /// Calculate user status $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified; $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///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) { $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>'; } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; } ///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 . '">' . $final_grade->str_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $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 . '">' . $final_grade->str_grade . '</div>'; } else { if ($quickgrade) { $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $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->str_grade . '</div>'; } else { if ($quickgrade) { // allow editing $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } 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; ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++; $button = link_to_popup_window($popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button' . $auser->id); $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>' . $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 { $outcomes .= ' '; $outcomes .= choose_from_menu($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_' . $n . '_' . $auser->id); } $outcomes .= '</div>'; } } $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } } /// Print quickgrade form around the table if ($quickgrade) { echo '<form action="submissions.php" id="fastg" method="post">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="fastgrade" />'; echo '<input type="hidden" name="page" value="' . $page . '" />'; echo '</div>'; //echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>'; } $table->print_html(); /// Print the whole table if ($quickgrade) { echo '<div style="text-align:center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>'; echo '</form>'; } /// End of fast grading form /// Mini form for setting user preference echo '<br />'; echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">'; echo '<div>'; echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />'; echo '<table id="optiontable" align="right">'; echo '<tr align="right"><td>'; echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>'; echo ':</td>'; echo '<td>'; echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />'; helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment'); echo '</td></tr>'; echo '<tr align="right">'; echo '<td>'; print_string('quickgrade', 'assignment'); echo ':</td>'; echo '<td>'; if ($quickgrade) { echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />'; } else { echo '<input type="checkbox" name="quickgrade" value="1" />'; } helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment') . '</p></div>'; echo '</td></tr>'; echo '<tr>'; echo '<td colspan="2" align="right">'; echo '<input type="submit" value="' . get_string('savepreferences') . '" />'; echo '</td></tr></table>'; echo '</div>'; echo '</form>'; ///End of mini form print_footer($this->course); }
/** * Return a more detailed criteria title for display in reports * * @return string */ public function get_title_detailed() { global $DB; $module = $DB->get_record('course_modules', array('id' => $this->moduleinstance)); $activity = $DB->get_record($this->module, array('id' => $module->instance)); return shorten_text(urldecode($activity->name)); }
/** * 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; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ if (isset($_POST['updatepref'])) { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); } /* 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); $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; $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); $navigation = build_navigation($this->strsubmissions, $this->cm); print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $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, 'submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit assignments if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) { $users = array_keys($users); } // if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), 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'); $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->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); if (empty($users)) { echo $OUTPUT->heading(get_string('nosubmitusers', 'assignment')); return true; } /// Construct the SQL if ($where = $table->get_sql_where()) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) 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) . ') '; $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'); $grademenu = make_grades_menu($this->assignment->grade); if (($ausers = $DB->get_records_sql($select . $sql . $sort, null, $table->get_page_start(), $table->get_page_size())) !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); foreach ($ausers as $auser) { $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'; } /// Calculate user status $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified; $picture = $OUTPUT->user_picture(moodle_user_picture::make($auser, $course->id)); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///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) { $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>'; } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; } ///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) { $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $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) { $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $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>'; } else { if ($quickgrade) { // allow editing $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } 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; ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++; $link = html_link::make($popup_url, $buttontext); $link->add_action(new popup_action('click', $link->url, 'grade' . $auser->id, array('height' => 600, 'width' => 700))); $link->title = $buttontext; $button = $OUTPUT->link($link); $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>' . $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 { $outcomes .= ' '; $select = html_select::make($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades')); $select->nothingvalue = '0'; $select->tabindex = $tabindex++; $select->id = 'outcome_' . $n . '_' . $auser->id; $outcomes .= $OUTPUT->select($select); } $outcomes .= '</div>'; } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser) . '</a>'; $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } } /// Print quickgrade form around the table if ($quickgrade) { echo '<form action="submissions.php" id="fastg" method="post">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="fastgrade" />'; echo '<input type="hidden" name="page" value="' . $page . '" />'; echo '</div>'; } $table->print_html(); /// Print the whole table if ($quickgrade) { $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? 'checked="checked"' : ''; echo '<div class="fgcontrols">'; echo '<div class="emailnotification">'; echo '<label for="mailinfo">' . get_string('enableemailnotification', 'assignment') . '</label>'; echo '<input type="hidden" name="mailinfo" value="0" />'; echo '<input type="checkbox" id="mailinfo" name="mailinfo" value="1" ' . $lastmailinfo . ' />'; echo $OUTPUT->help_icon(moodle_help_icon::make('emailnotification', get_string('enableemailnotification', 'assignment'), 'assignment')) . '</p></div>'; echo '</div>'; echo '<div class="fastgbutton"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>'; echo '</div>'; echo '</form>'; } /// End of fast grading form /// Mini form for setting user preference echo '<div class="qgprefs">'; echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post"><div>'; echo '<input type="hidden" name="updatepref" value="1" />'; echo '<table id="optiontable">'; echo '<tr><td>'; echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>'; echo '</td>'; echo '<td>'; echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />'; echo $OUTPUT->help_icon(moodle_help_icon::make('pagesize', get_string('pagesize', 'assignment'), 'assignment')); echo '</td></tr>'; echo '<tr><td>'; echo '<label for="quickgrade">' . get_string('quickgrade', 'assignment') . '</label>'; echo '</td>'; echo '<td>'; $checked = $quickgrade ? 'checked="checked"' : ''; echo '<input type="checkbox" id="quickgrade" name="quickgrade" value="1" ' . $checked . ' />'; echo $OUTPUT->help_icon(moodle_help_icon::make('quickgrade', get_string('quickgrade', 'assignment'), 'assignment')) . '</p></div>'; echo '</td></tr>'; echo '<tr><td colspan="2">'; echo '<input type="submit" value="' . get_string('savepreferences') . '" />'; echo '</td></tr></table>'; echo '</div></form></div>'; ///End of mini form echo $OUTPUT->footer(); }
/** * Print a forum post * * @global object * @global object * @uses FORUM_MODE_THREADED * @uses PORTFOLIO_FORMAT_PLAINHTML * @uses PORTFOLIO_FORMAT_FILE * @uses PORTFOLIO_FORMAT_RICHHTML * @uses PORTFOLIO_ADD_TEXT_LINK * @uses CONTEXT_MODULE * @param object $post The post to print. * @param object $discussion * @param object $forum * @param object $cm * @param object $course * @param boolean $ownpost Whether this post belongs to the current user. * @param boolean $reply Whether to print a 'reply' link at the bottom of the message. * @param boolean $link Just print a shortened version of the post as a link to the full post. * @param string $footer Extra stuff to print after the message. * @param string $highlight Space-separated list of terms to highlight. * @param int $post_read true, false or -99. If we already know whether this user * has read this post, pass that in, otherwise, pass in -99, and this * function will work it out. * @param boolean $dummyifcantsee When forum_user_can_see_post says that * the current user can't see this post, if this argument is true * (the default) then print a dummy 'you can't see this post' post. * If false, don't output anything at all. * @param bool|null $istracked * @return void */ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost = false, $reply = false, $link = false, $footer = "", $highlight = "", $postisread = null, $dummyifcantsee = true, $istracked = null, $return = false) { global $USER, $CFG, $OUTPUT; require_once $CFG->libdir . '/filelib.php'; // String cache static $str; $modcontext = context_module::instance($cm->id); $post->course = $course->id; $post->forum = $forum->id; $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_forum', 'post', $post->id); if (!empty($CFG->enableplagiarism)) { require_once $CFG->libdir . '/plagiarismlib.php'; $post->message .= plagiarism_get_links(array('userid' => $post->userid, 'content' => $post->message, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum)); } // caching if (!isset($cm->cache)) { $cm->cache = new stdClass(); } if (!isset($cm->cache->caps)) { $cm->cache->caps = array(); $cm->cache->caps['mod/forum:viewdiscussion'] = has_capability('mod/forum:viewdiscussion', $modcontext); $cm->cache->caps['moodle/site:viewfullnames'] = has_capability('moodle/site:viewfullnames', $modcontext); $cm->cache->caps['mod/forum:editanypost'] = has_capability('mod/forum:editanypost', $modcontext); $cm->cache->caps['mod/forum:splitdiscussions'] = has_capability('mod/forum:splitdiscussions', $modcontext); $cm->cache->caps['mod/forum:deleteownpost'] = has_capability('mod/forum:deleteownpost', $modcontext); $cm->cache->caps['mod/forum:deleteanypost'] = has_capability('mod/forum:deleteanypost', $modcontext); $cm->cache->caps['mod/forum:viewanyrating'] = has_capability('mod/forum:viewanyrating', $modcontext); $cm->cache->caps['mod/forum:exportpost'] = has_capability('mod/forum:exportpost', $modcontext); $cm->cache->caps['mod/forum:exportownpost'] = has_capability('mod/forum:exportownpost', $modcontext); } if (!isset($cm->uservisible)) { $cm->uservisible = \core_availability\info_module::is_user_visible($cm, 0, false); } if ($istracked && is_null($postisread)) { $postisread = forum_tp_is_post_read($USER->id, $post); } if (!forum_user_can_see_post($forum, $discussion, $post, NULL, $cm)) { $output = ''; if (!$dummyifcantsee) { if ($return) { return $output; } echo $output; return; } $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id)); $output .= html_writer::start_tag('div', array('class' => 'forumpost clearfix', 'role' => 'region', 'aria-label' => get_string('hiddenforumpost', 'forum'))); $output .= html_writer::start_tag('div', array('class' => 'row header')); $output .= html_writer::tag('div', '', array('class' => 'left picture')); // Picture if ($post->parent) { $output .= html_writer::start_tag('div', array('class' => 'topic')); } else { $output .= html_writer::start_tag('div', array('class' => 'topic starter')); } $output .= html_writer::tag('div', get_string('forumsubjecthidden', 'forum'), array('class' => 'subject', 'role' => 'header')); // Subject. $output .= html_writer::tag('div', get_string('forumauthorhidden', 'forum'), array('class' => 'author', 'role' => 'header')); // Author. $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); // row $output .= html_writer::start_tag('div', array('class' => 'row')); $output .= html_writer::tag('div', ' ', array('class' => 'left side')); // Groups $output .= html_writer::tag('div', get_string('forumbodyhidden', 'forum'), array('class' => 'content')); // Content $output .= html_writer::end_tag('div'); // row $output .= html_writer::end_tag('div'); // forumpost if ($return) { return $output; } echo $output; return; } if (empty($str)) { $str = new stdClass(); $str->edit = get_string('edit', 'forum'); $str->delete = get_string('delete', 'forum'); $str->reply = get_string('reply', 'forum'); $str->parent = get_string('parent', 'forum'); $str->pruneheading = get_string('pruneheading', 'forum'); $str->prune = get_string('prune', 'forum'); $str->displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); $str->markread = get_string('markread', 'forum'); $str->markunread = get_string('markunread', 'forum'); } $discussionlink = new moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion)); // Build an object that represents the posting user $postuser = new stdClass(); $postuserfields = explode(',', user_picture::fields()); $postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields); $postuser->id = $post->userid; $postuser->fullname = fullname($postuser, $cm->cache->caps['moodle/site:viewfullnames']); $postuser->profilelink = new moodle_url('/user/view.php', array('id' => $post->userid, 'course' => $course->id)); // Prepare the groups the posting user belongs to if (isset($cm->cache->usersgroups)) { $groups = array(); if (isset($cm->cache->usersgroups[$post->userid])) { foreach ($cm->cache->usersgroups[$post->userid] as $gid) { $groups[$gid] = $cm->cache->groups[$gid]; } } } else { $groups = groups_get_all_groups($course->id, $post->userid, $cm->groupingid); } // Prepare the attachements for the post, files then images list($attachments, $attachedimages) = forum_print_attachments($post, $cm, 'separateimages'); // Determine if we need to shorten this post $shortenpost = $link && strlen(strip_tags($post->message)) > $CFG->forum_longpost; // Prepare an array of commands $commands = array(); // SPECIAL CASE: The front page can display a news item post to non-logged in users. // Don't display the mark read / unread controls in this case. if ($istracked && $CFG->forum_usermarksread && isloggedin()) { $url = new moodle_url($discussionlink, array('postid' => $post->id, 'mark' => 'unread')); $text = $str->markunread; if (!$postisread) { $url->param('mark', 'read'); $text = $str->markread; } if ($str->displaymode == FORUM_MODE_THREADED) { $url->param('parent', $post->parent); } else { $url->set_anchor('p' . $post->id); } $commands[] = array('url' => $url, 'text' => $text); } // Zoom in to the parent specifically if ($post->parent) { $url = new moodle_url($discussionlink); if ($str->displaymode == FORUM_MODE_THREADED) { $url->param('parent', $post->parent); } else { $url->set_anchor('p' . $post->parent); } $commands[] = array('url' => $url, 'text' => $str->parent); } // Hack for allow to edit news posts those are not displayed yet until they are displayed $age = time() - $post->created; if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) { $age = 0; } if ($forum->type == 'single' and $discussion->firstpost == $post->id) { if (has_capability('moodle/course:manageactivities', $modcontext)) { // The first post in single simple is the forum description. $commands[] = array('url' => new moodle_url('/course/modedit.php', array('update' => $cm->id, 'sesskey' => sesskey(), 'return' => 1)), 'text' => $str->edit); } } else { if ($ownpost && $age < $CFG->maxeditingtime || $cm->cache->caps['mod/forum:editanypost']) { $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('edit' => $post->id)), 'text' => $str->edit); } } if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') { $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('prune' => $post->id)), 'text' => $str->prune, 'title' => $str->pruneheading); } if ($forum->type == 'single' and $discussion->firstpost == $post->id) { // Do not allow deleting of first post in single simple type. } else { if ($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost'] || $cm->cache->caps['mod/forum:deleteanypost']) { $commands[] = array('url' => new moodle_url('/mod/forum/post.php', array('delete' => $post->id)), 'text' => $str->delete); } } if ($reply) { $commands[] = array('url' => new moodle_url('/mod/forum/post.php#mformforum', array('reply' => $post->id)), 'text' => $str->reply); } if ($CFG->enableportfolios && ($cm->cache->caps['mod/forum:exportpost'] || $ownpost && $cm->cache->caps['mod/forum:exportownpost'])) { $p = array('postid' => $post->id); require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), 'mod_forum'); if (empty($attachments)) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); if (!empty($porfoliohtml)) { $commands[] = $porfoliohtml; } } // Finished building commands // Begin output $output = ''; if ($istracked) { if ($postisread) { $forumpostclass = ' read'; } else { $forumpostclass = ' unread'; $output .= html_writer::tag('a', '', array('name' => 'unread')); } } else { // ignore trackign status if not tracked or tracked param missing $forumpostclass = ''; } $topicclass = ''; if (empty($post->parent)) { $topicclass = ' firstpost starter'; } $postbyuser = new stdClass(); $postbyuser->post = $post->subject; $postbyuser->user = $postuser->fullname; $discussionbyuser = get_string('postbyuser', 'forum', $postbyuser); $output .= html_writer::tag('a', '', array('id' => 'p' . $post->id)); $output .= html_writer::start_tag('div', array('class' => 'forumpost clearfix' . $forumpostclass . $topicclass, 'role' => 'region', 'aria-label' => $discussionbyuser)); $output .= html_writer::start_tag('div', array('class' => 'row header clearfix')); $output .= html_writer::start_tag('div', array('class' => 'left picture')); $output .= $OUTPUT->user_picture($postuser, array('courseid' => $course->id)); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'topic' . $topicclass)); $postsubject = $post->subject; if (empty($post->subjectnoformat)) { $postsubject = format_string($postsubject); } $output .= html_writer::tag('div', $postsubject, array('class' => 'subject', 'role' => 'heading', 'aria-level' => '2')); $by = new stdClass(); $by->name = html_writer::link($postuser->profilelink, $postuser->fullname); $by->date = userdate($post->modified); $output .= html_writer::tag('div', get_string('bynameondate', 'forum', $by), array('class' => 'author', 'role' => 'heading', 'aria-level' => '2')); $output .= html_writer::end_tag('div'); //topic $output .= html_writer::end_tag('div'); //row $output .= html_writer::start_tag('div', array('class' => 'row maincontent clearfix')); $output .= html_writer::start_tag('div', array('class' => 'left')); $groupoutput = ''; if ($groups) { $groupoutput = print_group_picture($groups, $course->id, false, true, true); } if (empty($groupoutput)) { $groupoutput = ' '; } $output .= html_writer::tag('div', $groupoutput, array('class' => 'grouppictures')); $output .= html_writer::end_tag('div'); //left side $output .= html_writer::start_tag('div', array('class' => 'no-overflow')); $output .= html_writer::start_tag('div', array('class' => 'content')); $options = new stdClass(); $options->para = false; $options->trusted = $post->messagetrust; $options->context = $modcontext; if ($shortenpost) { // Prepare shortened version by filtering the text then shortening it. $postclass = 'shortenedpost'; $postcontent = format_text($post->message, $post->messageformat, $options); $postcontent = shorten_text($postcontent, $CFG->forum_shortpost); $postcontent .= html_writer::link($discussionlink, get_string('readtherest', 'forum')); $postcontent .= html_writer::tag('div', '(' . get_string('numwords', 'moodle', count_words($post->message)) . ')', array('class' => 'post-word-count')); } else { // Prepare whole post $postclass = 'fullpost'; $postcontent = format_text($post->message, $post->messageformat, $options, $course->id); if (!empty($highlight)) { $postcontent = highlight($highlight, $postcontent); } if (!empty($forum->displaywordcount)) { $postcontent .= html_writer::tag('div', get_string('numwords', 'moodle', count_words($post->message)), array('class' => 'post-word-count')); } $postcontent .= html_writer::tag('div', $attachedimages, array('class' => 'attachedimages')); } // Output the post content $output .= html_writer::tag('div', $postcontent, array('class' => 'posting ' . $postclass)); $output .= html_writer::end_tag('div'); // Content $output .= html_writer::end_tag('div'); // Content mask $output .= html_writer::end_tag('div'); // Row $output .= html_writer::start_tag('div', array('class' => 'row side')); $output .= html_writer::tag('div', ' ', array('class' => 'left')); $output .= html_writer::start_tag('div', array('class' => 'options clearfix')); if (!empty($attachments)) { $output .= html_writer::tag('div', $attachments, array('class' => 'attachments')); } // Output ratings if (!empty($post->rating)) { $output .= html_writer::tag('div', $OUTPUT->render($post->rating), array('class' => 'forum-post-rating')); } // Output the commands $commandhtml = array(); foreach ($commands as $command) { if (is_array($command)) { $commandhtml[] = html_writer::link($command['url'], $command['text']); } else { $commandhtml[] = $command; } } $output .= html_writer::tag('div', implode(' | ', $commandhtml), array('class' => 'commands')); // Output link to post if required if ($link && forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) { if ($post->replies == 1) { $replystring = get_string('repliesone', 'forum', $post->replies); } else { $replystring = get_string('repliesmany', 'forum', $post->replies); } $output .= html_writer::start_tag('div', array('class' => 'link')); $output .= html_writer::link($discussionlink, get_string('discussthistopic', 'forum')); $output .= ' (' . $replystring . ')'; $output .= html_writer::end_tag('div'); // link } // Output footer if required if ($footer) { $output .= html_writer::tag('div', $footer, array('class' => 'footer')); } // Close remaining open divs $output .= html_writer::end_tag('div'); // content $output .= html_writer::end_tag('div'); // row $output .= html_writer::end_tag('div'); // forumpost // Mark the forum post as read if required if ($istracked && !$CFG->forum_usermarksread && !$postisread) { forum_tp_mark_post_read($USER->id, $post, $forum->id); } if ($return) { return $output; } echo $output; return; }
/** * Return a more detailed criteria title for display in reports * * @return string */ public function get_title_detailed() { global $DB; $module = $DB->get_record('course_modules', array('id' => $this->moduleinstance)); $activity = $DB->get_record($this->module, array('id' => $module->instance)); return shorten_text(format_string($activity->name, true, array('context' => context_module::instance($module->id)))); }
$forum = $discussion->get_forum(); $cm = $forum->get_course_module(); $course = $forum->get_course(); // Check permission for change $discussion->require_edit(); // Is this the actual delete? if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($delete) { $discussion->delete(); redirect($forum->get_url(forum::PARAM_PLAIN)); } else { $discussion->undelete(); redirect('../../discuss.php?' . $discussion->get_link_params(forum::PARAM_PLAIN)); } } // Confirm page. Work out navigation for header $pagename = get_string($delete ? 'deletediscussion' : 'undeletediscussion', 'forumng', $discussion->get_subject(false)); $navigation = array(); $navigation[] = array('name' => shorten_text(htmlspecialchars($discussion->get_subject())), 'link' => $discussion->get_url(), 'type' => 'forumng'); $navigation[] = array('name' => $pagename, 'type' => 'forumng'); $PAGEWILLCALLSKIPMAINDESTINATION = true; print_header_simple(format_string($forum->get_name()) . ': ' . $pagename, "", build_navigation($navigation, $cm), "", "", true, '', navmenu($course, $cm)); print skip_main_destination(); // Show confirm option $confirmstring = get_string($delete ? 'confirmdeletediscussion' : 'confirmundeletediscussion', 'forumng'); notice_yesno($confirmstring, 'delete.php', '../../discuss.php', array('d' => $discussion->get_id(), 'delete' => $delete, 'clone' => $cloneid), array('d' => $discussion->get_id(), 'clone' => $cloneid), 'post', 'get'); // Display footer print_footer($course); } catch (forum_exception $e) { forum_utils::handle_exception($e); }
} } // 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 $activity->name = shorten_text($activity->name); if ($csv) { print $sep.csv_quote(strip_tags($activity->name)).$sep.csv_quote($datetext); } else { $formattedactivityname = format_string($activity->name, true, array('context' => $context)); print '<th scope="col" class="'.$activity->datepassedclass.'">'. '<a href="'.$CFG->wwwroot.'/mod/'.$activity->modname. '/view.php?id='.$activity->id.'" title="' . $formattedactivityname . '">'. '<img src="'.$OUTPUT->pix_url('icon', $activity->modname).'" alt="'. get_string('modulename',$activity->modname).'" /> <span class="completion-activityname">'. $formattedactivityname.'</span></a>'; if ($activity->completionexpected) { print '<div class="completion-expected"><span>'.$datetext.'</span></div>'; } print '</th>';
protected function print_category_info($category) { $formatoptions = new stdClass(); $formatoptions->noclean = true; $strcategory = get_string('category', 'quiz'); echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">' . $strcategory; echo ': <span class="categorynamefield">'; echo shorten_text(strip_tags(format_string($category->name)), 60); echo '</span></div><div class="categoryinfofieldcontainer">' . '<span class="categoryinfofield">'; echo shorten_text(strip_tags(format_text($category->info, $category->infoformat, $formatoptions, $this->course->id)), 200); echo '</span></div></div>'; }
function readquestion($qrec) { $type = trim($qrec['@']['type']); $question = $this->defaultquestion(); if (array_key_exists($type, $this->qtypes)) { $question->qtype = $this->qtypes[$type]; } else { $question->qtype = null; } $question->single = 1; // Only one answer is allowed $htmltext = $this->unxmlise($qrec['#']['text'][0]['#']); $question->questiontext = $htmltext; $question->name = shorten_text( $question->questiontext, 250 ); switch ($question->qtype) { case MULTICHOICE: $question = $this->parse_mc($qrec['#'], $question); break; case MATCH: $groupname = trim($qrec['@']['group']); $question = $this->parse_ma($qrec['#'], $groupname); break; case TRUEFALSE: $question = $this->parse_tf_yn($qrec['#'], $question); break; case SHORTANSWER: $question = $this->parse_co($qrec['#'], $question); break; case ESSAY: $question = $this->parse_sa($qrec['#'], $question); break; case NUMERICAL: $question = $this->parse_nr($qrec['#'], $question); break; break; default: print("<p>Question type ".$type." import not supported for ".$question->questiontext."<p>"); $question = NULL; } // end switch ($question->qtype) return $question; }
$trackedlink = $stryes; } else { if ($forum->trackingtype === FORUM_TRACKING_OFF || $USER->trackforums == 0) { $trackedlink = '-'; } else { $aurl = new moodle_url('/mod/forum/settracking.php', array('id' => $forum->id)); if (!isset($untracked[$forum->id])) { $trackedlink = $OUTPUT->single_button($aurl, $stryes, 'post', array('title' => $strnotrackforum)); } else { $trackedlink = $OUTPUT->single_button($aurl, $strno, 'post', array('title' => $strtrackforum)); } } } } } $forum->intro = shorten_text(format_module_intro('forum', $forum, $cm->id), $CFG->forum_shortpost); if ($cm->sectionnum != $currentsection) { $printsection = get_section_name($course, $cm->sectionnum); if ($currentsection) { $learningtable->data[] = 'hr'; } $currentsection = $cm->sectionnum; } else { $printsection = ''; } $forumname = format_string($forum->name, true); if ($cm->visible) { $style = ''; } else { $style = 'class="dimmed"'; }
data_print_header($course, $cm, $data, 'fields'); if (!$DB->record_exists('data_fields', array('dataid' => $data->id))) { echo $OUTPUT->notification(get_string('nofieldindatabase', 'data')); // nothing in database echo $OUTPUT->notification(get_string('pleaseaddsome', 'data', 'preset.php?id=' . $cm->id)); // link to presets } else { //else print quiz style list of fields $table = new html_table(); $table->head = array(get_string('fieldname', 'data'), get_string('type', 'data'), get_string('fielddescription', 'data'), get_string('action', 'data')); $table->align = array('left', 'left', 'left', 'center'); $table->wrap = array(false, false, false, false); if ($fff = $DB->get_records('data_fields', array('dataid' => $data->id), 'id')) { foreach ($fff as $ff) { $field = data_get_field($ff, $data); $table->data[] = array('<a href="field.php?mode=display&d=' . $data->id . '&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . $field->field->name . '</a>', $field->image() . ' ' . get_string($field->type, 'data'), shorten_text($field->field->description, 30), '<a href="field.php?d=' . $data->id . '&mode=display&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>' . ' ' . '<a href="field.php?d=' . $data->id . '&mode=delete&fid=' . $field->field->id . '&sesskey=' . sesskey() . '">' . '<img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>'); } } echo html_writer::table($table); } echo '<div class="fieldadd">'; echo '<label for="fieldform_jump">' . get_string('newfield', 'data') . '</label>'; $popupurl = $CFG->wwwroot . '/mod/data/field.php?d=' . $data->id . '&mode=new&sesskey=' . sesskey(); echo $OUTPUT->single_select(new moodle_url($popupurl), 'newtype', $menufield, null, array('' => 'choosedots'), 'fieldform'); echo $OUTPUT->help_icon('newfield', 'data'); echo '</div>'; echo '<div class="sortdefault">'; echo '<form id="sortdefault" action="' . $CFG->wwwroot . '/mod/data/field.php" method="get">'; echo '<div>'; echo '<input type="hidden" name="d" value="' . $data->id . '" />'; echo '<input type="hidden" name="mode" value="sort" />';
function response_summary($question, $state, $length = 80) { $responses = $this->get_actual_response($question, $state); $response = reset($responses); return shorten_text($response, $length); }
if ($unread > 0) { $unreadlink = '<span class="unread"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a>'; $unreadlink .= '<a title="' . $strmarkallread . '" href="markposts.php?f=' . $forum->id . '&mark=read"><img src="' . $CFG->pixpath . '/t/clear.gif" alt="' . $strmarkallread . '" /></a></span>'; } else { $unreadlink = '<span class="read"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a></span>'; } if ($forum->trackingtype == FORUM_TRACKING_OPTIONAL) { $trackedlink = print_single_button($CFG->wwwroot . '/mod/forum/settracking.php?id=' . $forum->id, '', $stryes, 'post', '_self', true, $strnotrackforum); } } else { $unreadlink = '-'; $trackedlink = print_single_button($CFG->wwwroot . '/mod/forum/settracking.php?id=' . $forum->id, '', $strno, 'post', '_self', true, $strtrackforum); } } $introoptions->para = false; $forum->intro = shorten_text(trim(format_text($forum->intro, FORMAT_HTML, $introoptions)), $CFG->forum_shortpost); if ($forum->section != $currentsection) { $printsection = $forum->section; if ($currentsection) { $learningtable->data[] = 'hr'; } $currentsection = $forum->section; } else { $printsection = ""; } $forumname = format_string($forum->name, true); if ($cantaccessagroup && $groupmode == SEPARATEGROUPS) { $forumlink = $forumname; $discussionlink = $count; } else { if ($forum->visible) {