Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 class ilCtrlStructureReader
00034 {
00035 var $class_script;
00036 var $class_childs;
00037 var $executed;
00038
00039 function ilCtrlStructureReader()
00040 {
00041 $this->class_script = array();
00042 $this->class_childs = array();
00043 $this->executed = false;
00044 }
00045
00046 function setErrorObject(&$err)
00047 {
00048 $this->err_object =& $err;
00049 }
00050
00054 function getStructure()
00055 {
00056 $this->get_structure = true;
00057 }
00058
00059 function readStructure($a_force = false)
00060 {
00061
00062 if (!$this->get_structure && !$a_force)
00063 {
00064 return;
00065 }
00066
00067
00068 if (!$this->executed)
00069 {
00070 $this->read(ILIAS_ABSOLUTE_PATH);
00071 $this->store();
00072 $this->executed = true;
00073 }
00074
00075
00076
00077
00078 require_once("../classes/class.ilCtrl.php");
00079 $ctrl = new ilCtrl();
00080 $ctrl->storeCommonStructures();
00081 }
00082
00088 function read($a_cdir)
00089 {
00090 global $ilDB, $lng;
00091
00092
00093 if (!@is_dir($a_cdir))
00094 {
00095 return false;
00096 }
00097
00098
00099 $dir = opendir($a_cdir);
00100
00101 while($file = readdir($dir))
00102 {
00103 if ($file != "." and
00104 $file != "..")
00105 {
00106
00107 if (@is_dir($a_cdir."/".$file))
00108 {
00109 if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data")
00110 {
00111 $this->read($a_cdir."/".$file);
00112 }
00113 }
00114
00115
00116 if (@is_file($a_cdir."/".$file))
00117 {
00118 if (eregi("^class.*php$", $file))
00119 {
00120 $handle = fopen($a_cdir."/".$file, "r");
00121
00122 while (!feof($handle)) {
00123 $line = fgets($handle, 4096);
00124
00125
00126 $pos = strpos(strtolower($line), "@ilctrl_calls");
00127 if (is_int($pos))
00128 {
00129 $com = substr($line, $pos + 14);
00130 $pos2 = strpos($com, ":");
00131 if (is_int($pos2))
00132 {
00133 $com_arr = explode(":", $com);
00134 $parent = strtolower(trim($com_arr[0]));
00135
00136
00137 if ($parent != "" && isset($this->class_script[$parent]) &&
00138 $this->class_script[$parent] != $a_cdir."/".$file)
00139 {
00140
00141 $q = "DELETE FROM ctrl_classfile";
00142 $ilDB->query($q);
00143
00144
00145 $q = "DELETE FROM ctrl_calls";
00146 $ilDB->query($q);
00147
00148 $this->err_object->raiseError(
00149 sprintf($lng->txt("duplicate_ctrl"),
00150 $parent,
00151 $this->class_script[$parent],
00152 $a_cdir."/".$file)
00153 , $this->err_object->MESSAGE);
00154 }
00155
00156 $this->class_script[$parent] = $a_cdir."/".$file;
00157 $childs = explode(",", $com_arr[1]);
00158 foreach($childs as $child)
00159 {
00160 $child = trim(strtolower($child));
00161 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00162 {
00163 $this->class_childs[$parent][] = $child;
00164 }
00165 }
00166 }
00167 }
00168
00169
00170 $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
00171 if (is_int($pos))
00172 {
00173 $com = substr($line, $pos + 19);
00174 $pos2 = strpos($com, ":");
00175 if (is_int($pos2))
00176 {
00177 $com_arr = explode(":", $com);
00178 $child = strtolower(trim($com_arr[0]));
00179
00180 $parents = explode(",", $com_arr[1]);
00181 foreach($parents as $parent)
00182 {
00183 $parent = trim(strtolower($parent));
00184 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00185 {
00186 $this->class_childs[$parent][] = $child;
00187 }
00188 }
00189 }
00190 }
00191 }
00192 fclose($handle);
00193 }
00194 }
00195 }
00196 }
00197 }
00198
00204 function store($a_cdir = "./..")
00205 {
00206 global $ilDB;
00207
00208
00209 $q = "DELETE FROM ctrl_classfile";
00210 $ilDB->query($q);
00211
00212
00213 $q = "DELETE FROM ctrl_calls";
00214 $ilDB->query($q);
00215
00216 foreach($this->class_script as $class => $script)
00217 {
00218 $file = substr($script, strlen(ILIAS_ABSOLUTE_PATH) + 1);
00219
00220
00221 $q = "INSERT INTO ctrl_classfile (class, file) VALUES".
00222 "(".$ilDB->quote($class).",".$ilDB->quote($file).")";
00223 $ilDB->query($q);
00224
00225 if (is_array($this->class_childs[$class]))
00226 {
00227 foreach($this->class_childs[$class] as $child)
00228 {
00229
00230 $q = "INSERT INTO ctrl_calls (parent, child) VALUES".
00231 "(".$ilDB->quote($class).",".$ilDB->quote($child).")";
00232 $ilDB->query($q);
00233 }
00234 }
00235 }
00236
00237 }
00238
00239 }