• Main Page
  • Related Pages
  • 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 
00325         function getSubobjectsToFilter($a_obj_type = "adm")
00326         {
00327                 foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
00328                 {
00329                         switch($key)
00330                         {
00331                                 case "rolf":
00332                                         // DO NOTHING
00333                                         break;
00334 
00335                                 default:
00336                                         $tmp_subs[] = $key;
00337                         }
00338                 }
00339                 // ADD adm and root object
00340                 $tmp_subs[] = "adm";
00341                 $tmp_subs[] = "root";
00342 
00343                 return $tmp_subs ? $tmp_subs : array();
00344         }
00345                 
00353         function getCreatableSubObjects($a_obj_type)
00354         {
00355                 $subobjects = $this->getSubObjects($a_obj_type);
00356 
00357                 // remove role folder object from list 
00358                 unset($subobjects["rolf"]);
00359                 
00360                 $sub_types = array_keys($subobjects);
00361 
00362                 // remove object types in development from list
00363                 foreach ($sub_types as $type)
00364                 {
00365                         if ($this->getDevMode($type))
00366                         {
00367                                 unset($subobjects[$type]);
00368                         }
00369                 }
00370 
00371                 return $subobjects;
00372         }
00373 
00380         function getActions($a_obj_name)
00381         {
00382                 $ret = (is_array($this->obj_data[$a_obj_name]["actions"])) ?
00383                         $this->obj_data[$a_obj_name]["actions"] :
00384                         array();
00385                 return $ret;
00386         }
00387 
00394         function getFirstProperty($a_obj_name)
00395         {
00396                 if (defined("ILIAS_MODULE"))
00397                 {
00398                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00399                         {
00400                                 if($prop["module"] != "n")
00401                                 {
00402                                         return $data;
00403                                 }
00404                         }
00405                 }
00406                 else
00407                 {
00408                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00409                         {
00410                                 if ($prop["module"] != 1)
00411                                 {
00412                                         return $data;
00413                                 }
00414                         }
00415                 }
00416         }
00417 
00424         function getPropertyName($a_cmd, $a_obj_name)
00425         {
00426                 return $this->obj_data[$a_obj_name]["properties"][$a_cmd]["lng"];
00427         }
00428 
00435         function getSubObjectsAsString($a_obj_type)
00436         {
00437                 $string = "";
00438 
00439                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00440                 {
00441                         $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
00442 
00443                         $string = "'".implode("','", $data)."'";
00444                 }
00445                 
00446                 return $string;
00447         }
00448 
00455         function getImportObjects($a_obj_type)
00456         {
00457                 $imp = array();
00458 
00459                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00460                 {
00461                         foreach ($this->obj_data[$a_obj_type]["subobjects"] as $sub)
00462                         {
00463                                 if ($sub["import"] == 1)
00464                                 {
00465                                         $imp[] = $sub["name"];
00466                                 }
00467                         }
00468                 }
00469 
00470                 return $imp;
00471         }
00472 
00473 // PRIVATE METHODS
00474 
00481         function setHandlers($a_xml_parser)
00482         {
00483                 xml_set_object($a_xml_parser,$this);
00484                 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00485                 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00486         }
00487 
00496         function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00497         {
00498                 switch ($a_name)
00499                 {
00500                         case 'objects':
00501                                 $this->current_tag = '';
00502                                 break;
00503                         case 'object':
00504                                 $this->parent_tag_name = $a_attribs["name"];
00505                                 $this->current_tag = '';
00506                                 $this->obj_data["$a_attribs[name]"]["name"] = $a_attribs["name"];
00507                                 $this->obj_data["$a_attribs[name]"]["class_name"] = $a_attribs["class_name"];
00508                                 $this->obj_data["$a_attribs[name]"]["location"] = $a_attribs["location"];
00509                                 $this->obj_data["$a_attribs[name]"]["checkbox"] = $a_attribs["checkbox"];
00510                                 $this->obj_data["$a_attribs[name]"]["inherit"] = $a_attribs["inherit"];
00511                                 $this->obj_data["$a_attribs[name]"]["module"] = $a_attribs["module"];
00512                                 $this->obj_data["$a_attribs[name]"]["translate"] = $a_attribs["translate"];
00513                                 $this->obj_data["$a_attribs[name]"]["devmode"] = $a_attribs["devmode"];
00514                                 $this->obj_data["$a_attribs[name]"]["allow_link"] = $a_attribs["allow_link"];
00515                                 $this->obj_data["$a_attribs[name]"]["rbac"] = $a_attribs["rbac"];
00516                                 break;
00517                         case 'subobj':
00518                                 $this->current_tag = "subobj";
00519                                 $this->current_tag_name = $a_attribs["name"];
00520                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["name"] = $a_attribs["name"];
00521                                 // NUMBER OF ALLOWED SUBOBJECTS (NULL means no limit)
00522                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["max"] = $a_attribs["max"];
00523                                 // also allow import ("1" means yes)
00524                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["import"] = $a_attribs["import"];
00525                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["module"] = $a_attribs["module"];
00526                                 break;
00527                         case 'property':
00528                                 $this->current_tag = "property";
00529                                 $this->current_tag_name = $a_attribs["name"];
00530                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
00531                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
00532                                 break;
00533                         case 'action':
00534                                 $this->current_tag = "action";
00535                                 $this->current_tag_name = $a_attribs["name"];
00536                                 $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["name"] = $a_attribs["name"];
00537                                 break;
00538                 }
00539         }
00540 
00548         function handlerCharacterData($a_xml_parser,$a_data)
00549         {
00550                 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
00551                 $a_data = preg_replace("/\n/","",$a_data);
00552                 $a_data = preg_replace("/\t+/","",$a_data);
00553 
00554                 if (!empty($a_data))
00555                 {
00556                         switch ($this->current_tag)
00557                         {
00558                                 case "subobj":
00559                                         $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["lng"] .= $a_data;
00560                                         break;
00561                                 case "action" :
00562                                         $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["lng"] .= $a_data;
00563                                         break;
00564                                 case "property" :
00565                                         $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["lng"] .= $a_data;
00566                                         break;
00567                                 default:
00568                                         break;
00569                         }
00570                 }
00571         }
00572 
00580         function handlerEndTag($a_xml_parser,$a_name)
00581         {
00582                 $this->current_tag = '';
00583                 $this->current_tag_name = '';
00584         }
00585 
00586         function __filterObjects(&$subobjects)
00587         {
00588                 foreach($subobjects as $type => $data)
00589                 {
00590                         switch($type)
00591                         {
00592                                 case "chat":
00593                                         if(!$this->ilias->getSetting("chat_active"))
00594                                         {
00595                                                 unset($subobjects[$type]);
00596                                         }
00597                                         break;
00598 
00599                                 case "icrs":
00600                                         if(!$this->ilias->getSetting("ilinc_active"))
00601                                         {
00602                                                 unset($subobjects[$type]);
00603                                         }
00604                                         break;                                  
00605 
00606                                 default:
00607                                         // DO NOTHING
00608                         }
00609                 }
00610         }
00611 }
00612 ?>

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