• 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 getModule($a_obj_name)
00102         {
00103                 return $this->obj_data[$a_obj_name]["module"];
00104         }
00105 
00106 
00113         function hasCheckbox($a_obj_name)
00114         {
00115                 return (bool) $this->obj_data[$a_obj_name]["checkbox"];
00116         }
00117         
00124         function getTranslationType($a_obj_name)
00125         {
00126                 return $this->obj_data[$a_obj_name]["translate"];
00127         }
00128 
00135         function stopInheritance($a_obj_name)
00136         {
00137                 return (bool) $this->obj_data[$a_obj_name]["inherit"];
00138         }
00139 
00146         function getProperties($a_obj_name)
00147         {
00148                 if (defined("ILIAS_MODULE"))
00149                 {
00150                         $props = array();
00151                         if (is_array($this->obj_data[$a_obj_name]["properties"]))
00152                         {
00153                                 foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00154                                 {
00155                                         if ($prop["module"] != "n")
00156                                         {
00157                                                 $props[$data] = $prop;
00158                                         }
00159                                 }
00160                         }
00161                         return $props;
00162                 }
00163                 else
00164                 {
00165                         $props = array();
00166                         if (is_array($this->obj_data[$a_obj_name]["properties"]))
00167                         {
00168                                 foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00169                                 {
00170                                         if ($prop["module"] != 1)
00171                                         {
00172                                                 $props[$data] = $prop;
00173                                         }
00174                                 }
00175                         }
00176                         return $props;
00177                 }
00178         }
00179 
00186         function getDevMode($a_obj_name)
00187         {
00188                 // always return false if devmode is enabled
00189                 if (DEVMODE)
00190                 {
00191                         return false;
00192                 }
00193                 
00194                 return (bool) $this->obj_data[$a_obj_name]["devmode"];
00195         }
00196 
00203         function getDevModeAll()
00204         {
00205                 // always return empty array if devmode is enabled
00206                 if (DEVMODE)
00207                 {
00208                         return array();
00209                 }
00210 
00211                 $types = array_keys($this->obj_data);
00212                 
00213                 foreach ($types as $type)
00214                 {
00215                         if ($this->getDevMode($type))
00216                         {
00217                                 $devtypes[] = $type;
00218                         }
00219                 }
00220 
00221                 return $devtypes ? $devtypes : array();
00222         }
00223 
00231         function isRBACObject($a_obj_name)
00232         {
00233                 return (bool) $this->obj_data[$a_obj_name]["rbac"];
00234         }
00235 
00242         function getAllRBACObjects()
00243         {
00244                 $types = array_keys($this->obj_data);
00245                 
00246                 foreach ($types as $type)
00247                 {
00248                         if ($this->isRBACObject($type))
00249                         {
00250                                 $rbactypes[] = $type;
00251                         }
00252                 }
00253 
00254                 return $rbactypes ? $rbactypes : array();
00255         }
00256 
00263         function allowLink($a_obj_name)
00264         {
00265                 return (bool) $this->obj_data[$a_obj_name]["allow_link"];
00266         }
00267 
00275         function getSubObjects($a_obj_type)
00276         {
00277                 $subs = array();
00278 
00279                 if ($subobjects = $this->obj_data[$a_obj_type]["subobjects"])
00280                 {
00281                         // Filter some objects e.g chat object are creatable if chat is active
00282                         $this->__filterObjects($subobjects);
00283 
00284                         foreach ($subobjects as $data => $sub)
00285                         {
00286                                 if ($sub["module"] != "n")
00287                                 {
00288                                         $subs[$data] = $sub;
00289                                 }
00290                         }
00291 
00292                         return $subs;
00293                 }
00294 
00295                 return $subs;
00296         }
00297 
00307         function getSubobjectsToFilter($a_obj_type = "adm")
00308         {
00309                 foreach($this->obj_data[$a_obj_type]["subobjects"] as $key => $value)
00310                 {
00311                         switch($key)
00312                         {
00313                                 case "rolf":
00314                                         // DO NOTHING
00315                                         break;
00316 
00317                                 default:
00318                                         $tmp_subs[] = $key;
00319                         }
00320                 }
00321                 // ADD adm and root object
00322                 $tmp_subs[] = "adm";
00323                 $tmp_subs[] = "root";
00324 
00325                 return $tmp_subs ? $tmp_subs : array();
00326         }
00327                 
00335         function getCreatableSubObjects($a_obj_type)
00336         {
00337                 $subobjects = $this->getSubObjects($a_obj_type);
00338 
00339                 // remove role folder object from list 
00340                 unset($subobjects["rolf"]);
00341                 
00342                 $sub_types = array_keys($subobjects);
00343 
00344                 // remove object types in development from list
00345                 foreach ($sub_types as $type)
00346                 {
00347                         if ($this->getDevMode($type))
00348                         {
00349                                 unset($subobjects[$type]);
00350                         }
00351                 }
00352 
00353                 return $subobjects;
00354         }
00355 
00362         function getActions($a_obj_name)
00363         {
00364                 $ret = (is_array($this->obj_data[$a_obj_name]["actions"])) ?
00365                         $this->obj_data[$a_obj_name]["actions"] :
00366                         array();
00367                 return $ret;
00368         }
00369 
00376         function getFirstProperty($a_obj_name)
00377         {
00378                 if (defined("ILIAS_MODULE"))
00379                 {
00380                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00381                         {
00382                                 if($prop["module"] != "n")
00383                                 {
00384                                         return $data;
00385                                 }
00386                         }
00387                 }
00388                 else
00389                 {
00390                         foreach ($this->obj_data[$a_obj_name]["properties"] as $data => $prop)
00391                         {
00392                                 if ($prop["module"] != 1)
00393                                 {
00394                                         return $data;
00395                                 }
00396                         }
00397                 }
00398         }
00399 
00406         function getPropertyName($a_cmd, $a_obj_name)
00407         {
00408                 return $this->obj_data[$a_obj_name]["properties"][$a_cmd]["lng"];
00409         }
00410 
00417         function getSubObjectsAsString($a_obj_type)
00418         {
00419                 $string = "";
00420 
00421                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00422                 {
00423                         $data = array_keys($this->obj_data[$a_obj_type]["subobjects"]);
00424 
00425                         $string = "'".implode("','", $data)."'";
00426                 }
00427                 
00428                 return $string;
00429         }
00430 
00437         function getImportObjects($a_obj_type)
00438         {
00439                 $imp = array();
00440 
00441                 if (is_array($this->obj_data[$a_obj_type]["subobjects"]))
00442                 {
00443                         foreach ($this->obj_data[$a_obj_type]["subobjects"] as $sub)
00444                         {
00445                                 if ($sub["import"] == 1)
00446                                 {
00447                                         $imp[] = $sub["name"];
00448                                 }
00449                         }
00450                 }
00451 
00452                 return $imp;
00453         }
00454 
00455 // PRIVATE METHODS
00456 
00463         function setHandlers($a_xml_parser)
00464         {
00465                 xml_set_object($a_xml_parser,$this);
00466                 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00467                 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00468         }
00469 
00478         function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00479         {
00480                 switch ($a_name)
00481                 {
00482                         case 'objects':
00483                                 $this->current_tag = '';
00484                                 break;
00485                         case 'object':
00486                                 $this->parent_tag_name = $a_attribs["name"];
00487                                 $this->current_tag = '';
00488                                 $this->obj_data["$a_attribs[name]"]["name"] = $a_attribs["name"];
00489                                 $this->obj_data["$a_attribs[name]"]["class_name"] = $a_attribs["class_name"];
00490                                 $this->obj_data["$a_attribs[name]"]["checkbox"] = $a_attribs["checkbox"];
00491                                 $this->obj_data["$a_attribs[name]"]["inherit"] = $a_attribs["inherit"];
00492                                 $this->obj_data["$a_attribs[name]"]["module"] = $a_attribs["module"];
00493                                 $this->obj_data["$a_attribs[name]"]["translate"] = $a_attribs["translate"];
00494                                 $this->obj_data["$a_attribs[name]"]["devmode"] = $a_attribs["devmode"];
00495                                 $this->obj_data["$a_attribs[name]"]["allow_link"] = $a_attribs["allow_link"];
00496                                 $this->obj_data["$a_attribs[name]"]["rbac"] = $a_attribs["rbac"];
00497                                 break;
00498                         case 'subobj':
00499                                 $this->current_tag = "subobj";
00500                                 $this->current_tag_name = $a_attribs["name"];
00501                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["name"] = $a_attribs["name"];
00502                                 // NUMBER OF ALLOWED SUBOBJECTS (NULL means no limit)
00503                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["max"] = $a_attribs["max"];
00504                                 // also allow import ("1" means yes)
00505                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["import"] = $a_attribs["import"];
00506                                 $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["module"] = $a_attribs["module"];
00507                                 break;
00508                         case 'property':
00509                                 $this->current_tag = "property";
00510                                 $this->current_tag_name = $a_attribs["name"];
00511                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["name"] = $a_attribs["name"];
00512                                 $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["module"] = $a_attribs["module"];
00513                                 break;
00514                         case 'action':
00515                                 $this->current_tag = "action";
00516                                 $this->current_tag_name = $a_attribs["name"];
00517                                 $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["name"] = $a_attribs["name"];
00518                                 break;
00519                 }
00520         }
00521 
00529         function handlerCharacterData($a_xml_parser,$a_data)
00530         {
00531                 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
00532                 $a_data = preg_replace("/\n/","",$a_data);
00533                 $a_data = preg_replace("/\t+/","",$a_data);
00534 
00535                 if (!empty($a_data))
00536                 {
00537                         switch ($this->current_tag)
00538                         {
00539                                 case "subobj":
00540                                         $this->obj_data[$this->parent_tag_name]["subobjects"][$this->current_tag_name]["lng"] .= $a_data;
00541                                         break;
00542                                 case "action" :
00543                                         $this->obj_data[$this->parent_tag_name]["actions"][$this->current_tag_name]["lng"] .= $a_data;
00544                                         break;
00545                                 case "property" :
00546                                         $this->obj_data[$this->parent_tag_name]["properties"][$this->current_tag_name]["lng"] .= $a_data;
00547                                         break;
00548                                 default:
00549                                         break;
00550                         }
00551                 }
00552         }
00553 
00561         function handlerEndTag($a_xml_parser,$a_name)
00562         {
00563                 $this->current_tag = '';
00564                 $this->current_tag_name = '';
00565         }
00566 
00567         function __filterObjects(&$subobjects)
00568         {
00569                 foreach($subobjects as $type => $data)
00570                 {
00571                         switch($type)
00572                         {
00573                                 case "chat":
00574                                         if(!$this->ilias->getSetting("chat_active"))
00575                                         {
00576                                                 unset($subobjects[$type]);
00577                                         }
00578                                         break;
00579 
00580                                 case "icrs":
00581                                 case "icla":
00582                                         if(!$this->ilias->ini->readVariable("iLinc","server_addr"))
00583                                         {
00584                                                 unset($subobjects[$type]);
00585                                         }
00586                                         break;                                  
00587 
00588                                 default:
00589                                         // DO NOTHING
00590                         }
00591                 }
00592         }
00593 }
00594 ?>

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