3 require_once("AOOSException.php");
4 require_once("AOOSModel.php");
5 require_once("AOOSStorageDevice.php");
11 * The core class of AOOS
13 * @author Sebastian Skejø
18 private $_exceptions = array();
19 private $_modules = null;
20 private $_settings = array();
21 private $_transStrings = array();
24 * During constructing a model is built with module names and properties
26 public function __construct()
28 require_once("config.php");
29 $this->_settings
= $settings; /* Set in config.php */
30 $l = $this->getSetting("lang");
31 require_once("lang.php");
32 if (!in_array($l, array_keys($lang))) /* $lang set in lang.php */
34 throw new AOOSException($this, "Language not found in lang.php. You will not be able to translate strings","",true, 1);
38 $this->_transStrings
= $lang[$l];
42 $s = new AOOSStorageDevice($this);
43 $s->setStorageType("mysql");
44 $s->setTable("modules");
45 $this->_modules
= $s->selectModel("*");
46 $this->_modules
->setEscape(false);
51 * @param AOOSException $e The exception
53 public function setException($e)
55 $this->_exceptions
[$e->getName()] = $e;
56 if ($e->getEcode() == 0)
64 public function printExceptions()
66 $str = "<div class=\"Exceptions\">";
67 foreach ($this->_exceptions
as $e)
75 public function getSetting($name, $module = "no")
77 $a = $this->_settings
;
82 if (!in_array($name, array_keys($a)))
84 throw new AOOSException($this, "Settingkey not found", "Key: ".$name, true, 2);
87 return $this->_settings
[$name];
90 public function getTranslatedString($string)
92 if (!in_array($string, array_keys($this->_transStrings
)))
94 throw new AOOSException($this, "Translated string not found", "String name: ".$string, true, 2);
97 return $this->_transStrings
[$string];
100 public function modules()
102 return $this->_modules
;
105 public function loadModule($name)
107 $m = $this->modules();
108 if (($r = $m->getRowFromValue("name", $name)) === false)
110 throw new AOOSException($this, $this->getTranslatedString("module_not_loadable"), "", true, 1);
114 $row = $m->getRow($r);
115 $dir = $this->getSetting("module_dir")."/".$row["name"]."/";
116 $filename = $row["name"].$this->getSetting("extension");
118 if ($row["instance"])
120 return $row["instance"];
123 require_once($dir.$filename);
124 $i = new $row["name"]($this);
125 $m->setData($i, $r, "instance");
126 if (file_exists($dir."settings".$this->getSetting("extension")))
128 require_once($dir."settings".$this->getSetting("extenstion"));
129 $this->_settings
[$row["name"]] = $settings;
136 * Returns true if $module is loaded, otherwise return false.
137 * @param string $name Module name
140 public function isLoaded($name)
142 $m = $this->modules();
143 if (($row = $m->getRowFromValue("name", $name)) === false)
145 // TODO: throw exception
153 * Returns an instance to the given $module
154 * @param string $module The name of the module
155 * @return false|AOOSModule
157 public function getModule($module)
159 $m = $this->modules();
160 if (($row = $m->getRowFromValue("name", $module)) === false)
163 throw new AOOSException($this, $this->getTranslatedString("module_not_found"), "", true, 1);
166 return $this->loadModule($module);
169 public function __toString()