From: stronk7 <stronk7>
Date: Mon, 13 Dec 2004 01:25:23 +0000 (+0000)
Subject: Now activity names are sorted by name length to avoid Bug 2282
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3a558dd9a8880598d6b5ab0b0e2daa89006b6fb9;p=moodle.git

Now activity names are sorted by name length to avoid Bug 2282
(http://moodle.org/bugs/bug.php?op=show&bugid=2282)

Merged from MOODLE_14_STABLE
---

diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php
index 5c5e6cc0be..8d222901a5 100644
--- a/filter/activitynames/filter.php
+++ b/filter/activitynames/filter.php
@@ -1,4 +1,4 @@
-<?PHP // $Id$
+<?php // $Id$
     //This function provides automatic linking to
     //activities when its name (title) is found inside every Moodle text
     //It's based in the glosssary filter by Williams Castillo
@@ -15,6 +15,9 @@
         $course = get_record("course","id",$courseid);
         $modinfo = unserialize($course->modinfo);
 
+        //Sort modinfo by name lenght
+        usort($modinfo,'comparemodulenamesbylenght'); 
+
         if (!empty($modinfo)) {
             $cm = '';
             foreach ($modinfo as $activity) {
@@ -111,4 +114,12 @@
         }
         return $text;
     }
+
+    //This function is used to order module names from longer to shorter
+    function comparemodulenamesbylenght($a, $b)  {
+        if (strlen($a->name) == strlen($b->name)) {
+            return 0;
+        }
+        return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
+    }
 ?>