• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

setup/classes/class.ilCtrlStructureReader.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00034 class ilCtrlStructureReader
00035 {
00036         var $class_script;
00037         var $class_childs;
00038         var $executed;
00039 
00040         function ilCtrlStructureReader()
00041         {
00042                 $this->class_script = array();
00043                 $this->class_childs = array();
00044                 $this->executed = false;
00045         }
00046 
00050         function getStructure()
00051         {
00052                 // only run one time per db_update request
00053                 if (!$this->executed)
00054                 {
00055                         $this->read(ILIAS_ABSOLUTE_PATH);
00056                         $this->store();
00057                         $this->executed = true;
00058                 }
00059                 
00060                 // read module information
00061                 // not clear wheter this is a good place for module reading info
00062                 // or not
00063 /*
00064                 require_once("classes/class.ilModuleReader.php");
00065                 $module_reader =& new ilModuleReader();
00066                 $module_reader->clearTables();
00067                 $module_reader->startParsing();
00068 */
00069         }
00070 
00076         function read($a_cdir)
00077         {
00078                 // check wether $a_cdir is a directory
00079                 if (!@is_dir($a_cdir))
00080                 {
00081                         return false;
00082                 }
00083 
00084                 // read current directory
00085                 $dir = opendir($a_cdir);
00086 
00087                 while($file = readdir($dir))
00088                 {
00089                         if ($file != "." and
00090                                 $file != "..")
00091                         {
00092                                 // directories
00093                                 if (@is_dir($a_cdir."/".$file))
00094                                 {
00095                                         if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data")
00096                                         {
00097                                                 $this->read($a_cdir."/".$file);
00098                                         }
00099                                 }
00100 
00101                                 // files
00102                                 if (@is_file($a_cdir."/".$file))
00103                                 {
00104                                         if (eregi("^class.*php$", $file))
00105                                         {
00106                                                 $handle = fopen($a_cdir."/".$file, "r");
00107                                                 while (!feof($handle)) {
00108                                                         $line = fgets($handle, 4096);
00109                                                         $pos = strpos(strtolower($line), "@ilctrl_calls");
00110                                                         if (is_int($pos))
00111                                                         {
00112                                                                 $com = substr($line, $pos + 14);
00113                                                                 $pos2 = strpos($com, ":");
00114                                                                 if (is_int($pos2))
00115                                                                 {
00116                                                                         $com_arr = explode(":", $com);
00117                                                                         $parent = strtolower(trim($com_arr[0]));
00118                                                                         $this->class_script[$parent] = $a_cdir."/".$file;
00119                                                                         $childs = explode(",", $com_arr[1]);
00120                                                                         foreach($childs as $child)
00121                                                                         {
00122                                                                                 $child = trim(strtolower($child));
00123                                                                                 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00124                                                                                 {
00125                                                                                         $this->class_childs[$parent][] = $child;
00126                                                                                 }
00127                                                                         }
00128                                                                 }
00129                                                         }
00130                                                 }
00131                                                 fclose($handle);
00132                                         }
00133                                 }
00134                         }
00135                 }
00136         }
00137 
00143         function store($a_cdir = "./..")
00144         {
00145                 global $ilDB;
00146 
00147                 // delete all class to file assignments
00148                 $q = "DELETE FROM ctrl_classfile";
00149                 $ilDB->query($q);
00150 
00151                 // delete all call entries
00152                 $q = "DELETE FROM ctrl_calls";
00153                 $ilDB->query($q);
00154 
00155                 foreach($this->class_script as $class => $script)
00156                 {
00157                         $file = substr($script, strlen(ILIAS_ABSOLUTE_PATH) + 1);
00158 
00159                         // store class to file assignment
00160                         $q = "INSERT INTO ctrl_classfile (class, file) VALUES".
00161                                 "(".$ilDB->quote($class).",".$ilDB->quote($file).")";
00162                         $ilDB->query($q);
00163 
00164                         if (is_array($this->class_childs[$class]))
00165                         {
00166                                 foreach($this->class_childs[$class] as $child)
00167                                 {
00168                                         // store call entry
00169                                         $q = "INSERT INTO ctrl_calls (parent, child) VALUES".
00170                                                 "(".$ilDB->quote($class).",".$ilDB->quote($child).")";
00171                                         $ilDB->query($q);
00172                                 }
00173                         }
00174                 }
00175 
00176         }
00177 
00178 }

Generated on Fri Dec 13 2013 10:18:31 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1