Displays the list of submissions
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:01:40 +0000 (18:01 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:01:40 +0000 (18:01 +0000)
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/styles.php
mod/workshop/submission.php
mod/workshop/tabs.php
mod/workshop/view.php

index 70cdaf4..2e41d82 100644 (file)
@@ -74,6 +74,7 @@ $string['editassessmentform'] = 'Edit assessment form';
 $string['editassessmentformstrategy'] = 'Edit assessment form ($a)';
 $string['editingassessmentform'] = 'Editing assessment form';
 $string['editingsubmission'] = 'Editing submission';
+$string['mysubmission'] = 'My submission';
 $string['editsubmission'] = 'Edit submission';
 $string['err_removegrademappings'] = 'Unable to remove the unused grade mappings';
 $string['examplesbeforeassessment'] = 'Examples are available after own submission and must be assessed before peer/self assessment phase';
index bed1b6a..a2ba6f5 100644 (file)
@@ -217,7 +217,7 @@ class workshop {
     /**
      * Returns submissions from this workshop
      *
-     * Fetches data from {workshop_submissions} and adds some useful information from other
+     * Fetches no-big-text data from {workshop_submissions} and adds some useful information from other
      * tables.
      *
      * @param mixed $userid int|array|'all' If set to [array of] integer, return submission[s] of the given user[s] only
@@ -227,7 +227,10 @@ class workshop {
     public function get_submissions_recordset($userid='all', $examples=false) {
         global $DB;
 
-        $sql = 'SELECT s.*, u.lastname AS authorlastname, u.firstname AS authorfirstname
+        $sql = 'SELECT s.id, s.workshopid, s.example, s.userid, s.timecreated, s.timemodified,
+                       s.title, s.grade, s.gradeover, s.gradeoverby, s.gradinggrade,
+                       u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
+                       u.picture AS authorpicture, u.imagealt AS authorimagealt
                   FROM {workshop_submissions} s
             INNER JOIN {user} u ON (s.userid = u.id)
                  WHERE s.workshopid = :workshopid';
@@ -242,6 +245,7 @@ class workshop {
         } else {
             throw new coding_exception('Illegal parameter value: $examples may be false|true|"all"');
         }
+        $sql .= ' ORDER BY u.lastname, u.firstname';
 
         if ('all' === $userid) {
             // no additional conditions
@@ -260,39 +264,36 @@ class workshop {
     /**
      * Returns a submission submitted by the given author or authors.
      *
-     * This is intended for regular workshop participants, not for example submissions by teachers.
-     * If an array of authors is provided, returns array of stripped submission records so they do not
-     * include text fields (to prevent possible memory-lack issues).
+     * If the single one submission is requested, returns the first found record including text fields.
+     * If multiple records are requested, uses {@link self::get_submissions_recordset()}.
+     * Does not return example submissions.
      *
      * @param mixed $id integer|array author ID or IDs
      * @return mixed false if not found, stdClass if $id is int, array if $id is array
      */
     public function get_submission_by_author($id) {
+        global $DB;
+
         if (empty($id)) {
             return false;
         }
-        $rs = $this->get_submissions_recordset($id, false);
         if (is_array($id)) {
+            $rs = $this->get_submissions_recordset($id, false);
             $submissions = array();
             foreach ($rs as $submission) {
-                $submissions[$submission->id] = new stdClass();
-                foreach ($submission as $property => $value) {
-                    // we do not want text fields here to prevent possible memory issues
-                    if (in_array($property, array('id', 'workshopid', 'example', 'userid', 'authorlastname', 'authorfirstname',
-                            'timecreated', 'timemodified', 'grade', 'gradeover', 'gradeoverby', 'gradinggrade'))) {
-                        $submissions[$submission->id]->{$property} = $value;
-                    }
-                }
+                $submissions[$submission->id] = $submission;
             }
+            $rs->close();
             return $submissions;
         } else {
-            $submission = $rs->current();
-            $rs->close();
-            if (empty($submission->id)) {
-                return false;
-            } else {
-                return $submission;
-            }
+            $sql = 'SELECT s.*,
+                           u.lastname AS authorlastname, u.firstname AS authorfirstname, u.id AS authorid,
+                           u.picture AS authorpicture, u.imagealt AS authorimagealt
+                      FROM {workshop_submissions} s
+                INNER JOIN {user} u ON (s.userid = u.id)
+                     WHERE s.example = 0 AND s.workshopid = :workshopid AND s.userid = :userid';
+            $params = array('workshopid' => $this->id, 'userid' => $id);
+            return $DB->get_record_sql($sql, $params);
         }
     }
 
index b18486e..ffd494d 100644 (file)
@@ -111,6 +111,64 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
         return $o;
     }
 
+    /**
+     * Display a short summary of the submission
+     *
+     * @param stdClass $submission     The submission record
+     * @param bool     $showauthorname Should the author name be displayed
+     * @return string html to be echoed
+     */
+    public function submission_summary(stdClass $submission, $showauthorname=false) {
+        global $CFG;
+
+        $o  = '';    // output HTML code
+        $classes = 'submission-summary';
+        if (!$showauthorname) {
+            $classes .= ' anonymous';
+        }
+        $o .= $this->output->container_start($classes);  // main wrapper
+        $link = new html_link();
+        $link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/submission.php',
+                                    array('cmid' => $this->page->context->instanceid, 'id' => $submission->id));
+        $link->text = format_string($submission->title);
+        $link->set_classes('title');
+        $o .= $this->output->link($link);
+        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;
+            $userpic            = new moodle_user_picture();
+            $userpic->user      = $author;
+            $userpic->courseid  = $this->page->course->id;
+            $userpic->url       = true;
+            $userpic->size      = 35;
+            $userpic            = $this->output->user_picture($userpic);
+            $userurl            = new moodle_url($CFG->wwwroot . '/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');
+        }
+        $o .= $this->output->container_end(); // end of the main wrapper
+
+        return $o;
+    }
+
+
     /**
      * Displays the submission fulltext
      *
@@ -118,54 +176,59 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
      *
      * @param stdClass $submission     The submission record
      * @param bool     $showauthorname Should the author name be displayed
-     * @param stdClass $author         If author's name should be displayed, this object contains the author data
      * @return string html to be echoed
      */
-    public function submission_full(stdClass $submission, $showauthorname=false, stdClass $author=null) {
+    public function submission_full(stdClass $submission, $showauthorname=false) {
         global $CFG;
 
-        $o  = '';    // output code
-        $at = array('class' => 'submission-full');
-        if (!$showauthorname || !$author) {
-            $at['class'] .= ' anonymous';
+        $o  = '';    // output HTML code
+        $classes = 'submission-full';
+        if (!$showauthorname) {
+            $classes .= ' anonymous';
         }
-        $o .= $this->output->output_start_tag('div', $at);                                                      //+
-        $o .= $this->output->output_start_tag('div', array('class' => 'header'));                               //++
+        $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) {
-            $o .= $this->output->output_start_tag('div', array('class' => 'author'));                           //+++
-            $userpic    = new moodle_user_picture();
-            $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',
+        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;
+            $userpic            = new moodle_user_picture();
+            $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));
-            $a          = new stdClass();
-            $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                                        //++
+            $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->output_tag('div', array('class' => 'userdate created'), $created);
+        $o .= $this->output->container($created, 'userdate 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->container($modified, 'userdate modified');
         }
-        $o .= $this->output->output_end_tag('div'); // end of header                                            //+
+        $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,
                                                         'workshop_submission_content', $submission->id);
-        $o .= $this->output->output_tag('div', array('class' => 'content'), $content);
+        $o .= $this->output->container($content, 'content');
 
         $o .= $this->submission_attachments($submission);
 
-        $o .= $this->output->output_end_tag('div'); // end of submission-full                                   //
+        $o .= $this->output->container_end(); // end of submission-full
 
         return $o;
     }
@@ -224,7 +287,7 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
                     $preview->set_classes('preview');
                     $preview        = $this->output->image($preview);
                     $preview        = $this->output->link($fileurl, $preview);
-                    $outputimgs    .= $this->output->output_tag('div', array(), $preview);
+                    $outputimgs    .= $this->output->container($preview);
                 } else {
                     // this is the same as the code in html if-branch
                     $outputfiles .= $this->output->output_tag('li', array('class' => $type), $linkhtml);
@@ -233,12 +296,12 @@ class moodle_mod_workshop_renderer extends moodle_renderer_base {
         }
 
         if ($outputimgs) {
-            $outputimgs = $this->output->output_tag('div', array('class' => 'images'), $outputimgs);
+            $outputimgs = $this->output->container($outputimgs, 'images');
         }
         if ($format !== "text") {
             $outputfiles = $this->output->output_tag('ul', array('class' => 'files'), $outputfiles);
         }
-        return $this->output->output_tag('div', array('class' => 'attachments'), $outputimgs . $outputfiles);
+        return $this->output->container($outputimgs . $outputfiles, 'attachments');
     }
 
     /**
index 4545a08..3100e54 100644 (file)
@@ -1,3 +1,48 @@
+/**
+ * Submission - one line summary display
+ */
+.submission-summary {
+    position: relative;
+    margin-bottom: 10px;
+}
+
+.submission-summary .title,
+.submission-summary .author,
+.submission-summary .author .fullname,
+.submission-summary .author .picture {
+    display: inline;
+}
+
+.submission-summary .title,
+.submission-summary .userdate {
+    margin: 0px 0px 0px 40px;
+}
+
+.submission-summary .author {
+    margin-left: 1ex;
+}
+
+.submission-summary.anonymous .title,
+.submission-summary.anonymous .author,
+.submission-summary.anonymous .userdate {
+    margin: 0px 0px 0px 5px;
+}
+
+.submission-summary .userdate {
+    font-size: x-small;
+    color: #333;
+}
+
+.submission-summary .userdate span {
+    font-style: italic;
+}
+
+.submission-summary .author .picture {
+    position: absolute;
+    top: 0px;
+    left: 0px;
+}
+
 /**
  * Submission - full display
  */
index 60f5e11..76cf537 100644 (file)
@@ -121,7 +121,7 @@ if ($edit) {
 
 if (!empty($submission->id)) {
     $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
-    echo $wsoutput->submission_full($submission, true, $USER);
+    echo $wsoutput->submission_full($submission, true);
 }
 
 if ($workshop->submitting_allowed()) {
index 6c18792..b423ada 100644 (file)
@@ -47,7 +47,7 @@ if (has_capability('mod/workshop:editdimensions', $workshop->context)) {
     $row[] = new tabobject('editform', $workshop->editform_url()->out(), get_string('editassessmentform', 'workshop'));
 }
 if (has_capability('mod/workshop:submit', $workshop->context)) {
-    $row[] = new tabobject('submission', $workshop->submission_url()->out(), get_string('editsubmission', 'workshop'));
+    $row[] = new tabobject('submission', $workshop->submission_url()->out(), get_string('mysubmission', 'workshop'));
 }
 if (has_capability('mod/workshop:allocate', $workshop->context)) {
     $row[] = new tabobject('allocation', $workshop->allocation_url()->out(), get_string('allocate', 'workshop'));
index 337c315..97666c0 100644 (file)
@@ -75,17 +75,39 @@ $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
 
 echo $OUTPUT->header();
 include(dirname(__FILE__) . '/tabs.php');
-echo $OUTPUT->heading(format_string($workshop->name));
+echo $OUTPUT->heading(format_string($workshop->name), 2);
 echo $wsoutput->user_plan($workshop->prepare_user_plan($USER->id));
 
 switch ($workshop->phase) {
 case workshop::PHASE_SETUP:
-    // print workshop name and description
     if (trim(strip_tags($workshop->intro))) {
         echo $OUTPUT->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox', 'intro');
     }
     break;
 case workshop::PHASE_SUBMISSION:
+    if (has_capability('mod/workshop:submit', $PAGE->context)) {
+        if ($submission = $workshop->get_submission_by_author($USER->id)) {
+            echo $OUTPUT->box_start('generalbox mysubmission');
+            echo $wsoutput->submission_summary($submission, true);
+            echo $OUTPUT->box_end();
+        }
+    }
+    if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) {
+        $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context);
+        echo $OUTPUT->box_start('generalbox allsubmissions');
+        $counter = 0;
+        $rs = $workshop->get_submissions_recordset('all', false);
+        foreach ($rs as $submission) {
+            $counter++;
+            echo $wsoutput->submission_summary($submission, $shownames);
+        }
+        $rs->close();
+        if ($counter == 0) {
+            echo $OUTPUT->container(get_string('nosubmissions', 'workshop'), 'nosubmissions');
+        }
+        echo $OUTPUT->box_end();
+    }
+    break;
 case workshop::PHASE_ASSESSMENT:
 case workshop::PHASE_EVALUATION:
 case workshop::PHASE_CLOSED: