/** * Output the results. * * @param int $total total courses. * @param int $created count of courses created. * @param int $updated count of courses updated. * @param int $deleted count of courses deleted. * @param int $errors count of errors. * @return void */ public function results($total, $created, $updated, $deleted, $errors) { if ($this->outputmode == self::NO_OUTPUT) { return; } $message = array(get_string('coursestotal', 'tool_uploadcourse', $total), get_string('coursescreated', 'tool_uploadcourse', $created), get_string('coursesupdated', 'tool_uploadcourse', $updated), get_string('coursesdeleted', 'tool_uploadcourse', $deleted), get_string('courseserrors', 'tool_uploadcourse', $errors)); if ($this->outputmode == self::OUTPUT_PLAIN) { foreach ($message as $msg) { $this->buffer->output($msg); } } else { if ($this->outputmode == self::OUTPUT_HTML) { $buffer = new progress_trace_buffer(new html_list_progress_trace()); foreach ($message as $msg) { $buffer->output($msg); } $buffer->finished(); } } }
public function test_progres_trace_buffer() { $this->resetAfterTest(false); $trace = new progress_trace_buffer(new html_progress_trace()); ob_start(); $trace->output('do'); $trace->output('re', 1); $trace->output('mi', 2); $trace->finished(); $output = ob_get_contents(); ob_end_clean(); $this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $output); $this->assertSame($output, $trace->get_buffer()); $trace = new progress_trace_buffer(new html_progress_trace(), false); $trace->output('do'); $trace->output('re', 1); $trace->output('mi', 2); $trace->finished(); $this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer()); $this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer()); $trace->reset_buffer(); $this->assertSame('', $trace->get_buffer()); $this->expectOutputString(''); }
/** * Start the output. * * @return void */ public function start() { if ($this->outputmode == self::NO_OUTPUT) { return; } if ($this->outputmode == self::OUTPUT_CLI) { switch ($this->mode) { case tool_coursearchiver_processor::MODE_COURSELIST: $this->buffer->output("\n\n" . str_repeat('-', 50)); $this->buffer->output("Search Results"); $this->buffer->output(sprintf($this->maskcourses, 'Status', 'ID', 'Shortname', 'Fullname', 'Last Use')); break; case tool_coursearchiver_processor::MODE_GETEMAILS: $this->buffer->output("\n\n" . str_repeat('-', 50)); $this->buffer->output("Course Owners"); $this->buffer->output(sprintf($this->maskusers, 'Firstname', 'Lastname', 'Email')); break; case tool_coursearchiver_processor::MODE_HIDE: case tool_coursearchiver_processor::MODE_ARCHIVE: case tool_coursearchiver_processor::MODE_HIDEEMAIL: case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL: break; } } else { if ($this->outputmode == self::OUTPUT_HTML) { switch ($this->mode) { case tool_coursearchiver_processor::MODE_COURSELIST: $style = '<style> .fitemtitle { width: auto !important; } .felement { margin: 0 !important; display: inline; } th .fitem { display: inline-block; } </style>'; $this->mform->addElement('html', $style . html_writer::start_tag('table', array('style' => 'width:100%')) . html_writer::start_tag('tr', array('style' => 'text-align:left;')) . html_writer::tag('th', get_string('outselected', 'tool_coursearchiver'), array('style' => 'width:10%;text-align:center;')) . html_writer::tag('th', get_string('outid', 'tool_coursearchiver'), array('style' => 'width:10%')) . html_writer::tag('th', get_string('outfullname', 'tool_coursearchiver'), array('style' => 'width:38%')) . html_writer::tag('th', get_string('outshortname', 'tool_coursearchiver'), array('style' => 'width:22%')) . html_writer::tag('th', get_string('outidnumber', 'tool_coursearchiver'), array('style' => 'width:10%')) . html_writer::tag('th', get_string('outaccess', 'tool_coursearchiver'), array('style' => 'width:10%;text-align:center;')) . html_writer::end_tag('tr') . html_writer::end_tag('table')); break; case tool_coursearchiver_processor::MODE_GETEMAILS: $style = '<style> .fitemtitle { width: auto !important; } .felement { margin: 0 !important; display: inline; } th .fitem { display: inline-block; } .courseheader td { background-color: #F5F5F5; color: #7D7D7D; padding: 10px; } </style>'; $this->mform->addElement('html', $style . html_writer::start_tag('table', array('style' => 'width:100%')) . html_writer::start_tag('tr', array('style' => 'text-align:left;')) . html_writer::tag('th', get_string('outselected', 'tool_coursearchiver'), array('style' => 'width:10%;text-align:center;')) . html_writer::tag('th', get_string('outemail', 'tool_coursearchiver'), array('style' => 'width:40%')) . html_writer::tag('th', get_string('outfirstname', 'tool_coursearchiver'), array('style' => 'width:15%')) . html_writer::tag('th', get_string('outlastname', 'tool_coursearchiver')) . html_writer::end_tag('tr') . html_writer::end_tag('table')); break; case tool_coursearchiver_processor::MODE_HIDE: $buffer = new progress_trace_buffer(new text_progress_trace()); $buffer->output('<h3>Hiding selected courses</h3><div style="margin-bottom: 60px;"></div><br />'); $buffer->finished(); break; case tool_coursearchiver_processor::MODE_ARCHIVE: $buffer = new progress_trace_buffer(new text_progress_trace()); $buffer->output('<h3>Archiving selected courses</h3><div style="margin-bottom: 60px;"></div><br />'); $buffer->finished(); break; case tool_coursearchiver_processor::MODE_HIDEEMAIL: case tool_coursearchiver_processor::MODE_ARCHIVEEMAIL: $buffer = new progress_trace_buffer(new text_progress_trace()); $buffer->output('<h3>Sending Emails</h3><div style="margin-bottom: 60px;"></div><br />'); $buffer->finished(); break; } } } }