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

classes/class.ilObjectDefinition.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 
00024 
00035 class ilObjectDefinition extends ilSaxParser
00036 {
00043         var $obj_id;
00044 
00050         var $parent;
00051 
00057         var $obj_data;
00058 
00065         function ilObjectDefinition()
00066         {
00067                 parent::ilSaxParser(ILIAS_ABSOLUTE_PATH."/objects.xml");
00068         }
00069 
00070 // PUBLIC METHODS
00071 
00078         function getDefinition($a_obj_name)
00079         {
00080                 return $this->obj_data[$a_obj_name];
00081         }
00082 
00089         function getClassName($a_obj_name)
00090         {
00091                 return $this->obj_data[$a_obj_name]["class_name"];
00092         }
00093 
00094 
00101         function getLocation($a_obj_name)
00102         {
00103                 return $this->obj_data[$a_obj_name]["location"];
00104         }
00105 
00106 
00113         function getModule($a_obj_name)
00114         {
00115                 return $this->obj_data[$a_obj_name]["module"];
00116         }
00117 
00118 
00125         function hasCheckbox($a_obj_name)
00126         {
00127                 return (bool) $this->obj_data[$a_obj_name]["checkbox"];
00128         }
00129         
00136         function getTranslationType($a_obj_name)
00137         {
00138                 return $this->obj_data[$a_obj_name]["translate"];
00139         }
00140 
00147         function stopInheritance($a_obj_name)
00148         {
00149                 return (bool) $this->obj_data[$a_obj_name]["inherit"];
00150         }
00151 
00158         function getProperties($a_obj_name)
00159         {
00160                 // dirty hack, has to be implemented better, if ilias.php
00161                 // is established
00162                 if (defined("ILIAS_MODULE") || $_GET["baseClass"] != "")
00163                 {
00164                         $props = array();
00165                         if (is_array($this->obj_data[$a_obj_name]["properties"]))
00166                         {
00167                                 foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00168                                 {
00169                                         if ($prop["module"] != "n")
00170                                         {
00171                                                 $props[$data] = $prop;
00172                                         }
00173                                 }
00174                         }
00175                         return $props;
00176                 }
00177                 else
00178                 {
00179                         $props = array();
00180                         if (is_array($this->obj_data[$a_obj_name]["properties"]))
00181                         {
00182                                 foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00183                                 {
00184                                         if ($prop["module"] != 1)
00185                                         {
00186                                                 $props[$data] = $prop;
00187                                         }
00188                                 }
00189                         }
00190                         return $props;
00191                 }
00192         }
00193 
00200         function getDevMode($a_obj_name)
00201         {
00202                 // always return false if devmode is enabled
00203                 if (DEVMODE)
00204                 {
00205                         return false;
00206                 }
00207                 
00208                 return (bool) $this->obj_data[$a_obj_name]["devmode"];
00209         }
00210 
00217         function getDevModeAll()
00218         {
00219                 // always return empty array if devmode is enabled
00220                 if (DEVMODE)
00221                 {
00222                         return array();
00223                 }
00224 
00225                 $types = array_keys($this->obj_data);
00226                 
00227                 foreach ($types as $type)
00228                 {
00229                         if ($this->getDevMode($type))
00230                         {
00231                                 $devtypes[] = $type;
00232                         }
00233                 }
00234 
00235                 return $devtypes ? $devtypes : array();
00236         }
00237 
00245         function isRBACObject($a_obj_name)
00246         {
00247                 return (bool) $this->obj_data[$a_obj_name]["rbac"];
00248         }
00249 
00256         function getAllRBACObjects()
00257         {
00258                 $types = array_keys($this->obj_data);
00259                 
00260                 foreach ($types as $type)
00261                 {
00262                         if ($this->isRBACObject($type))
00263                         {
00264                                 $rbactypes[] = $type;
00265                         }
00266                 }
00267 
00268                 return $rbactypes ? $rbactypes : array();
00269         }
00270 
00277         function allowLink($a_obj_name)
00278         {
00279                 return (bool) $this->obj_data[$a_obj_name]["allow_link"];
00280         }
00281 
00290         function getSubObjects($a_obj_type,$a_filter = true)
00291         {
00292                 $subs = array();
00293 
00294                 if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
00295                 {
00296                         // Filter some objects e.g chat object are creatable if chat is active
00297                         if ($a_filter)
00298                         {
00299                                 $this->__filterObjects($subobjects);
00300                         }
00301 
00302                         foreach ($subobjects as $data => $sub)
00303                         {
00304                                 if ($sub["module"] != "n")
00305                                 {
00306                                         $subs[$data] = $sub;
00307                                 }
00308                         }
00309 
00310                         return $subs;
00311                 }
00312 
00313                 return $subs;
00314         }
00315 
00329         function getSubObjectsRecursively($a_obj_type)
00330         {
00331                 // This associative array is used to collect all subobject types.
00332                 // key=>type, value=data
00333                 $recursivesubs = array();
00334 
00335                 // This array is used to keep track of the object types, we
00336                 // need to call function getSubobjects() for.
00337                 $to_do = array($a_obj_type);
00338 
00339                 // This array is used to keep track of the object types, we
00340                 // have called function getSubobjects() already. This is to
00341                 // prevent endless loops, for object types that support 
00342                 // themselves as subobject types either directly or indirectly.
00343                 $done = array();
00344 
00345                 while (count($to_do) > 0)
00346                 {
00347                         $type = array_pop($to_do);
00348                         $done[] = $type;
00349                         $subs = $this->getSubObjects($type);
00350                         foreach ($subs as $subtype => $data)
00351                         {
00352                                 $recursivesubs[$subtype] = $data;
00353                                 if (! in_array($subtype, $done)
00354                                 && ! in_array($subtype, $to_do))
00355                                 {
00356                                         $to_do[] = $subtype;
00357                                 }
00358                         }
00359                 }
00360 
00361                 return $recursivesubs;
00362         }
00363 
00373         function getSubobjectsToFilter($a_obj_type = "adm")
00374         {
00375                 foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
00376                 {
00377                         switch($key)
00378                         {
00379                                 case "rolf":
00380                                         // DO NOTHING
00381                                         break;
00382 
00383                                 default:
00384                                         $tmp_subs[] = $key;
00385                         }
00386                 }
00387                 // ADD adm and root object
00388                 $tmp_subs[] = "adm";
00389                 $tmp_subs[] = "root";
00390 
00391                 return $tmp_subs ? $tmp_subs : array();
00392         }
00393                 
00401         function getCreatableSubObjects($a_obj_type)
00402         {
00403                 $subobjects = $this->getSubObjects($a_obj_type);
00404 
00405                 // remove role folder object from list 
00406                 unset($subobjects["rolf"]);
00407                 
00408                 $sub_types = array_keys($subobjects);
00409 
00410                 // remove object types in development from list
00411                 foreach ($sub_types as $type)
00412                 {
00413                         if ($this->getDevMode($type))
00414                         {
00415                                 unset($subobjects[$type]);
00416                         }
00417                 }
00418 
00419                 return $subobjects;
00420         }
00421 
00428         function getActions($a_obj_name)
00429         {
00430                 $ret = (is_array($this->obj_data[$a_obj_name]["actions"])) ?
00431                         $this->obj_data[$a_obj_name]["actions"] :
00432                         array();
00433                 return $ret;
00434         }
00435 
00442         function getFirstProperty($a_obj_name)
00443         {
00444                 if (defined("ILIAS_MODULE"))
00445                 {
00446                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00447                         {
00448                                 if($prop["module"] != "n")
00449                                 {
00450                                         return $data;
00451                                 }
00452                         }
00453                 }
00454                 else
00455                 {
00456                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00457                         {
00458                                 if ($prop["module"] != 1)
00459                                 {
00460                                         return $data;
00461                                 }
00462                         }
00463                 }
00464         }
00465 
00472         function getPropertyName($a_cmd, $a_obj_name)
00473         {
00474                 return $this->obj_data[$a_obj_name]["properties"][$a_cmd]["lng"];
00475         }
00476 
00483         function getSubObjectsAsString($a_obj_type)
00484         {
00485                 $string = "";
00486 
00487                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00488                 {
00489                         $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
00490 
00491                         $string = "'".implode("','", $data)."'";
00492                 }
00493                 
00494                 return $string;
00495         }
00496 
00503         function getImportObjects($a_obj_type)
00504         {
00505                 $imp = array();
00506 
00507                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00508                 {
00509                         foreach ($this->obj_data[$a_obj_type]["subobjects"] as $sub)
00510                         {
00511                                 if ($sub["import"] == 1)
00512                                 {
00513                                         $imp[] = $sub["name"];
00514                                 }
00515                         }
00516                 }
00517 
00518                 return $imp;
00519         }
00520 
00521 // PRIVATE METHODS
00522 
00529         function setHandlers($a_xml_parser)
00530         {
00531                 xml_set_object($a_xml_parser,$this);
00532                 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00533                 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00534         }
00535 
00544         function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00545         {
00546                 switch ($a_name)
00547                 {
00548                         case 'objects':
00549                                 $this->current_tag = '';
00550                                 break;
00551                         case 'object':
00552                                 $this->parent_tag_name = $a_attribs["name"];
00553                                 $this->current_tag = '';
00554                                 $this->obj_data["$a_attribs[name]"]["name"] = $a_attribs["name"];
00555                                 $this->obj_data["$a_attribs[name]"]["class_name"] = $a_attribs["class_name"];
00556                                 $this->obj_data["$a_attribs[name]"]["location"] = $a_attribs["location"];
00557                                 $this->obj_data["$a_attribs[name]"]["checkbox"] = $a_attribs["checkbox"];
00558                                 $this->obj_data["$a_attribs[name]"]["inherit"] = $a_attribs["inherit"];
00559                                 $this->obj_data["$a_attribs[name]"]["module"] = $a_attribs["module"];
00560                                 $this->obj_data["$a_attribs[name]"]["translate"] = $a_attribs["translate"];
00561                                 $this->obj_data["$a_attribs[name]"]["devmode"] = $a_attribs["devmode"];
00562                                 $this->obj_data["$a_attribs[name]"]["allow_link"] = $a_attribs["allow_link"];
00563                                 $this->obj_data["$a_attribs[name]"]["rbac"] = $a_attribs["rbac"];
00564                                 break;
00565                         case 'subobj':
00566                                 $this->current_tag = "subobj";
00567                                 $this->current_tag_name = $a_attribs["name"];
00568                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["name"] = $a_attribs["name"];
00569                                 // NUMBER OF ALLOWED SUBOBJECTS (NULL means no limit)
00570                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["max"] = $a_attribs["max"];
00571                                 // also allow import ("1" means yes)
00572                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["import"] = $a_attribs["import"];
00573                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["module"] = $a_attribs["module"];
00574                                 break;
00575                         case 'property':
00576                                 $this->current_tag = "property";
00577                                 $this->current_tag_name = $a_attribs["name"];
00578                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
00579                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
00580                                 break;
00581                         case 'action':
00582                                 $this->current_tag = "action";
00583                                 $this->current_tag_name = $a_attribs["name"];
00584                                 $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["name"] = $a_attribs["name"];
00585                                 break;
00586                 }
00587         }
00588 
00596         function handlerCharacterData($a_xml_parser,$a_data)
00597         {
00598                 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
00599                 $a_data = preg_replace("/\n/","",$a_data);
00600                 $a_data = preg_replace("/\t+/","",$a_data);
00601 
00602                 if (!empty($a_data))
00603                 {
00604                         switch ($this->current_tag)
00605                         {
00606                                 case "subobj":
00607                                         $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["lng"] .= $a_data;
00608                                         break;
00609                                 case "action" :
00610                                         $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["lng"] .= $a_data;
00611                                         break;
00612                                 case "property" :
00613                                         $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["lng"] .= $a_data;
00614                                         break;
00615                                 default:
00616                                         break;
00617                         }
00618                 }
00619         }
00620 
00628         function handlerEndTag($a_xml_parser,$a_name)
00629         {
00630                 $this->current_tag = '';
00631                 $this->current_tag_name = '';
00632         }
00633 
00634         function __filterObjects(&$subobjects)
00635         {
00636                 foreach($subobjects as $type => $data)
00637                 {
00638                         switch($type)
00639                         {
00640                                 case "chat":
00641                                         if(!$this->ilias->getSetting("chat_active"))
00642                                         {
00643                                                 unset($subobjects[$type]);
00644                                         }
00645                                         break;
00646 
00647                                 case "icrs":
00648                                         if(!$this->ilias->getSetting("ilinc_active"))
00649                                         {
00650                                                 unset($subobjects[$type]);
00651                                         }
00652                                         break;                                  
00653 
00654                                 default:
00655                                         // DO NOTHING
00656                         }
00657                 }
00658         }
00659 }
00660 ?>

Generated on Fri Dec 13 2013 13:52:07 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1