ILIAS  release_4-3 Revision
 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 "./Services/Object/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, $a_default_value = NULL)
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  if(isset($rec['value']))
202  {
203  return $rec["value"];
204  }
205  if($a_default_value === NULL)
206  {
207  return '';
208  }
209  return $a_default_value;
210  }
211 
212  function _writeContainerSetting($a_id, $a_keyword, $a_value)
213  {
214  global $ilDB;
215 
216  $query = "DELETE FROM container_settings WHERE ".
217  "id = ".$ilDB->quote($a_id,'integer')." ".
218  "AND keyword = ".$ilDB->quote($a_keyword,'text');
219  $res = $ilDB->manipulate($query);
220 
221  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (".
222  $ilDB->quote($a_id ,'integer').", ".
223  $ilDB->quote($a_keyword ,'text').", ".
224  $ilDB->quote($a_value ,'text').
225  ")";
226  $res = $ilDB->manipulate($query);
227  }
228 
235  function _lookupIconPath($a_id, $a_size = "big")
236  {
237  if ($a_size == "")
238  {
239  $a_size = "big";
240  }
241 
242  $size = $a_size;
243 
244  if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
245  {
246  $cont_dir = ilContainer::_getContainerDirectory($a_id);
247 
248  // png version? (introduced with ILIAS 4.3)
249  $file_name = $cont_dir."/icon_".$a_size.".png";
250  if (is_file($file_name))
251  {
252  return $file_name;
253  }
254 
255  // gif version? (prior to ILIAS 4.3)
256  $file_name = $cont_dir."/icon_".$a_size.".gif";
257  if (is_file($file_name))
258  {
259  return $file_name;
260  }
261  }
262 
263  return "";
264  }
265 
269  function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
270  {
271  global $ilDB;
272 
273  $this->createContainerDirectory();
274  $cont_dir = $this->getContainerDirectory();
275 
276  // save big icon
277  $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
278  $this->ilias->getSetting("custom_icon_big_height");
279  $big_file_name = $cont_dir."/icon_big.png";
280 
281  if (is_file($a_big_icon))
282  {
283  $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
284  $big_file_name = ilUtil::escapeShellArg($big_file_name);
285  ilUtil::execConvert($a_big_icon."[0] -geometry ".$big_geom." PNG:".$big_file_name);
286  }
287 
288  if (is_file($cont_dir."/icon_big.png"))
289  {
290  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
291  }
292  else
293  {
294  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
295  }
296 
297  // save small icon
298  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
299  $this->ilias->getSetting("custom_icon_small_height");
300  $small_file_name = $cont_dir."/icon_small.png";
301 
302  if (is_file($a_small_icon))
303  {
304  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
305  $small_file_name = ilUtil::escapeShellArg($small_file_name);
306  ilUtil::execConvert($a_small_icon."[0] -geometry ".$small_geom." PNG:".$small_file_name);
307  }
308  if (is_file($cont_dir."/icon_small.png"))
309  {
310  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
311  }
312  else
313  {
314  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
315  }
316 
317  // save tiny icon
318  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
319  $this->ilias->getSetting("custom_icon_tiny_height");
320  $tiny_file_name = $cont_dir."/icon_tiny.png";
321 
322  if (is_file($a_tiny_icon))
323  {
324  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
325  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
326  ilUtil::execConvert($a_tiny_icon."[0] -geometry ".$tiny_geom." PNG:".$tiny_file_name);
327  }
328  if (is_file($cont_dir."/icon_tiny.png"))
329  {
330  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
331  }
332  else
333  {
334  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
335  }
336 
337  }
338 
342  function removeBigIcon()
343  {
344  $cont_dir = $this->getContainerDirectory();
345  $big_file_name = $cont_dir."/icon_big.png";
346  @unlink($big_file_name);
347  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
348  }
349 
353  function removeSmallIcon()
354  {
355  $cont_dir = $this->getContainerDirectory();
356  $small_file_name = $cont_dir."/icon_small.png";
357  @unlink($small_file_name);
358  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
359  }
360 
364  function removeTinyIcon()
365  {
366  $cont_dir = $this->getContainerDirectory();
367  $tiny_file_name = $cont_dir."/icon_tiny.png";
368  @unlink($tiny_file_name);
369  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
370  }
371 
380  public function cloneObject($a_target_id,$a_copy_id = 0)
381  {
382  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
383 
384  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
385  $sorting = new ilContainerSortingSettings($new_obj->getId());
386  $sorting->setSortMode($this->getOrderType());
387  $sorting->update();
388 
389  // copy content page
390  include_once("./Services/COPage/classes/class.ilPageObject.php");
391  if (ilPageObject::_exists($this->getType(),
392  $this->getId()))
393  {
394  $orig_page = new ilPageObject($this->getType(), $this->getId());
395  $new_page_object = new ilPageObject($this->getType());
396  $new_page_object->setParentId($new_obj->getId());
397  $new_page_object->setId($new_obj->getId());
398  $new_page_object->createFromXML();
399  $new_page_object->setXMLContent($orig_page->getXMLContent());
400  $new_page_object->buildDom();
401  $new_page_object->update();
402  }
403 
404  return $new_obj;
405  }
406 
415  public function cloneDependencies($a_target_id,$a_copy_id)
416  {
417  parent::cloneDependencies($a_target_id, $a_copy_id);
418 
419  include_once('./Services/Container/classes/class.ilContainerSorting.php');
420  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
421 
422  // fix item group references in page content
423  include_once("./Modules/ItemGroup/classes/class.ilObjItemGroup.php");
425 
426  return true;
427  }
428 
440  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
441  {
442  global $ilLog;
443 
444  include_once('./Services/Link/classes/class.ilLink.php');
445  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
446 
447  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
448 
449  // Save wizard options
451  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
452  $wizard_options->saveOwner($ilUser->getId());
453  $wizard_options->saveRoot($clone_source);
454 
455  // add entry for source container
456  $wizard_options->initContainer($clone_source, $ref_id);
457 
458  foreach($options as $source_id => $option)
459  {
460  $wizard_options->addEntry($source_id,$option);
461  }
462  $wizard_options->read();
463  $wizard_options->storeTree($clone_source);
464 
465  // Special handling for course in existing courses
466  if($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs')
467  {
468  $ilLog->write(__METHOD__.': Copy course in course...');
469  $ilLog->write(__METHOD__.': Added mapping, source ID: '.$clone_source.', target ID: '.$ref_id);
470  $wizard_options->read();
471  $wizard_options->dropFirstNode();
472  $wizard_options->appendMapping($clone_source,$ref_id);
473  }
474 
475  #print_r($options);
476  // Duplicate session to avoid logout problems with backgrounded SOAP calls
477  $new_session_id = ilSession::_duplicate($session_id);
478  // Start cloning process using soap call
479  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
480 
481  $soap_client = new ilSoapClient();
482  $soap_client->setResponseTimeout(30);
483  $soap_client->enableWSDL(true);
484 
485  $ilLog->write(__METHOD__.': Trying to call Soap client...');
486  if($soap_client->init())
487  {
488  $ilLog->write(__METHOD__.': Calling soap clone method...');
489  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
490  }
491  else
492  {
493  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
494  $wizard_options->disableSOAP();
495  $wizard_options->read();
496  include_once('./webservice/soap/include/inc.soap_functions.php');
497  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
498  }
499  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
500  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
501  {
502  return $res;
503  }
504  else
505  {
506  return $ref_id;
507  }
508  }
509 
513  function getViewMode()
514  {
516  }
517 
521  function getOrderType()
522  {
523  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
524  }
525 
526  function setOrderType($a_value)
527  {
528  $this->order_type = $a_value;
529  }
530 
539  function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false,
540  $a_get_single = 0)
541  {
542  global $objDefinition, $ilBench, $tree, $ilObjDataCache, $ilUser, $rbacsystem,
543  $ilSetting;
544 
545  // Caching
546  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
547  !$a_get_single)
548  {
549  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
550  }
551 
552  $type_grps = $this->getGroupedObjTypes();
553  $objects = $tree->getChilds($this->getRefId(), "title");
554 
555  // using long descriptions?
556  $short_desc = $ilSetting->get("rep_shorten_description");
557  $short_desc_max_length = $ilSetting->get("rep_shorten_description_length");
558  if(!$short_desc || $short_desc_max_length != ilObject::TITLE_LENGTH)
559  {
560  // using (part of) shortened description
561  if($short_desc && $short_desc_max_length && $short_desc_max_length < ilObject::TITLE_LENGTH)
562  {
563  foreach($objects as $key => $object)
564  {
565  $objects[$key]["description"] = ilUtil::shortenText($object["description"], $short_desc_max_length, true);
566  }
567  }
568  // using (part of) long description
569  else
570  {
571  $obj_ids = array();
572  foreach($objects as $key => $object)
573  {
574  $obj_ids[] = $object["obj_id"];
575  }
576  if(sizeof($obj_ids))
577  {
579  foreach($objects as $key => $object)
580  {
581  // #12166 - keep translation, ignore long description
582  if($ilObjDataCache->isTranslatedDescription($object["obj_id"]))
583  {
584  $long_desc[$object["obj_id"]] = $object["description"];
585  }
586  if($short_desc && $short_desc_max_length)
587  {
588  $long_desc[$object["obj_id"]] = ilUtil::shortenText($long_desc[$object["obj_id"]], $short_desc_max_length, true);
589  }
590  $objects[$key]["description"] = $long_desc[$object["obj_id"]];
591  }
592  }
593  }
594  }
595 
596  $found = false;
597  $all_obj_types = array();
598  $all_ref_ids = array();
599  $all_obj_ids = array();
600 
601  include_once('Services/Container/classes/class.ilContainerSorting.php');
602  $sort = ilContainerSorting::_getInstance($this->getId());
603 
604  // TODO: check this
605  // get items attached to a session
606  include_once './Modules/Session/classes/class.ilEventItems.php';
607  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
608 
609  foreach ($objects as $key => $object)
610  {
611  if ($a_get_single > 0 && $object["child"] != $a_get_single)
612  {
613  continue;
614  }
615 
616  // hide object types in devmode
617  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
618  || $object["type"] == "rolf")
619  {
620  continue;
621  }
622 
623  // remove inactive plugins
624  if ($objDefinition->isInactivePlugin($object["type"]))
625  {
626  continue;
627  }
628 
629  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
630  if (in_array($object['type'], array('file','fold','cat')))
631  {
632  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
633  if (ilObjFileAccess::_isFileHidden($object['title']))
634  {
635  $this->setHiddenFilesFound(true);
636  if (!$a_admin_panel_enabled)
637  {
638  continue;
639  }
640  }
641  }
642  // END WebDAV: Don't display hidden Files, Folders and Categories
643 
644  // filter out items that are attached to an event
645  if (in_array($object['ref_id'],$event_items))
646  {
647  continue;
648  }
649 
650  // filter side block items
651  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
652  {
653  continue;
654  }
655 
656  $all_obj_types[$object["type"]] = $object["type"];
657  $obj_ids_of_type[$object["type"]][] = $object["obj_id"];
658  $ref_ids_of_type[$object["type"]][] = $object["child"];
659 
660  $all_ref_ids[] = $object["child"];
661  $all_obj_ids[] = $object["obj_id"];
662  }
663 
664  // data preloader
665  if (!self::$data_preloaded && sizeof($all_ref_ids))
666  {
667  // type specific preloads
668  foreach ($all_obj_types as $t)
669  {
670  // condition handler: preload conditions
671  include_once("./Services/AccessControl/classes/class.ilConditionHandler.php");
673  $obj_ids_of_type[$t]);
674 
675  $class = $objDefinition->getClassName($t);
676  $location = $objDefinition->getLocation($t);
677  $full_class = "ilObj".$class."Access";
678  include_once($location."/class.".$full_class.".php");
679  call_user_func(array($full_class, "_preloadData"),
680  $obj_ids_of_type[$t], $ref_ids_of_type[$t]);
681  }
682 
683  // general preloads
684  $tree->preloadDeleted($all_ref_ids);
685  $tree->preloadDepthParent($all_ref_ids);
686  $ilObjDataCache->preloadReferenceCache($all_ref_ids, false);
687  ilObjUser::preloadIsDesktopItem($ilUser->getId(), $all_ref_ids);
688  $rbacsystem->preloadRbacPaCache($all_ref_ids, $ilUser->getId());
689 
690  include_once("./Services/Object/classes/class.ilObjectListGUI.php");
692 
693  include_once("./Services/Object/classes/class.ilObjectActivation.php");
694  ilObjectActivation::preloadData($all_ref_ids);
695 
696  self::$data_preloaded = true;
697  }
698 
699  foreach($objects as $key => $object)
700  {
701  // see above, objects were filtered
702  if(!in_array($object["child"], $all_ref_ids))
703  {
704  continue;
705  }
706 
707  // group object type groups together (e.g. learning resources)
708  $type = $objDefinition->getGroupOfObj($object["type"]);
709  if ($type == "")
710  {
711  $type = $object["type"];
712  }
713 
714  // this will add activation properties (ilObjActivation)
715  $this->addAdditionalSubItemInformation($object);
716 
717  $this->items[$type][$key] = $object;
718 
719  $this->items["_all"][$key] = $object;
720  if ($object["type"] != "sess")
721  {
722  $this->items["_non_sess"][$key] = $object;
723  }
724  }
725 
726  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
727  = $sort->sortItems($this->items);
728 
729  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
730  }
731 
735  function gotItems()
736  {
737  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
738  {
739  return true;
740  }
741  return false;
742  }
743 
749  {
750  }
751 
758  {
759  global $objDefinition;
760 
761  if (empty($this->type_grps))
762  {
763  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
764  }
765  return $this->type_grps;
766  }
767 
771  function enablePageEditing()
772  {
773  global $ilSetting;
774 
775  // @todo: this will need a more general approach
776  if ($ilSetting->get("enable_cat_page_edit"))
777  {
778  return true;
779  }
780  }
781 
785  function create()
786  {
787  $ret = parent::create();
788 
789  if (((int) $this->getStyleSheetId()) > 0)
790  {
791  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
793  }
794 
795  return $ret;
796  }
797 
801  function update()
802  {
803  $ret = parent::update();
804 
805  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
807 
808  return $ret;
809  }
810 
811 
819  public function read()
820  {
821  parent::read();
822 
823  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
825 
826  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
828  }
829 
830 } // END class ilContainer
831 ?>