示例#1
0
function checklist_print_overview($courses, &$htmlarray)
{
    global $USER, $CFG, $DB;
    $config = get_config('checklist');
    if (isset($config->showmymoodle) && !$config->showmymoodle) {
        return;
        // Disabled via global config.
    }
    if (!isset($config->showcompletemymoodle)) {
        $config->showcompletemymoodle = 1;
    }
    if (empty($courses) || !is_array($courses) || count($courses) == 0) {
        return;
    }
    if (!($checklists = get_all_instances_in_courses('checklist', $courses))) {
        return;
    }
    $strchecklist = get_string('modulename', 'checklist');
    foreach ($checklists as $checklist) {
        $show_all = true;
        if ($checklist->teacheredit == CHECKLIST_MARKING_STUDENT) {
            if ($CFG->version < 2011120100) {
                $context = get_context_instance(CONTEXT_MODULE, $checklist->coursemodule);
            } else {
                $context = context_module::instance($checklist->coursemodule);
            }
            $show_all = !has_capability('mod/checklist:updateown', $context);
        }
        $progressbar = checklist_class::print_user_progressbar($checklist->id, $USER->id, '270px', true, true, !$config->showcompletemymoodle);
        if (empty($progressbar)) {
            continue;
        }
        // Do not worry about hidden items / groupings as automatic items cannot have dates
        // (and manual items cannot be hidden / have groupings)
        if ($show_all) {
            // Show all items whether or not they are checked off (as this user is unable to check them off)
            $date_items = $DB->get_records_select('checklist_item', 'checklist = ? AND duetime > 0', array($checklist->id), 'duetime');
        } else {
            // Show only items that have not been checked off
            $date_items = $DB->get_records_sql('SELECT i.* FROM {checklist_item} i JOIN {checklist_check} c ON c.item = i.id ' . 'WHERE i.checklist = ? AND i.duetime > 0 AND c.userid = ? AND usertimestamp = 0 ' . 'ORDER BY i.duetime', array($checklist->id, $USER->id));
        }
        $str = '<div class="checklist overview"><div class="name">' . $strchecklist . ': ' . '<a title="' . $strchecklist . '" href="' . $CFG->wwwroot . '/mod/checklist/view.php?id=' . $checklist->coursemodule . '">' . $checklist->name . '</a></div>';
        $str .= '<div class="info">' . $progressbar . '</div>';
        foreach ($date_items as $item) {
            $str .= '<div class="info">' . $item->displaytext . ': ';
            if ($item->duetime > time()) {
                $str .= '<span class="itemdue">';
            } else {
                $str .= '<span class="itemoverdue">';
            }
            $str .= date('j M Y', $item->duetime) . '</span></div>';
        }
        $str .= '</div>';
        if (empty($htmlarray[$checklist->course]['checklist'])) {
            $htmlarray[$checklist->course]['checklist'] = $str;
        } else {
            $htmlarray[$checklist->course]['checklist'] .= $str;
        }
    }
}
 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;
 }
        $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);
 function view_intro()
 {
     global $CFG, $USER, $OUTPUT, $DB;
     echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
     echo format_module_intro('assignment', $this->assignment, $this->cm->id);
     if ($this->import_checklist_plugin()) {
         $extra = $DB->get_record('assignment_uploadpdf', array('assignment' => $this->assignment->id));
         if ($extra->checklist) {
             $checklist = $DB->get_record('checklist', array('id' => $extra->checklist));
             if ($checklist) {
                 $chklink = $CFG->wwwroot . '/mod/checklist/view.php?checklist=' . $checklist->id;
                 echo '<div><a href="' . $chklink . '" target="_blank"><div style="float: left; dispaly: inline; margin-left: 40px; margin-right: 20px;">' . $checklist->name . ': </div>';
                 checklist_class::print_user_progressbar($checklist->id, $USER->id);
                 echo '</a></div>';
             }
         }
     }
     echo $OUTPUT->box_end();
 }
 function view_intro()
 {
     global $CFG, $USER;
     print_simple_box_start('center', '', '', 0, 'generalbox', 'intro');
     $formatoptions = new stdClass();
     $formatoptions->noclean = true;
     echo format_text($this->assignment->description, $this->assignment->format, $formatoptions);
     if ($this->import_checklist_plugin()) {
         $extra = get_record('assignment_uploadpdf', 'assignment', $this->assignment->id);
         if ($extra->checklist) {
             $checklist = get_record('checklist', 'id', $extra->checklist);
             if ($checklist) {
                 $chklink = $CFG->wwwroot . '/mod/checklist/view.php?checklist=' . $checklist->id;
                 echo '<div><a href="' . $chklink . '" target="_blank"><div style="float: left; dispaly: inline; margin-left: 40px; margin-right: 20px;">' . $checklist->name . ': </div>';
                 checklist_class::print_user_progressbar($checklist->id, $USER->id);
                 echo '</a></div>';
             }
         }
     }
     print_simple_box_end();
 }
 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;
 }