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; }
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') . ');" > </div>'; $output .= '</div>'; if ($showpercent) { $output .= '<span class="checklist_progress_percent"> ' . sprintf('%0d%%', $percent) . '</span>'; } $output .= '<br style="clear:both;" />'; if ($return) { return $output; } else { echo $output; } }
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 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;" > </div>'; $output .= '</div>'; if ($showpercent) { $output .= '<div style="float:' . $alignleft . '; width: 3em;"> ' . sprintf('%0d%%', $percent) . '</div>'; } // echo '<div style="float:'.$alignleft.';"> ('.$ticked.'/'.$total.')</div>'; $output .= '<br style="clear:both;" />'; if ($return) { return $output; } else { echo $output; } }