// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * All workshop module renderers are defined here
+ * Workshop module renderering methods are defined here
*
* @package mod
* @subpackage workshop
class mod_workshop_renderer extends plugin_renderer_base {
////////////////////////////////////////////////////////////////////////////
- // Methods to render workshop renderable components
+ // External API - methods to render workshop renderable components
////////////////////////////////////////////////////////////////////////////
/**
return $o;
}
- ////////////////////////////////////////////////////////////////////////////
- // Rendering helper methods
- ////////////////////////////////////////////////////////////////////////////
-
- /**
- * Renders a list of files attached to the submission
- *
- * If format==html, then format a html string. If format==text, then format a text-only string.
- * Otherwise, returns html for non-images and html to display the image inline.
- *
- * @param int $submissionid submission identifier
- * @param string format the format of the returned string - html|text
- * @return string formatted text to be echoed
- */
- protected function helper_submission_attachments($submissionid, $format = 'html') {
- global $CFG;
- require_once($CFG->libdir.'/filelib.php');
-
- $fs = get_file_storage();
- $ctx = $this->page->context;
- $files = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
-
- $outputimgs = ''; // images to be displayed inline
- $outputfiles = ''; // list of attachment files
-
- foreach ($files as $file) {
- if ($file->is_directory()) {
- continue;
- }
-
- $filepath = $file->get_filepath();
- $filename = $file->get_filename();
- $fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php',
- '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
- $type = $file->get_mimetype();
- $type = mimeinfo_from_type('type', $type);
- $image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
-
- $linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
- $linktxt = "$filename [$fileurl]";
-
- if ($format == 'html') {
- if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
- $preview = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
- $preview = html_writer::tag('a', $preview, array('href' => $fileurl));
- $outputimgs .= $this->output->container($preview);
-
- } else {
- $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
- }
-
- } else if ($format == 'text') {
- $outputfiles .= $linktxt . PHP_EOL;
- }
- }
-
- if ($format == 'html') {
- if ($outputimgs) {
- $outputimgs = $this->output->container($outputimgs, 'images');
- }
-
- if ($outputfiles) {
- $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
- }
-
- return $this->output->container($outputimgs . $outputfiles, 'attachments');
-
- } else {
- return $outputfiles;
- }
- }
-
- /**
- * Renders the tasks for the single phase in the user plan
- *
- * @param stdClass $tasks
- * @return string html code
- */
- protected function helper_user_plan_tasks(array $tasks) {
- $out = '';
- foreach ($tasks as $taskcode => $task) {
- $classes = '';
- $icon = null;
- if ($task->completed === true) {
- $classes .= ' completed';
- } elseif ($task->completed === false) {
- $classes .= ' fail';
- } elseif ($task->completed === 'info') {
- $classes .= ' info';
- }
- if (is_null($task->link)) {
- $title = $task->title;
- } else {
- $title = html_writer::link($task->link, $task->title);
- }
- $title = $this->output->container($title, 'title');
- $details = $this->output->container($task->details, 'details');
- $out .= html_writer::tag('li', $title . $details, array('class' => $classes));
- }
- if ($out) {
- $out = html_writer::tag('ul', $out, array('class' => 'tasks'));
- }
- return $out;
- }
-
-
- ////////////////////////////////////////////////////////////////////////////
- // TODO Obsolete
- //
-
/**
* Renders the workshop grading report
*
- * Grades must be already rounded to the set number of decimals or must be null (in which later case,
- * the [[nullgrade]] string shall be displayed).
- *
- * @param stdClass $data prepared by {@link workshop::prepare_grading_report()}
- * @param stdClass $options display options object with properties ->showauthornames ->showreviewernames ->sortby ->sorthow
- * ->showsubmissiongrade ->showgradinggrade
+ * @param workshop_grading_report $gradingreport
* @return string html code
*/
- public function grading_report(stdclass $data, stdclass $options) {
- $grades = $data->grades;
- $userinfo = $data->userinfo;
+ protected function render_workshop_grading_report(workshop_grading_report $gradingreport) {
+
+ $data = $gradingreport->get_data();
+ $options = $gradingreport->get_options();
+ $grades = $data->grades;
+ $userinfo = $data->userinfo;
if (empty($grades)) {
return '';
$table = new html_table();
$table->attributes['class'] = 'grading-report';
- $sortbyfirstname = $this->sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
- $sortbylastname = $this->sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
+ $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
+ $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
if (self::fullname_format() == 'lf') {
$sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
} else {
$table->head = array();
$table->head[] = $sortbyname;
- $table->head[] = $this->sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
+ $table->head[] = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
$options->sortby, $options->sorthow);
- $table->head[] = $this->sortable_heading(get_string('receivedgrades', 'workshop'));
+ $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
if ($options->showsubmissiongrade) {
- $table->head[] = $this->sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
+ $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
'submissiongrade', $options->sortby, $options->sorthow);
}
- $table->head[] = $this->sortable_heading(get_string('givengrades', 'workshop'));
+ $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
if ($options->showgradinggrade) {
- $table->head[] = $this->sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
+ $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
'gradinggrade', $options->sortby, $options->sorthow);
}
// column #1 - participant - spans over all rows
if ($tr == 0) {
$cell = new html_table_cell();
- $cell->text = $this->grading_report_participant($participant, $userinfo);
+ $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'participant';
$row->cells[] = $cell;
// column #2 - submission - spans over all rows
if ($tr == 0) {
$cell = new html_table_cell();
- $cell->text = $this->grading_report_submission($participant);
+ $cell->text = $this->helper_grading_report_submission($participant);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'submission';
$row->cells[] = $cell;
$idx = intval($tr / $spanreceived);
$assessment = self::array_nth($participant->reviewedby, $idx);
$cell = new html_table_cell();
- $cell->text = $this->grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
+ $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
get_string('gradereceivedfrom', 'workshop'));
$cell->rowspan = $spanreceived;
$cell->attributes['class'] = 'receivedgrade';
// column #4 - total grade for submission
if ($options->showsubmissiongrade and $tr == 0) {
$cell = new html_table_cell();
- $cell->text = $this->grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
+ $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'submissiongrade';
$row->cells[] = $cell;
$idx = intval($tr / $spangiven);
$assessment = self::array_nth($participant->reviewerof, $idx);
$cell = new html_table_cell();
- $cell->text = $this->grading_report_assessment($assessment, $options->showauthornames, $userinfo,
+ $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo,
get_string('gradegivento', 'workshop'));
$cell->rowspan = $spangiven;
$cell->attributes['class'] = 'givengrade';
// column #6 - total grade for assessment
if ($options->showgradinggrade and $tr == 0) {
$cell = new html_table_cell();
- $cell->text = $this->grading_report_grade($participant->gradinggrade);
+ $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
$cell->rowspan = $numoftrs;
$cell->attributes['class'] = 'gradinggrade';
$row->cells[] = $cell;
return html_writer::table($table);
}
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Internal rendering helper methods
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Renders a list of files attached to the submission
+ *
+ * If format==html, then format a html string. If format==text, then format a text-only string.
+ * Otherwise, returns html for non-images and html to display the image inline.
+ *
+ * @param int $submissionid submission identifier
+ * @param string format the format of the returned string - html|text
+ * @return string formatted text to be echoed
+ */
+ protected function helper_submission_attachments($submissionid, $format = 'html') {
+ global $CFG;
+ require_once($CFG->libdir.'/filelib.php');
+
+ $fs = get_file_storage();
+ $ctx = $this->page->context;
+ $files = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
+
+ $outputimgs = ''; // images to be displayed inline
+ $outputfiles = ''; // list of attachment files
+
+ foreach ($files as $file) {
+ if ($file->is_directory()) {
+ continue;
+ }
+
+ $filepath = $file->get_filepath();
+ $filename = $file->get_filename();
+ $fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php',
+ '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
+ $type = $file->get_mimetype();
+ $type = mimeinfo_from_type('type', $type);
+ $image = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
+
+ $linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
+ $linktxt = "$filename [$fileurl]";
+
+ if ($format == 'html') {
+ if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
+ $preview = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
+ $preview = html_writer::tag('a', $preview, array('href' => $fileurl));
+ $outputimgs .= $this->output->container($preview);
+
+ } else {
+ $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
+ }
+
+ } else if ($format == 'text') {
+ $outputfiles .= $linktxt . PHP_EOL;
+ }
+ }
+
+ if ($format == 'html') {
+ if ($outputimgs) {
+ $outputimgs = $this->output->container($outputimgs, 'images');
+ }
+
+ if ($outputfiles) {
+ $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
+ }
+
+ return $this->output->container($outputimgs . $outputfiles, 'attachments');
+
+ } else {
+ return $outputfiles;
+ }
+ }
+
+ /**
+ * Renders the tasks for the single phase in the user plan
+ *
+ * @param stdClass $tasks
+ * @return string html code
+ */
+ protected function helper_user_plan_tasks(array $tasks) {
+ $out = '';
+ foreach ($tasks as $taskcode => $task) {
+ $classes = '';
+ $icon = null;
+ if ($task->completed === true) {
+ $classes .= ' completed';
+ } elseif ($task->completed === false) {
+ $classes .= ' fail';
+ } elseif ($task->completed === 'info') {
+ $classes .= ' info';
+ }
+ if (is_null($task->link)) {
+ $title = $task->title;
+ } else {
+ $title = html_writer::link($task->link, $task->title);
+ }
+ $title = $this->output->container($title, 'title');
+ $details = $this->output->container($task->details, 'details');
+ $out .= html_writer::tag('li', $title . $details, array('class' => $classes));
+ }
+ if ($out) {
+ $out = html_writer::tag('ul', $out, array('class' => 'tasks'));
+ }
+ return $out;
+ }
+
/**
* Renders a text with icons to sort by the given column
*
*
* @return string
*/
- protected function sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
+ protected function helper_sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
global $PAGE;
$out = html_writer::tag('span', $text, array('class'=>'text'));
* @param array $userinfo
* @return string
*/
- protected function grading_report_participant(stdclass $participant, array $userinfo) {
+ protected function helper_grading_report_participant(stdclass $participant, array $userinfo) {
$userid = $participant->userid;
$out = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 35));
$out .= html_writer::tag('span', fullname($userinfo[$userid]));
* @param stdClass $participant
* @return string
*/
- protected function grading_report_submission(stdclass $participant) {
+ protected function helper_grading_report_submission(stdclass $participant) {
global $CFG;
if (is_null($participant->submissionid)) {
* @param string $separator between the grade and the reviewer/author
* @return string
*/
- protected function grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
+ protected function helper_grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
global $CFG;
if (is_null($assessment)) {
/**
* Formats the aggreagated grades
*/
- protected function grading_report_grade($grade, $over=null) {
+ protected function helper_grading_report_grade($grade, $over=null) {
$a = new stdclass();
$a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade;
if (is_null($over)) {
}
////////////////////////////////////////////////////////////////////////////
- // Helper methods //
+ // Static helpers
////////////////////////////////////////////////////////////////////////////
/**
return 'fl';
}
}
-
}
$perpage = 10; // todo let the user modify this
$groups = ''; // todo let the user choose the group
$PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
- $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
+ $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
if ($data) {
$showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
$showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
$reportopts->showgradinggrade = false;
echo $output->render($pagingbar);
- echo $output->grading_report($data, $reportopts);
+ echo $output->render(new workshop_grading_report($data, $reportopts));
echo $output->render($pagingbar);
}
}
$perpage = 10; // todo let the user modify this
$groups = ''; // todo let the user choose the group
$PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
- $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
+ $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
if ($data) {
$showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
$showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
$reportopts->showgradinggrade = true;
echo $output->render($pagingbar);
- echo $output->grading_report($data, $reportopts);
+ echo $output->render(new workshop_grading_report($data, $reportopts));
echo $output->render($pagingbar);
}
}
$perpage = 10; // todo let the user modify this
$groups = ''; // todo let the user choose the group
$PAGE->set_url($PAGE->url, compact('sortby', 'sorthow', 'page')); // TODO: this is suspicious
- $data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
+ $data = $workshop->prepare_grading_report_data($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
if ($data) {
$showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
$showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'));
echo $output->render($pagingbar);
- echo $output->grading_report($data, $reportopts);
+ echo $output->render(new workshop_grading_report($data, $reportopts));
echo $output->render($pagingbar);
print_collapsible_region_end();
}