ILIAS  Release_4_4_x_branch Revision 61816
 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  if (is_file($cont_dir."/icon_big.png"))
288  {
289  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
290  }
291  else
292  {
293  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
294  }
295  // save small icon
296  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
297  $this->ilias->getSetting("custom_icon_small_height");
298  $small_file_name = $cont_dir."/icon_small.png";
299 
300  if (is_file($a_small_icon))
301  {
302  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
303  $small_file_name = ilUtil::escapeShellArg($small_file_name);
304  ilUtil::execConvert($a_small_icon."[0] -geometry ".$small_geom." PNG:".$small_file_name);
305  }
306  if (is_file($cont_dir."/icon_small.png"))
307  {
308  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
309  }
310  else
311  {
312  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
313  }
314 
315  // save tiny icon
316  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
317  $this->ilias->getSetting("custom_icon_tiny_height");
318  $tiny_file_name = $cont_dir."/icon_tiny.png";
319 
320  if (is_file($a_tiny_icon))
321  {
322  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
323  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
324  ilUtil::execConvert($a_tiny_icon."[0] -geometry ".$tiny_geom." PNG:".$tiny_file_name);
325  }
326  if (is_file($cont_dir."/icon_tiny.png"))
327  {
328  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
329  }
330  else
331  {
332  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
333  }
334 
335  }
336 
340  function removeBigIcon()
341  {
342  $cont_dir = $this->getContainerDirectory();
343  $big_file_name = $cont_dir."/icon_big.png";
344  @unlink($big_file_name);
345  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
346  }
347 
351  function removeSmallIcon()
352  {
353  $cont_dir = $this->getContainerDirectory();
354  $small_file_name = $cont_dir."/icon_small.png";
355  @unlink($small_file_name);
356  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
357  }
358 
362  function removeTinyIcon()
363  {
364  $cont_dir = $this->getContainerDirectory();
365  $tiny_file_name = $cont_dir."/icon_tiny.png";
366  @unlink($tiny_file_name);
367  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
368  }
369 
378  public function cloneObject($a_target_id,$a_copy_id = 0)
379  {
380  global $ilLog;
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 // $ilLog->write("copy container, lookup page");
391  include_once("./Services/Container/classes/class.ilContainerPage.php");
392  if (ilContainerPage::_exists("cont",
393  $this->getId()))
394  {
395  //$ilLog->write("...page found");
396  $orig_page = new ilContainerPage($this->getId());
397  $orig_page->copy($new_obj->getId(), "cont", $new_obj->getId());
398  /*$new_page_object = new ilContainerPage();
399  $new_page_object->setParentId($new_obj->getId());
400  $new_page_object->setId($new_obj->getId());
401  $new_page_object->createFromXML();
402  $new_page_object->setXMLContent($orig_page->getXMLContent());
403  $new_page_object->buildDom(true);
404  $new_page_object->update();*/
405 
406  //$ilLog->write("...copy ml");
407 
408  // copy (page) multilang settings
409  /*include_once("./Services/COPage/classes/class.ilPageMultiLang.php");
410  $ml = new ilPageMultiLang("cont", $this->getId());
411  $ml->copy("cont", $new_obj->getId());*/
412 
413  }
414 
415  return $new_obj;
416  }
417 
426  public function cloneDependencies($a_target_id,$a_copy_id)
427  {
428  global $ilLog;
429 
430  parent::cloneDependencies($a_target_id, $a_copy_id);
431 
432  include_once('./Services/Container/classes/class.ilContainerSorting.php');
433  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
434 
435  // fix item group references in page content
436  include_once("./Modules/ItemGroup/classes/class.ilObjItemGroup.php");
438 
439  include_once('Services/Object/classes/class.ilObjectLP.php');
440  $olp = ilObjectLP::getInstance($this->getId());
441  $collection = $olp->getCollectionInstance();
442  if($collection)
443  {
444  $collection->cloneCollection($a_target_id, $a_copy_id);
445  }
446 
447  return true;
448  }
449 
461  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
462  {
463  global $ilLog;
464 
465  include_once('./Services/Link/classes/class.ilLink.php');
466  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
467 
468  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
469 
470  // Save wizard options
472  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
473  $wizard_options->saveOwner($ilUser->getId());
474  $wizard_options->saveRoot($clone_source);
475 
476  // add entry for source container
477  $wizard_options->initContainer($clone_source, $ref_id);
478 
479  foreach($options as $source_id => $option)
480  {
481  $wizard_options->addEntry($source_id,$option);
482  }
483  $wizard_options->read();
484  $wizard_options->storeTree($clone_source);
485 
486  // Special handling for course in existing courses
487  if($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs')
488  {
489  $ilLog->write(__METHOD__.': Copy course in course...');
490  $ilLog->write(__METHOD__.': Added mapping, source ID: '.$clone_source.', target ID: '.$ref_id);
491  $wizard_options->read();
492  $wizard_options->dropFirstNode();
493  $wizard_options->appendMapping($clone_source,$ref_id);
494  }
495 
496  #print_r($options);
497  // Duplicate session to avoid logout problems with backgrounded SOAP calls
498  $new_session_id = ilSession::_duplicate($session_id);
499  // Start cloning process using soap call
500  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
501 
502  $soap_client = new ilSoapClient();
503  $soap_client->setResponseTimeout(30);
504  $soap_client->enableWSDL(true);
505 
506  $ilLog->write(__METHOD__.': Trying to call Soap client...');
507  if($soap_client->init())
508  {
509  $ilLog->write(__METHOD__.': Calling soap clone method...');
510  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
511  }
512  else
513  {
514  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
515  $wizard_options->disableSOAP();
516  $wizard_options->read();
517  include_once('./webservice/soap/include/inc.soap_functions.php');
518  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
519  }
520  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
521  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
522  {
523  return $res;
524  }
525  else
526  {
527  return $ref_id;
528  }
529  }
530 
534  function getViewMode()
535  {
537  }
538 
542  function getOrderType()
543  {
544  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
545  }
546 
547  function setOrderType($a_value)
548  {
549  $this->order_type = $a_value;
550  }
551 
560  function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false,
561  $a_get_single = 0)
562  {
563  global $objDefinition, $ilBench, $tree, $ilObjDataCache, $ilUser, $rbacsystem,
564  $ilSetting;
565 
566  // Caching
567  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
568  !$a_get_single)
569  {
570  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
571  }
572 
573  $type_grps = $this->getGroupedObjTypes();
574  $objects = $tree->getChilds($this->getRefId(), "title");
575 
576  $objects = self::getCompleteDescriptions($objects);
577 
578  $found = false;
579  $all_ref_ids = array();
580 
581  if(!self::$data_preloaded)
582  {
583  include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
585  }
586 
587  include_once('Services/Container/classes/class.ilContainerSorting.php');
588  $sort = ilContainerSorting::_getInstance($this->getId());
589 
590  // TODO: check this
591  // get items attached to a session
592  include_once './Modules/Session/classes/class.ilEventItems.php';
593  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
594 
595  foreach ($objects as $key => $object)
596  {
597  if ($a_get_single > 0 && $object["child"] != $a_get_single)
598  {
599  continue;
600  }
601 
602  // hide object types in devmode
603  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
604  || $object["type"] == "rolf")
605  {
606  continue;
607  }
608 
609  // remove inactive plugins
610  if ($objDefinition->isInactivePlugin($object["type"]))
611  {
612  continue;
613  }
614 
615  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
616  if (in_array($object['type'], array('file','fold','cat')))
617  {
618  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
619  if (ilObjFileAccess::_isFileHidden($object['title']))
620  {
621  $this->setHiddenFilesFound(true);
622  if (!$a_admin_panel_enabled)
623  {
624  continue;
625  }
626  }
627  }
628  // END WebDAV: Don't display hidden Files, Folders and Categories
629 
630  // including event items!
631  if (!self::$data_preloaded)
632  {
633  $preloader->addItem($object["obj_id"], $object["type"], $object["child"]);
634  }
635 
636  // filter out items that are attached to an event
637  if (in_array($object['ref_id'],$event_items))
638  {
639  continue;
640  }
641 
642  // filter side block items
643  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
644  {
645  continue;
646  }
647 
648  $all_ref_ids[] = $object["child"];
649  }
650 
651  // data preloader
652  if (!self::$data_preloaded)
653  {
654  $preloader->preload();
655  unset($preloader);
656 
657  self::$data_preloaded = true;
658  }
659 
660  foreach($objects as $key => $object)
661  {
662  // see above, objects were filtered
663  if(!in_array($object["child"], $all_ref_ids))
664  {
665  continue;
666  }
667 
668  // group object type groups together (e.g. learning resources)
669  $type = $objDefinition->getGroupOfObj($object["type"]);
670  if ($type == "")
671  {
672  $type = $object["type"];
673  }
674 
675  // this will add activation properties
676  $this->addAdditionalSubItemInformation($object);
677 
678  $this->items[$type][$key] = $object;
679 
680  $this->items["_all"][$key] = $object;
681  if ($object["type"] != "sess")
682  {
683  $this->items["_non_sess"][$key] = $object;
684  }
685  }
686 
687  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
688  = $sort->sortItems($this->items);
689 
690  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
691  }
692 
696  function gotItems()
697  {
698  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
699  {
700  return true;
701  }
702  return false;
703  }
704 
710  {
711  }
712 
719  {
720  global $objDefinition;
721 
722  if (empty($this->type_grps))
723  {
724  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
725  }
726  return $this->type_grps;
727  }
728 
732  function enablePageEditing()
733  {
734  global $ilSetting;
735 
736  // @todo: this will need a more general approach
737  if ($ilSetting->get("enable_cat_page_edit"))
738  {
739  return true;
740  }
741  }
742 
746  function create()
747  {
748  $ret = parent::create();
749 
750  if (((int) $this->getStyleSheetId()) > 0)
751  {
752  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
754  }
755 
756  return $ret;
757  }
758 
762  function update()
763  {
764  $ret = parent::update();
765 
766  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
768 
769  return $ret;
770  }
771 
772 
780  public function read()
781  {
782  parent::read();
783 
784  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
786 
787  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
789  }
790 
798  public static function getCompleteDescriptions(array $objects)
799  {
800  global $ilSetting, $ilObjDataCache;
801  // using long descriptions?
802  $short_desc = $ilSetting->get("rep_shorten_description");
803  $short_desc_max_length = $ilSetting->get("rep_shorten_description_length");
804  if(!$short_desc || $short_desc_max_length != ilObject::DESC_LENGTH)
805  {
806  // using (part of) shortened description
807  if($short_desc && $short_desc_max_length && $short_desc_max_length < ilObject::DESC_LENGTH)
808  {
809  foreach($objects as $key => $object)
810  {
811  $objects[$key]["description"] = ilUtil::shortenText($object["description"], $short_desc_max_length, true);
812  }
813  }
814  // using (part of) long description
815  else
816  {
817  $obj_ids = array();
818  foreach($objects as $key => $object)
819  {
820  $obj_ids[] = $object["obj_id"];
821  }
822  if(sizeof($obj_ids))
823  {
825  foreach($objects as $key => $object)
826  {
827  // #12166 - keep translation, ignore long description
828  if($ilObjDataCache->isTranslatedDescription($object["obj_id"]))
829  {
830  $long_desc[$object["obj_id"]] = $object["description"];
831  }
832  if($short_desc && $short_desc_max_length)
833  {
834  $long_desc[$object["obj_id"]] = ilUtil::shortenText($long_desc[$object["obj_id"]], $short_desc_max_length, true);
835  }
836  $objects[$key]["description"] = $long_desc[$object["obj_id"]];
837  }
838  }
839  }
840  }
841  return $objects;
842  }
843 
844 } // END class ilContainer
845 ?>