MDL-22507 workshop rendering fixed for submissions and example submissions
authorDavid Mudrak <david.mudrak@gmail.com>
Wed, 20 Oct 2010 13:12:31 +0000 (13:12 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Wed, 20 Oct 2010 13:12:31 +0000 (13:12 +0000)
mod/workshop/assessment.php
mod/workshop/exassessment.php
mod/workshop/excompare.php
mod/workshop/exsubmission.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/styles.css
mod/workshop/submission.php
mod/workshop/view.php

index 994c6e7..1e65f78 100644 (file)
@@ -89,18 +89,18 @@ if ($assessmenteditable and $workshop->useexamples and $workshop->examplesmode =
     if (!$reviewersubmission) {
         // no money, no love
         $assessmenteditable = false;
-        echo $OUTPUT->header();
-        echo $OUTPUT->heading(get_string('exampleneedsubmission', 'workshop'), 2);
-        echo $OUTPUT->footer();
+        echo $output->header();
+        echo $output->heading(get_string('exampleneedsubmission', 'workshop'), 2);
+        echo $output->footer();
         exit;
     } else {
         $examples = $workshop->get_examples_for_reviewer($assessment->reviewerid);
         foreach ($examples as $exampleid => $example) {
             if (is_null($example->grade)) {
                 $assessmenteditable = false;
-                echo $OUTPUT->header();
-                echo $OUTPUT->heading(get_string('exampleneedassessed', 'workshop'), 2);
-                echo $OUTPUT->footer();
+                echo $output->header();
+                echo $output->heading(get_string('exampleneedassessed', 'workshop'), 2);
+                echo $output->footer();
                 exit;
             }
         }
@@ -160,12 +160,12 @@ if ($canoverridegrades or $cansetassessmentweight) {
 }
 
 // output starts here
-echo $OUTPUT->header();
-echo $OUTPUT->heading(get_string('assessedsubmission', 'workshop'), 2);
+$output = $PAGE->get_renderer('mod_workshop');      // workshop renderer
+echo $output->header();
+echo $output->heading(get_string('assessedsubmission', 'workshop'), 2);
 
-$wsoutput = $PAGE->get_renderer('mod_workshop');      // workshop renderer
 $submission = $workshop->get_submission_by_id($submission->id);     // reload so can be passed to the renderer
-echo $wsoutput->submission_full($submission, has_capability('mod/workshop:viewauthornames', $workshop->context));
+echo $output->render($workshop->prepare_submission($submission, has_capability('mod/workshop:viewauthornames', $workshop->context)));
 
 // show instructions for assessing as they may contain important information
 // for evaluating the assessment
@@ -173,28 +173,28 @@ if (trim($workshop->instructreviewers)) {
     $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
         'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
     print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
-    echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
+    echo $output->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
     print_collapsible_region_end();
 }
 
 if ($isreviewer) {
-    echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentbyyourself', 'workshop'), 2);
 } elseif (has_capability('mod/workshop:viewreviewernames', $workshop->context)) {
     $assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
     $reviewer   = new stdclass();
     $reviewer->firstname = $assessment->reviewerfirstname;
     $reviewer->lastname = $assessment->reviewerlastname;
-    echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
+    echo $output->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
 } else {
-    echo $OUTPUT->heading(get_string('assessmentbyunknown', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentbyunknown', 'workshop'), 2);
 }
 
 if ($mform) {
     $mform->display();
 } else {
-    echo $OUTPUT->heading(get_string('notassessed', 'workshop'));
+    echo $output->heading(get_string('notassessed', 'workshop'));
 }
 if ($canoverridegrades) {
     $feedbackform->display();
 }
-echo $OUTPUT->footer();
+echo $output->footer();
index 7008015..6875191 100644 (file)
@@ -89,12 +89,12 @@ if ($mform->is_cancelled()) {
 }
 
 // output starts here
-echo $OUTPUT->header();
-echo $OUTPUT->heading(get_string('assessedexample', 'workshop'), 2);
+$output = $PAGE->get_renderer('mod_workshop');      // workshop renderer
+echo $output->header();
+echo $output->heading(get_string('assessedexample', 'workshop'), 2);
 
-$wsoutput = $PAGE->get_renderer('mod_workshop');      // workshop renderer
 $example = $workshop->get_example_by_id($example->id);     // reload so can be passed to the renderer
-echo $wsoutput->example_full($example);
+echo $output->render($workshop->prepare_example_submission(($example)));
 
 // show instructions for assessing as thay may contain important information
 // for evaluating the assessment
@@ -102,21 +102,21 @@ if (trim($workshop->instructreviewers)) {
     $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
         'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
     print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
-    echo $OUTPUT->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
+    echo $output->box(format_text($instructions, $workshop->instructreviewersformat), array('generalbox', 'instructions'));
     print_collapsible_region_end();
 }
 
 if ($canmanage) {
-    echo $OUTPUT->heading(get_string('assessmentreference', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentreference', 'workshop'), 2);
 } elseif ($isreviewer) {
-    echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentbyyourself', 'workshop'), 2);
 } else {
     $assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
     $reviewer   = new stdclass();
     $reviewer->firstname = $assessment->reviewerfirstname;
     $reviewer->lastname = $assessment->reviewerlastname;
-    echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
+    echo $output->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
 }
 
 $mform->display();
-echo $OUTPUT->footer();
+echo $output->footer();
index 86e88d7..5662860 100644 (file)
@@ -70,41 +70,41 @@ if ($canmanage) {
 $PAGE->set_title($workshop->name);
 $PAGE->set_heading($course->fullname);
 $PAGE->navbar->add(get_string('examplecomparing', 'workshop'));
-$wsoutput = $PAGE->get_renderer('mod_workshop');
 
 // Output starts here
-echo $OUTPUT->header();
-echo $OUTPUT->heading(get_string('assessedexample', 'workshop'), 2);
+$output = $PAGE->get_renderer('mod_workshop');
+echo $output->header();
+echo $output->heading(get_string('assessedexample', 'workshop'), 2);
 
-echo $wsoutput->example_full($example, true);
+echo $output->render($workshop->prepare_example_submission($example));
 
 if (!empty($mformreference)) {
-    echo $OUTPUT->heading(get_string('assessmentreference', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentreference', 'workshop'), 2);
     $a = new stdclass();
     $a->received = $workshop->real_grade($reference->grade);
     $a->max = $workshop->real_grade(100);
-    echo $OUTPUT->heading(get_string('gradeinfo', 'workshop' , $a), 3);
+    echo $output->heading(get_string('gradeinfo', 'workshop' , $a), 3);
     $mformreference->display();
 }
 
 if ($isreviewer) {
-    echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentbyyourself', 'workshop'), 2);
 } elseif ($canmanage) {
     $reviewer   = new stdclass();
     $reviewer->firstname = $assessment->reviewerfirstname;
     $reviewer->lastname = $assessment->reviewerlastname;
-    echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
+    echo $output->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
 }
 $a = new stdclass();
 $a->received = $workshop->real_grade($assessment->grade);
 $a->max = $workshop->real_grade(100);
-echo $OUTPUT->heading(get_string('gradeinfo', 'workshop' , $a), 3);
+echo $output->heading(get_string('gradeinfo', 'workshop' , $a), 3);
 $mformassessment->display();
-echo $OUTPUT->container_start('buttonsbar');
+echo $output->container_start('buttonsbar');
 if ($isreviewer and $workshop->assessing_examples_allowed()) {
     $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey()));
-    echo $OUTPUT->single_button($aurl, get_string('reassess', 'workshop'), 'get');
+    echo $output->single_button($aurl, get_string('reassess', 'workshop'), 'get');
 }
-echo $OUTPUT->container_end(); // buttonsbar
+echo $output->container_end(); // buttonsbar
 
-echo $OUTPUT->footer();
+echo $output->footer();
index 5354f10..3f64d38 100644 (file)
@@ -166,8 +166,9 @@ if ($edit) {
 }
 
 // Output starts here
-echo $OUTPUT->header();
-echo $OUTPUT->heading(format_string($workshop->name), 2);
+$output = $PAGE->get_renderer('mod_workshop');
+echo $output->header();
+echo $output->heading(format_string($workshop->name), 2);
 
 // show instructions for submitting as they may contain some list of questions and we need to know them
 // while reading the submitted answer
@@ -175,47 +176,46 @@ if (trim($workshop->instructauthors)) {
     $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
         'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
     print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
-    echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
+    echo $output->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
     print_collapsible_region_end();
 }
 
 // if in edit mode, display the form to edit the example
 if ($edit and $canmanage) {
     $mform->display();
-    echo $OUTPUT->footer();
+    echo $output->footer();
     die();
 }
 
 // else display the example...
 if ($example->id) {
     if ($canmanage and $delete) {
-    echo $OUTPUT->confirm(get_string('exampledeleteconfirm', 'workshop'),
+    echo $output->confirm(get_string('exampledeleteconfirm', 'workshop'),
             new moodle_url($PAGE->url, array('delete' => 1, 'confirm' => 1)), $workshop->view_url());
     }
     if ($canmanage and !$delete and !$DB->record_exists_select('workshop_assessments',
             'grade IS NOT NULL AND weight=1 AND submissionid = ?', array($example->id))) {
-        echo $OUTPUT->confirm(get_string('assessmentreferenceneeded', 'workshop'),
+        echo $output->confirm(get_string('assessmentreferenceneeded', 'workshop'),
                 new moodle_url($PAGE->url, array('assess' => 1)), $workshop->view_url());
     }
-    $wsoutput = $PAGE->get_renderer('mod_workshop');
-    echo $wsoutput->example_full($example, true);
+    echo $output->render($workshop->prepare_example_submission($example));
 }
 // ...with an option to edit or remove it
-echo $OUTPUT->container_start('buttonsbar');
+echo $output->container_start('buttonsbar');
 if ($canmanage) {
     if (empty($edit) and empty($delete)) {
         $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('edit' => 'on'));
-        echo $OUTPUT->single_button($aurl, get_string('exampleedit', 'workshop'), 'get');
+        echo $output->single_button($aurl, get_string('exampleedit', 'workshop'), 'get');
 
         $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('delete' => 'on'));
-        echo $OUTPUT->single_button($aurl, get_string('exampledelete', 'workshop'), 'get');
+        echo $output->single_button($aurl, get_string('exampledelete', 'workshop'), 'get');
     }
 }
 // ...and optionally assess it
 if ($canassess or ($canmanage and empty($edit) and empty($delete))) {
     $aurl = new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey()));
-    echo $OUTPUT->single_button($aurl, get_string('exampleassess', 'workshop'), 'get');
+    echo $output->single_button($aurl, get_string('exampleassess', 'workshop'), 'get');
 }
-echo $OUTPUT->container_end(); // buttonsbar
+echo $output->container_end(); // buttonsbar
 // and possibly display the example's review(s) - todo
-echo $OUTPUT->footer();
+echo $output->footer();
index d3e6da8..e678163 100644 (file)
@@ -599,7 +599,7 @@ class workshop {
         global $DB;
 
         $sql = 'SELECT s.id, s.title,
-                       a.id AS assessmentid, a.weight, a.grade, a.gradinggrade
+                       a.id AS assessmentid, a.grade, a.gradinggrade
                   FROM {workshop_submissions} s
              LEFT JOIN {workshop_assessments} a ON (a.submissionid = s.id AND a.weight = 1)
                  WHERE s.example = 1 AND s.workshopid = :workshopid
@@ -621,7 +621,7 @@ class workshop {
             return false;
         }
         $sql = 'SELECT s.id, s.title,
-                       a.id AS assessmentid, a.weight, a.grade, a.gradinggrade
+                       a.id AS assessmentid, a.grade, a.gradinggrade
                   FROM {workshop_submissions} s
              LEFT JOIN {workshop_assessments} a ON (a.submissionid = s.id AND a.reviewerid = :reviewerid AND a.weight = 0)
                  WHERE s.example = 1 AND s.workshopid = :workshopid
@@ -630,29 +630,75 @@ class workshop {
     }
 
     /**
-     * Prepares component containing summary of given example to be rendered
+     * Prepares renderable submission component
+     *
+     * @param stdClass $record required by {@see workshop_submission}
+     * @param bool $showauthor show the author-related information
+     * @return workshop_submission
+     */
+    public function prepare_submission(stdClass $record, $showauthor = false) {
+
+        $submission         = new workshop_submission($record, $showauthor);
+        $submission->url    = $this->submission_url($record->id);
+
+        return $submission;
+    }
+
+    /**
+     * Prepares renderable submission summary component
+     *
+     * @param stdClass $record required by {@see workshop_submission_summary}
+     * @param bool $showauthor show the author-related information
+     * @return workshop_submission_summary
+     */
+    public function prepare_submission_summary(stdClass $record, $showauthor = false) {
+
+        $summary        = new workshop_submission_summary($record, $showauthor);
+        $summary->url   = $this->submission_url($record->id);
+
+        return $summary;
+    }
+
+    /**
+     * Prepares renderable example submission component
+     *
+     * @param stdClass $record required by {@see workshop_example_submission}
+     * @return workshop_example_submission
+     */
+    public function prepare_example_submission(stdClass $record) {
+
+        $example = new workshop_example_submission($record);
+
+        return $example;
+    }
+
+    /**
+     * Prepares renderable example submission summary component
+     *
+     * If the example is editable, the caller must set the 'editable' flag explicitly.
      *
      * @param stdClass $example as returned by {@link workshop::get_examples_for_manager()} or {@link workshop::get_examples_for_reviewer()}
-     * @return stdclass component to be rendered
+     * @return workshop_example_submission_summary to be rendered
      */
-    public function prepare_example_summary(stdclass $example) {
+    public function prepare_example_summary(stdClass $example) {
+
+        $summary = new workshop_example_submission_summary($example);
 
-        $summary = new stdclass();
-        $summary->example = $example;
         if (is_null($example->grade)) {
-            $summary->status   = 'notgraded';
-            $buttontext = get_string('assess', 'workshop');
+            $summary->status = 'notgraded';
+            $summary->assesslabel = get_string('assess', 'workshop');
         } else {
-            $summary->status   = 'graded';
-            $buttontext = get_string('reassess', 'workshop');
+            $summary->status = 'graded';
+            $summary->assesslabel = get_string('reassess', 'workshop');
         }
 
         $summary->gradeinfo           = new stdclass();
         $summary->gradeinfo->received = $this->real_grade($example->grade);
         $summary->gradeinfo->max      = $this->real_grade(100);
 
-        $aurl = new moodle_url($this->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey()));
-        $summary->btnform = new single_button($aurl, $buttontext, 'get');
+        $summary->url       = new moodle_url($this->exsubmission_url($example->id));
+        $summary->editurl   = new moodle_url($this->exsubmission_url($example->id), array('edit' => 'on'));
+        $summary->assessurl = new moodle_url($this->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey()));
 
         return $summary;
     }
@@ -1917,6 +1963,10 @@ class workshop {
 
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// Renderable components
+////////////////////////////////////////////////////////////////////////////////
+
 /**
  * Represents the user planner tool
  *
@@ -2299,3 +2349,201 @@ class workshop_user_plan implements renderable {
         return $this->examples;
     }
 }
+
+/**
+ * Common base class for submissions and example submissions rendering
+ *
+ * Subclasses of this class convert raw submission record from
+ * workshop_submissions table (as returned by {@see workshop::get_submission_by_id()}
+ * for example) into renderable objects.
+ */
+abstract class workshop_submission_base {
+
+    /** @var bool is the submission anonymous (ie contains author information) */
+    protected $anonymous;
+
+    /* @var array of columns from workshop_submissions that are assigned as properties */
+    protected $fields = array();
+
+    /**
+     * Copies the properties of the given database record into properties of $this instance
+     *
+     * @param stdClass $submission full record
+     * @param bool $showauthor show the author-related information
+     * @param array $options additional properties
+     */
+    public function __construct(stdClass $submission, $showauthor = false) {
+
+        foreach ($this->fields as $field) {
+            if (!property_exists($submission, $field)) {
+                throw new coding_exception('Submission record must provide public property ' . $field);
+            }
+            if (!property_exists($this, $field)) {
+                throw new coding_exception('Renderable component must accept public property ' . $field);
+            }
+            $this->{$field} = $submission->{$field};
+        }
+
+        if ($showauthor) {
+            $this->anonymous = false;
+        } else {
+            $this->anonymize();
+        }
+    }
+
+    /**
+     * Unsets all author-related properties so that the renderer does not have access to them
+     *
+     * Usually this is called by the contructor but can be called explicitely, too.
+     */
+    public function anonymize() {
+        foreach (array('authorid', 'authorfirstname', 'authorlastname',
+               'authorpicture', 'authorimagealt', 'authoremail') as $field) {
+            unset($this->{$field});
+        }
+        $this->anonymous = true;
+    }
+
+    /**
+     * Does the submission object contain author-related information?
+     *
+     * @return null|boolean
+     */
+    public function is_anonymous() {
+        return $this->anonymous;
+    }
+}
+
+/**
+ * Renderable object containing a basic set of information needed to display the submission summary
+ *
+ * @see workshop_renderer::render_workshop_submission_summary
+ */
+class workshop_submission_summary extends workshop_submission_base implements renderable {
+
+    /** @var int */
+    public $id;
+    /** @var string */
+    public $title;
+    /** @var string graded|notgraded */
+    public $status;
+    /** @var int */
+    public $timecreated;
+    /** @var int */
+    public $timemodified;
+    /** @var int */
+    public $authorid;
+    /** @var string */
+    public $authorfirstname;
+    /** @var string */
+    public $authorlastname;
+    /** @var int */
+    public $authorpicture;
+    /** @var string */
+    public $authorimagealt;
+    /** @var string */
+    public $authoremail;
+    /** @var moodle_url to display submission */
+    public $url;
+
+    /**
+     * @var array of columns from workshop_submissions that are assigned as properties
+     * of instances of this class
+     */
+    protected $fields = array(
+        'id', 'title', 'timecreated', 'timemodified',
+        'authorid', 'authorfirstname', 'authorlastname', 'authorpicture',
+        'authorimagealt', 'authoremail');
+}
+
+/**
+ * Renderable object containing all the information needed to display the submission
+ *
+ * @see workshop_renderer::render_workshop_submission()
+ */
+class workshop_submission extends workshop_submission_summary implements renderable {
+
+    /** @var string */
+    public $content;
+    /** @var int */
+    public $contentformat;
+    /** @var bool */
+    public $contenttrust;
+    /** @var array */
+    public $attachment;
+
+    /**
+     * @var array of columns from workshop_submissions that are assigned as properties
+     * of instances of this class
+     */
+    protected $fields = array(
+        'id', 'title', 'timecreated', 'timemodified', 'content', 'contentformat', 'contenttrust',
+        'attachment', 'authorid', 'authorfirstname', 'authorlastname', 'authorpicture',
+        'authorimagealt', 'authoremail');
+}
+
+/**
+ * Renderable object containing a basic set of information needed to display the example submission summary
+ *
+ * @see workshop::prepare_example_summary()
+ * @see workshop_renderer::render_workshop_example_submission_summary()
+ */
+class workshop_example_submission_summary extends workshop_submission_base implements renderable {
+
+    /** @var int */
+    public $id;
+    /** @var string */
+    public $title;
+    /** @var string graded|notgraded */
+    public $status;
+    /** @var stdClass */
+    public $gradeinfo;
+    /** @var moodle_url */
+    public $url;
+    /** @var moodle_url */
+    public $editurl;
+    /** @var string */
+    public $assesslabel;
+    /** @var moodle_url */
+    public $assessurl;
+    /** @var bool must be set explicitly by the caller */
+    public $editable = false;
+
+    /**
+     * @var array of columns from workshop_submissions that are assigned as properties
+     * of instances of this class
+     */
+    protected $fields = array('id', 'title');
+
+    /**
+     * Example submissions are always anonymous
+     *
+     * @return true
+     */
+    public function is_anonymous() {
+        return true;
+    }
+}
+
+/**
+ * Renderable object containing all the information needed to display the example submission
+ *
+ * @see workshop_renderer::render_workshop_example_submission()
+ */
+class workshop_example_submission extends workshop_example_submission_summary implements renderable {
+
+    /** @var string */
+    public $content;
+    /** @var int */
+    public $contentformat;
+    /** @var bool */
+    public $contenttrust;
+    /** @var array */
+    public $attachment;
+
+    /**
+     * @var array of columns from workshop_submissions that are assigned as properties
+     * of instances of this class
+     */
+    protected $fields = array('id', 'title', 'content', 'contentformat', 'contenttrust', 'attachment');
+}
index ff94d15..9169b35 100644 (file)
@@ -34,87 +34,29 @@ defined('MOODLE_INTERNAL') || die();
  */
 class mod_workshop_renderer extends plugin_renderer_base {
 
-    /**
-     * 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
-     */
-    public function status_message(stdclass $message) {
-        if (empty($message->text)) {
-            return '';
-        }
-        $sty = empty($message->sty) ? 'info' : $message->sty;
-
-        $o = html_writer::tag('span', $message->text);
-        if (isset($message->extra)) {
-            $o .= $message->extra;
-        }
-        return $this->output->container($o, array('status-message', $sty));
-    }
-
-    /**
-     * 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()
-     * @return string html to be echoed
-     */
-    public function allocation_init_result($result='') {
-        $msg = new stdclass();
-        if ($result === workshop::ALLOCATION_ERROR) {
-            $msg = (object)array('text' => get_string('allocationerror', 'workshop'), 'sty' => 'error');
-        } else {
-            $msg = (object)array('text' => get_string('allocationdone', 'workshop'), 'sty' => 'ok');
-        }
-        $o = $this->status_message($msg);
-        if (is_array($result)) {
-            $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
-            foreach ($result as $message) {
-                $parts  = explode('::', $message);
-                $text   = array_pop($parts);
-                $class  = implode(' ', $parts);
-                if (in_array('debug', $parts) && !debugging('', DEBUG_DEVELOPER)) {
-                    // do not display allocation debugging messages
-                    continue;
-                }
-                $o .= html_writer::tag('li', $text, array('class' => $class)) . "\n";
-            }
-            $o .= html_writer::end_tag('ul');
-            $o .= $this->output->continue_button($this->page->url->out());
-        }
-        return $o;
-    }
+    ////////////////////////////////////////////////////////////////////////////
+    // Methods to render workshop renderable components
+    ////////////////////////////////////////////////////////////////////////////
 
     /**
-     * Display a short summary of the submission
+     * Renders full workshop submission
      *
-     * The passed submission object must define at least: id, title, timecreated, timemodified,
-     * authorid, authorfirstname, authorlastname, authorpicture, authorimagealt and email. Optional
-     * property is status (graded, notgraded).
-     *
-     * @param stdClass $submission     The submission record
-     * @param bool     $showauthorname Should the author name be displayed
-     * @return string html to be echoed
+     * @param workshop_submission $submission
+     * @return string HTML
      */
-    public function submission_summary(stdclass $submission, $showauthorname=false) {
-        global $CFG;
+    protected function render_workshop_submission(workshop_submission $submission) {
 
         $o  = '';    // output HTML code
-        $classes = 'submission-summary';
-        if (!$showauthorname) {
+        $anonymous = $submission->is_anonymous();
+        $classes = 'submission-full';
+        if ($anonymous) {
             $classes .= ' anonymous';
         }
-        $o .= $this->output->container_start($classes);  // main wrapper
-        $url = new moodle_url('/mod/workshop/submission.php',
-                              array('cmid' => $this->page->context->instanceid, 'id' => $submission->id));
-        $o .= html_writer::link($url, format_string($submission->title), array('class'=>'title'));
-        if ($showauthorname) {
+        $o .= $this->output->container_start($classes);
+        $o .= $this->output->container_start('header');
+        $o .= $this->output->heading(format_string($submission->title), 3, 'title');
+
+        if (!$anonymous) {
             $author             = new stdclass();
             $author->id         = $submission->authorid;
             $author->firstname  = $submission->authorfirstname;
@@ -122,172 +64,139 @@ class mod_workshop_renderer extends plugin_renderer_base {
             $author->picture    = $submission->authorpicture;
             $author->imagealt   = $submission->authorimagealt;
             $author->email      = $submission->authoremail;
-            $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
+            $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
             $userurl            = new moodle_url('/user/view.php',
                                             array('id' => $author->id, 'course' => $this->page->course->id));
             $a                  = new stdclass();
             $a->name            = fullname($author);
             $a->url             = $userurl->out();
             $byfullname         = get_string('byfullname', 'workshop', $a);
-
             $oo  = $this->output->container($userpic, 'picture');
             $oo .= $this->output->container($byfullname, 'fullname');
+
             $o .= $this->output->container($oo, 'author');
         }
+
         $created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
         $o .= $this->output->container($created, 'userdate created');
+
         if ($submission->timemodified > $submission->timecreated) {
             $modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
             $o .= $this->output->container($modified, 'userdate modified');
         }
-        if (!empty($submission->status)) {
-            if ($submission->status == 'notgraded') {
-                $o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status notgraded');
-            } else {
-                $o .= $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status graded');
-            }
-        }
 
-        $o .= $this->output->container_end(); // end of the main wrapper
+        $o .= $this->output->container_end(); // end of header
+
+        $content = format_text($submission->content, $submission->contentformat);
+        $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
+                                                        'mod_workshop', 'submission_content', $submission->id);
+        $o .= $this->output->container($content, 'content');
+
+        $o .= $this->helper_submission_attachments($submission->id, 'html');
+
+        $o .= $this->output->container_end(); // end of submission-full
 
         return $o;
     }
 
     /**
-     * Displays the submission fulltext
-     *
-     * By default, this looks similar to a forum post.
+     * Renders short summary of the submission
      *
-     * @param stdClass $submission     The submission data
-     * @param bool     $showauthorname Should the author name be displayed
-     * @return string html to be echoed
+     * @param workshop_submission_summary $summary
+     * @return string text to be echo'ed
      */
-    public function submission_full(stdclass $submission, $showauthorname=false) {
-        global $CFG;
+    protected function render_workshop_submission_summary(workshop_submission_summary $summary) {
 
         $o  = '';    // output HTML code
-        $classes = 'submission-full';
-        if (!$showauthorname) {
+        $anonymous = $summary->is_anonymous();
+        $classes = 'submission-summary';
+
+        if ($anonymous) {
             $classes .= ' anonymous';
         }
-        $o .= $this->output->container_start($classes);
-        $o .= $this->output->container_start('header');
-        $o .= $this->output->heading(format_string($submission->title), 3, 'title');
-        if ($showauthorname) {
-            $author             = new stdclass();
-            $author->id         = $submission->authorid;
-            $author->firstname  = $submission->authorfirstname;
-            $author->lastname   = $submission->authorlastname;
-            $author->picture    = $submission->authorpicture;
-            $author->imagealt   = $submission->authorimagealt;
-            $author->email      = $submission->authoremail;
-            $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
+
+        $gradestatus = '';
+
+        if ($summary->status == 'notgraded') {
+            $classes    .= ' notgraded';
+            $gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status');
+
+        } else if ($summary->status == 'graded') {
+            $classes    .= ' graded';
+            $gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status');
+        }
+
+        $o .= $this->output->container_start($classes);  // main wrapper
+        $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
+
+        if (!$anonymous) {
+            $author             = new stdClass();
+            $author->id         = $summary->authorid;
+            $author->firstname  = $summary->authorfirstname;
+            $author->lastname   = $summary->authorlastname;
+            $author->picture    = $summary->authorpicture;
+            $author->imagealt   = $summary->authorimagealt;
+            $author->email      = $summary->authoremail;
+            $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
             $userurl            = new moodle_url('/user/view.php',
                                             array('id' => $author->id, 'course' => $this->page->course->id));
-            $a                  = new stdclass();
+            $a                  = new stdClass();
             $a->name            = fullname($author);
             $a->url             = $userurl->out();
             $byfullname         = get_string('byfullname', 'workshop', $a);
+
             $oo  = $this->output->container($userpic, 'picture');
             $oo .= $this->output->container($byfullname, 'fullname');
-
-            $o .= $this->output->container($oo, 'author');
+            $o  .= $this->output->container($oo, 'author');
         }
-        $created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
+
+        $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated));
         $o .= $this->output->container($created, 'userdate created');
-        if ($submission->timemodified > $submission->timecreated) {
-            $modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
+
+        if ($summary->timemodified > $summary->timecreated) {
+            $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified));
             $o .= $this->output->container($modified, 'userdate modified');
         }
-        $o .= $this->output->container_end(); // end of header
-
-        $content = format_text($submission->content, $submission->contentformat);
-        $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
-                                                        'mod_workshop', 'submission_content', $submission->id);
-        $o .= $this->output->container($content, 'content');
-
-        $o .= $this->submission_attachments($submission);
-
-        $o .= $this->output->container_end(); // end of submission-full
 
+        $o .= $gradestatus;
+        $o .= $this->output->container_end(); // end of the main wrapper
         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.
+     * Renders full workshop example submission
      *
-     * @param stdClass $submission Submission record
-     * @param string format        The format of the returned string
-     * @return string              HTML code to be echoed
+     * @param workshop_example_submission $example
+     * @return string HTML
      */
-    public function submission_attachments(stdclass $submission, $format=null) {
-        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', $submission->id);
+    protected function render_workshop_example_submission(workshop_example_submission $example) {
 
-        $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/' . $submission->id . $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]";
+        $o  = '';    // output HTML code
+        $classes = 'submission-full example';
+        $o .= $this->output->container_start($classes);
+        $o .= $this->output->container_start('header');
+        $o .= $this->output->heading(format_string($example->title), 3, 'title');
+        $o .= $this->output->container_end(); // end of header
 
-            if ($format == "html") {
-                // this is the same as the code in the last else-branch
-                $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
+        $content = format_text($example->content, $example->contentformat);
+        $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
+                                                        'mod_workshop', 'submission_content', $example->id);
+        $o .= $this->output->container($content, 'content');
 
-            } else if ($format == "text") {
-                $outputfiles .= $linktxt . "\n";
+        $o .= $this->helper_submission_attachments($example->id, 'html');
 
-            } else {
-                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 {
-                    // this is the same as the code in html if-branch
-                    $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
-                }
-            }
-        }
+        $o .= $this->output->container_end(); // end of submission-full
 
-        if ($outputimgs) {
-            $outputimgs = $this->output->container($outputimgs, 'images');
-        }
-        if ($format !== "text") {
-            $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
-        }
-        return $this->output->container($outputimgs . $outputfiles, 'attachments');
+        return $o;
     }
 
     /**
-     * Display a short summary of the example submission
-     *
-     * The passed submission object must define at least: id and title
+     * Renders short summary of the example submission
      *
-     * @param stdClass $data prepared by workshop::prepare_example_summary()
-     * @return string html to be echoed
+     * @param workshop_example_submission_summary $summary
+     * @return string text to be echo'ed
      */
-    public function example_summary(stdclass $summary) {
-        global $CFG;
+    protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) {
 
         $o  = '';    // output HTML code
 
@@ -296,15 +205,10 @@ class mod_workshop_renderer extends plugin_renderer_base {
 
         // title
         $o .= $this->output->container_start('example-title');
-        $url = new moodle_url('/mod/workshop/exsubmission.php',
-                              array('cmid' => $this->page->context->instanceid, 'id' => $summary->example->id));
-        $o .= html_writer::link($url, format_string($summary->example->title), array('class'=>'title'));
-
-        // dirty hack to guess if the current user is example manager or not
-        if ($summary->example->weight == 1) {
-            $url = new moodle_url('/mod/workshop/exsubmission.php',
-                                        array('cmid' => $this->page->context->instanceid, 'id' => $summary->example->id, 'edit' => 'on'));
-            $o .= $this->output->action_icon($url, new pix_icon('i/edit', get_string('edit')));
+        $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
+
+        if ($summary->editable) {
+            $o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit')));
         }
         $o .= $this->output->container_end();
 
@@ -316,7 +220,8 @@ class mod_workshop_renderer extends plugin_renderer_base {
         }
 
         // button to assess
-        $o .= $this->output->container($this->output->render($summary->btnform), 'example-actions');
+        $button = new single_button($summary->assessurl, $summary->assesslabel, 'get');
+        $o .= $this->output->container($this->output->render($button), 'example-actions');
 
         // end of wrapping box
         $o .= $this->output->box_end();
@@ -324,42 +229,6 @@ class mod_workshop_renderer extends plugin_renderer_base {
         return $o;
     }
 
-    /**
-     * Displays the example submission fulltext
-     *
-     * By default, this looks similar to a forum post.
-     *
-     * @param stdClass $example        The example submission data
-     * @return string html to be echoed
-     */
-    public function example_full(stdclass $example) {
-        global $CFG;
-
-        $o  = '';    // output HTML code
-        $classes = 'submission-full example';
-        $o .= $this->output->container_start($classes);
-        $o .= $this->output->container_start('header');
-        $o .= $this->output->heading(format_string($example->title), 3, 'title');
-        $created = get_string('userdatecreated', 'workshop', userdate($example->timecreated));
-        $o .= $this->output->container($created, 'userdate created');
-        if ($example->timemodified > $example->timecreated) {
-            $modified = get_string('userdatemodified', 'workshop', userdate($example->timemodified));
-            $o .= $this->output->container($modified, 'userdate modified');
-        }
-        $o .= $this->output->container_end(); // end of header
-
-        $content = format_text($example->content, $example->contentformat);
-        $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
-                                                        'mod_workshop', 'submission_content', $example->id);
-        $o .= $this->output->container($content, 'content');
-
-        $o .= $this->submission_attachments($example);
-
-        $o .= $this->output->container_end(); // end of example-full
-
-        return $o;
-    }
-
     /**
      * Renders the user plannner tool
      *
@@ -395,7 +264,7 @@ class mod_workshop_renderer extends plugin_renderer_base {
             }
             $table->colclasses[] = $classes;
             $cell = new html_table_cell();
-            $cell->text = $this->user_plan_tasks($phase->tasks);
+            $cell->text = $this->helper_user_plan_tasks($phase->tasks);
             $row->cells[] = $cell;
         }
         $table->data = array($row);
@@ -403,13 +272,85 @@ class mod_workshop_renderer extends plugin_renderer_base {
         return html_writer::table($table);
     }
 
+    ////////////////////////////////////////////////////////////////////////////
+    // 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 user_plan_tasks(array $tasks) {
+    protected function helper_user_plan_tasks(array $tasks) {
         $out = '';
         foreach ($tasks as $taskcode => $task) {
             $classes = '';
@@ -436,6 +377,68 @@ class mod_workshop_renderer extends plugin_renderer_base {
         return $out;
     }
 
+
+    ////////////////////////////////////////////////////////////////////////////
+    // TODO Obsolete
+    //
+
+    /**
+     * 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
+     */
+    public function status_message(stdclass $message) {
+        if (empty($message->text)) {
+            return '';
+        }
+        $sty = empty($message->sty) ? 'info' : $message->sty;
+
+        $o = html_writer::tag('span', $message->text);
+        if (isset($message->extra)) {
+            $o .= $message->extra;
+        }
+        return $this->output->container($o, array('status-message', $sty));
+    }
+
+    /**
+     * 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()
+     * @return string html to be echoed
+     */
+    public function allocation_init_result($result='') {
+        $msg = new stdclass();
+        if ($result === workshop::ALLOCATION_ERROR) {
+            $msg = (object)array('text' => get_string('allocationerror', 'workshop'), 'sty' => 'error');
+        } else {
+            $msg = (object)array('text' => get_string('allocationdone', 'workshop'), 'sty' => 'ok');
+        }
+        $o = $this->status_message($msg);
+        if (is_array($result)) {
+            $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
+            foreach ($result as $message) {
+                $parts  = explode('::', $message);
+                $text   = array_pop($parts);
+                $class  = implode(' ', $parts);
+                if (in_array('debug', $parts) && !debugging('', DEBUG_DEVELOPER)) {
+                    // do not display allocation debugging messages
+                    continue;
+                }
+                $o .= html_writer::tag('li', $text, array('class' => $class)) . "\n";
+            }
+            $o .= html_writer::end_tag('ul');
+            $o .= $this->output->continue_button($this->page->url->out());
+        }
+        return $o;
+    }
+
     /**
      * Renders the workshop grading report
      *
index 51b0b30..d466416 100644 (file)
@@ -91,6 +91,7 @@
 
 .path-mod-workshop .submission-full .header .userdate.modified {
     padding-left: 10px;
+    margin-left: 0px;
     border-left: 1px solid #000;
 }
 
 /**
  * Example submission - full display
  */
-.path-mod-workshop .submission-full.example .header .title,
-.path-mod-workshop .submission-full.example .header .userdate {
+.path-mod-workshop .submission-full.example .header {
+    min-height: 0px;
+}
+
+.path-mod-workshop .submission-full.example .header .title {
     margin: 0px 0px 0px 0px;
 }
 
index 8fbbd5f..e7d5ab8 100644 (file)
@@ -210,8 +210,9 @@ if ($edit) {
 }
 
 // Output starts here
-echo $OUTPUT->header();
-echo $OUTPUT->heading(format_string($workshop->name), 2);
+$output = $PAGE->get_renderer('mod_workshop');
+echo $output->header();
+echo $output->heading(format_string($workshop->name), 2);
 
 // show instructions for submitting as thay may contain some list of questions and we need to know them
 // while reading the submitted answer
@@ -219,7 +220,7 @@ if (trim($workshop->instructauthors)) {
     $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
         'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
     print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
-    echo $OUTPUT->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
+    echo $output->box(format_text($instructions, $workshop->instructauthorsformat), array('generalbox', 'instructions'));
     print_collapsible_region_end();
 }
 
@@ -227,17 +228,16 @@ if (trim($workshop->instructauthors)) {
 
 if ($edit) {
     $mform->display();
-    echo $OUTPUT->footer();
+    echo $output->footer();
     die();
 }
 
 // else display the submission
 
 if ($submission->id) {
-    $wsoutput = $PAGE->get_renderer('mod_workshop');
-    echo $wsoutput->submission_full($submission, has_capability('mod/workshop:viewauthornames', $workshop->context));
+    echo $output->render($workshop->prepare_submission($submission, has_capability('mod/workshop:viewauthornames', $workshop->context)));
 } else {
-    echo $OUTPUT->box(get_string('noyoursubmission', 'workshop'));
+    echo $output->box(get_string('noyoursubmission', 'workshop'));
 }
 
 if ($editable) {
@@ -248,12 +248,12 @@ if ($editable) {
         $btnurl = new moodle_url($PAGE->url, array('edit' => 'on'));
         $btntxt = get_string('createsubmission', 'workshop');
     }
-    echo $OUTPUT->single_button($btnurl, $btntxt, 'get');
+    echo $output->single_button($btnurl, $btntxt, 'get');
 }
 
 if ($submission->id and !$edit and !$isreviewer and $canallocate and $workshop->assessing_allowed()) {
     $url = new moodle_url($PAGE->url, array('assess' => 1));
-    echo $OUTPUT->single_button($url, get_string('assess', 'workshop'), 'post');
+    echo $output->single_button($url, get_string('assess', 'workshop'), 'post');
 }
 
 // and possibly display the submission's review(s)
@@ -261,24 +261,24 @@ if ($submission->id and !$edit and !$isreviewer and $canallocate and $workshop->
 if ($isreviewer) {
     $strategy = $workshop->grading_strategy_instance();
     $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $userassessment, false);
-    echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
+    echo $output->heading(get_string('assessmentbyyourself', 'workshop'), 2);
     // reviewers can always see the grades they gave even they are not available yet
     if (is_null($userassessment->grade)) {
-        echo $OUTPUT->heading(get_string('notassessed', 'workshop'), 3);
+        echo $output->heading(get_string('notassessed', 'workshop'), 3);
         if ($workshop->assessing_allowed()) {
-            echo $OUTPUT->container($OUTPUT->single_button($workshop->assess_url($userassessment->id), get_string('assess', 'workshop'), 'get'),
+            echo $output->container($output->single_button($workshop->assess_url($userassessment->id), get_string('assess', 'workshop'), 'get'),
                     array('class' => 'buttonsbar'));
         }
     } else {
         $a = new stdclass();
         $a->max = $workshop->real_grade(100);
         $a->received = $workshop->real_grade($userassessment->grade);
-        echo $OUTPUT->heading(get_string('gradeinfo', 'workshop', $a), 3);
+        echo $output->heading(get_string('gradeinfo', 'workshop', $a), 3);
         if ($userassessment->weight != 1) {
-            echo $OUTPUT->heading(get_string('weightinfo', 'workshop', $userassessment->weight), 3);
+            echo $output->heading(get_string('weightinfo', 'workshop', $userassessment->weight), 3);
         }
         if ($workshop->assessing_allowed()) {
-            echo $OUTPUT->container($OUTPUT->single_button($workshop->assess_url($userassessment->id), get_string('reassess', 'workshop'), 'get'),
+            echo $output->container($output->single_button($workshop->assess_url($userassessment->id), get_string('reassess', 'workshop'), 'get'),
                     array('class' => 'buttonsbar'));
         }
         $mform->display();
@@ -302,19 +302,19 @@ if (has_capability('mod/workshop:viewallassessments', $workshop->context) or ($o
             $reviewer = new stdclass();
             $reviewer->firstname = $assessment->reviewerfirstname;
             $reviewer->lastname = $assessment->reviewerlastname;
-            echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
+            echo $output->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
         } else {
-            echo $OUTPUT->heading(get_string('assessmentbyunknown', 'workshop'), 2);
+            echo $output->heading(get_string('assessmentbyunknown', 'workshop'), 2);
         }
         $a = new stdclass();
         $a->max = $workshop->real_grade(100);
         $a->received = $workshop->real_grade($assessment->grade);
-        echo $OUTPUT->heading(get_string('gradeinfo', 'workshop', $a), 3);
+        echo $output->heading(get_string('gradeinfo', 'workshop', $a), 3);
         if ($assessment->weight != 1) {
-            echo $OUTPUT->heading(get_string('weightinfo', 'workshop', $assessment->weight), 3);
+            echo $output->heading(get_string('weightinfo', 'workshop', $assessment->weight), 3);
         }
         if (has_capability('mod/workshop:overridegrades', $workshop->context)) {
-            echo $OUTPUT->container($OUTPUT->single_button($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'), 'get'),
+            echo $output->container($output->single_button($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'), 'get'),
                     array('class' => 'buttonsbar'));
         }
         $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false);
@@ -327,4 +327,4 @@ if (!$edit and $canoverride) {
     $feedbackform->display();
 }
 
-echo $OUTPUT->footer();
+echo $output->footer();
index 4534ddb..9db9bd4 100644 (file)
@@ -83,7 +83,8 @@ case workshop::PHASE_SETUP:
             }
             foreach ($examples as $example) {
                 $summary = $workshop->prepare_example_summary($example);
-                echo $output->example_summary($summary);
+                $summary->editable = true;
+                echo $output->render($summary);
             }
             $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on'));
             echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get');
@@ -135,7 +136,7 @@ case workshop::PHASE_SUBMISSION:
         } else {
             foreach ($examples as $example) {
                 $summary = $workshop->prepare_example_summary($example);
-                echo $output->example_summary($summary);
+                echo $output->render($summary);
             }
         }
         echo $output->box_end();
@@ -146,7 +147,7 @@ case workshop::PHASE_SUBMISSION:
         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
         echo $output->box_start('generalbox ownsubmission');
         if ($submission = $workshop->get_submission_by_author($USER->id)) {
-            echo $output->submission_summary($submission, true);
+            echo $output->render($workshop->prepare_submission_summary($submission, true));
             if ($workshop->modifying_submission_allowed()) {
                 $btnurl = new moodle_url($workshop->submission_url(), array('edit' => 'on'));
                 $btntxt = get_string('editsubmission', 'workshop');
@@ -173,7 +174,7 @@ case workshop::PHASE_SUBMISSION:
             echo $output->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
         }
         foreach ($submissions as $submission) {
-            echo $output->submission_summary($submission, $shownames);
+            echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
         }
         echo $output->box_end();
         print_collapsible_region_end();
@@ -188,7 +189,7 @@ case workshop::PHASE_ASSESSMENT:
         if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) {
             print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), false, true);
             echo $output->box_start('generalbox ownsubmission');
-            echo $output->submission_summary($ownsubmission, true);
+            echo $output->render($workshop->prepare_submission_summary($ownsubmission, true));
             $ownsubmissionexists = true;
         } else {
             print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
@@ -288,7 +289,7 @@ case workshop::PHASE_ASSESSMENT:
         } else {
             foreach ($examples as $example) {
                 $summary = $workshop->prepare_example_summary($example);
-                echo $output->example_summary($summary);
+                echo $output->render($summary);
             }
         }
         echo $output->box_end();
@@ -303,7 +304,7 @@ case workshop::PHASE_ASSESSMENT:
         } else {
             $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
             foreach ($assessments as $assessment) {
-                $submission                     = new stdclass();
+                $submission                     = new stdClass();
                 $submission->id                 = $assessment->submissionid;
                 $submission->title              = $assessment->submissiontitle;
                 $submission->timecreated        = $assessment->submissioncreated;
@@ -314,18 +315,22 @@ case workshop::PHASE_ASSESSMENT:
                 $submission->authorpicture      = $assessment->authorpicture;
                 $submission->authorimagealt     = $assessment->authorimagealt;
                 $submission->authoremail        = $assessment->authoremail;
+
+                // transform the submission object into renderable component
+                $submission = $workshop->prepare_submission_summary($submission, $shownames);
+
                 if (is_null($assessment->grade)) {
-                    $class = ' notgraded';
                     $submission->status = 'notgraded';
+                    $class = ' notgraded';
                     $buttontext = get_string('assess', 'workshop');
                 } else {
-                    $class = ' graded';
                     $submission->status = 'graded';
+                    $class = ' graded';
                     $buttontext = get_string('reassess', 'workshop');
                 }
 
                 echo $output->box_start('generalbox assessment-summary' . $class);
-                echo $output->submission_summary($submission, $shownames);
+                echo $output->render($submission);
                 $aurl = $workshop->assess_url($assessment->id);
                 echo $output->single_button($aurl, $buttontext, 'get');
                 echo $output->box_end();
@@ -403,7 +408,7 @@ case workshop::PHASE_EVALUATION:
         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
         echo $output->box_start('generalbox ownsubmission');
         if ($submission = $workshop->get_submission_by_author($USER->id)) {
-            echo $output->submission_summary($submission, true);
+            echo $output->render(new workshop_submission_summary($submission, true));
         } else {
             echo $output->container(get_string('noyoursubmission', 'workshop'));
         }
@@ -436,7 +441,7 @@ case workshop::PHASE_EVALUATION:
                 $buttontext = get_string('reassess', 'workshop');
             }
             echo $output->box_start('generalbox assessment-summary' . $class);
-            echo $output->submission_summary($submission, $shownames);
+            echo $output->render($workshop->prepare_submission_summary($submission, $shownames));
             echo $output->box_end();
         }
         print_collapsible_region_end();
@@ -478,7 +483,7 @@ case workshop::PHASE_CLOSED:
         print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'));
         echo $output->box_start('generalbox ownsubmission');
         if ($submission = $workshop->get_submission_by_author($USER->id)) {
-            echo $output->submission_summary($submission, true);
+            echo $output->render($workshop->prepare_submission_summary($submission, true));
         } else {
             echo $output->container(get_string('noyoursubmission', 'workshop'));
         }
@@ -490,7 +495,7 @@ case workshop::PHASE_CLOSED:
             print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'));
             foreach ($submissions as $submission) {
                 echo $output->box_start('generalbox submission-summary');
-                echo $output->submission_summary($submission, true);
+                echo $output->render($workshop->prepare_submission_summary($submission, true));
                 echo $output->box_end();
             }
             print_collapsible_region_end();