]> git.mjollnir.org Git - moodle.git/commitdiff
Commiting all changes reported in MDL-14646 - fixes stat report that could not show...
authordiml <diml>
Fri, 2 May 2008 15:23:13 +0000 (15:23 +0000)
committerdiml <diml>
Fri, 2 May 2008 15:23:13 +0000 (15:23 +0000)
search/indexlib.php
search/lib.php

index be250ca39e54613b7b529712881666686927f4e1..737c2da4748e5af47cc2868b85a69c88d9658792 100644 (file)
@@ -78,7 +78,8 @@ class IndexInfo {
             $this->dbcount = count_records(SEARCH_DATABASE_TABLE);
             
             //individual document types
-            $types = search_get_document_types();
+            // $types = search_get_document_types();
+            $types = search_collect_searchables(true, false);
             sort($types);
             
             foreach($types as $type) {
index c38290f5781c6349024f4caa4b6249d6927c19ee..9a5f23ac761877753d81744cf0a7bd16c2b95e8c 100644 (file)
@@ -22,6 +22,7 @@ function search_get_document_types($prefix = 'SEARCH_TYPE_') {
 function search_get_additional_modules() {
 function search_shorten_url($url, $length=30) {
 function search_escape_string($str) {
+function search_check_php5($feedback = false) {
 function search_stopwatch($cli = false) {
 function search_pexit($str = "") {
 */
@@ -29,24 +30,79 @@ function search_pexit($str = "") {
 define('SEARCH_INDEX_PATH', "$CFG->dataroot/search");
 define('SEARCH_DATABASE_TABLE', 'block_search_documents');
 
-//document types that can be searched
-//define('SEARCH_TYPE_NONE', 'none');
-define('SEARCH_TYPE_WIKI', 'wiki');
-define('PATH_FOR_SEARCH_TYPE_WIKI', 'mod/wiki');
-define('SEARCH_TYPE_FORUM', 'forum');
-define('PATH_FOR_SEARCH_TYPE_FORUM', 'mod/forum');
-define('SEARCH_TYPE_GLOSSARY', 'glossary');
-define('PATH_FOR_SEARCH_TYPE_GLOSSARY', 'mod/glossary');
-define('SEARCH_TYPE_RESOURCE', 'resource');
-define('PATH_FOR_SEARCH_TYPE_RESOURCE', 'mod/resource');
-define('SEARCH_TYPE_TECHPROJECT', 'techproject');
-define('PATH_FOR_SEARCH_TYPE_TECHPROJECT', 'mod/techproject');
-define('SEARCH_TYPE_DATA', 'data');
-define('PATH_FOR_SEARCH_TYPE_DATA', 'mod/data');
-define('SEARCH_TYPE_CHAT', 'chat');
-define('PATH_FOR_SEARCH_TYPE_CHAT', 'mod/chat');
-define('SEARCH_TYPE_LESSON', 'lesson');
-define('PATH_FOR_SEARCH_TYPE_LESSON', 'mod/lesson');
+// get document types
+include "{$CFG->dirroot}/search/searchtypes.php";
+
+/**
+* collects all searchable items identities
+* @param boolean $namelist
+* @param boolean $verbose
+* @return an array of names or an array of type descriptors
+*/
+function search_collect_searchables($namelist=false, $verbose=true){
+    global $CFG;
+    
+    $searchables = array();
+    $searchables_names = array();
+    
+/// get all installed modules
+    if ($mods = get_records('modules', '', '', 'name', 'id,name')){
+
+        $searchabletypes = array_values(search_get_document_types());
+
+        foreach($mods as $mod){
+            if (in_array($mod->name, $searchabletypes)){
+                $mod->location = 'internal';
+                $searchables[] = $mod;
+                $searchables_names[] = $mod->name;
+            } else {
+                $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php";
+                $mod->location = 'mod';
+                if (file_exists($documentfile)){
+                    $searchables[] = $mod;
+                    $searchables_names[] = $mod->name;
+                }
+            }        
+        }    
+        if ($verbose) mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
+    }
+      
+/// collects blocks as indexable information may be found in blocks either
+    if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
+        $blocks_searchables = array();
+        // prepend the "block_" prefix to discriminate document type plugins
+        foreach($blocks as $block){
+            $block->dirname = $block->name;
+            $block->name = 'block_'.$block->name;
+            if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){
+                $mod->location = 'internal';
+                $blocks_searchables[] = $block;
+                $searchables_names[] = $block->name;
+            } else {
+                $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php";
+                if (file_exists($documentfile)){
+                    $mod->location = 'blocks';
+                    $blocks_searchables[] = $block;
+                    $searchables_names[] = $block->name;
+                }
+            }        
+        }    
+        if ($verbose) mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
+        $searchables = array_merge($searchables, $blocks_searchables);
+    }
+      
+/// add virtual modules onto the back of the array
+
+    $additional = search_get_additional_modules();
+    if (!empty($additional)){
+        if ($verbose) mtrace(count($additional).' additional to search in.');
+        $searchables = array_merge($searchables, $additional);
+    }
+    
+    if ($namelist)
+        return $searchables_names;
+    return $searchables;
+}
 
 /**
 * returns all the document type constants
@@ -62,7 +118,7 @@ function search_get_document_types($prefix = 'SEARCH_TYPE_') {
     } 
     sort($ret);
     return $ret;
-} //search_get_document_types
+}
 
 /**
 * additional virtual modules to index
@@ -74,9 +130,14 @@ function search_get_document_types($prefix = 'SEARCH_TYPE_') {
 */
 function search_get_additional_modules() {
     $extras = array(/* additional keywords go here */);
+    if (defined('SEARCH_EXTRAS')){
+        $extras = explode(',', SEARCH_EXTRAS);
+    }
+
     $ret = array();
     foreach($extras as $extra) {
         $temp->name = $extra;
+        $temp->location = 'internal';
         $ret[] = clone($temp);
     } 
     return $ret;
@@ -112,6 +173,23 @@ function search_escape_string($str) {
     return $s;
 } //search_escape_string
 
+/**
+* get a real php 5 version number, using 5.0.0 arbitrarily
+* @param feedback if true, prints a feedback message to output.
+* @return true if version of PHP is high enough
+*/
+function search_check_php5($feedback = false) {
+    if (!check_php_version("5.0.0")) {
+        if ($feedback) {
+            print_heading(get_string('versiontoolow', 'search'));
+        }
+        return false;
+    } 
+    else {
+      return true;
+    } 
+} //search_check_php5
+
 /**
 * simple timer function, on first call, records a current microtime stamp, outputs result on 2nd call
 * @param cli an output formatting switch