2010-01-04 17:46:33 +00:00
|
|
|
<?php
|
2010-01-04 17:47:09 +00:00
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
2010-01-04 17:46:33 +00:00
|
|
|
// 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.
|
2010-01-04 17:47:09 +00:00
|
|
|
//
|
2010-01-04 17:46:33 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-04 17:47:09 +00:00
|
|
|
|
2010-01-04 17:46:33 +00:00
|
|
|
/**
|
|
|
|
* All workshop module renderers are defined here
|
|
|
|
*
|
|
|
|
* @package mod-workshop
|
|
|
|
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
|
|
/**
|
2010-01-04 17:47:09 +00:00
|
|
|
* Workshop module renderer class
|
|
|
|
*
|
|
|
|
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2010-01-04 17:46:33 +00:00
|
|
|
*/
|
2010-01-04 17:47:09 +00:00
|
|
|
class moodle_mod_workshop_renderer extends moodle_renderer_base {
|
2010-01-04 17:46:33 +00:00
|
|
|
|
|
|
|
/** the underlying renderer to use */
|
|
|
|
protected $output;
|
|
|
|
|
|
|
|
/** the page we are doing output for */
|
|
|
|
protected $page;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Workshop renderer constructor
|
2010-01-04 17:47:09 +00:00
|
|
|
*
|
2010-01-04 17:46:33 +00:00
|
|
|
* @param mixed $page the page we are doing output for
|
|
|
|
* @param mixed $output lower-level renderer, typically moodle_core_renderer
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct($page, $output) {
|
|
|
|
$this->page = $page;
|
|
|
|
$this->output = $output;
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:47:09 +00:00
|
|
|
/**
|
|
|
|
* Returns html code for a status message
|
|
|
|
*
|
|
|
|
* This should be replaced by a core system of displaying messages, as for example Mahara has.
|
|
|
|
*
|
|
|
|
* @param string $message to display
|
|
|
|
* @return string html
|
|
|
|
*/
|
2010-01-04 17:55:02 +00:00
|
|
|
public function status_message(stdClass $message) {
|
2010-01-04 17:47:09 +00:00
|
|
|
if (empty($message->text)) {
|
|
|
|
return '';
|
|
|
|
}
|
2010-01-04 18:01:05 +00:00
|
|
|
$sty = empty($message->sty) ? 'info' : $message->sty;
|
2010-01-04 17:47:09 +00:00
|
|
|
|
|
|
|
$o = $this->output->output_tag('span', array(), $message->text);
|
|
|
|
$closer = $this->output->output_tag('a', array('href' => $this->page->url->out()),
|
|
|
|
get_string('messageclose', 'workshop'));
|
|
|
|
$o .= $this->output->container($closer, 'status-message-closer');
|
|
|
|
if (isset($message->extra)) {
|
|
|
|
$o .= $message->extra;
|
|
|
|
}
|
|
|
|
return $this->output->container($o, array('status-message', $sty));
|
|
|
|
}
|
2010-01-04 17:46:33 +00:00
|
|
|
|
2010-01-04 17:47:09 +00:00
|
|
|
/**
|
|
|
|
* Wraps html code returned by the allocator init() method
|
|
|
|
*
|
|
|
|
* Supplied argument can be either integer status code or an array of string messages. Messages
|
|
|
|
* in a array can have optional prefix or prefixes, using '::' as delimiter. Prefixes determine
|
|
|
|
* the type of the message and may influence its visualisation.
|
|
|
|
*
|
|
|
|
* @param mixed $result int|array returned by init()
|
2010-01-04 17:48:33 +00:00
|
|
|
* @return string html to be echoed
|
2010-01-04 17:47:09 +00:00
|
|
|
*/
|
|
|
|
public function allocation_init_result($result='') {
|
2010-01-04 17:55:02 +00:00
|
|
|
$msg = new stdClass();
|
2010-01-04 18:00:54 +00:00
|
|
|
if ($result === workshop::ALLOCATION_ERROR) {
|
2010-01-04 17:59:34 +00:00
|
|
|
$msg = (object)array('text' => get_string('allocationerror', 'workshop'), 'sty' => 'error');
|
2010-01-04 17:47:09 +00:00
|
|
|
} else {
|
2010-01-04 17:59:34 +00:00
|
|
|
$msg = (object)array('text' => get_string('allocationdone', 'workshop'), 'sty' => 'ok');
|
2010-01-04 17:47:09 +00:00
|
|
|
}
|
|
|
|
$o = $this->status_message($msg);
|
|
|
|
if (is_array($result)) {
|
|
|
|
$o .= $this->output->output_start_tag('ul', array('class' => 'allocation-init-results'));
|
|
|
|
foreach ($result as $message) {
|
|
|
|
$parts = explode('::', $message);
|
|
|
|
$text = array_pop($parts);
|
|
|
|
$class = implode(' ', $parts);
|
2010-01-04 17:47:32 +00:00
|
|
|
if (in_array('debug', $parts) && !debugging('', DEBUG_DEVELOPER)) {
|
|
|
|
// do not display allocation debugging messages
|
|
|
|
continue;
|
|
|
|
}
|
2010-01-04 17:47:09 +00:00
|
|
|
$o .= $this->output->output_tag('li', array('class' => $class), $text);
|
|
|
|
}
|
|
|
|
$o .= $this->output->output_end_tag('ul');
|
|
|
|
$o .= $this->output->continue_button($this->page->url->out());
|
|
|
|
}
|
|
|
|
return $o;
|
|
|
|
}
|
2010-01-04 17:46:33 +00:00
|
|
|
|
2010-01-04 17:48:33 +00:00
|
|
|
/**
|
|
|
|
* Displays the submission fulltext
|
|
|
|
*
|
|
|
|
* By default, this looks similar to a forum post.
|
|
|
|
*
|
2010-01-04 17:54:23 +00:00
|
|
|
* @param stdClass $submission The submission record
|
2010-01-04 17:48:33 +00:00
|
|
|
* @param bool $showauthorname Should the author name be displayed
|
2010-01-04 17:54:23 +00:00
|
|
|
* @param stdClass $author If author's name should be displayed, this object contains the author data
|
2010-01-04 17:48:33 +00:00
|
|
|
* @return string html to be echoed
|
|
|
|
*/
|
2010-01-04 17:54:23 +00:00
|
|
|
public function submission_full(stdClass $submission, $showauthorname=false, stdClass $author=null) {
|
2010-01-04 17:48:33 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$o = ''; // output code
|
|
|
|
$at = array('class' => 'submission-full');
|
|
|
|
if (!$showauthorname || !$author) {
|
|
|
|
$at['class'] .= ' anonymous';
|
|
|
|
}
|
|
|
|
$o .= $this->output->output_start_tag('div', $at); //+
|
|
|
|
$o .= $this->output->output_start_tag('div', array('class' => 'header')); //++
|
|
|
|
$o .= $this->output->heading(format_string($submission->title), 3, 'title');
|
|
|
|
if ($showauthorname && $author) {
|
|
|
|
$o .= $this->output->output_start_tag('div', array('class' => 'author')); //+++
|
2010-01-04 17:51:22 +00:00
|
|
|
$userpic = new moodle_user_picture();
|
2010-01-04 17:48:33 +00:00
|
|
|
$userpic->user = $author;
|
|
|
|
$userpic->courseid = $this->page->course->id;
|
|
|
|
$userpic->url = true;
|
|
|
|
$userpic->size = 64;
|
|
|
|
$userpic = $this->output->user_picture($userpic);
|
|
|
|
$userurl = new moodle_url($CFG->wwwroot . '/user/view.php',
|
|
|
|
array('id' => $author->id, 'course' => $this->page->course->id));
|
2010-01-04 17:55:02 +00:00
|
|
|
$a = new stdClass();
|
2010-01-04 17:48:33 +00:00
|
|
|
$a->name = fullname($author);
|
|
|
|
$a->url = $userurl->out();
|
|
|
|
$byfullname = get_string('byfullname', 'workshop', $a);
|
|
|
|
$o .= $this->output->output_tag('div', array('class' => 'picture'), $userpic);
|
|
|
|
$o .= $this->output->output_tag('div', array('class' => 'fullname'), $byfullname);
|
|
|
|
$o .= $this->output->output_end_tag('div'); // end of author //++
|
|
|
|
}
|
|
|
|
$created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
|
|
|
|
$o .= $this->output->output_tag('div', array('class' => 'userdate created'), $created);
|
|
|
|
if ($submission->timemodified > $submission->timecreated) {
|
|
|
|
$modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
|
|
|
|
$o .= $this->output->output_tag('div', array('class' => 'userdate modified'), $modified);
|
|
|
|
}
|
|
|
|
$o .= $this->output->output_end_tag('div'); // end of header //+
|
|
|
|
|
|
|
|
$content = format_text($submission->content, $submission->contentformat);
|
|
|
|
$content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
|
|
|
|
'workshop_submission_content', $submission->id);
|
|
|
|
$o .= $this->output->output_tag('div', array('class' => 'content'), $content);
|
|
|
|
|
|
|
|
$o .= $this->submission_attachments($submission);
|
|
|
|
|
|
|
|
$o .= $this->output->output_end_tag('div'); // end of submission-full //
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-01-04 17:54:23 +00:00
|
|
|
* @param stdClass $submission Submission record
|
2010-01-04 17:48:33 +00:00
|
|
|
* @param string format The format of the returned string
|
|
|
|
* @return string HTML code to be echoed
|
|
|
|
*/
|
2010-01-04 17:54:23 +00:00
|
|
|
public function submission_attachments(stdClass $submission, $format=null) {
|
2010-01-04 17:48:33 +00:00
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
$ctx = $this->page->context;
|
|
|
|
$files = $fs->get_area_files($ctx->id, 'workshop_submission_attachment', $submission->id);
|
|
|
|
|
|
|
|
$outputimgs = ""; // images to be displayed inline
|
|
|
|
$outputfiles = ""; // list of attachment files
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file->is_directory()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$filename = $file->get_filename();
|
|
|
|
$fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php',
|
|
|
|
'/' . $ctx->id . '/workshop_submission_attachment/' . $submission->id . '/' . $filename, true);
|
|
|
|
$type = $file->get_mimetype();
|
|
|
|
$type = mimeinfo_from_type("type", $type);
|
|
|
|
$icon = new html_image();
|
|
|
|
$icon->src = $this->output->old_icon_url(file_mimetype_icon($type));
|
|
|
|
$icon->set_classes('icon');
|
|
|
|
$icon->alt = $type;
|
|
|
|
$image = $this->output->image($icon);
|
|
|
|
|
|
|
|
$linkhtml = $this->output->link($fileurl, $image) . $this->output->link($fileurl, $filename);
|
|
|
|
$linktxt = "$filename [$fileurl]";
|
|
|
|
|
|
|
|
if ($format == "html") {
|
|
|
|
// this is the same as the code in the last else-branch
|
|
|
|
$outputfiles .= $this->output->output_tag('li', array('class' => $type), $linkhtml);
|
|
|
|
|
|
|
|
} else if ($format == "text") {
|
|
|
|
$outputfiles .= $linktxt . "\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
|
|
|
|
$preview = new html_image();
|
|
|
|
$preview->src = $fileurl;
|
|
|
|
$preview->set_classes('preview');
|
|
|
|
$preview = $this->output->image($preview);
|
|
|
|
$preview = $this->output->link($fileurl, $preview);
|
|
|
|
$outputimgs .= $this->output->output_tag('div', array(), $preview);
|
|
|
|
} else {
|
|
|
|
// this is the same as the code in html if-branch
|
|
|
|
$outputfiles .= $this->output->output_tag('li', array('class' => $type), $linkhtml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($outputimgs) {
|
|
|
|
$outputimgs = $this->output->output_tag('div', array('class' => 'images'), $outputimgs);
|
|
|
|
}
|
|
|
|
if ($format !== "text") {
|
|
|
|
$outputfiles = $this->output->output_tag('ul', array('class' => 'files'), $outputfiles);
|
|
|
|
}
|
|
|
|
return $this->output->output_tag('div', array('class' => 'attachments'), $outputimgs . $outputfiles);
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:00:54 +00:00
|
|
|
/**
|
|
|
|
* TODO: short description.
|
|
|
|
*
|
|
|
|
* @param array $plan
|
|
|
|
* @return TODO
|
|
|
|
*/
|
|
|
|
public function user_plan(array $plan) {
|
|
|
|
if (empty($plan)) {
|
|
|
|
throw new coding_exception('you must provide the prepared user plan to be rendered');
|
|
|
|
}
|
|
|
|
$table = new html_table();
|
|
|
|
$table->set_classes('userplan');
|
|
|
|
$table->head = array();
|
|
|
|
$table->colclasses = array();
|
|
|
|
$row = new html_table_row();
|
|
|
|
$row->set_classes('phasetasks');
|
|
|
|
foreach ($plan as $phasecode => $phase) {
|
|
|
|
$table->head[] = $this->output->container($this->output->output_tag('span', array(), $phase->title));
|
|
|
|
$classes = 'phase' . $phasecode;
|
|
|
|
if ($phase->active) {
|
|
|
|
$classes .= ' active';
|
|
|
|
} else {
|
|
|
|
$classes .= ' nonactive';
|
|
|
|
}
|
|
|
|
$table->colclasses[] = $classes;
|
|
|
|
$cell = new html_table_cell();
|
|
|
|
$cell->text = $this->user_plan_tasks($phase->tasks);
|
|
|
|
$row->cells[] = $cell;
|
|
|
|
}
|
|
|
|
$table->data = array($row);
|
|
|
|
|
|
|
|
return $this->output->table($table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: short description.
|
|
|
|
*
|
|
|
|
* @param stdClass $tasks
|
|
|
|
* @return TODO
|
|
|
|
*/
|
|
|
|
protected function user_plan_tasks(array $tasks) {
|
|
|
|
$out = '';
|
|
|
|
foreach ($tasks as $taskcode => $task) {
|
|
|
|
$classes = '';
|
|
|
|
$icon = null;
|
|
|
|
if ($task->completed === true) {
|
|
|
|
$classes .= ' completed';
|
|
|
|
} elseif ($task->completed === false) {
|
2010-01-04 18:01:05 +00:00
|
|
|
$classes .= ' fail';
|
|
|
|
} elseif ($task->completed === 'info') {
|
|
|
|
$classes .= ' info';
|
|
|
|
}
|
|
|
|
if (is_null($task->link)) {
|
|
|
|
$title = $task->title;
|
2010-01-04 18:00:54 +00:00
|
|
|
} else {
|
2010-01-04 18:01:05 +00:00
|
|
|
$link = new html_link();
|
|
|
|
$link->url = $task->link;
|
|
|
|
$link->text = $task->title;
|
|
|
|
$title = $this->output->link($link);
|
2010-01-04 18:00:54 +00:00
|
|
|
}
|
2010-01-04 18:01:05 +00:00
|
|
|
$title = $this->output->container($title, 'title');
|
|
|
|
$details = $this->output->container($task->details, 'details');
|
|
|
|
$out .= $this->output->output_tag('li', array('class' => $classes), $title . $details);
|
2010-01-04 18:00:54 +00:00
|
|
|
}
|
|
|
|
if ($out) {
|
|
|
|
$out = $this->output->output_tag('ul', array('class' => 'tasks'), $out);
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2010-01-04 17:46:33 +00:00
|
|
|
}
|