| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: view_reserved_words.class.php,v 1.5 2007/10/10 05:25:28 nicolasconnault Exp $ 2 3 /////////////////////////////////////////////////////////////////////////// 4 // // 5 // NOTICE OF COPYRIGHT // 6 // // 7 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 8 // http://moodle.com // 9 // // 10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // 11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // 12 // // 13 // This program is free software; you can redistribute it and/or modify // 14 // it under the terms of the GNU General Public License as published by // 15 // the Free Software Foundation; either version 2 of the License, or // 16 // (at your option) any later version. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details: // 22 // // 23 // http://www.gnu.org/copyleft/gpl.html // 24 // // 25 /////////////////////////////////////////////////////////////////////////// 26 27 /// This class will show all the reserved words in a format suitable to 28 /// be pasted to: http://docs.moodle.org/en/XMLDB_reserved_words and 29 /// http://docs.moodle.org/en/Database_reserved_words 30 /// Also, it introspects te DB looking for such words and informing about 31 32 class view_reserved_words extends XMLDBAction { 33 34 /** 35 * Init method, every subclass will have its own 36 */ 37 function init() { 38 parent::init(); 39 40 /// Set own custom attributes 41 42 /// Get needed strings 43 $this->loadStrings(array( 44 'listreservedwords' => 'xmldb', 45 'wrongreservedwords' => 'xmldb', 46 'table' => 'xmldb', 47 'field' => 'xmldb', 48 'back' => 'xmldb' 49 )); 50 } 51 52 /** 53 * Invoke method, every class will have its own 54 * returns true/false on completion, setting both 55 * errormsg and output as necessary 56 */ 57 function invoke() { 58 parent::invoke(); 59 60 $result = true; 61 62 /// Set own core attributes 63 $this->does_generate = ACTION_GENERATE_HTML; 64 65 /// These are always here 66 global $CFG, $XMLDB, $db; 67 68 /// Calculate list of available SQL generators 69 $plugins = get_list_of_plugins('lib/xmldb/classes/generators'); 70 $reserved_words = array(); 71 $reserved_words_bydb = array(); 72 foreach($plugins as $plugin) { 73 $classname = 'XMLDB' . $plugin; 74 $generator = new $classname(); 75 $reserved_words = array_merge($reserved_words, $generator->getReservedWords()); 76 $reserved_words_bydb[$plugin] = $generator->getReservedWords(); 77 } 78 sort($reserved_words); 79 $reserved_words = array_unique($reserved_words); 80 81 /// Now, calculate, looking into current DB (with AdoDB Metadata), which fields are 82 /// in the list of reserved words 83 $wronguses = array(); 84 $dbtables = $db->MetaTables('TABLES'); 85 if ($dbtables) { 86 foreach ($dbtables as $dbtable) { 87 $table = str_replace($CFG->prefix, '', $dbtable); 88 if (in_array($table, $reserved_words)) { 89 $list_of_db = array(); 90 foreach ($reserved_words_bydb as $key=>$words) { 91 if (in_array($table, $words)) { 92 $list_of_db[] = $key; 93 } 94 } 95 $wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$list_of_db) . ')'; 96 97 } 98 $dbfields = $db->MetaColumns($dbtable); 99 if ($dbfields) { 100 foreach ($dbfields as $dbfield) { 101 if (in_array($dbfield->name, $reserved_words)) { 102 $list_of_db = array(); 103 foreach ($reserved_words_bydb as $key=>$words) { 104 if (in_array($dbfield->name, $words)) { 105 $list_of_db[] = $key; 106 } 107 } 108 $wronguses[] = $this->str['field'] . ' - ' . $table . '->' . $dbfield->name . ' (' . implode(', ',$list_of_db) . ')'; 109 } 110 } 111 } 112 } 113 } 114 115 /// Sort the wrong uses 116 sort($wronguses); 117 118 /// The back to edit table button 119 $b = ' <p class="centerpara buttons">'; 120 $b .= '<a href="index.php">[' . $this->str['back'] . ']</a>'; 121 $b .= '</p>'; 122 $o = $b; 123 124 /// The list of currently wrong field names 125 if ($wronguses) { 126 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">'; 127 $o.= ' <tr><td align="center"><font color="red">' . $this->str['wrongreservedwords'] . '</font></td></tr>'; 128 $o.= ' <tr><td>'; 129 $o.= ' <ul><li>' . implode('</li><li>', $wronguses) . '</li></ul>'; 130 $o.= ' </td></tr>'; 131 $o.= ' </table>'; 132 } 133 134 /// The textarea showing all the reserved words 135 $o.= ' <table id="formelements" class="boxaligncenter" cellpadding="5">'; 136 $o.= ' <tr><td align="center">' . $this->str['listreservedwords'].'</td></tr>'; 137 $o.= ' <tr><td><textarea cols="80" rows="32">'; 138 $o.= s(implode(', ', $reserved_words)); 139 $o.= '</textarea></td></tr>'; 140 $o.= ' </table>'; 141 142 $this->output = $o; 143 144 /// Launch postaction if exists (leave this here!) 145 if ($this->getPostAction() && $result) { 146 return $this->launch($this->getPostAction()); 147 } 148 149 /// Return ok if arrived here 150 return $result; 151 } 152 } 153 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |