|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00038 class output_controller { 00039 00040 private static $instance; // The unique instance of output_controller available along the request 00041 private $list; // progress_trace object we are going to use for output 00042 private $active; // To be able to stop output completely or active it again 00043 00044 private function __construct() { // Private constructor 00045 if (defined('STDOUT')) { // text mode 00046 $this->list = new text_progress_trace(); 00047 } else { 00048 $this->list = new html_list_progress_trace(); 00049 } 00050 $this->active = false; // Somebody has to active me before outputing anything 00051 } 00052 00053 public static function get_instance() { 00054 if (!isset(self::$instance)) { 00055 self::$instance = new output_controller(); 00056 } 00057 return self::$instance; 00058 } 00059 00060 public function set_active($active) { 00061 if ($this->active && (bool)$active == false) { // Stopping, call finished() 00062 $this->list->finished(); 00063 } 00064 $this->active = (bool)$active; 00065 } 00066 00067 public function output($message, $langfile, $a, $depth) { 00068 if ($this->active) { 00069 $stringkey = preg_replace('/\s/', '', $message); // String key is message without whitespace 00070 $message = get_string($stringkey, $langfile, $a); 00071 $this->list->output($message, $depth); 00072 } 00073 } 00074 }