ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainer.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 // note: the values are derived from ilObjCourse constants
25 // to enable easy migration from course view setting to container view setting
26 
27 require_once "./classes/class.ilObject.php";
28 
39 class ilContainer extends ilObject
40 {
41  protected $order_type = 0;
42  protected $hiddenfilesfound = false;
43 
44  // container view constants
45  const VIEW_SESSIONS = 0;
46  const VIEW_OBJECTIVE = 1;
47  const VIEW_TIMING = 2;
48  const VIEW_ARCHIVE = 3;
49  const VIEW_SIMPLE = 4;
50  const VIEW_BY_TYPE = 5;
51  const VIEW_INHERIT = 6;
52  const VIEW_ILINC = 7;
53 
55 
56 
57  const SORT_TITLE = 0;
58  const SORT_MANUAL = 1;
59  const SORT_ACTIVATION = 2;
60  const SORT_INHERIT = 3;
61 
62  static $data_preloaded = false;
63 
70  function ilContainer($a_id = 0, $a_call_by_reference = true)
71  {
72  parent::__construct($a_id, $a_call_by_reference);
73  }
74 
75 
76 
82  {
83  $webspace_dir = ilUtil::getWebspaceDir();
84  $cont_dir = $webspace_dir."/container_data";
85  if (!is_dir($cont_dir))
86  {
87  ilUtil::makeDir($cont_dir);
88  }
89  $obj_dir = $cont_dir."/obj_".$this->getId();
90  if (!is_dir($obj_dir))
91  {
92  ilUtil::makeDir($obj_dir);
93  }
94  }
95 
102  {
103  return $this->_getContainerDirectory($this->getId());
104  }
105 
111  function _getContainerDirectory($a_id)
112  {
113  return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
114  }
115 
121  function getBigIconPath()
122  {
123  return ilContainer::_lookupIconPath($this->getId(), "big");
124  }
125 
131  function getSmallIconPath()
132  {
133  return ilContainer::_lookupIconPath($this->getId(), "small");
134  }
135 
141  function getTinyIconPath()
142  {
143  return ilContainer::_lookupIconPath($this->getId(), "tiny");
144  }
145 
146 
152  function setHiddenFilesFound($a_hiddenfilesfound)
153  {
154  $this->hiddenfilesfound = $a_hiddenfilesfound;
155  }
156 
163  {
165  }
166 
170  function getStyleSheetId()
171  {
172  return $this->style_id;
173  }
174 
178  function setStyleSheetId($a_style_id)
179  {
180  $this->style_id = $a_style_id;
181  }
182 
191  function _lookupContainerSetting($a_id, $a_keyword)
192  {
193  global $ilDB;
194 
195  $q = "SELECT * FROM container_settings WHERE ".
196  " id = ".$ilDB->quote($a_id ,'integer')." AND ".
197  " keyword = ".$ilDB->quote($a_keyword ,'text');
198  $set = $ilDB->query($q);
199  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
200 
201  return $rec["value"];
202  }
203 
204  function _writeContainerSetting($a_id, $a_keyword, $a_value)
205  {
206  global $ilDB;
207 
208  $query = "DELETE FROM container_settings WHERE ".
209  "id = ".$ilDB->quote($a_id,'integer')." ".
210  "AND keyword = ".$ilDB->quote($a_keyword,'text');
211  $res = $ilDB->manipulate($query);
212 
213  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (".
214  $ilDB->quote($a_id ,'integer').", ".
215  $ilDB->quote($a_keyword ,'text').", ".
216  $ilDB->quote($a_value ,'text').
217  ")";
218  $res = $ilDB->manipulate($query);
219  }
220 
227  function _lookupIconPath($a_id, $a_size = "big")
228  {
229  if ($a_size == "")
230  {
231  $a_size = "big";
232  }
233 
234  $size = $a_size;
235 
236  if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
237  {
238  $cont_dir = ilContainer::_getContainerDirectory($a_id);
239  $file_name = $cont_dir."/icon_".$a_size.".gif";
240 
241  if (is_file($file_name))
242  {
243  return $file_name;
244  }
245  }
246 
247  return "";
248  }
249 
253  function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
254  {
255  global $ilDB;
256 
257  $this->createContainerDirectory();
258  $cont_dir = $this->getContainerDirectory();
259 
260  // save big icon
261  $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
262  $this->ilias->getSetting("custom_icon_big_height");
263  $big_file_name = $cont_dir."/icon_big.gif";
264 
265  if (is_file($a_big_icon))
266  {
267  $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
268  $big_file_name = ilUtil::escapeShellArg($big_file_name);
269  ilUtil::execConvert($a_big_icon."[0] -geometry ".$big_geom." GIF:".$big_file_name);
270  }
271 
272  if (is_file($cont_dir."/icon_big.gif"))
273  {
274  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
275  }
276  else
277  {
278  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
279  }
280 
281  // save small icon
282  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
283  $this->ilias->getSetting("custom_icon_small_height");
284  $small_file_name = $cont_dir."/icon_small.gif";
285 
286  if (is_file($a_small_icon))
287  {
288  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
289  $small_file_name = ilUtil::escapeShellArg($small_file_name);
290  ilUtil::execConvert($a_small_icon."[0] -geometry ".$small_geom." GIF:".$small_file_name);
291  }
292  if (is_file($cont_dir."/icon_small.gif"))
293  {
294  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
295  }
296  else
297  {
298  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
299  }
300 
301  // save tiny icon
302  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
303  $this->ilias->getSetting("custom_icon_tiny_height");
304  $tiny_file_name = $cont_dir."/icon_tiny.gif";
305 
306  if (is_file($a_tiny_icon))
307  {
308  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
309  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
310  ilUtil::execConvert($a_tiny_icon."[0] -geometry ".$tiny_geom." GIF:".$tiny_file_name);
311  }
312  if (is_file($cont_dir."/icon_tiny.gif"))
313  {
314  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
315  }
316  else
317  {
318  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
319  }
320 
321  }
322 
326  function removeBigIcon()
327  {
328  $cont_dir = $this->getContainerDirectory();
329  $big_file_name = $cont_dir."/icon_big.gif";
330  @unlink($big_file_name);
331  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
332  }
333 
337  function removeSmallIcon()
338  {
339  $cont_dir = $this->getContainerDirectory();
340  $small_file_name = $cont_dir."/icon_small.gif";
341  @unlink($small_file_name);
342  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
343  }
344 
348  function removeTinyIcon()
349  {
350  $cont_dir = $this->getContainerDirectory();
351  $tiny_file_name = $cont_dir."/icon_tiny.gif";
352  @unlink($tiny_file_name);
353  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
354  }
355 
361  function getFirstColumn()
362  {
363  $col_id = ilContainer::_lookupContainerSetting($this->getId(), "first_column");
364  if ($col_id > 0)
365  {
366  include_once("./Services/Blocks/class.ilBlockColumn.php");
367  $block_column = new ilBlockColumn($col_id);
368  return $block_column;
369  }
370  return false;
371  }
372 
381  public function cloneObject($a_target_id,$a_copy_id = 0)
382  {
383  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
384 
385  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
386  $sorting = new ilContainerSortingSettings($new_obj->getId());
387  $sorting->setSortMode($this->getOrderType());
388  $sorting->update();
389 
390  // copy content page
391  include_once("./Services/COPage/classes/class.ilPageObject.php");
392  if (ilPageObject::_exists($this->getType(),
393  $this->getId()))
394  {
395  $orig_page = new ilPageObject($this->getType(), $this->getId());
396  $new_page_object = new ilPageObject($this->getType());
397  $new_page_object->setParentId($new_obj->getId());
398  $new_page_object->setId($new_obj->getId());
399  $new_page_object->createFromXML();
400  $new_page_object->setXMLContent($orig_page->getXMLContent());
401  $new_page_object->buildDom();
402  $new_page_object->update();
403  }
404 
405  return $new_obj;
406  }
407 
416  public function cloneDependencies($a_target_id,$a_copy_id)
417  {
418  parent::cloneDependencies($a_target_id, $a_copy_id);
419 
420  include_once('./Services/Container/classes/class.ilContainerSorting.php');
421  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
422  return true;
423  }
424 
436  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
437  {
438  global $ilLog;
439 
440  include_once('classes/class.ilLink.php');
441  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
442 
443  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
444 
445  // Save wizard options
447  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
448  $wizard_options->saveOwner($ilUser->getId());
449  $wizard_options->saveRoot($clone_source);
450 
451  // add entry for source container
452  $wizard_options->initContainer($clone_source, $ref_id);
453 
454  foreach($options as $source_id => $option)
455  {
456  $wizard_options->addEntry($source_id,$option);
457  }
458  $wizard_options->read();
459  $wizard_options->storeTree($clone_source);
460 
461  // Special handling for course in existing courses
462  if($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs')
463  {
464  $ilLog->write(__METHOD__.': Copy course in course...');
465  $ilLog->write(__METHOD__.': Added mapping, source ID: '.$clone_source.', target ID: '.$ref_id);
466  $wizard_options->read();
467  $wizard_options->dropFirstNode();
468  $wizard_options->appendMapping($clone_source,$ref_id);
469  }
470 
471  #print_r($options);
472  // Duplicate session to avoid logout problems with backgrounded SOAP calls
473  $new_session_id = duplicate_session($session_id);
474  // Start cloning process using soap call
475  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
476 
477  $soap_client = new ilSoapClient();
478  $soap_client->setResponseTimeout(30);
479  $soap_client->enableWSDL(true);
480 
481  $ilLog->write(__METHOD__.': Trying to call Soap client...');
482  if($soap_client->init())
483  {
484  $ilLog->write(__METHOD__.': Calling soap clone method...');
485  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
486  }
487  else
488  {
489  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
490  $wizard_options->disableSOAP();
491  $wizard_options->read();
492  include_once('./webservice/soap/include/inc.soap_functions.php');
493  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
494  }
495  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
496  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
497  {
498  return $res;
499  }
500  else
501  {
502  return $ref_id;
503  }
504  }
505 
509  function getViewMode()
510  {
512  }
513 
517  function getOrderType()
518  {
519  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
520  }
521 
522  function setOrderType($a_value)
523  {
524  $this->order_type = $a_value;
525  }
526 
535  function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false,
536  $a_get_single = 0)
537  {
538  global $objDefinition, $ilBench, $tree, $ilObjDataCache, $ilUser, $rbacsystem,
539  $ilSetting;
540 
541  // Caching
542  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
543  !$a_get_single)
544  {
545  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
546  }
547 
548  $type_grps = $this->getGroupedObjTypes();
549  $objects = $tree->getChilds($this->getRefId(), "title");
550 
551  $found = false;
552  $all_obj_types = array();
553  $all_ref_ids = array();
554  $all_obj_ids = array();
555 
556  include_once('Services/Container/classes/class.ilContainerSorting.php');
557  $sort = ilContainerSorting::_getInstance($this->getId());
558 
559  // TODO: check this
560  // get items attached to a session
561  include_once './Modules/Session/classes/class.ilEventItems.php';
562  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
563 
564  foreach ($objects as $key => $object)
565  {
566  if ($a_get_single > 0 && $object["child"] != $a_get_single)
567  {
568  continue;
569  }
570 
571  // hide object types in devmode
572  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
573  || $object["type"] == "rolf")
574  {
575  continue;
576  }
577 
578  // remove inactive plugins
579  if ($objDefinition->isInactivePlugin($object["type"]))
580  {
581  continue;
582  }
583 
584  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
585  if (in_array($object['type'], array('file','fold','cat')))
586  {
587  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
588  if (ilObjFileAccess::_isFileHidden($object['title']))
589  {
590  $this->setHiddenFilesFound(true);
591  if (!$a_admin_panel_enabled)
592  {
593  continue;
594  }
595  }
596  }
597  // END WebDAV: Don't display hidden Files, Folders and Categories
598 
599  // filter out items that are attached to an event
600  if (in_array($object['ref_id'],$event_items))
601  {
602  continue;
603  }
604 
605  // filter side block items
606  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
607  {
608  continue;
609  }
610 
611  // group object type groups together (e.g. learning resources)
612  $type = $objDefinition->getGroupOfObj($object["type"]);
613  if ($type == "")
614  {
615  $type = $object["type"];
616  }
617 
618  $this->addAdditionalSubItemInformation($object);
619 
620  $this->items[$type][$key] = $object;
621 
622  $all_obj_types[$object["type"]] = $object["type"];
623  $obj_ids_of_type[$object["type"]][] = $object["obj_id"];
624  $ref_ids_of_type[$object["type"]][] = $object["child"];
625 
626  $all_ref_ids[] = $object["child"];
627  $all_obj_ids[] = $object["obj_id"];
628 
629  $this->items["_all"][$key] = $object;
630  if ($object["type"] != "sess")
631  {
632  $this->items["_non_sess"][$key] = $object;
633  }
634  }
635 
636  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
637  = $sort->sortItems($this->items);
638 
639  // data preloader
640  if (!self::$data_preloaded && is_array($this->items))
641  {
642  // type specific preloads
643  foreach ($all_obj_types as $t)
644  {
645  // condition handler: preload conditions
646  include_once("./Services/AccessControl/classes/class.ilConditionHandler.php");
648  $obj_ids_of_type[$t]);
649 
650  $class = $objDefinition->getClassName($t);
651  $location = $objDefinition->getLocation($t);
652  $full_class = "ilObj".$class."Access";
653  include_once($location."/class.".$full_class.".php");
654  call_user_func(array($full_class, "_preloadData"),
655  $obj_ids_of_type[$t], $ref_ids_of_type[$t]);
656  }
657 
658  // general preloads
659  $tree->preloadDeleted($all_ref_ids);
660  $tree->preloadDepthParent($all_ref_ids);
661  $ilObjDataCache->preloadReferenceCache($all_ref_ids, false);
662  ilObjUser::preloadIsDesktopItem($ilUser->getId(), $all_ref_ids);
663  $rbacsystem->preloadRbacPaCache($all_ref_ids, $ilUser->getId());
664  include_once("./Services/Object/classes/class.ilObjectListGUI.php");
665 
667 
668  self::$data_preloaded = true;
669  }
670 
671  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
672  }
673 
677  function gotItems()
678  {
679  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
680  {
681  return true;
682  }
683  return false;
684  }
685 
691  {
692  }
693 
700  {
701  global $objDefinition;
702 
703  if (empty($this->type_grps))
704  {
705  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
706  }
707  return $this->type_grps;
708  }
709 
713  function enablePageEditing()
714  {
715  global $ilSetting;
716 
717  // @todo: this will need a more general approach
718  if ($ilSetting->get("enable_cat_page_edit"))
719  {
720  return true;
721  }
722  }
723 
727  function create()
728  {
729  $ret = parent::create();
730 
731  if (((int) $this->getStyleSheetId()) > 0)
732  {
733  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
735  }
736 
737  return $ret;
738  }
739 
743  function update()
744  {
745  $ret = parent::update();
746 
747  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
749 
750  return $ret;
751  }
752 
753 
761  public function read()
762  {
763  parent::read();
764 
765  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
767 
768  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
770  }
771 
772 } // END class ilContainer
773 ?>