mod-assignment MDL-20241 Upgraded assignment to use new navigation blocks
authorsamhemelryk <samhemelryk>
Wed, 9 Sep 2009 08:23:41 +0000 (08:23 +0000)
committersamhemelryk <samhemelryk>
Wed, 9 Sep 2009 08:23:41 +0000 (08:23 +0000)
course/format/weeks/lib.php
lang/en_utf8/assignment.php
mod/assignment/lib.php
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php
mod/assignment/type/uploadsingle/assignment.class.php

index 0f40233..0130dc4 100644 (file)
@@ -29,9 +29,9 @@
  * This is called automatically by {@link load_course()} if the current course
  * format = weeks.
  *
- * @param array $path An array of keys to the course node in the navigation
- * @param stdClass $modinfo The mod info object for the current course
- * @return bool Returns true
+ * @param navigation_node $navigation The course node
+ * @param array $path An array of keys to the course node
+ * @param stdClass $course The course we are loading the section for
  */
 function callback_weeks_load_content(&$navigation, $keys, $course) {
     $navigation->add_course_section_generic($keys, $course, get_string('week'), 'week');
@@ -43,9 +43,10 @@ function callback_weeks_load_content(&$navigation, $keys, $course) {
  * This is called automatically by {@link load_course()} if the current course
  * format = weeks and the navigation was requested via AJAX
  *
- * @param array $path An array of keys to the course node in the navigation
- * @param stdClass $modinfo The mod info object for the current course
- * @return bool Returns true
+ * @param navigation_node $navigation The course node
+ * @param array $path An array of keys to the course node
+ * @param stdClass $course The course we are loading the section for
+ * @param stdClass $section The section to load
  */
 function callback_weeks_load_limited_section(&$navigation, $keys, $course, $section) {
     $navigation->limited_load_section_generic($keys, $course, $section, get_string('week'), 'week');
index 8fb3f1d..0bce5cc 100644 (file)
@@ -12,6 +12,7 @@ $string['assignment:exportsubmission'] = 'Export submission';
 $string['assignment:grade'] = 'Grade assignment';
 $string['assignment:submit'] = 'Submit assignment';
 $string['assignment:view'] = 'View assignment';
+$string['assignmentadministration'] = 'Assignment administration';
 $string['assignmentdetails'] = 'Assignment details';
 $string['assignmentmail'] = '$a->teacher has posted some feedback on your
 assignment submission for \'$a->assignment\'
@@ -146,6 +147,7 @@ $string['uploadnotregistered'] = '\'$a\' was uploaded OK but submission did not
 $string['uploadsuccess'] = 'Uploaded \'$a\' successfully';
 $string['usermisconf'] = 'User is misconfigured';
 $string['viewfeedback'] = 'View assignment grades and feedback';
+$string['viewmysubmission'] = 'View my submission';
 $string['viewsubmissions'] = 'View $a submitted assignments';
 $string['yoursubmission'] = 'Your submission';
 $string['maxpublishstate'] = 'Maximum visibility for blog entry before duedate';
index ff0125e..b3d1736 100644 (file)
@@ -1595,8 +1595,7 @@ class assignment_base {
         $submission = new Object;
         $submission->assignment   = $this->assignment->id;
         $submission->userid       = $userid;
-        //$submission->timecreated  = time();
-        $submission->timecreated = '';
+        $submission->timecreated = time();
         // teachers should not be modifying modified date, except offline assignments
         if ($teachermodified) {
             $submission->timemodified = 0;
@@ -3437,3 +3436,55 @@ function assignment_supports($feature) {
         default: return null;
     }
 }
+
+function assignment_extend_settings_navigation($navnode, $module) {
+    global $PAGE, $DB, $USER, $CFG;
+
+    $allgroups = false;
+
+    $assignmentrow = $DB->get_record("assignment", array("id" => $PAGE->cm->instance));
+    require_once "$CFG->dirroot/mod/assignment/type/$assignmentrow->assignmenttype/assignment.class.php";
+    $assignmentclass = 'assignment_'.$assignmentrow->assignmenttype;
+    $assignmentinstance = new $assignmentclass($PAGE->cm->id, $assignmentrow, $PAGE->cm, $PAGE->course);
+
+    $assignmentnodekey = $navnode->add(get_string('assignmentadministration', 'assignment'));
+    $assignmentnode = $navnode->get($assignmentnodekey);
+    $assignmentnode->forceopen = true;
+
+    if (!empty($USER->id) && !has_capability('moodle/legacy:guest', $PAGE->cm->context, NULL, false)) {
+
+        $allgroups = false;
+
+        // Add assignment submission information
+        if (has_capability('mod/assignment:grade', $PAGE->cm->context)) {
+            if ($allgroups && has_capability('moodle/site:accessallgroups', $PAGE->cm->context)) {
+                $group = 0;
+            } else {
+                $group = groups_get_activity_group($PAGE->cm);
+            }
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/submissions.php', array('id'=>$PAGE->cm->id));
+            if ($count = $assignmentinstance->count_real_submissions($group)) {
+                $string = get_string('viewsubmissions', 'assignment', $count);
+            } else {
+                $string = get_string('noattempts', 'assignment');
+            }
+            $assignmentnode->add($string, $link, navigation_node::TYPE_SETTING);
+        }
+
+        if (is_object($assignmentinstance) && method_exists($assignmentinstance, 'extend_settings_navigation')) {
+            $assignmentinstance->extend_settings_navigation($assignmentnode);
+        }
+
+        // Add update this activity link
+        if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) {
+            $modulename = get_string('modulename', 'assignment');
+            $string = get_string('updatethis', '', $modulename);
+            $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()));
+            $assignmentnode->add($string, $url, navigation_node::TYPE_SETTING);
+        }
+
+        if (count($assignmentnode->children)<1) {
+            $navnode->remove_child($assignmentnodekey);
+        }
+    }
+}
\ No newline at end of file
index eb69f3f..f9d82b4 100644 (file)
@@ -187,7 +187,7 @@ class assignment_online extends assignment_base {
             return '';
         }
         
-        $link = html_link::make("/mod/assignment/type/online/file.php?id=$this->cm->id&userid=$submission->userid", shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15));
+        $link = html_link::make("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}", shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15));
         $link->add_action(new popup_action('click', $link->url, 'file'.$userid, array('height' => 450, 'width' => 580)));
         $link->title = get_string('submission', 'assignment');
         $popup = $OUTPUT->link($link);                    
@@ -200,13 +200,13 @@ class assignment_online extends assignment_base {
     }
 
     function print_user_files($userid, $return=false) {
-        global $OUTPUT;
+        global $OUTPUT, $CFG;
 
         if (!$submission = $this->get_submission($userid)) {
             return '';
         }
         
-        $link = html_link::make("/mod/assignment/type/online/file.php?id=$this->cm->id&userid=$submission->userid", shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15));
+        $link = html_link::make("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}", shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15));
         $link->add_action(new popup_action('click', $link->url, 'file'.$userid, array('height' => 450, 'width' => 580)));
         $link->title = get_string('submission', 'assignment');
         $popup = $OUTPUT->link($link);                    
@@ -286,6 +286,42 @@ class assignment_online extends assignment_base {
     function portfolio_supported_formats() {
         return array(PORTFOLIO_FORMAT_PLAINHTML);
     }
+
+    function extend_settings_navigation($node) {
+        global $PAGE, $CFG, $USER;
+
+        // get users submission if there is one
+        $submission = $this->get_submission();
+        if (has_capability('mod/assignment:submit', $PAGE->cm->context)) {
+            $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
+        } else {
+            $editable = false;
+        }
+
+        // If the user has submitted something add a bit more stuff
+        if ($submission) {
+            // Add a view link to the settings nav
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/view.php', array('id'=>$PAGE->cm->id));
+            $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
+
+            if (!empty($submission->timemodified)) {
+                $key = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
+                $node->get($key)->text = preg_replace('#([^,])\s#', '$1&nbsp;', $node->get($key)->text);
+                $node->get($key)->add_class('note');
+                if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
+                    $node->get($key)->add_class('early');
+                } else {
+                    $node->get($key)->add_class('late');
+                }
+            }
+        }
+
+        if (!$submission || $editable) {
+            // If this assignment is editable once submitted add an edit link to the settings nav
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/view.php', array('id'=>$PAGE->cm->id, 'edit'=>1, 'sesskey'=>sesskey()));
+            $node->add(get_string('editmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
+        }
+    }
 }
 
 class mod_assignment_online_edit_form extends moodleform {
index 31951ba..02ffac8 100644 (file)
@@ -1047,6 +1047,58 @@ class assignment_upload extends assignment_base {
         return true;
     }
 
+    function extend_settings_navigation($node) {
+        global $CFG, $USER, $OUTPUT;
+
+        // get users submission if there is one
+        $submission = $this->get_submission();
+        if (has_capability('mod/assignment:submit', $this->cm->context)) {
+            $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
+        } else {
+            $editable = false;
+        }
+
+        // If the user has submitted something add a bit more stuff
+        if ($submission) {
+            // Add a view link to the settings nav
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/view.php', array('id'=>$this->cm->id));
+            $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
+            if (!empty($submission->timemodified)) {
+                $key = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
+                $node->get($key)->text = preg_replace('#([^,])\s#', '$1&nbsp;', $node->get($key)->text);
+                $node->get($key)->add_class('note');
+                if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
+                    $node->get($key)->add_class('early');
+                } else {
+                    $node->get($key)->add_class('late');
+                }
+            }
+        }
+
+        // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav
+        if ($submission && has_capability('mod/assignment:submit', $this->context) && $this->count_user_files($USER->id)) {
+            $fs = get_file_storage();
+            if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $USER->id, "timemodified", false)) {
+                if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) {
+                    $filekey = $node->add(get_string('submission', 'assignment'));
+                } else {
+                    $filekey = $node->add(get_string('submissiondraft', 'assignment'));
+                }
+                foreach ($files as $file) {
+                    $filename = $file->get_filename();
+                    $mimetype = $file->get_mimetype();
+                    $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$USER->id.'/'.$filename);
+                    $node->get($filekey)->add($filename, $link, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)));
+                }
+            }
+        }
+
+        // Show a notes link if they are enabled
+        if ($this->notes_allowed()) {
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/upload.php', array('id'=>$this->cm->id, 'action'=>'editnotes', 'sesskey'=>sesskey()));
+            $node->add(get_string('notes', 'assignment'), $link);
+        }
+    }
 }
 
 class mod_assignment_upload_notes_form extends moodleform {
index 90ebce1..b026732 100644 (file)
@@ -177,6 +177,48 @@ class assignment_uploadsingle extends assignment_base {
         send_stored_file($file, 0, 0, true); // download MUST be forced - security!
     }
 
+    function extend_settings_navigation($node) {
+        global $CFG, $USER, $OUTPUT;
+
+        // get users submission if there is one
+        $submission = $this->get_submission();
+        if (has_capability('mod/assignment:submit', $this->cm->context)) {
+            $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
+        } else {
+            $editable = false;
+        }
+
+        // If the user has submitted something add a bit more stuff
+        if ($submission) {
+            // Add a view link to the settings nav
+            $link = new moodle_url($CFG->wwwroot.'/mod/assignment/view.php', array('id'=>$this->cm->id));
+            $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
+            if (!empty($submission->timemodified)) {
+                $key = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
+                $node->get($key)->text = preg_replace('#([^,])\s#', '$1&nbsp;', $node->get($key)->text);
+                $node->get($key)->add_class('note');
+                if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
+                    $node->get($key)->add_class('early');
+                } else {
+                    $node->get($key)->add_class('late');
+                }
+            }
+        }
+
+        // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav
+        if ($submission && has_capability('mod/assignment:submit', $this->context) && $this->count_user_files($USER->id)) {
+            $fs = get_file_storage();
+            if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $USER->id, "timemodified", false)) {
+                $filekey = $node->add(get_string('submission', 'assignment'));
+                foreach ($files as $file) {
+                    $filename = $file->get_filename();
+                    $mimetype = $file->get_mimetype();
+                    $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$USER->id.'/'.$filename);
+                    $node->get($filekey)->add($filename, $link, navigation_node::TYPE_SETTING, null, null, $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)));
+                }
+            }
+        }
+    }
 }
 
 ?>