Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/dml/moodle_temptables.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00044 defined('MOODLE_INTERNAL') || die();
00045 
00046 class moodle_temptables {
00047 
00048     protected $mdb;        // circular reference, to be able to use DB facilities here if needed
00049     protected $prefix;     // prefix to be used for all the DB objects
00050     protected $temptables; // simple array of moodle, not prefixed 'tablename' => DB, final (prefixed) 'tablename'
00051 
00056     public function __construct($mdb) {
00057         $this->mdb        = $mdb;
00058         $this->prefix     = $mdb->get_prefix();
00059         $this->temptables = array();
00060     }
00061 
00073     public function add_temptable($tablename) {
00074         // TODO: throw exception if exists: if ($this->is_temptable...
00075         $this->temptables[$tablename] = $tablename;
00076     }
00077 
00083     public function delete_temptable($tablename) {
00084         // TODO: throw exception if not exists: if (!$this->is_temptable....
00085         unset($this->temptables[$tablename]);
00086     }
00087 
00093     public function get_temptables() {
00094         return array_keys($this->temptables);
00095     }
00096 
00103     public function is_temptable($tablename) {
00104         return !empty($this->temptables[$tablename]);
00105     }
00106 
00114     public function get_correct_name($tablename) {
00115         if ($this->is_temptable($tablename)) {
00116             return $this->temptables[$tablename];
00117         }
00118         return null;
00119     }
00120 
00124     public function dispose() {
00125         // We shouldn't have any temp table registered at the end of the script.
00126         // So we error_log that and, at the same time, drop all the pending temptables
00127         if ($temptables = $this->get_temptables()) {
00128             error_log('Potential coding error - existing temptables found when disposing database. Must be dropped!');
00129             foreach ($temptables as $temptable) {
00130                  $this->mdb->get_manager()->drop_temp_table(new xmldb_table($temptable));
00131             }
00132         }
00133         $this->mdb = null;
00134     }
00135 }
 All Data Structures Namespaces Files Functions Variables Enumerations