/** * course_report * * @param mixed $indicators * @param mixed $data * @access public * @return void */ public function course_report($indicators, $data) { global $DB, $COURSE; if (empty($data)) { return ''; } $table = new flexible_table('engagement-course-report'); $table->define_baseurl(new moodle_url('/report/engagement/index.php', array('id' => $COURSE->id))); $headers = array(); $columns = array(); $headers[] = get_string('username'); $columns[] = 'username'; foreach ($indicators as $indicator) { $headers[] = get_string('pluginname', "engagementindicator_{$indicator}"); $columns[] = "indicator_{$indicator}"; } $headers[] = get_string('total'); $columns[] = 'total'; $table->define_headers($headers); $table->define_columns($columns); $table->sortable(true, 'total', SORT_DESC); $table->no_sorting('username'); $table->column_class('username', 'student'); foreach ($indicators as $indicator) { $table->column_class("indicator_{$indicator}", 'indicator'); } $table->column_class('total', 'total'); $table->set_attribute('id', 'engagement-course-report'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); $table->setup(); foreach ($data as $user => $ind_data) { $row = array(); $displayname = fullname($DB->get_record('user', array('id' => $user))); $url = new moodle_url('/course/report/engagement/index.php', array('id' => $COURSE->id, 'userid' => $user)); $row[] = html_writer::link($url, $displayname); $total = 0; $total_raw = 0; foreach ($indicators as $indicator) { if (isset($ind_data["indicator_{$indicator}"]['raw'])) { $ind_value = $ind_data["indicator_{$indicator}"]['raw']; $weight = $ind_data["indicator_{$indicator}"]['weight']; } else { $ind_value = 0; $weight = 0; } $weighted_value = sprintf("%.0f%%", $ind_value * $weight * 100); $raw_value = sprintf("%.0f%%", 100 * $ind_value); $row[] = $weighted_value . " ({$raw_value})"; $total += $ind_value * $weight; $total_raw += $ind_value; } $row[] = sprintf("%.0f%%", $total * 100); $table->add_data($row); } $html = $this->output->notification(get_string('reportdescription', 'coursereport_engagement')); ob_start(); $table->finish_output(); $html .= ob_get_clean(); return $html; }
protected function run_table_test($columns, $headers, $sortable, $collapsible, $suppress, $nosorting, $data, $pagesize) { $table = new flexible_table('tablelib_test'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl('/invalid.php'); $table->sortable($sortable); $table->collapsible($collapsible); foreach ($suppress as $column) { $table->column_suppress($column); } foreach ($nosorting as $column) { $table->no_sorting($column); } $table->setup(); $table->pagesize($pagesize, count($data)); foreach ($data as $row) { $table->add_data_keyed($row); } $table->finish_output(); }
function display($quiz, $cm, $course) { /// This function just displays the report global $CFG, $SESSION, $db, $QTYPES; $strnoquiz = get_string('noquiz', 'quiz'); $strnoattempts = get_string('noattempts', 'quiz'); /// Only print headers if not asked to download data $download = optional_param('download', NULL); if (!$download) { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode = "analysis"); } /// Construct the table for this particular report if (!$quiz->questions) { print_heading($strnoattempts); return true; } /// Check to see if groups are being used in this quiz if ($groupmode = groupmode($course, $cm)) { // Groups are being used if (!$download) { $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=analysis"); } else { $currentgroup = get_and_set_current_group($course, $groupmode); } } else { $currentgroup = get_and_set_current_group($course, $groupmode); } // set Table and Analysis stats options if (!isset($SESSION->quiz_analysis_table)) { $SESSION->quiz_analysis_table = array('attemptselection' => 0, 'lowmarklimit' => 0, 'pagesize' => 10); } foreach ($SESSION->quiz_analysis_table as $option => $value) { $urlparam = optional_param($option, NULL); if ($urlparam === NULL) { ${$option} = $value; } else { ${$option} = $SESSION->quiz_analysis_table[$option] = $urlparam; } } $scorelimit = $quiz->sumgrades * $lowmarklimit / 100; // ULPGC ecastro DEBUG this is here to allow for different SQL to select attempts switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $limit = ''; $group = ''; break; case QUIZ_HIGHESTATTEMPT: $limit = ', max(qa.sumgrades) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_FIRSTATTEMPT: $limit = ', min(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; case QUIZ_LASTATTEMPT: $limit = ', max(qa.timemodified) '; $group = ' GROUP BY qa.userid '; break; } if ($attemptselection != QUIZ_ALLATTEMPTS) { $sql = 'SELECT qa.userid ' . $limit . 'FROM ' . $CFG->prefix . 'user u LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON u.id = qa.userid ' . 'WHERE qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 ' . $group; $usermax = get_records_sql_menu($sql); } $groupmembers = ''; $groupwhere = ''; //Add this to the SQL to show only group users if ($currentgroup) { $groupmembers = ', ' . groups_members_from_sql(); $groupwhere = ' AND ' . groups_members_where_sql($currentgroup, 'u.id'); } $sql = 'SELECT qa.* FROM ' . $CFG->prefix . 'quiz_attempts qa, ' . $CFG->prefix . 'user u ' . $groupmembers . 'WHERE u.id = qa.userid AND qa.quiz = ' . $quiz->id . ' AND qa.preview = 0 AND ( qa.sumgrades >= ' . $scorelimit . ' ) ' . $groupwhere; // ^^^^^^ es posible seleccionar aqu TODOS los quizzes, como quiere Jussi, // pero habra que llevar la cuenta ed cada quiz para restaura las preguntas (quizquestions, states) /// Fetch the attempts $attempts = get_records_sql($sql); if (empty($attempts)) { print_heading(get_string('nothingtodisplay')); $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; } /// Here we rewiew all attempts and record data to construct the table $questions = array(); $statstable = array(); $questionarray = array(); foreach ($attempts as $attempt) { $questionarray[] = quiz_questions_in_quiz($attempt->layout); } $questionlist = quiz_questions_in_quiz(implode(",", $questionarray)); $questionarray = array_unique(explode(",", $questionlist)); $questionlist = implode(",", $questionarray); unset($questionarray); foreach ($attempts as $attempt) { switch ($attemptselection) { case QUIZ_ALLATTEMPTS: $userscore = 0; // can be anything, not used break; case QUIZ_HIGHESTATTEMPT: $userscore = $attempt->sumgrades; break; case QUIZ_FIRSTATTEMPT: $userscore = $attempt->timemodified; break; case QUIZ_LASTATTEMPT: $userscore = $attempt->timemodified; break; } if ($attemptselection == QUIZ_ALLATTEMPTS || $userscore == $usermax[$attempt->userid]) { $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance" . " FROM {$CFG->prefix}question q," . " {$CFG->prefix}quiz_question_instances i" . " WHERE i.quiz = '{$quiz->id}' AND q.id = i.question" . " AND q.id IN ({$questionlist})"; if (!($quizquestions = get_records_sql($sql))) { error('No questions found'); } // Load the question type specific information if (!get_question_options($quizquestions)) { error('Could not load question options'); } // Restore the question sessions to their most recent states // creating new sessions where required if (!($states = get_question_states($quizquestions, $quiz, $attempt))) { error('Could not restore question sessions'); } $numbers = explode(',', $questionlist); $statsrow = array(); foreach ($numbers as $i) { if (!isset($quizquestions[$i]) or !isset($states[$i])) { continue; } $qtype = $quizquestions[$i]->qtype == 'random' ? $states[$i]->options->question->qtype : $quizquestions[$i]->qtype; $q = get_question_responses($quizquestions[$i], $states[$i]); if (empty($q)) { continue; } $qid = $q->id; if (!isset($questions[$qid])) { $questions[$qid]['id'] = $qid; $questions[$qid]['qname'] = $quizquestions[$i]->name; foreach ($q->responses as $answer => $r) { $r->count = 0; $questions[$qid]['responses'][$answer] = $r->answer; $questions[$qid]['rcounts'][$answer] = 0; $questions[$qid]['credits'][$answer] = $r->credit; $statsrow[$qid] = 0; } } $responses = get_question_actual_response($quizquestions[$i], $states[$i]); foreach ($responses as $resp) { if ($resp) { if ($key = array_search($resp, $questions[$qid]['responses'])) { $questions[$qid]['rcounts'][$key]++; } else { $test = new stdClass(); $test->responses = $QTYPES[$quizquestions[$i]->qtype]->get_correct_responses($quizquestions[$i], $states[$i]); if ($key = $QTYPES[$quizquestions[$i]->qtype]->check_response($quizquestions[$i], $states[$i], $test)) { $questions[$qid]['rcounts'][$key]++; } else { $questions[$qid]['responses'][] = $resp; $questions[$qid]['rcounts'][] = 1; $questions[$qid]['credits'][] = 0; } } } } $statsrow[$qid] = get_question_fraction_grade($quizquestions[$i], $states[$i]); } $attemptscores[$attempt->id] = $attempt->sumgrades; $statstable[$attempt->id] = $statsrow; } } // Statistics Data table built unset($attempts); unset($quizquestions); unset($states); // now calculate statistics and set the values in the $questions array $top = max($attemptscores); $bottom = min($attemptscores); $gap = ($top - $bottom) / 3; $top -= $gap; $bottom += $gap; foreach ($questions as $qid => $q) { $questions[$qid] = $this->report_question_stats($q, $attemptscores, $statstable, $top, $bottom); } unset($attemptscores); unset($statstable); /// Now check if asked download of data if ($download = optional_param('download', NULL)) { $filename = clean_filename("{$course->shortname} " . format_string($quiz->name, true)); switch ($download) { case "Excel": $this->Export_Excel($questions, $filename); break; case "ODS": $this->Export_ODS($questions, $filename); break; case "CSV": $this->Export_CSV($questions, $filename); break; } } /// Construct the table for this particular report $tablecolumns = array('id', 'qname', 'responses', 'credits', 'rcounts', 'rpercent', 'facility', 'qsd', 'disc_index', 'disc_coeff'); $tableheaders = array(get_string('qidtitle', 'quiz_analysis'), get_string('qtexttitle', 'quiz_analysis'), get_string('responsestitle', 'quiz_analysis'), get_string('rfractiontitle', 'quiz_analysis'), get_string('rcounttitle', 'quiz_analysis'), get_string('rpercenttitle', 'quiz_analysis'), get_string('facilitytitle', 'quiz_analysis'), get_string('stddevtitle', 'quiz_analysis'), get_string('dicsindextitle', 'quiz_analysis'), get_string('disccoefftitle', 'quiz_analysis')); $table = new flexible_table('mod-quiz-report-itemanalysis'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id . '&mode=analysis'); $table->sortable(true); $table->no_sorting('rpercent'); $table->collapsible(true); $table->initialbars(false); $table->column_class('id', 'numcol'); $table->column_class('credits', 'numcol'); $table->column_class('rcounts', 'numcol'); $table->column_class('rpercent', 'numcol'); $table->column_class('facility', 'numcol'); $table->column_class('qsd', 'numcol'); $table->column_class('disc_index', 'numcol'); $table->column_class('disc_coeff', 'numcol'); $table->column_suppress('id'); $table->column_suppress('qname'); $table->column_suppress('facility'); $table->column_suppress('qsd'); $table->column_suppress('disc_index'); $table->column_suppress('disc_coeff'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'itemanalysis'); $table->set_attribute('class', 'generaltable generalbox'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); $tablesort = $table->get_sql_sort(); $sorts = explode(",", trim($tablesort)); if ($tablesort and is_array($sorts)) { $sortindex = array(); $sortorder = array(); foreach ($sorts as $sort) { $data = explode(" ", trim($sort)); $sortindex[] = trim($data[0]); $s = trim($data[1]); if ($s == "ASC") { $sortorder[] = SORT_ASC; } else { $sortorder[] = SORT_DESC; } } if (count($sortindex) > 0) { $sortindex[] = "id"; $sortorder[] = SORT_ASC; foreach ($questions as $qid => $row) { $index1[$qid] = $row[$sortindex[0]]; $index2[$qid] = $row[$sortindex[1]]; } array_multisort($index1, $sortorder[0], $index2, $sortorder[1], $questions); } } $format_options = new stdClass(); $format_options->para = false; $format_options->noclean = true; $format_options->newlines = false; // Now it is time to page the data, simply slice the keys in the array if (!isset($pagesize) || (int) $pagesize < 1) { $pagesize = 10; } $table->pagesize($pagesize, count($questions)); $start = $table->get_page_start(); $pagequestions = array_slice(array_keys($questions), $start, $pagesize); foreach ($pagequestions as $qnum) { $q = $questions[$qnum]; $qid = $q['id']; $question = get_record('question', 'id', $qid); if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $course->id))) { $qnumber = " (" . link_to_popup_window('/question/question.php?id=' . $qid, '&cmid=' . $cm->id . 'editquestion', $qid, 450, 550, get_string('edit'), 'none', true) . ") "; } else { $qnumber = $qid; } $qname = '<div class="qname">' . format_text($question->name . " : ", $question->questiontextformat, $format_options, $quiz->course) . '</div>'; $qicon = print_question_icon($question, true); $qreview = quiz_question_preview_button($quiz, $question); $qtext = format_text($question->questiontext, $question->questiontextformat, $format_options, $quiz->course); $qquestion = $qname . "\n" . $qtext . "\n"; $responses = array(); foreach ($q['responses'] as $aid => $resp) { $response = new stdClass(); if ($q['credits'][$aid] <= 0) { $qclass = 'uncorrect'; } elseif ($q['credits'][$aid] == 1) { $qclass = 'correct'; } else { $qclass = 'partialcorrect'; } $response->credit = '<span class="' . $qclass . '">(' . format_float($q['credits'][$aid], 2) . ') </span>'; $response->text = '<span class="' . $qclass . '">' . format_text($resp, FORMAT_MOODLE, $format_options, $quiz->course) . ' </span>'; $count = $q['rcounts'][$aid] . '/' . $q['count']; $response->rcount = $count; $response->rpercent = '(' . format_float($q['rcounts'][$aid] / $q['count'] * 100, 0) . '%)'; $responses[] = $response; } $facility = format_float($q['facility'] * 100, 0) . "%"; $qsd = format_float($q['qsd'], 3); $di = format_float($q['disc_index'], 2); $dc = format_float($q['disc_coeff'], 2); $response = array_shift($responses); $table->add_data(array($qnumber . "\n<br />" . $qicon . "\n " . $qreview, $qquestion, $response->text, $response->credit, $response->rcount, $response->rpercent, $facility, $qsd, $di, $dc)); foreach ($responses as $response) { $table->add_data(array('', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '')); } } print_heading_with_help(get_string("analysistitle", "quiz_analysis"), "itemanalysis", "quiz"); echo '<div id="tablecontainer">'; $table->print_html(); echo '</div>'; $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; }
/** * 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); }
/** * 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(); }
$orderby = " ORDER BY t.id"; } } } } if (!empty($orderby) && ($dir == 'asc' || $dir == 'desc')) { $orderby .= " " . $dir; } } $count = $DB->count_records_sql($sqlcount); $unplagfiles = $DB->get_records_sql($sqlallfiles . $orderby, null, $page * $limit, $limit); $table->define_columns(array('id', 'name', 'module', 'identifier', 'status', 'attempts', 'action')); $table->define_headers(array(get_string('id', 'plagiarism_unplag'), get_string('user'), get_string('module', 'plagiarism_unplag'), get_string('identifier', 'plagiarism_unplag'), get_string('status', 'plagiarism_unplag'), get_string('attempts', 'plagiarism_unplag'), '')); $table->define_baseurl('unplag_debug.php'); $table->sortable(true); $table->no_sorting('file', 'action'); $table->collapsible(true); $table->set_attribute('cellspacing', '0'); $table->set_attribute('class', 'generaltable generalbox'); $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); $table->setup(); $fs = get_file_storage(); foreach ($unplagfiles as $tf) { $modulecontext = context_module::instance($tf->cm); $coursemodule = get_coursemodule_from_id($tf->moduletype, $tf->cm); $user = "******" . $CFG->wwwroot . "/user/profile.php?id=" . $tf->userid . "'>" . fullname($tf) . "</a>"; if ($tf->statuscode == UNPLAG_STATUSCODE_ACCEPTED) { // Sanity Check. $reset = '<a href="unplag_debug.php?reset=2&id=' . $tf->id . '&sesskey=' . sesskey() . '">' . get_string('getscore', 'plagiarism_unplag') . '</a> | '; } else { $reset = '<a href="unplag_debug.php?reset=1&id=' . $tf->id . '&sesskey=' . sesskey() . '">' . get_string('resubmit', 'plagiarism_unplag') . '</a> | ';
$columns[] = 'select'; // Define flexible table (can be sorted in different ways). $showpages = new flexible_table('emarking-view-' . $cm->id); $showpages->set_attribute('id', 'emarking-main'); $showpages->define_headers($headers); $showpages->define_columns($columns); $showpages->define_baseurl($urlemarking); $showpages->column_class('actions', 'actions'); $showpages->column_class('lastname', 'lastname'); if ($emarking->type == EMARKING_TYPE_MARKER_TRAINING || $emarking->type == EMARKING_TYPE_PEER_REVIEW && $issupervisor) { $showpages->column_class('marker', 'lastname'); } $defaulttsort = $emarking->anonymous < 2 ? null : 'lastname'; $showpages->sortable(true, $defaulttsort, SORT_ASC); if ($emarking->anonymous < 2) { $showpages->no_sorting('lastname'); } $showpages->no_sorting('comment'); $showpages->no_sorting('actions'); $showpages->no_sorting('select'); $showpages->pageable(true); $showpages->pagesize($perpage, $totalstudents); $showpages->setup(); // Decide on sorting depending on URL parameters and flexible table configuration. $orderby = $emarking->anonymous < 2 ? 'ORDER BY sort ASC' : 'ORDER BY u.lastname ASC'; if ($showpages->get_sql_sort()) { $orderby = 'ORDER BY ' . $showpages->get_sql_sort(); $tsort = $showpages->get_sql_sort(); } // Get submissions with extra info to show. $sqldrafts .= $orderby;
/** * 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')); } }
$bcoursename = $result->bcoursename; } else { list($bid, $boublogid, $bcontextid, $boublogname, $bcoursename) = oublog_import_getbloginfo($bid); } echo html_writer::start_tag('p', array('class' => 'oublog_import_step1_from')); echo get_string('import_step1_from', 'oublog') . '<br />' . html_writer::tag('span', $boublogname); echo html_writer::end_tag('p'); // Setup table early so sort can be determined (needs setup to be called first). $table = new flexible_table($cm->id * $bid); $url = new moodle_url('/mod/oublog/import.php', $params + $stepinfo); $table->define_baseurl($url); $table->define_columns(array('title', 'timeposted', 'tags', 'include')); $table->column_style('include', 'text-align', 'center'); $table->sortable(true, 'timeposted', SORT_DESC); $table->maxsortkeys = 1; $table->no_sorting('tags'); $table->no_sorting('include'); $table->setup(); $sort = flexible_table::get_sort_for_table($cm->id * $bid); if (empty($sort)) { $sort = 'timeposted DESC'; } if ($tags = optional_param('tags', null, PARAM_SEQUENCE)) { // Filter by joining tag instances. $stepinfo['tags'] = $tags; } $perpage = 100; // Must match value in oublog_import_getallposts. $page = optional_param('page', 0, PARAM_INT); $stepinfo['page'] = $page; $preselected = optional_param('preselected', '', PARAM_SEQUENCE);
public function display_allfilesform() { global $CFG, $OUTPUT, $DB, $USER; $cm = $this->coursemodule; $context = $this->context; $course = $this->course; $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('publication_perpage', $perpage); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('publication_perpage', 10); $quickgrade = get_user_preferences('publication_quickgrade', 0); $filter = get_user_preferences('publicationfilter', 0); $page = optional_param('page', 0, PARAM_INT); $formattrs = array(); $formattrs['action'] = new moodle_url('/mod/publication/view.php'); $formattrs['id'] = 'fastg'; $formattrs['method'] = 'post'; $formattrs['class'] = 'mform'; $html = ''; $html .= html_writer::start_tag('form', $formattrs); $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $this->get_coursemodule()->id)); $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $page)); $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); echo $html; echo html_writer::start_tag('div', array('id' => 'id_allfiles', 'class' => 'clearfix', 'aria-live' => 'polite')); $title = has_capability('mod/publication:approve', $context) ? get_string('allfiles', 'publication') : get_string('publicfiles', 'publication'); echo html_writer::tag('div', $title, array('class' => 'legend')); echo html_writer::start_div('fcontainer clearfix'); // 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); echo groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/publication/view.php?id=' . $cm->id, true); $html = ''; // Get all ppl that are allowed to submit assignments. list($esql, $params) = get_enrolled_sql($context, 'mod/publication:view', $currentgroup); $showall = false; if (has_capability('mod/publication:approve', $context) || has_capability('mod/publication:grantextension', $context)) { $showall = true; } if ($showall) { $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 { $sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'LEFT JOIN {publication_file} files ON (u.id = files.userid) ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . 'AND files.publication = ' . $this->get_instance()->id . ' '; if ($this->get_instance()->mode == PUBLICATION_MODE_UPLOAD) { // Node upload. if ($this->get_instance()->obtainteacherapproval) { // Need teacher approval. $where = 'files.teacherapproval = 1'; } else { // No need for teacher approval. // Teacher only hasnt rejected. $where = '(files.teacherapproval = 1 OR files.teacherapproval IS NULL)'; } } else { // Mode import. if (!$this->get_instance()->obtainstudentapproval) { // No need to ask student and teacher has approved. $where = 'files.teacherapproval = 1'; } else { // Student and teacher have approved. $where = 'files.teacherapproval = 1 AND files.studentapproval = 1'; } } $sql .= 'AND ' . $where . ' '; $sql .= 'GROUP BY 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)); } } $selectallnone = html_writer::checkbox('selectallnone', false, false, '', array('id' => 'selectallnone', 'onClick' => 'toggle_userselection()')); $tablecolumns = array('selection', 'fullname'); $tableheaders = array($selectallnone, get_string('fullnameuser')); $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array(); foreach ($useridentity as $cur) { if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) { $tablecolumns[] = $cur; $tableheaders[] = $cur == 'phone1' ? get_string('phone') : get_string($cur); } } $tableheaders[] = get_string('lastmodified'); $tablecolumns[] = 'timemodified'; if (has_capability('mod/publication:approve', $context)) { // Not necessary in upload mode without studentapproval. if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) { $tablecolumns[] = 'studentapproval'; $tableheaders[] = get_string('studentapproval', 'publication') . ' ' . $OUTPUT->help_icon('studentapproval', 'publication'); } $tablecolumns[] = 'teacherapproval'; if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) { $tableheaders[] = get_string('obtainstudentapproval', 'publication'); } else { $tableheaders[] = get_string('teacherapproval', 'publication'); } $tablecolumns[] = 'visibleforstudents'; $tableheaders[] = get_string('visibleforstudents', 'publication'); } require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-publication-allfiles'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/publication/view.php?id=' . $cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); // Sorted by lastname by default. $table->collapsible(false); $table->initialbars(true); $table->column_class('fullname', 'fullname'); $table->column_class('timemodified', 'timemodified'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'publications'); $table->set_attribute('width', '100%'); $table->no_sorting('studentapproval'); $table->no_sorting('selection'); $table->no_sorting('teacherapproval'); $table->no_sorting('visibleforstudents'); // 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'); $useridentityfields = $CFG->showuseridentity != '' ? 'u.' . str_replace(', ', ', u.', $CFG->showuseridentity) . ', ' : ''; $totalfiles = 0; if (!empty($users)) { $select = 'SELECT ' . $ufields . ', ' . $useridentityfields . ' username, COUNT(*) filecount, SUM(files.studentapproval) as status, MAX(files.timecreated) timemodified '; $sql = 'FROM {user} u ' . 'LEFT JOIN {publication_file} files ON u.id = files.userid AND files.publication = ' . $this->get_instance()->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(', ', $users) . ') ' . 'GROUP BY ' . $ufields . ', ' . $useridentityfields . ' username '; $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'); if ($ausers !== false) { $endposition = $offset + $perpage; $currentposition = 0; $valid = $OUTPUT->pix_icon('i/valid', get_string('student_approved', 'publication')); $questionmark = $OUTPUT->pix_icon('questionmark', get_string('student_pending', 'publication'), 'mod_publication'); $invalid = $OUTPUT->pix_icon('i/invalid', get_string('student_rejected', 'publication')); $visibleforstundetsyes = $OUTPUT->pix_icon('i/valid', get_string('visibleforstudents_yes', 'publication')); $visibleforstundetsno = $OUTPUT->pix_icon('i/invalid', get_string('visibleforstudents_no', 'publication')); $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context); foreach ($ausers as $auser) { if ($currentposition >= $offset && $currentposition < $endposition) { // Calculate user status. $selecteduser = html_writer::checkbox('selectedeuser[' . $auser->id . ']', 'selected', false, null, array('class' => 'userselection')); $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array(); foreach ($useridentity as $cur) { if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) { if (!empty($auser->{$cur})) { ${$cur} = html_writer::tag('div', $auser->{$cur}, array('id' => 'u' . $cur . $auser->id)); } else { ${$cur} = html_writer::tag('div', '-', array('id' => 'u' . $cur . $auser->id)); } } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, $viewfullnames) . '</a>'; $extension = $this->user_extensionduedate($auser->id); if ($extension) { if (has_capability('mod/publication:grantextension', $context) || has_capability('mod/publication:approve', $context)) { $userlink .= '<br/>' . get_string('extensionto', 'publication') . ': ' . userdate($extension); } } $row = array($selecteduser, $userlink); $useridentity = $CFG->showuseridentity != '' ? explode(',', $CFG->showuseridentity) : array(); foreach ($useridentity as $cur) { if (!(get_config('publication', 'hideidnumberfromstudents') && $cur == "idnumber" && !has_capability('mod/publication:approve', $context)) && !($cur != "idnumber" && !has_capability('mod/publication:approve', $context))) { if (true) { $row[] = ${$cur}; } else { $row[] = ""; } } } $filearea = 'attachment'; $sid = $auser->id; $fs = get_file_storage(); $files = $fs->get_area_files($this->get_context()->id, 'mod_publication', $filearea, $sid, 'timemodified', false); $filetable = new html_table(); $filetable->attributes = array('class' => 'filetable'); $statustable = new html_table(); $statustable->attributes = array('class' => 'statustable'); $permissiontable = new html_table(); $permissiontable->attributes = array('class' => 'permissionstable'); $visibleforuserstable = new html_table(); $visibleforuserstable->attributes = array('class' => 'statustable'); $conditions = array(); $conditions['publication'] = $this->get_instance()->id; $conditions['userid'] = $auser->id; foreach ($files as $file) { $conditions['fileid'] = $file->get_id(); $filepermissions = $DB->get_record('publication_file', $conditions); $showfile = false; if (has_capability('mod/publication:approve', $context)) { $showfile = true; } else { if ($this->has_filepermission($file->get_id())) { $showfile = true; } } if ($this->has_filepermission($file->get_id())) { $visibleforuserstable->data[] = array($visibleforstundetsyes); } else { $visibleforuserstable->data[] = array($visibleforstundetsno); } if ($showfile) { $filerow = array(); $filerow[] = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file)); $url = new moodle_url('/mod/publication/view.php', array('id' => $cm->id, 'download' => $file->get_id())); $filerow[] = html_writer::link($url, $file->get_filename()); if (has_capability('mod/publication:approve', $context)) { $checked = $filepermissions->teacherapproval; if (is_null($checked)) { $checked = ""; } else { $checked = $checked + 1; } $permissionrow = array(); $options = array(); $options['2'] = get_string('yes'); $options['1'] = get_string('no'); $permissionrow[] = html_writer::select($options, 'files[' . $file->get_id() . ']', $checked); $statusrow = array(); if (is_null($filepermissions->studentapproval)) { $statusrow[] = $questionmark; } else { if ($filepermissions->studentapproval) { $statusrow[] = $valid; } else { $statusrow[] = $invalid; } } $statustable->data[] = $statusrow; $permissiontable->data[] = $permissionrow; } $filetable->data[] = $filerow; $totalfiles++; } } $lastmodified = ""; if (count($filetable->data) > 0) { $lastmodified = html_writer::table($filetable); $lastmodified .= html_writer::span(userdate($auser->timemodified), "timemodified"); } else { $lastmodified = get_string('nofiles', 'publication'); } $row[] = $lastmodified; if (has_capability('mod/publication:approve', $context)) { // Not necessary in upload mode without studentapproval. if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) { if (count($statustable->data) > 0) { $status = html_writer::table($statustable); } else { $status = ''; } $row[] = $status; } if (count($permissiontable->data) > 0) { $permissions = html_writer::table($permissiontable); } else { $permissions = ''; } $row[] = $permissions; $row[] = html_writer::table($visibleforuserstable); } $table->add_data($row); } $currentposition++; } if (true) { // Always display download option. $html .= html_writer::start_tag('div', array('class' => 'mod-publication-download-link')); $html .= html_writer::link(new moodle_url('/mod/publication/view.php', array('id' => $this->coursemodule->id, 'action' => 'zip')), get_string('downloadall', 'publication')); $html .= html_writer::end_tag('div'); } echo $html; $html = ""; $table->print_html(); // Print the whole table. $options = array(); if (true) { // Always display download option. $options['zipusers'] = get_string('zipusers', 'publication'); } if ($totalfiles > 0) { if (has_capability('mod/publication:approve', $context)) { $options['approveusers'] = get_string('approveusers', 'publication'); $options['rejectusers'] = get_string('rejectusers', 'publication'); if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) { $options['resetstudentapproval'] = get_string('resetstudentapproval', 'publication'); } } } if (has_capability('mod/publication:grantextension', $this->get_context())) { $options['grantextension'] = get_string('grantextension', 'publication'); } if (count($options) > 0) { if (has_capability('mod/publication:approve', $context)) { $html .= html_writer::empty_tag('input', array('type' => 'reset', 'name' => 'resetvisibility', 'value' => get_string('reset', 'publication'), 'class' => 'visibilitysaver')); if ($this->get_instance()->mode == PUBLICATION_MODE_IMPORT && $this->get_instance()->obtainstudentapproval) { $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'savevisibility', 'value' => get_string('saveapproval', 'publication'), 'class' => 'visibilitysaver')); } else { $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'savevisibility', 'value' => get_string('saveteacherapproval', 'publication'), 'class' => 'visibilitysaver')); } } $html .= html_writer::start_div('withselection'); $html .= html_writer::span(get_string('withselected', 'publication')); $html .= html_writer::select($options, 'action'); $html .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'submitgo', 'value' => get_string('go', 'publication'))); $html .= html_writer::end_div(); } } else { $html .= html_writer::tag('div', get_string('nothingtodisplay', 'publication'), array('class' => 'nosubmisson')); } } else { $html .= html_writer::tag('div', get_string('nothingtodisplay', 'publication'), array('class' => 'nosubmisson')); } // Select all/none. $html .= html_writer::start_tag('div', array('class' => 'checkboxcontroller')); $html .= "<script type=\"text/javascript\">\n function toggle_userselection() {\n var checkboxes = document.getElementsByClassName('userselection');\n var sel = document.getElementById('selectallnone');\n\n if (checkboxes.length > 0) {\n checkboxes[0].checked = sel.checked;\n\n for(var i = 1; i < checkboxes.length;i++) {\n checkboxes[i].checked = checkboxes[0].checked;\n }\n }\n }\n </script>"; $html .= html_writer::end_div(); $html .= html_writer::end_div(); $html .= html_writer::end_div(); echo $html; echo html_writer::end_tag('form'); // Mini form for setting user preference. $html = ''; $formaction = new moodle_url('/mod/publication/view.php', array('id' => $this->coursemodule->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', 'publication')); $mform->addElement('text', 'perpage', get_string('entiresperpage', 'publication'), array('size' => 1)); $mform->setDefault('perpage', $perpage); $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); $mform->display(); return $html; }
} //if($mode === MODE_PICTURES) { //$tablecolumns = array('userpic'); //$tableheaders = array('User'); //unset($hiddenfields['lastaccess']); //} $table = new flexible_table('user-index-participants-' . $course->id); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($baseurl->out()); if (!isset($hiddenfields['lastaccess'])) { $table->sortable(true, 'lastaccess', SORT_DESC); } else { $table->sortable(true, 'firstname', SORT_ASC); } $table->no_sorting('roles'); //$table->no_sorting('groups'); //$table->no_sorting('groupings'); $table->no_sorting('select'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'participants'); $table->set_attribute('class', 'generaltable generalbox'); $table->set_control_variables(array(TABLE_VAR_SORT => 'ssort', TABLE_VAR_HIDE => 'shide', TABLE_VAR_SHOW => 'sshow', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage')); $table->setup(); // we are looking for all users with this role assigned in this context or higher $parents = $context->get_parent_context_ids(true); $contextlist = implode(',', $parents); //list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup, true); list($esql, $params) = get_enrolled_sql($context, NULL, NULL, true); $joins = array("FROM {user} u"); $wheres = array();
} /// Get perpage param from database $perpage = get_user_preferences('stampcoll_perpage', STAMPCOLL_USERS_PER_PAGE); $showupdateforms = get_user_preferences('stampcoll_showupdateforms', 1); $tablecolumns = array('picture', 'fullname', 'count', 'comment'); $tableheaders = array('', get_string('fullname'), get_string('numberofstamps', 'stampcoll'), ''); require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-stampcoll-editstamps'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/stampcoll/editstamps.php?id=' . $cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); // default sort - do not use "count" here! if (!$cap_viewotherstamps) { // prevent sorting by stamps count and so guessing the number of them $table->no_sorting('count'); } $table->collapsible(false); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); $table->column_class('count', 'count'); $table->column_class('comment', 'comment'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'stamps'); $table->set_attribute('class', 'stamps'); $table->set_attribute('width', '90%'); $table->set_attribute('align', 'center'); $table->setup();
array_push($tableheaders, get_string('inboxtableheaderphone', 'block_moodletxt')); array_push($tableheaders, get_string('inboxtableheadername', 'block_moodletxt')); } array_push($tablecolumns, 'timereceived'); array_push($tableheaders, get_string('inboxtableheadertime', 'block_moodletxt')); array_push($tablecolumns, 'tags'); array_push($tableheaders, get_string('inboxtableheadertags', 'block_moodletxt')); if (!$table->is_downloading()) { array_push($tablecolumns, 'options'); array_push($tableheaders, get_string('inboxtableheaderoptions', 'block_moodletxt')); } // Finish off table options $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->sortable(true, 'timereceived', SORT_DESC); $table->no_sorting('checkbox'); $table->no_sorting('messagetext'); $table->no_sorting('options'); $table->no_sorting('tags'); $table->column_class('tags', 'tagDrop'); $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); $table->setup(); // Output errors if necessary if (!$table->is_downloading()) { // Drop in page header echo $output->header(); $addTagListItems = ''; $tagCloud = new moodletxt_message_tag_cloud(get_string('headertags', 'block_moodletxt')); $tagCloud->set_attribute('class', 'mdltxt_right'); $tagCloud->set_attribute('style', 'text-align:right;'); $maxCount = 1;
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'); } }
/** * Create a table with properties as passed in params. * * @param string[] $columns * @param string[] $headers * @param bool $sortable * @param bool $collapsible * @param string[] $suppress * @param string[] $nosorting * @return flexible_table */ protected function create_and_setup_table($columns, $headers, $sortable, $collapsible, $suppress, $nosorting) { $table = new flexible_table('tablelib_test'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl('/invalid.php'); $table->sortable($sortable); $table->collapsible($collapsible); foreach ($suppress as $column) { $table->column_suppress($column); } foreach ($nosorting as $column) { $table->no_sorting($column); } $table->setup(); return $table; }
/** * Display the report. */ function display($quiz, $cm, $course) { global $CFG, $db; // Define some strings $strreallydel = addslashes(get_string('deleteattemptcheck', 'quiz')); $strtimeformat = get_string('strftimedatetime'); $strreviewquestion = get_string('reviewresponse', 'quiz'); $context = get_context_instance(CONTEXT_MODULE, $cm->id); // Only print headers if not asked to download data if (!($download = optional_param('download', NULL))) { $this->print_header_and_tabs($cm, $course, $quiz, "overview"); } if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) { //attempts need to be deleted require_capability('mod/quiz:deleteattempts', $context); $attemptids = optional_param('attemptid', array(), PARAM_INT); foreach ($attemptids as $attemptid) { add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id, $attemptid, $cm->id); quiz_delete_attempt($attemptid, $quiz); } //No need for a redirect, any attemptids that do not exist are ignored. //So no problem if the user refreshes and tries to delete the same attempts //twice. } // Work out some display options - whether there is feedback, and whether scores should be shown. $hasfeedback = quiz_has_feedback($quiz->id) && $quiz->grade > 1.0E-7 && $quiz->sumgrades > 1.0E-7; $fakeattempt = new stdClass(); $fakeattempt->preview = false; $fakeattempt->timefinish = $quiz->timeopen; $reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context); $showgrades = $quiz->grade && $quiz->sumgrades && $reviewoptions->scores; $pageoptions = array(); $pageoptions['id'] = $cm->id; $pageoptions['q'] = $quiz->id; $pageoptions['mode'] = 'overview'; /// find out current groups mode $currentgroup = groups_get_activity_group($cm, true); $reporturl = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions); $qmsubselect = quiz_report_qm_filter_select($quiz); $mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz', 'currentgroup')); if ($fromform = $mform->get_data()) { $attemptsmode = $fromform->attemptsmode; if ($qmsubselect) { //control is not on the form if //the grading method is not set //to grade one attempt per user eg. for average attempt grade. $qmfilter = $fromform->qmfilter; } else { $qmfilter = 0; } set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks); set_user_preference('quiz_report_pagesize', $fromform->pagesize); $detailedmarks = $fromform->detailedmarks; $pagesize = $fromform->pagesize; } else { $qmfilter = optional_param('qmfilter', 0, PARAM_INT); $attemptsmode = optional_param('attemptsmode', QUIZ_REPORT_ATTEMPTS_ALL, PARAM_INT); $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1); $pagesize = get_user_preferences('quiz_report_pagesize', 0); } if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup) { $attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH; } if (!$reviewoptions->scores) { $detailedmarks = 0; } if ($pagesize < 1) { $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE; } // 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/quiz:deleteattempts', $context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO; $displayoptions = array(); $displayoptions['attemptsmode'] = $attemptsmode; $displayoptions['qmfilter'] = $qmfilter; $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions + $displayoptions); if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$download) { groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out()); } } // Print information on the number of existing attempts if (!$download) { //do not print notices when downloading if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) { echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>'; } } $nostudents = false; if (!($students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', '', '', false))) { notify(get_string('nostudentsyet')); $nostudents = true; $studentslist = ''; } else { $studentslist = join(',', array_keys($students)); } if (empty($currentgroup)) { // all users who can attempt quizzes $groupstudentslist = ''; $allowedlist = $studentslist; } else { // all users who can attempt quizzes and who are in the currently selected group if (!($groupstudents = get_users_by_capability($context, 'mod/quiz:attempt', '', '', '', '', $currentgroup, '', false))) { notify(get_string('nostudentsingroup')); $nostudents = true; $groupstudents = array(); } $groupstudentslist = join(',', array_keys($groupstudents)); $allowedlist = $groupstudentslist; } if (!$nostudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) { // Print information on the grading method and whether we are displaying // if (!$download) { //do not print notices when downloading if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) { echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>'; } } // Now check if asked download of data if ($download) { $filename = clean_filename("{$course->shortname} " . format_string($quiz->name, true)); } // 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'); if ($CFG->grade_report_showuseridnumber) { $columns[] = 'idnumber'; $headers[] = get_string('idnumber'); } $columns[] = 'timestart'; $headers[] = get_string('startedon', 'quiz'); $columns[] = 'timefinish'; $headers[] = get_string('timecompleted', 'quiz'); $columns[] = 'duration'; $headers[] = get_string('attemptduration', 'quiz'); if ($showgrades) { $columns[] = 'sumgrades'; $headers[] = get_string('grade', 'quiz') . '/' . $quiz->grade; } if ($detailedmarks) { // we want to display marks for all questions $questions = quiz_report_load_questions($quiz); foreach ($questions as $id => $question) { // Ignore questions of zero length $columns[] = 'qsgrade' . $id; $headers[] = '#' . $question->number; } } if ($hasfeedback) { $columns[] = 'feedbacktext'; $headers[] = get_string('feedback', 'quiz'); } if (!$download) { // Set up the table $table = new flexible_table('mod-quiz-report-overview-report'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl($reporturlwithdisplayoptions->out()); $table->sortable(true); $table->collapsible(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_suppress('idnumber'); $table->no_sorting('feedbacktext'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'bold'); $table->column_class('sumgrades', '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('reportoverview', 'quiz'); $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('reportoverview', 'quiz'); $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"; } } } } // Construct the SQL $select = 'SELECT ' . sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')) . ' AS uniqueid, '; if ($qmsubselect) { $select .= "(CASE " . " WHEN {$qmsubselect} THEN 1" . " ELSE 0 " . "END) AS gradedattempt, "; } $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' . 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, ' . 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration '; // This part is the same for all cases - join users and quiz_attempts tables $from = 'FROM ' . $CFG->prefix . 'user u '; $from .= 'LEFT JOIN ' . $CFG->prefix . 'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = ' . $quiz->id; if ($qmsubselect && $qmfilter) { $from .= ' AND ' . $qmsubselect; } switch ($attemptsmode) { case QUIZ_REPORT_ATTEMPTS_ALL: // Show all attempts, including students who are no longer in the course $where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0'; break; case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH: // Show only students with attempts $where = ' WHERE u.id IN (' . $allowedlist . ') AND qa.preview = 0 AND qa.id IS NOT NULL'; break; case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO: // Show only students without attempts $where = ' WHERE u.id IN (' . $allowedlist . ') AND qa.id IS NULL'; break; case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS: // Show all students with or without attempts $where = ' WHERE u.id IN (' . $allowedlist . ') AND (qa.preview = 0 OR qa.preview IS NULL)'; break; } $countsql = 'SELECT COUNT(DISTINCT(' . sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)') . ')) ' . $from . $where; // Add table joins so we can sort by question grade // unfortunately can't join all tables necessary to fetch all grades // to get the state for one question per attempt row we must join two tables // and there is a limit to how many joins you can have in one query. In MySQL it // is 61. This means that when having more than 29 questions the query will fail. // So we join just the tables needed to sort the attempts. if (!$download && ($sort = $table->get_sql_sort())) { if (!$download && $detailedmarks) { $from .= ' '; $sortparts = explode(',', $sort); $matches = array(); foreach ($sortparts as $sortpart) { $sortpart = trim($sortpart); if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)) { $qid = intval($matches[1]); $select .= ", qs{$qid}.grade AS qsgrade{$qid}, qs{$qid}.event AS qsevent{$qid}, qs{$qid}.id AS qsid{$qid}"; $from .= "LEFT JOIN {$CFG->prefix}question_sessions qns{$qid} ON qns{$qid}.attemptid = qa.uniqueid AND qns{$qid}.questionid = {$qid} "; $from .= "LEFT JOIN {$CFG->prefix}question_states qs{$qid} ON qs{$qid}.id = qns{$qid}.newgraded "; } else { $newsort[] = $sortpart; } } $select .= ' '; } } if ($download) { $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 if ($table->get_sql_where()) { $where .= ' AND ' . $table->get_sql_where(); } if (!empty($countsql)) { $totalinitials = count_records_sql($countsql); if ($table->get_sql_where()) { $countsql .= ' AND ' . $table->get_sql_where(); } $total = count_records_sql($countsql); } $table->pagesize($pagesize, $total); } // Fetch the attempts if (!$download) { $attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size()); } else { $attempts = get_records_sql($select . $from . $where . $sort); } // Build table rows if (!$download) { $table->initialbars($totalinitials > 20); } if ($attempts) { if ($detailedmarks) { //get all the attempt ids we want to display on this page //or to export for download. $attemptids = array(); foreach ($attempts as $attempt) { if ($attempt->attemptuniqueid > 0) { $attemptids[] = $attempt->attemptuniqueid; } } $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt'); } foreach ($attempts as $attempt) { // Username columns. $row = array(); if (in_array('checkbox', $columns)) { if ($attempt->attempt) { $row[] = '<input type="checkbox" name="attemptid[]" value="' . $attempt->attempt . '" />'; } else { $row[] = ''; } } if (in_array('picture', $columns)) { $attempt->id = $attempt->userid; $picture = print_user_picture($attempt, $course->id, NULL, false, true); $row[] = $picture; } if (!$download) { $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $attempt->userid . '&course=' . $course->id . '">' . fullname($attempt) . '</a>'; $row[] = $userlink; } else { $row[] = fullname($attempt); } if (in_array('idnumber', $columns)) { $row[] = $attempt->idnumber; } // Timing columns. if ($attempt->attempt) { $startdate = userdate($attempt->timestart, $strtimeformat); if (!$download) { $row[] = '<a href="review.php?q=' . $quiz->id . '&attempt=' . $attempt->attempt . '">' . $startdate . '</a>'; } else { $row[] = $startdate; } if ($attempt->timefinish) { $timefinish = userdate($attempt->timefinish, $strtimeformat); $duration = format_time($attempt->duration); if (!$download) { $row[] = '<a href="review.php?q=' . $quiz->id . '&attempt=' . $attempt->attempt . '">' . $timefinish . '</a>'; } else { $row[] = $timefinish; } $row[] = $duration; } else { $row[] = '-'; $row[] = get_string('unfinished', 'quiz'); } } else { $row[] = '-'; $row[] = '-'; $row[] = '-'; } // Grades columns. if ($showgrades) { if ($attempt->timefinish) { $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); if (!$download) { $gradehtml = '<a href="review.php?q=' . $quiz->id . '&attempt=' . $attempt->attempt . '">' . $grade . '</a>'; if ($qmsubselect && $attempt->gradedattempt) { $gradehtml = '<div class="highlight">' . $gradehtml . '</div>'; } $row[] = $gradehtml; } else { $row[] = $grade; } } else { $row[] = '-'; } } if ($detailedmarks) { if (empty($attempt->attempt)) { foreach ($questions as $question) { $row[] = '-'; } } else { foreach ($questions as $questionid => $question) { $stateforqinattempt = $gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid]; if (question_state_is_graded($stateforqinattempt)) { $grade = quiz_rescale_grade($stateforqinattempt->grade, $quiz); } else { $grade = '--'; } if (!$download) { $grade = $grade . '/' . quiz_rescale_grade($question->grade, $quiz); $row[] = link_to_popup_window('/mod/quiz/reviewquestion.php?state=' . $stateforqinattempt->id . '&number=' . $question->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true); } else { $row[] = $grade; } } } } // Feedback column. if ($hasfeedback) { if ($attempt->timefinish) { $row[] = quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $quiz), $quiz->id); } else { $row[] = '-'; } } 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"; } } } } //end of adding data from attempts data to table / download //now add averages : if (!$download && $attempts) { $averagesql = "SELECT AVG(qg.grade) AS grade " . "FROM {$CFG->prefix}quiz_grades qg " . "WHERE quiz=" . $quiz->id; $table->add_separator(); if ($groupstudentslist) { $groupaveragesql = $averagesql . " AND qg.userid IN ({$groupstudentslist})"; $groupaverage = get_record_sql($groupaveragesql); $groupaveragerow = array('fullname' => get_string('groupavg', 'grades'), 'sumgrades' => round($groupaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($groupaverage->grade, $quiz->id)); if ($detailedmarks && $qmsubselect) { $avggradebyq = quiz_get_average_grade_for_questions($quiz, $groupstudentslist); $groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download); } $table->add_data_keyed($groupaveragerow); } $overallaverage = get_record_sql($averagesql . " AND qg.userid IN ({$studentslist})"); $overallaveragerow = array('fullname' => get_string('overallaverage', 'grades'), 'sumgrades' => round($overallaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($overallaverage->grade, $quiz->id)); if ($detailedmarks && $qmsubselect) { $avggradebyq = quiz_get_average_grade_for_questions($quiz, $studentslist); $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download); } $table->add_data_keyed($overallaveragerow); } if (!$download) { // Start form echo '<div id="tablecontainer">'; echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) . '" onsubmit="return confirm(\'' . $strreallydel . '\');">'; echo '<div style="display: none;">'; echo $reporturlwithdisplayoptions->hidden_params_out(); echo '</div>'; echo '<div>'; // Print table $table->print_html(); // Print "Select all" etc. if (!empty($attempts) && $candelete) { echo '<table id="commands">'; echo '<tr><td>'; echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'quiz') . '</a> / '; echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'quiz') . '</a> '; echo ' '; echo '<input type="submit" value="' . get_string('deleteselected', 'quiz_overview') . '"/>'; echo '</td></tr></table>'; } // Close form echo '</div>'; echo '</form></div>'; if (!empty($attempts)) { echo '<table class="boxaligncenter"><tr>'; echo '<td>'; print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'ODS'), get_string('downloadods')); echo "</td>\n"; echo '<td>'; print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'Excel'), get_string('downloadexcel')); echo "</td>\n"; echo '<td>'; print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'CSV'), get_string('downloadtext')); echo "</td>\n"; echo "<td>"; helpbutton('overviewdownload', get_string('overviewdownload', 'quiz_overview'), 'quiz'); echo "</td>\n"; echo '</tr></table>'; } } } else { if (!$download) { $table->print_html(); } } if ($download == 'Excel' or $download == 'ODS') { $workbook->close(); exit; } else { if ($download == 'CSV') { exit; } } } if (!$download) { // Print display options $mform->set_data($displayoptions + compact('detailedmarks', 'pagesize')); $mform->display(); //should be quicker than a COUNT to test if there is at least one record : if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)) { $imageurl = $CFG->wwwroot . '/mod/quiz/report/overview/overviewgraph.php?id=' . $quiz->id; print_heading(get_string('overviewreportgraph', 'quiz_overview')); echo '<div class="mdl-align"><img src="' . $imageurl . '" alt="' . get_string('overviewreportgraph', 'quiz_overview') . '" /></div>'; } } return true; }
$table = new flexible_table('mod-block-progress-overview'); $table->pagesize($perpage, $numberofusers); $tablecolumns = array('select', 'picture', 'fullname', 'lastonline', 'progressbar', 'progress'); $table->define_columns($tablecolumns); $tableheaders = array('', '', get_string('fullname'), get_string('lastonline', 'block_progress'), get_string('progressbar', 'block_progress'), get_string('progress', 'block_progress')); $table->define_headers($tableheaders); $table->sortable(true); $table->set_attribute('class', 'overviewTable'); $table->column_style_all('padding', '5px'); $table->column_style_all('text-align', 'left'); $table->column_style_all('vertical-align', 'middle'); $table->column_style('select', 'text-align', 'right'); $table->column_style('select', 'padding', '5px 0 5px 5px'); $table->column_style('progressbar', 'width', '200px'); $table->column_style('progress', 'text-align', 'center'); $table->no_sorting('select'); $select = ''; $table->no_sorting('picture'); $table->no_sorting('progressbar'); if ($paged) { $table->no_sorting('progress'); } $table->define_baseurl($PAGE->url); $table->setup(); // Sort the users (except by progress). $sort = $table->get_sql_sort(); $sortbyprogress = strncmp($sort, 'progress', 8) == 0; if (!$sort || $paged && $sortbyprogress) { $sort = 'lastname DESC'; } if (!$sortbyprogress) {
function print_memorybank_report2($instid, $course = false) { global $CFG, $USER; require_once $CFG->libdir . '/tablelib.php'; $tablecolumns = array('lastname', 'last_access', 'average_score', 'number_of_questions'); $tableheaders = array(get_string('name', 'memorybank'), get_string('last_access', 'memorybank'), get_string('average_score', 'memorybank'), get_string('number_of_questions', 'memorybank')); $table = new flexible_table('memorybank_report2'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->sortable(true, 'lastname'); $table->no_sorting('number_of_questions'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('cellpadding', '5'); $table->set_attribute('id', 'memorybank-report'); $table->set_attribute('class', 'boxaligncenter generaltable'); $table->setup(); $sort = $table->get_sql_sort(); $SQL = "\r\n SELECT \r\n {$CFG->prefix}user.id,\r\n {$CFG->prefix}user.firstname,\r\n\t {$CFG->prefix}user.lastname,\r\n\t AVG({$CFG->prefix}memorybank_submissions.grade) AS average_score,\r\n\t MAX({$CFG->prefix}memorybank_submissions.timeanswered) AS last_access\r\n FROM\r\n {$CFG->prefix}user\r\n INNER JOIN {$CFG->prefix}memorybank_schedule ON ({$CFG->prefix}user.id={$CFG->prefix}memorybank_schedule.userid)\r\n LEFT OUTER JOIN {$CFG->prefix}memorybank_submissions ON ({$CFG->prefix}memorybank_schedule.userid={$CFG->prefix}memorybank_submissions.userid) AND ({$CFG->prefix}memorybank_schedule.questionid={$CFG->prefix}memorybank_submissions.qid)\r\n INNER JOIN {$CFG->prefix}memorybank_bank ON ({$CFG->prefix}memorybank_schedule.questionid={$CFG->prefix}memorybank_bank.id)\r\n WHERE\r\n ({$CFG->prefix}memorybank_bank.modid = '{$instid}')\r\n GROUP BY\r\n {$CFG->prefix}user.id\r\n ORDER BY {$sort}\r\n \t"; $results = get_records_sql($SQL, 0, 500); if (is_array($results)) { foreach ($results as $result) { $result->name = $result->firstname . ' ' . $result->lastname; $data[$result->id] = array($result->name, $result->last_access ? date(MEMORYBANK_DATE_FORMAT, $result->last_access) : '', $result->average_score); } } $SQL = "\r\n SELECT\r\n {$CFG->prefix}user.id,\r\n COUNT({$CFG->prefix}memorybank_bank.id) as number_of_questions\r\n FROM\r\n {$CFG->prefix}user\r\n INNER JOIN {$CFG->prefix}memorybank_schedule ON ({$CFG->prefix}user.id={$CFG->prefix}memorybank_schedule.userid)\r\n INNER JOIN {$CFG->prefix}memorybank_bank ON ({$CFG->prefix}memorybank_schedule.questionid={$CFG->prefix}memorybank_bank.id)\r\n WHERE\r\n ({$CFG->prefix}memorybank_bank.modid = '{$instid}') AND\r\n ({$CFG->prefix}memorybank_schedule.nextviewing > NOW())\r\n GROUP BY\r\n {$CFG->prefix}user.id\r\n "; $results = get_records_sql($SQL, 0, 500); if (is_array($results)) { foreach ($results as $result) { $data[$result->id][] = $result->number_of_questions; } } $table->data = $data; $options = array(); // $options = array('0'=>get_string('listallbanks', 'memorybank').'...'); foreach (get_all_instances_in_course("memorybank", $course) as $memorybank) { $options[$memorybank->id] = $memorybank->name; } echo '<div style="text-align: center; padding: 20px;">'; popup_form("{$CFG->wwwroot}/mod/memorybank/view.php?what=studentlist&instid=", $options, 'instid', $instid, '', '', '', false, 'self', ''); echo '</div>'; $table->print_html(); print_footer(); die; }
$table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($baseurl); $table->sortable(true, 'lastname', SORT_DESC); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'showentrytable'); $table->set_attribute('class', 'generaltable generalbox'); $table->set_control_variables(array( TABLE_VAR_SORT => 'ssort', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage' )); $table->no_sorting('select'); $table->no_sorting('status'); $table->setup(); if ($table->get_sql_sort()) { $sort = $table->get_sql_sort(); } else { $sort = ''; } //get students in conjunction with groupmode if ($groupmode > 0) { if ($mygroupid > 0) { $usedgroupid = $mygroupid; } else {
$columns[] = 'address'; $headers[] = get_string('address', 'facetoface'); $columns[] = 'capacity'; $headers[] = get_string('capacity', 'facetoface'); $columns[] = 'options'; /*changed by hameed on 21 dec reg: bug fix*/ $headers[] = '<span style="color:#0080a6">'.get_string('options', 'facetoface').'</span>'; $title = 'facetoface_rooms'; $table = new flexible_table($title); $table->define_baseurl($CFG->wwwroot . '/mod/facetoface/room/manage.php'); $table->define_columns($columns); $table->define_headers($headers); $table->set_attribute('class', 'generalbox mod-facetoface-room-list'); $table->sortable(true, 'name'); $table->no_sorting('options'); $table->setup(); if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $sql = 'SELECT * FROM {facetoface_room} WHERE custom = 0'; $perpage = 25; $totalcount = $DB->count_records_select('facetoface_room', 'custom = 0'); $table->initialbars($totalcount > $perpage); $table->pagesize($perpage, $totalcount);
/** * 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
$table->define_baseurl($CFG->wwwroot . '/blocks/moodletxt/sent.php' . $pageParams); // Required in 2.2 for export $table->set_attribute('id', 'sentMessagesList'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide mtxtCentredCells'); // Set structure $tablecolumns = array("user", "account", "message", "time"); $tableheaders = array(get_string('tableheaderuser', 'block_moodletxt'), get_string('tableheadertxttoolsaccount', 'block_moodletxt'), get_string('tableheadermessagetext', 'block_moodletxt'), get_string('tableheadertimesent', 'block_moodletxt')); // ;) if ($includeEvents == TxttoolsSentMessageDAO::$EVENT_QUERY_INCLUDE || $includeEvents == TxttoolsSentMessageDAO::$EVENT_QUERY_EXCLUSIVE) { array_push($tablecolumns, "generation"); array_push($tableheaders, get_string('tableheadergeneration', 'block_moodletxt')); } $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->sortable(true, 'time', SORT_DESC); $table->no_sorting('message'); $table->collapsible(true); $table->pageable(true); $table->pagesize($MESSAGES_PER_PAGE, $sentMessagesDAO->countMessagesSent(0, $USER->id)); if ($download != '') { $table->is_downloading($download, get_string('exportsheetsent', 'block_moodletxt'), get_string('exporttitlesent', 'block_moodletxt')); } $table->is_downloadable(true); $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); $table->setup(); // BEGIN PAGE OUTPUT if (!$table->is_downloading()) { // Drop in page header echo $output->header(); echo $output->box($sentMessagesDAO->countMessagesSent() . get_string('sentnoticefrag1', 'block_moodletxt') . $sentMessagesDAO->countMessageRecipients() . get_string('sentnoticefrag2', 'block_moodletxt') . html_writer::empty_tag('br') . $sentMessagesDAO->countMessagesSent(0, $userToView) . get_string('sentnoticefrag3', 'block_moodletxt')); // Show select box allow user to show/hide event-generated messages
} } } else { $scoes = NULL; } if (!$download) { $table = new flexible_table('mod-scorm-report'); $table->define_columns($columns); $table->define_headers($headers); $table->define_baseurl($reporturlwithdisplayoptions->out()); $table->sortable(true); $table->collapsible(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_suppress('idnumber'); $table->no_sorting('start'); $table->no_sorting('finish'); $table->no_sorting('score'); if ($scoes) { 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');
$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('lastupdate', 'lastupdate'); $table->column_class('viewgiportfolio', 'viewgiportfolio'); $table->column_class('grade', 'grade'); $table->column_class('feedback', 'feedback'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '100%'); $table->no_sorting('lastupdate'); $table->no_sorting('feedback'); $table->no_sorting('grade'); $table->no_sorting('viewgiportfolio'); // Start working -- this is necessary as soon as the niceties are over. $table->setup(); // Construct the SQL. $extratables = ''; list($where, $params) = $table->get_sql_where(); if ($where) { $where .= ' AND '; } if ($username) { $where .= ' (u.lastname like \'%' . $username . '%\' OR u.firstname like \'%' . $username . '%\' ) AND '; } if ($currenttab == 'sincelastlogin') {
$cm = $modinfo->cms[$instanceid]; // Group security checks. if (!groups_group_visible($currentgroup, $course, $cm)) { echo $OUTPUT->heading(get_string("notingroup")); echo $OUTPUT->footer(); exit; } $table = new flexible_table('course-participation-' . $course->id . '-' . $cm->id . '-' . $roleid); $table->course = $course; $table->define_columns(array('fullname', 'count', 'select')); $table->define_headers(array(get_string('user'), !empty($action) ? get_string($action) : get_string('allactions'), get_string('select'))); $table->define_baseurl($baseurl); $table->set_attribute('cellpadding', '5'); $table->set_attribute('class', 'generaltable generalbox reporttable'); $table->sortable(true, 'lastname', 'ASC'); $table->no_sorting('select'); $table->set_control_variables(array(TABLE_VAR_SORT => 'ssort', TABLE_VAR_HIDE => 'shide', TABLE_VAR_SHOW => 'sshow', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage')); $table->setup(); // We want to query both the current context and parent contexts. list($relatedctxsql, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx'); $params['roleid'] = $roleid; $params['instanceid'] = $instanceid; $params['timefrom'] = $timefrom; $groupsql = ""; if (!empty($currentgroup)) { $groupsql = "JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = :groupid)"; $params['groupid'] = $currentgroup; } $countsql = "SELECT COUNT(DISTINCT(ra.userid))\n FROM {role_assignments} ra\n JOIN {user} u ON u.id = ra.userid\n {$groupsql}\n WHERE ra.contextid {$relatedctxsql} AND ra.roleid = :roleid"; $totalcount = $DB->count_records_sql($countsql, $params); list($twhere, $tparams) = $table->get_sql_where();
$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('starttime'); $table->no_sorting('solveddone'); $table->no_sorting('totaltime'); $table->no_sorting('attempts'); $table->no_sorting('grade'); // 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);
/** * 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(); }
/** * authorize_print_orders * */ function authorize_print_orders($courseid, $userid) { global $course; global $CFG, $USER, $SITE, $DB, $OUTPUT, $PAGE; global $strs, $authstrs; $plugin = enrol_get_plugin('authorize'); require_once $CFG->libdir . '/tablelib.php'; $perpage = optional_param('perpage', 10, PARAM_INT); $showonlymy = optional_param('showonlymy', 0, PARAM_BOOL); $searchquery = optional_param('searchquery', '0', PARAM_INT); $searchtype = optional_param('searchtype', 'orderid', PARAM_ALPHA); $status = optional_param('status', AN_STATUS_NONE, PARAM_INT); $coursecontext = context_course::instance($courseid); $searchmenu = array('orderid' => $authstrs->orderid, 'transid' => $authstrs->transid, 'cclastfour' => $authstrs->cclastfour); $buttons = "<form method='post' action='index.php' autocomplete='off'><div>"; $buttons .= html_writer::label(get_string('orderdetails', 'enrol_authorize'), 'menusearchtype', false, array('class' => 'accesshide')); $buttons .= html_writer::select($searchmenu, 'searchtype', $searchtype, false); $buttons .= html_writer::label(get_string('search'), 'searchquery', false, array('class' => 'accesshide')); $buttons .= "<input id='searchquery' type='text' size='16' name='searchquery' value='' />"; $buttons .= "<input type='submit' value='{$strs->search}' />"; $buttons .= "</div></form>"; if (has_capability('enrol/authorize:uploadcsv', context_user::instance($USER->id))) { $buttons .= "<form method='get' action='uploadcsv.php'><div><input type='submit' value='" . get_string('uploadcsv', 'enrol_authorize') . "' /></div></form>"; } $canmanagepayments = has_capability('enrol/authorize:managepayments', $coursecontext); if ($showonlymy || !$canmanagepayments) { $userid = $USER->id; } $baseurl = $CFG->wwwroot . '/enrol/authorize/index.php?user='******'userid' => $userid); $sql = "SELECT c.id, c.fullname FROM {course} c JOIN {enrol_authorize} e ON c.id = e.courseid "; $sql .= $userid > 0 ? "WHERE (e.userid=:userid) " : ''; $sql .= "ORDER BY c.sortorder, c.fullname"; if ($popupcrs = $DB->get_records_sql_menu($sql, $params)) { $popupcrs = array($SITE->id => $SITE->fullname) + $popupcrs; } $popupmenu = empty($popupcrs) ? '' : $OUTPUT->single_select(new moodle_url($baseurl . '&status=' . $status), 'course', $popupcrs, $courseid, null, 'coursesmenu'); $popupmenu .= '<br />'; $statusmenu = array(AN_STATUS_NONE => $strs->all, AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW => $authstrs->allpendingorders, AN_STATUS_AUTH => $authstrs->authorizedpendingcapture, AN_STATUS_AUTHCAPTURE => $authstrs->authcaptured, AN_STATUS_CREDIT => $authstrs->refunded, AN_STATUS_VOID => $authstrs->cancelled, AN_STATUS_EXPIRE => $authstrs->expired, AN_STATUS_UNDERREVIEW => $authstrs->underreview, AN_STATUS_APPROVEDREVIEW => $authstrs->approvedreview, AN_STATUS_REVIEWFAILED => $authstrs->reviewfailed, AN_STATUS_TEST => $authstrs->tested); $popupmenu .= $OUTPUT->single_select(new moodle_url($baseurl . '&course=' . $courseid), 'status', $statusmenu, $status, null, 'statusmenu'); if ($canmanagepayments) { $popupmenu .= '<br />'; $PAGE->requires->js('/enrol/authorize/authorize.js'); $aid = $OUTPUT->add_action_handler(new component_action('click', 'authorize_jump_to_mypayments', array('userid' => $USER->id, 'status' => $status))); $popupmenu .= html_writer::checkbox('enrol_authorize', 1, $userid == $USER->id, get_string('mypaymentsonly', 'enrol_authorize'), array('id' => $aid)); } if (SITEID != $courseid) { $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); $PAGE->navbar->add($shortname, new moodle_url('/course/view.php', array('id' => $course->id))); } $PAGE->navbar->add($authstrs->paymentmanagement, 'index.php'); $PAGE->set_title("{$course->shortname}: {$authstrs->paymentmanagement}"); $PAGE->set_heading($authstrs->paymentmanagement); $PAGE->set_headingmenu($popupmenu); $PAGE->set_button($buttons); echo $OUTPUT->header(); $table = new flexible_table('enrol-authorize'); $table->set_attribute('width', '100%'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('cellpadding', '3'); $table->set_attribute('id', 'orders'); $table->set_attribute('class', 'generaltable generalbox'); if ($perpage > 100) { $perpage = 100; } $perpagemenus = array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100); $perpagemenu = $OUTPUT->single_select(new moodle_url($baseurl . '&status=' . $status . '&course=' . $courseid), 'perpage', $perpagemenus, $perpage, array('' => 'choosedots'), 'perpagemenu'); $table->define_columns(array('id', 'userid', 'timecreated', 'status', 'action')); $table->define_headers(array($authstrs->orderid, $authstrs->shopper, $strs->time, $strs->status, $perpagemenu)); $table->define_baseurl($baseurl . "&status={$status}&course={$courseid}&perpage={$perpage}"); $table->no_sorting('action'); $table->sortable(true, 'id', SORT_DESC); $table->pageable(true); $table->setup(); $select = "SELECT e.id, e.paymentmethod, e.refundinfo, e.transid, e.courseid, e.userid, e.status, e.ccname, e.timecreated, e.settletime "; $from = "FROM {enrol_authorize} e "; $where = "WHERE (1=1) "; $params = array(); if (!empty($searchquery)) { switch ($searchtype) { case 'orderid': $where = "WHERE (e.id = :searchquery) "; $params['searchquery'] = $searchquery; break; case 'transid': $where = "WHERE (e.transid = :searchquery) "; $params['searchquery'] = $searchquery; break; case 'cclastfour': $searchquery = sprintf("%04d", $searchquery); $where = "WHERE (e.refundinfo = :searchquery) AND (e.paymentmethod=:method) "; $params['searchquery'] = $searchquery; $params['method'] = AN_METHOD_CC; break; } } else { switch ($status) { case AN_STATUS_NONE: if (!$plugin->get_config('an_test')) { $where .= "AND (e.status != :status) "; $params['status'] = AN_STATUS_NONE; } break; case AN_STATUS_TEST: $newordertime = time() - 120; // -2 minutes. Order may be still in process. $where .= "AND (e.status = :status) AND (e.transid = '0') AND (e.timecreated < :newordertime) "; $params['status'] = AN_STATUS_NONE; $params['newordertime'] = $newordertime; break; case AN_STATUS_AUTH | AN_STATUS_UNDERREVIEW | AN_STATUS_APPROVEDREVIEW: $where .= 'AND (e.status IN(:status1,:status2,:status3)) '; $params['status1'] = AN_STATUS_AUTH; $params['status2'] = AN_STATUS_UNDERREVIEW; $params['status3'] = AN_STATUS_APPROVEDREVIEW; break; case AN_STATUS_CREDIT: $from .= "INNER JOIN {enrol_authorize_refunds} r ON e.id = r.orderid "; $where .= "AND (e.status = :status) "; $params['status'] = AN_STATUS_AUTHCAPTURE; break; default: $where .= "AND (e.status = :status) "; $params['status'] = $status; break; } if (SITEID != $courseid) { $where .= "AND (e.courseid = :courseid) "; $params['courseid'] = $courseid; } } // This must be always LAST where!!! if ($userid > 0) { $where .= "AND (e.userid = :userid) "; $params['userid'] = $userid; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $totalcount = $DB->count_records_sql('SELECT COUNT(*) ' . $from . $where, $params); $table->initialbars($totalcount > $perpage); $table->pagesize($perpage, $totalcount); if ($records = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size())) { foreach ($records as $record) { $actionstatus = authorize_get_status_action($record); $color = authorize_get_status_color($actionstatus->status); $actions = ''; if (empty($actionstatus->actions)) { $actions .= $strs->none; } else { foreach ($actionstatus->actions as $val) { $actions .= authorize_print_action_button($record->id, $val); } } $table->add_data(array("<a href='index.php?order={$record->id}'>{$record->id}</a>", $record->ccname, userdate($record->timecreated), "<font style='color:{$color}'>" . $authstrs->{$actionstatus->status} . "</font>", $actions)); } } $table->print_html(); echo $OUTPUT->footer(); }
} } if ($bulkoperations && $mode === MODE_USERDETAILS) { $tablecolumns[] = 'select'; $tableheaders[] = get_string('select'); } $table = new flexible_table('user-index-participants-' . $course->id); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($baseurl->out()); if (!isset($hiddenfields['lastaccess'])) { $table->sortable(true, 'lastaccess', SORT_DESC); } else { $table->sortable(true, 'firstname', SORT_ASC); } $table->no_sorting('roles'); $table->no_sorting('groups'); $table->no_sorting('groupings'); $table->no_sorting('select'); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'participants'); $table->set_attribute('class', 'generaltable generalbox'); $table->set_control_variables(array(TABLE_VAR_SORT => 'ssort', TABLE_VAR_HIDE => 'shide', TABLE_VAR_SHOW => 'sshow', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage')); $table->setup(); list($esql, $params) = get_enrolled_sql($context, null, $currentgroup, true); $joins = array("FROM {user} u"); $wheres = array(); $userfields = array('username', 'email', 'city', 'country', 'lang', 'timezone', 'maildisplay'); $mainuserfields = user_picture::fields('u', $userfields); $extrasql = get_extra_user_fields_sql($context, 'u', '', $userfields); if ($isfrontpage) {
$table->column_class('finalgrade', 'finalgrade'); if ($grading_interface) { $table->column_class('grade', 'grade'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'grades'); $table->set_attribute('width', '90%'); //$table->set_attribute('align', 'center'); if ($grading_interface) { $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); } // Start working -- this is necessary as soon as the niceties are over $table->setup(); /// Construct the SQL if (!empty($users) && ($showungraded || $showgraded || $showneedsregrade)) { if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } if ($where = $table->get_sql_where()) { $where .= ' AND '; } //unfortunately we cannot use status in WHERE clause switch ($showungraded . $showneedsregrade . $showgraded) { case '001':