Beispiel #1
0
function checklist_get_completion_state($course, $cm, $userid, $type)
{
    global $DB;
    if (!($checklist = $DB->get_record('checklist', array('id' => $cm->instance)))) {
        throw new Exception("Can't find checklist {$cm->instance}");
    }
    $result = $type;
    // Default return value
    if ($checklist->completionpercent) {
        list($ticked, $total) = checklist_class::get_user_progress($cm->instance, $userid);
        $value = $checklist->completionpercent <= $ticked * 100 / $total;
        if ($type == COMPLETION_AND) {
            $result = $result && $value;
        } else {
            $result = $result || $value;
        }
    }
    return $result;
}
 protected function show_single_checklist($checklistid)
 {
     global $DB, $CFG, $USER;
     if (!($checklist = $DB->get_record('checklist', array('id' => $checklistid)))) {
         $this->content->items = array(get_string('nochecklist', 'block_checklist'));
         return $this->content;
     }
     if (!($cm = get_coursemodule_from_instance('checklist', $checklist->id, $checklist->course))) {
         $this->content->items = array('Error - course module not found');
         return $this->content;
     }
     if ($CFG->version < 2011120100) {
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     } else {
         $context = context_module::instance($cm->id);
     }
     $viewallreports = has_capability('mod/checklist:viewreports', $context);
     $viewmenteereports = has_capability('mod/checklist:viewmenteereports', $context);
     $updateownchecklist = has_capability('mod/checklist:updateown', $context);
     // Show results for all users for a particular checklist.
     if ($viewallreports || $viewmenteereports) {
         $orderby = 'ORDER BY firstname ASC';
         $ausers = false;
         // Add the groups selector to the footer.
         $this->content->footer = $this->get_groups_menu($cm);
         $showgroup = $this->get_selected_group($cm);
         if ($users = get_users_by_capability($this->context, 'mod/checklist:updateown', 'u.id', '', '', '', $showgroup, '', false)) {
             $users = array_keys($users);
             if (!$viewallreports) {
                 // can only see reports for their mentees
                 $users = checklist_class::filter_mentee_users($users);
             }
             if (!empty($users)) {
                 if ($CFG->version < 2013111800) {
                     $fields = 'u.firstname, u.lastname';
                 } else {
                     $fields = get_all_user_name_fields(true, 'u');
                 }
                 $ausers = $DB->get_records_sql("SELECT u.id, {$fields} FROM {user} u WHERE u.id IN (" . implode(',', $users) . ') ' . $orderby);
             }
         }
         if ($ausers) {
             $this->content->items = array();
             $reporturl = new moodle_url('/mod/checklist/report.php', array('id' => $cm->id));
             foreach ($ausers as $auser) {
                 $link = '<a href="' . $reporturl->out(true, array('studentid' => $auser->id)) . '" >&nbsp;';
                 $this->content->items[] = $link . fullname($auser) . checklist_class::print_user_progressbar($checklist->id, $auser->id, '50px', false, true) . '</a>';
             }
         } else {
             $this->content->items = array(get_string('nousers', 'block_checklist'));
         }
     } else {
         if ($updateownchecklist) {
             $viewurl = new moodle_url('/mod/checklist/view.php', array('id' => $cm->id));
             $link = '<a href="' . $viewurl . '" >&nbsp;';
             $this->content->items = array($link . checklist_class::print_user_progressbar($checklist->id, $USER->id, '150px', false, true) . '</a>');
         } else {
             $this->content = null;
         }
     }
     return $this->content;
 }
Beispiel #3
0
$checklistid = optional_param('checklist', 0, PARAM_INT);
// checklist instance ID
$url = new moodle_url('/mod/checklist/view.php');
if ($id) {
    $cm = get_coursemodule_from_id('checklist', $id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST);
    $url->param('id', $id);
} else {
    if ($checklistid) {
        $checklist = $DB->get_record('checklist', array('id' => $checklistid), '*', MUST_EXIST);
        $course = $DB->get_record('course', array('id' => $checklist->course), '*', MUST_EXIST);
        $cm = get_coursemodule_from_instance('checklist', $checklist->id, $course->id, false, MUST_EXIST);
        $url->param('checklist', $checklistid);
    } else {
        error('You must specify a course_module ID or an instance ID');
    }
}
$PAGE->set_url($url);
require_login($course, true, $cm);
if ($CFG->version < 2011120100) {
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
    $context = context_module::instance($cm->id);
}
$userid = 0;
if (has_capability('mod/checklist:updateown', $context)) {
    $userid = $USER->id;
}
$chk = new checklist_class($cm->id, $userid, $checklist, $cm, $course);
$chk->view();
        $table->head = array($strname);
        $table->align = array('left', 'left', 'left');
    }
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$canupdateown = has_capability('mod/checklist:updateown', $context);
if ($canupdateown) {
    $table->head[] = $strprogress;
}
foreach ($checklists as $checklist) {
    if (!$checklist->visible) {
        //Show dimmed if the mod is hidden
        $link = '<a class="dimmed" href="view.php?id=' . $checklist->coursemodule . '">' . format_string($checklist->name) . '</a>';
    } else {
        //Show normal if the mod is visible
        $link = '<a href="view.php?id=' . $checklist->coursemodule . '">' . format_string($checklist->name) . '</a>';
    }
    if ($course->format == 'weeks' or $course->format == 'topics') {
        $row = array($checklist->section, $link);
    } else {
        $row = array($link);
    }
    if ($canupdateown) {
        $row[] = checklist_class::print_user_progressbar($checklist->id, $USER->id, '300px', true, true);
    }
    $table->data[] = $row;
}
print_heading($strchecklists);
print_table($table);
/// Finish the page
print_footer($course);
Beispiel #5
0
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This page prints a list of all student's results
 *
 * @author  David Smith <*****@*****.**>
 * @package mod/checklist
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/lib.php';
require_once dirname(__FILE__) . '/locallib.php';
global $DB, $PAGE;
$id = required_param('id', PARAM_INT);
// Course_module ID.
$studentid = optional_param('studentid', false, PARAM_INT);
$url = new moodle_url('/mod/checklist/report.php', array('id' => $id));
if ($studentid) {
    $url->param('studentid', $studentid);
}
$cm = get_coursemodule_from_id('checklist', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST);
$url->param('studentid', $studentid);
$PAGE->set_url($url);
require_login($course, true, $cm);
$chk = new checklist_class($cm->id, $studentid, $checklist, $cm, $course);
$chk->report();
Beispiel #6
0
    $items = optional_param_array('items', false, PARAM_INT);
}
$url = new moodle_url('/mod/checklist/view.php', array('id' => $id));
$cm = get_coursemodule_from_id('checklist', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST);
$PAGE->set_url($url);
require_login($course, true, $cm);
if ($CFG->version < 2011120100) {
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
    $context = context_module::instance($cm->id);
}
$userid = $USER->id;
if (!has_capability('mod/checklist:updateown', $context)) {
    echo 'Error: you do not have permission to update this checklist';
    die;
}
if (!confirm_sesskey()) {
    echo 'Error: invalid sesskey';
    die;
}
if (!$items || !is_array($items)) {
    echo 'Error: invalid (or missing) items list';
    die;
}
if (!empty($items)) {
    $chk = new checklist_class($cm->id, $userid, $checklist, $cm, $course);
    $chk->ajaxupdatechecks($items);
}
echo 'OK';
 function finalize()
 {
     global $USER, $DB, $OUTPUT;
     $confirm = optional_param('confirm', 0, PARAM_BOOL);
     $confirmnotpdf = optional_param('confirmnotpdf', 0, PARAM_BOOL);
     $returnurl = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id));
     $continueurl = new moodle_url('/mod/assignment/upload.php', array('id' => $this->cm->id, 'action' => 'finalize', 'sesskey' => sesskey()));
     $submission = $this->get_submission($USER->id);
     if (!$this->can_finalize($submission)) {
         redirect($returnurl);
         // probably already graded, redirect to assignment page, the reason should be obvious
     }
     $extra = $DB->get_record('assignment_uploadpdf', array('assignment' => $this->cm->instance));
     // Check that they have finished everything on the checklist (if that option is selected)
     if ($extra->checklist && $extra->checklist_percent) {
         if ($this->import_checklist_plugin()) {
             list($ticked, $total) = checklist_class::get_user_progress($extra->checklist, $USER->id);
             if ($total && $ticked * 100 / $total < $extra->checklist_percent) {
                 $this->view_header();
                 echo $OUTPUT->heading(get_string('checklistunfinishedheading', 'assignment_uploadpdf'));
                 echo $OUTPUT->notification(get_string('checklistunfinished', 'assignment_uploadpdf'));
                 echo $OUTPUT->continue_button($returnurl);
                 $this->view_footer();
                 die;
             }
         }
     }
     // Check that form for coversheet has been filled in
     // (but don't complain about it until the PDF check has been done)
     $templatedataOK = true;
     $templateitems = false;
     if ($extra && $extra->template > 0) {
         $fs = get_file_storage();
         $coversheet = $fs->get_area_files($this->context->id, 'mod_assignment', 'coversheet', false, '', false);
         if (!empty($coversheet)) {
             $templateitems = $DB->get_records('assignment_uploadpdf_tmplitm', array('template' => $extra->template));
             $ticount = 0;
             foreach ($templateitems as $ti) {
                 if ($ti->type == 'text' || $ti->type == 'shorttext') {
                     $ticount++;
                     $itemname = 'templ' . $ticount;
                     $param = optional_param('templ' . $ticount, '', PARAM_TEXT);
                     if (trim($param) == '') {
                         $templatedataOK = false;
                     } else {
                         $continueurl->param('templ' . $ticount, $param);
                         /* Keep to pass on after yes/no questions answered */
                         $ti->data = $param;
                         /* Keep to pass on to the coversheet generation */
                     }
                 }
             }
         }
     }
     // Check that all files submitted are PDFs
     if ($file = $this->get_not_pdf($submission->id)) {
         if (!$confirmnotpdf) {
             $this->view_header();
             echo $OUTPUT->heading(get_string('nonpdfheading', 'assignment_uploadpdf'));
             if ($extra && $extra->onlypdf) {
                 echo $OUTPUT->notification(get_string('filenotpdf', 'assignment_uploadpdf', $file));
                 echo $OUTPUT->continue_button($returnurl);
             } else {
                 if ($this->get_pdf_count($submission->id) < 1) {
                     echo $OUTPUT->notification(get_string('nopdf', 'assignment_uploadpdf'));
                     echo $OUTPUT->continue_button($returnurl);
                 } else {
                     $continueurl->param('confirmnotpdf', 1);
                     echo $OUTPUT->confirm(get_string('filenotpdf_continue', 'assignment_uploadpdf', $file), $continueurl, $returnurl);
                 }
             }
             $this->view_footer();
             die;
         }
     }
     if (!$templatedataOK) {
         $this->view_header();
         echo $OUTPUT->heading(get_string('heading_templatedatamissing', 'assignment_uploadpdf'));
         echo $OUTPUT->notification(get_string('templatedatamissing', 'assignment_uploadpdf'));
         echo $OUTPUT->continue_button($returnurl);
         die;
     }
     if (!data_submitted() or !$confirm or !confirm_sesskey()) {
         $continueurl->param('confirmnotpdf', 1);
         $continueurl->param('confirm', 1);
         $this->view_header(get_string('submitformarking', 'assignment'));
         echo $OUTPUT->heading(get_string('submitformarking', 'assignment'));
         echo $OUTPUT->confirm(get_string('onceassignmentsent', 'assignment'), $continueurl, $returnurl);
         $this->view_footer();
         die;
     } else {
         if (!($pagecount = $this->create_submission_pdf($submission->id, $templateitems))) {
             $this->view_header(get_string('submitformarking', 'assignment'));
             echo $OUTPUT->notification(get_string('createsubmissionfailed', 'assignment_uploadpdf'));
             echo $OUTPUT->continue_button($returnurl);
             $this->view_footer();
             die;
         }
         $updated = new stdClass();
         $updated->id = $submission->id;
         $updated->data2 = ASSIGNMENT_UPLOADPDF_STATUS_SUBMITTED;
         $updated->timemodified = time();
         $updated->numfiles = $pagecount << 1;
         // Last bit is already used to indicate which folders the cron job should check for images to delete
         if ($DB->update_record('assignment_submissions', $updated)) {
             add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
             $this->email_teachers($submission);
         } else {
             $this->view_header(get_string('submitformarking', 'assignment'));
             echo $OUTPUT->notification(get_string('finalizeerror', 'assignment'));
             echo $OUTPUT->continue_button($returnurl);
             $this->view_footer();
             die;
         }
     }
     redirect($returnurl);
 }
function checklist_refresh_events($courseid = 0)
{
    if ($courseid) {
        $checklists = get_records('checklist', 'course', $courseid);
        $course = get_record('course', 'id', $courseid);
    } else {
        $checklists = get_records('checklist');
        $course = NULL;
    }
    if (!$checklists) {
        return true;
    }
    foreach ($checklists as $checklist) {
        if ($checklist->duedatesoncalendar) {
            $cm = get_coursemodule_from_instance('checklist', $checklist->id, $checklist->course);
            $chk = new checklist_class($cm->id, 0, $checklist, $cm, $course);
            $chk->setallevents();
        }
    }
    return true;
}
Beispiel #9
0
<?php

// This file is part of the Checklist plugin for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/lib.php';
require_once dirname(__FILE__) . '/locallib.php';
global $DB, $PAGE;
$id = required_param('id', PARAM_INT);
// course_module ID
$url = new moodle_url('/mod/checklist/view.php', array('id' => $id));
$cm = get_coursemodule_from_id('checklist', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$checklist = $DB->get_record('checklist', array('id' => $cm->instance), '*', MUST_EXIST);
$PAGE->set_url($url);
require_login($course, true, $cm);
if ($chk = new checklist_class($cm->id, 0, $checklist, $cm, $course)) {
    $chk->edit();
}
 /**
  * Check off the given items in the checklist for the given user
  *
  * @Given /^the following items are checked off in checklist "(?P<checklist_string>[^"]*)" for user "(?P<user_string>[^"]*)":$/
  * @param string $checklistname
  * @param $username
  * @param TableNode $table
  */
 public function the_following_items_are_checked_off_in_checklist_for_user($checklistname, $username, TableNode $table)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/checklist/locallib.php';
     $required = array('itemtext');
     $optional = array('studentmark' => 'yes', 'teachermark' => 'none', 'teachername' => 'admin');
     // Valid settings for field 'studentmark'.
     $studentmarkmap = array('yes' => 1, 'no' => 0);
     // Valid settings for field 'teachermark'.
     $teachermarkmap = array('none' => CHECKLIST_TEACHERMARK_UNDECIDED, 'yes' => CHECKLIST_TEACHERMARK_YES, 'no' => CHECKLIST_TEACHERMARK_NO);
     $data = $table->getHash();
     $firstrow = reset($data);
     // Check required fields are present.
     foreach ($required as $reqname) {
         if (!isset($firstrow[$reqname])) {
             throw new Exception('Checklist item updates require the field ' . $reqname . ' to be set');
         }
     }
     // Get the checklist data.
     $checklist = $DB->get_record('checklist', array('name' => $checklistname), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($checklist, 'checklist');
     $userid = $DB->get_field('user', 'id', array('username' => $username), MUST_EXIST);
     $chk = new checklist_class($cm->id, $userid, $checklist, $cm, $course);
     $updatestudent = $checklist->teacheredit != CHECKLIST_MARKING_TEACHER && isset($firstrow['studentmark']);
     $updateteacher = $checklist->teacheredit != CHECKLIST_MARKING_STUDENT && isset($firstrow['teachermark']);
     if (!$updateteacher && !$updatestudent) {
         throw new Exception('Checklist update must specify a teachermark (for teacher/both checklists) or a studentmark ' . '(for student/both checklists)');
     }
     // Gather together all the updated marks.
     $studentupdates = array();
     $teacherupdates = array();
     foreach ($data as $row) {
         $update = $optional;
         foreach ($row as $fieldname => $value) {
             if (!in_array($fieldname, $required) && !isset($optional[$fieldname])) {
                 throw new Exception('Unknown checklist item update field \'', $fieldname . '\'');
             }
             $update[$fieldname] = $value;
         }
         if (!in_array($update['studentmark'], $studentmarkmap)) {
             throw new Exception('Invalid studentmark value \'' . $update['studentmark'] . '\' in checklist update');
         }
         if (!in_array($update['teachermark'], $teachermarkmap)) {
             throw new Exception('Invalid teachermark value \'' . $update['teachermark'] . '\' in checklist update');
         }
         $itemid = $chk->get_itemid_by_name($update['itemtext']);
         if ($updatestudent) {
             $studentupdates[$itemid] = $studentmarkmap[$update['studentmark']];
         }
         if ($updateteacher) {
             if (!isset($teacherupdates[$update['teachername']])) {
                 $teacherupdates[$update['teachername']] = array();
             }
             $teacherupdates[$update['teachername']][$itemid] = $teachermarkmap[$update['teachermark']];
         }
     }
     // Process the updated marks.
     if ($updatestudent) {
         $chk->ajaxupdatechecks($studentupdates);
     }
     if ($updateteacher) {
         foreach ($teacherupdates as $teachername => $checkmarks) {
             $teacherid = $DB->get_field('user', 'id', array('username' => $teachername), MUST_EXIST);
             $chk->update_teachermarks($checkmarks, $teacherid);
         }
     }
 }
Beispiel #11
0
 static function get_user_progress($checklistid, $userid)
 {
     global $DB, $CFG;
     $userid = intval($userid);
     // Just to be on the safe side...
     $checklist = $DB->get_record('checklist', array('id' => $checklistid));
     if (!$checklist) {
         return array(false, false);
     }
     $groupings_sel = '';
     if (isset($CFG->enablegroupmembersonly) && $CFG->enablegroupmembersonly && $checklist->autopopulate) {
         $groupings = checklist_class::get_user_groupings($userid, $checklist->course);
         $groupings[] = 0;
         $groupings_sel = ' AND grouping IN (' . implode(',', $groupings) . ') ';
     }
     $items = $DB->get_records_select('checklist_item', 'checklist = ? AND userid = 0 AND itemoptional = ' . CHECKLIST_OPTIONAL_NO . ' AND hidden = ' . CHECKLIST_HIDDEN_NO . $groupings_sel, array($checklist->id), '', 'id');
     if (empty($items)) {
         return array(false, false);
     }
     $total = count($items);
     list($isql, $iparams) = $DB->get_in_or_equal(array_keys($items));
     $params = array_merge(array($userid), $iparams);
     $sql = "userid = ? AND item {$isql} AND ";
     if ($checklist->teacheredit == CHECKLIST_MARKING_STUDENT) {
         $sql .= 'usertimestamp > 0';
     } else {
         $sql .= 'teachermark = ' . CHECKLIST_TEACHERMARK_YES;
     }
     $ticked = $DB->count_records_select('checklist_check', $sql, $params);
     return array($ticked, $total);
 }
Beispiel #12
0
 static function print_user_progressbar($checklistid, $userid, $width = '300px', $showpercent = true, $return = false, $hidecomplete = false)
 {
     global $OUTPUT;
     list($ticked, $total) = checklist_class::get_user_progress($checklistid, $userid);
     if (!$total) {
         return '';
     }
     if ($hidecomplete && $ticked == $total) {
         return '';
     }
     $percent = $ticked * 100 / $total;
     // TODO - fix this now that styles.css is included
     $output = '<div class="checklist_progress_outer" style="width: ' . $width . ';" >';
     $output .= '<div class="checklist_progress_inner" style="width:' . $percent . '%; background-image: url(' . $OUTPUT->pix_url('progress', 'checklist') . ');" >&nbsp;</div>';
     $output .= '</div>';
     if ($showpercent) {
         $output .= '<span class="checklist_progress_percent">&nbsp;' . sprintf('%0d%%', $percent) . '</span>';
     }
     $output .= '<br style="clear:both;" />';
     if ($return) {
         return $output;
     }
     echo $output;
     return '';
 }
 function get_content()
 {
     global $CFG, $USER, $DB, $COURSE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $this->content->icons = array();
     if (!$this->import_checklist_plugin()) {
         $this->content->items = array(get_string('nochecklistplugin', 'block_checklist'));
         return $this->content;
     }
     if (empty($this->config->checklistid)) {
         $this->content->items = array(get_string('nochecklist', 'block_checklist'));
         return $this->content;
     }
     if (!($checklist = $DB->get_record('checklist', array('id' => $this->config->checklistid)))) {
         $this->content->items = array(get_string('nochecklist', 'block_checklist'));
         return $this->content;
     }
     if (!($cm = get_coursemodule_from_instance('checklist', $checklist->id, $checklist->course))) {
         $this->content->items = array('Error - course module not found');
         return $this->content;
     }
     if ($CFG->version < 2011120100) {
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     } else {
         $context = context_module::instance($cm->id);
     }
     $viewallreports = has_capability('mod/checklist:viewreports', $context);
     $viewmenteereports = has_capability('mod/checklist:viewmenteereports', $context);
     if ($viewallreports || $viewmenteereports) {
         $orderby = 'ORDER BY firstname ASC';
         $ausers = false;
         $showgroup = false;
         if (!empty($this->config->groupid)) {
             $showgroup = $this->config->groupid;
         }
         $separate = $COURSE->groupmode == SEPARATEGROUPS;
         if ($separate && !has_capability('moodle/site:accessallgroups', $context)) {
             // Teacher can only see own groups
             $groups = groups_get_all_groups($COURSE->id, $USER->id, 0, 'g.id, g.name');
             if (!$groups) {
                 $groups = array();
             }
             if (!$showgroup || !array_key_exists($showgroup, $groups)) {
                 // Showgroup not set OR teacher not member of showgroup
                 $showgroup = array_keys($groups);
                 // Show all students for group(s) teacher is member of
             }
         }
         if ($users = get_users_by_capability($context, 'mod/checklist:updateown', 'u.id', '', '', '', $showgroup, '', false)) {
             $users = array_keys($users);
             if (!$viewallreports) {
                 // can only see reports for their mentees
                 $users = checklist_class::filter_mentee_users($users);
             }
             if (!empty($users)) {
                 $ausers = $DB->get_records_sql('SELECT u.id, u.firstname, u.lastname FROM {user} u WHERE u.id IN (' . implode(',', $users) . ') ' . $orderby);
             }
         }
         if ($ausers) {
             $this->content->items = array();
             $reporturl = new moodle_url('/mod/checklist/report.php', array('id' => $cm->id));
             foreach ($ausers as $auser) {
                 $link = '<a href="' . $reporturl->out(true, array('studentid' => $auser->id)) . '" >&nbsp;';
                 $this->content->items[] = $link . fullname($auser) . checklist_class::print_user_progressbar($checklist->id, $auser->id, '50px', false, true) . '</a>';
             }
         } else {
             $this->content->items = array(get_string('nousers', 'block_checklist'));
         }
     } else {
         $viewurl = new moodle_url('/mod/checklist/view.php', array('id' => $cm->id));
         $link = '<a href="' . $viewurl . '" >&nbsp;';
         $this->content->items = array($link . checklist_class::print_user_progressbar($checklist->id, $USER->id, '150px', false, true) . '</a>');
     }
     return $this->content;
 }
 function print_user_progressbar($checklistid, $userid, $width = '300px', $showpercent = true, $return = false)
 {
     global $CFG;
     list($ticked, $total) = checklist_class::get_user_progress($checklistid, $userid);
     if (!$total) {
         return;
     }
     $percent = $ticked * 100 / $total;
     // Sadly 'styles.php' will not be included from outside the module, so I have to hard-code the styles here
     $output = '<div class="checklist_progress_outer" style="border-width: 1px; border-style: solid; border-color: black; width: ' . $width . '; background-colour: transparent; height: 15px; float: ' . $alignleft . ';" >';
     $output .= '<div class="checklist_progress_inner" style="width:' . $percent . '%; background-image: url(' . $CFG->wwwroot . '/mod/checklist/images/progress.gif); background-color: #229b15; height: 100%; background-repeat: repeat-x; background-position: top;" >&nbsp;</div>';
     $output .= '</div>';
     if ($showpercent) {
         $output .= '<div style="float:' . $alignleft . '; width: 3em;">&nbsp;' . sprintf('%0d%%', $percent) . '</div>';
     }
     //        echo '<div style="float:'.$alignleft.';">&nbsp;('.$ticked.'/'.$total.')</div>';
     $output .= '<br style="clear:both;" />';
     if ($return) {
         return $output;
     } else {
         echo $output;
     }
 }