]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10674 and MDL-10675 finished
authornicolasconnault <nicolasconnault>
Wed, 1 Aug 2007 14:08:50 +0000 (14:08 +0000)
committernicolasconnault <nicolasconnault>
Wed, 1 Aug 2007 14:08:50 +0000 (14:08 +0000)
grade/report/grader/lib.php
grade/report/lib.php
lib/weblib.php

index c8b3aa12b10ed0e22306e20293a69b139b6a984e..20ec0b7488f5d875efbaccbf16f8cdc3afba176f 100644 (file)
@@ -432,10 +432,17 @@ class grade_report_grader extends grade_report {
             }
 
             foreach ($row as $columnkey => $element) {
+                $sort_link = '';
+                if (isset($element['object']->id)) {
+                    $sort_link = $this->baseurl.'&amp;sortitemid=' . $element['object']->id;
+                }
+
                 $eid    = $element['eid'];
                 $object = $element['object'];
                 $type   = $element['type'];
                 $categorystate = @$element['categorystate'];
+                $itemmodule = null;
+                $iteminstance = null;
 
                 if (!empty($element['colspan'])) {
                     $colspan = 'colspan="'.$element['colspan'].'"';
@@ -467,14 +474,17 @@ class grade_report_grader extends grade_report {
                 }
 // Element is a grade_item
                 else {
+                    $itemmodule = $element['object']->itemmodule;
+                    $iteminstance = $element['object']->iteminstance;
+
                     if ($element['object']->id == $this->sortitemid) {
                         if ($this->sortorder == 'ASC') {
-                            $arrow = print_arrow('up', $strsortasc, true);
+                            $arrow = $this->get_sort_arrow('up', $sort_link);
                         } else {
-                            $arrow = print_arrow('down', $strsortdesc, true);
+                            $arrow = $this->get_sort_arrow('down', $sort_link);
                         }
                     } else {
-                        $arrow = '';
+                        $arrow = $this->get_sort_arrow('move', $sort_link);
                     }
 
                     $dimmed = '';
@@ -487,15 +497,12 @@ class grade_report_grader extends grade_report {
                               .$this->get_lang_string('modulename', $object->itemmodule).'"/>';
                     } else if ($object->itemtype == 'manual') {
                         //TODO: add manual grading icon
-                        $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'.$this->get_lang_string('manualgrade', 'grades')
-                              .'"/>';
+                        $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'
+                                .$this->get_lang_string('manualgrade', 'grades') .'"/>';
                     }
 
-
-                    $headerhtml .= '<th class="'.$type.$catlevel.$dimmed.'"><a href="'.$this->baseurl.'&amp;sortitemid='
-                              . $element['object']->id .'">'. $element['object']->get_name()
-                              . '</a>' . $arrow;
-
+                    $headerlink = $this->get_module_link($element['object']->get_name(), $itemmodule, $iteminstance);
+                    $headerhtml .= '<th class="'.$type.$catlevel.$dimmed.'">'. $headerlink . $arrow;
                     $headerhtml .= $this->get_icons($element) . '</th>';
 
                     $this->items[$element['object']->sortorder] =& $element['object'];
index 5b95cdea7af1aa63648c4ef5cf1a7efd40d59692..c457af4dfce1417698a79de2ea3ca7faead1cf75 100755 (executable)
@@ -342,5 +342,50 @@ class grade_report {
             $this->groupwheresql = " AND gm.groupid = $this->currentgroup ";
         }
     }
+
+    /**
+     * Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.
+     * @param string $direction
+     * @param string $sort_link
+     * @param string HTML
+     */
+    function get_sort_arrow($direction='move', $sort_link=null) {
+        $matrix = array('up' => 'asc', 'down' => 'desc', 'move' => 'asc');
+        $strsort = $this->get_lang_string('sort' . $matrix[$direction]);
+        $arrow = print_arrow($direction, $strsort, true);
+        $html = '<a href="'.$sort_link .'">' . $arrow . '</a>';
+        return $html;
+    }
+
+    /**
+     * Builds and returns a HTML link to the grade or view page of the module given.
+     * If no itemmodule is given, only the name of the category/item is returned, no link.
+     * @param string $modulename The shortname of the module, will become the visible header
+     * @param string $itemmodule The name of the module type (e.g. assignment, quiz...)
+     * @param int $iteminstance The instance number of the module
+     * @return string HTML
+     */
+    function get_module_link($modulename, $itemmodule=null, $iteminstance=null) {
+        global $CFG, $COURSE;
+
+        $link = null;
+        if (!is_null($itemmodule) AND !is_null($iteminstance)) {
+            $coursemodule = get_coursemodule_from_instance($itemmodule, $iteminstance, $COURSE->id);
+
+            $dir = $CFG->dirroot . "/mod/$itemmodule/";
+            $url = $CFG->wwwroot . "/mod/$itemmodule/";
+
+            if (file_exists($dir . 'grade.php')) {
+                $url .= 'grade.php';
+            } else {
+                $url .= 'view.php';
+            }
+
+            $url .= "?id=$coursemodule->id";
+            return '<a href="' . $url . '">' . $modulename . '</a>';
+        }
+
+        return $modulename;
+    }
 }
 ?>
index 214d12d3b1a96a9646627a2de3713428e76d5298..419db6a822c2b1d29d6ffd44a9773abc9c748ebf 100644 (file)
@@ -2136,7 +2136,7 @@ function convert_urls_into_links(&$text) {
  *
  * @param string $needle The string to search for
  * @param string $haystack The string to search for $needle in
- * @param int $case whether to do case-sensitive or insensitive matching. 
+ * @param int $case whether to do case-sensitive or insensitive matching.
  * @return string
  * @todo Finish documenting this function
  */
@@ -2897,7 +2897,7 @@ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='', $force
     }
 
     $oppositlangdir = ($langdir == 'rtl') ? '_ltr' : '_rtl';
-    
+
     if ($files) {
     /// Produce a list of all the files first
         echo '/**************************************'."\n";
@@ -2979,7 +2979,7 @@ function theme_setup($theme = '', $params=NULL) {
     if ($langdir == 'rtl') {
         $params[] = 'langdir='.get_string('thisdirection');
     }
-    
+
     if ($theme != $CFG->theme) {
         $params[] = 'forceconfig='.$theme;
     }
@@ -5839,7 +5839,7 @@ function print_side_block_start($heading='', $attributes = array()) {
     }
 
     echo '<div '.$attrtext.'>';
-    
+
     if (!empty($THEME->customcorners)) {
         echo '<div class="wrap">'."\n";
     }
@@ -5884,9 +5884,9 @@ function print_side_block_end($attributes = array()) {
         require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
         print_custom_corners_end();
     }
-    
+
     echo '</div>';
-    
+
     // IE workaround: if I do it THIS way, it works! WTF?
     if (!empty($CFG->allowuserblockhiding) && isset($attributes['id'])) {
         echo '<script type="text/javascript">'."\n//<![CDATA[\n".'elementCookieHide("'.$attributes['id'].'"); '.
@@ -6347,7 +6347,7 @@ function print_location_comment($file, $line, $return = false)
 function print_arrow($direction='up', $strsort=null, $return=false) {
     global $CFG;
 
-    if (!in_array($direction, array('up', 'down', 'right', 'left'))) {
+    if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
         return null;
     }
 
@@ -6360,6 +6360,9 @@ function print_arrow($direction='up', $strsort=null, $return=false) {
         case 'down':
             $sortdir = 'desc';
             break;
+        case 'move':
+            $sortdir = 'asc';
+            break;
         default:
             $sortdir = null;
             break;