• 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 
00066         function read($a_cdir)
00067         {
00068                 // check wether $a_cdir is a directory
00069                 if (!@is_dir($a_cdir))
00070                 {
00071                         return false;
00072                 }
00073 
00074                 // read current directory
00075                 $dir = opendir($a_cdir);
00076 
00077                 while($file = readdir($dir))
00078                 {
00079                         if ($file != "." and
00080                                 $file != "..")
00081                         {
00082                                 // directories
00083                                 if (@is_dir($a_cdir."/".$file))
00084                                 {
00085                                         if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data")
00086                                         {
00087                                                 $this->read($a_cdir."/".$file);
00088                                         }
00089                                 }
00090 
00091                                 // files
00092                                 if (@is_file($a_cdir."/".$file))
00093                                 {
00094                                         if (eregi("^class.*php$", $file))
00095                                         {
00096                                                 $handle = fopen($a_cdir."/".$file, "r");
00097                                                 while (!feof($handle)) {
00098                                                         $line = fgets($handle, 4096);
00099                                                         $pos = strpos(strtolower($line), "@ilctrl_calls");
00100                                                         if (is_int($pos))
00101                                                         {
00102                                                                 $com = substr($line, $pos + 14);
00103                                                                 $pos2 = strpos($com, ":");
00104                                                                 if (is_int($pos2))
00105                                                                 {
00106                                                                         $com_arr = explode(":", $com);
00107                                                                         $parent = strtolower(trim($com_arr[0]));
00108                                                                         $this->class_script[$parent] = $a_cdir."/".$file;
00109                                                                         $childs = explode(",", $com_arr[1]);
00110                                                                         foreach($childs as $child)
00111                                                                         {
00112                                                                                 $child = trim(strtolower($child));
00113                                                                                 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00114                                                                                 {
00115                                                                                         $this->class_childs[$parent][] = $child;
00116                                                                                 }
00117                                                                         }
00118                                                                 }
00119                                                         }
00120                                                 }
00121                                                 fclose($handle);
00122                                         }
00123                                 }
00124                         }
00125                 }
00126         }
00127 
00133         function store($a_cdir = "./..")
00134         {
00135                 global $ilDB;
00136 
00137                 // delete all class to file assignments
00138                 $q = "DELETE FROM ctrl_classfile";
00139                 $ilDB->query($q);
00140 
00141                 // delete all call entries
00142                 $q = "DELETE FROM ctrl_calls";
00143                 $ilDB->query($q);
00144 
00145                 foreach($this->class_script as $class => $script)
00146                 {
00147                         $file = substr($script, strlen(ILIAS_ABSOLUTE_PATH) + 1);
00148 
00149                         // store class to file assignment
00150                         $q = "INSERT INTO ctrl_classfile (class, file) VALUES".
00151                                 "(".$ilDB->quote($class).",".$ilDB->quote($file).")";
00152                         $ilDB->query($q);
00153 
00154                         if (is_array($this->class_childs[$class]))
00155                         {
00156                                 foreach($this->class_childs[$class] as $child)
00157                                 {
00158                                         // store call entry
00159                                         $q = "INSERT INTO ctrl_calls (parent, child) VALUES".
00160                                                 "(".$ilDB->quote($class).",".$ilDB->quote($child).")";
00161                                         $ilDB->query($q);
00162                                 }
00163                         }
00164                 }
00165 
00166         }
00167 
00168 }

Generated on Fri Dec 13 2013 09:06:37 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1