ILIAS  Release_5_0_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  const SORT_CREATION = 4;
62 
63  const SORT_DIRECTION_ASC = 0;
65 
68 
72 
73 
74  static $data_preloaded = false;
75 
82  function ilContainer($a_id = 0, $a_call_by_reference = true)
83  {
84  parent::__construct($a_id, $a_call_by_reference);
85  }
86 
87 
88 
94  {
95  $webspace_dir = ilUtil::getWebspaceDir();
96  $cont_dir = $webspace_dir."/container_data";
97  if (!is_dir($cont_dir))
98  {
99  ilUtil::makeDir($cont_dir);
100  }
101  $obj_dir = $cont_dir."/obj_".$this->getId();
102  if (!is_dir($obj_dir))
103  {
104  ilUtil::makeDir($obj_dir);
105  }
106  }
107 
114  {
115  return $this->_getContainerDirectory($this->getId());
116  }
117 
123  function _getContainerDirectory($a_id)
124  {
125  return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
126  }
127 
134  function getBigIconPath()
135  {
136  return self::_lookupIconPath($this->getId());
137  }
138 
145  function getSmallIconPath()
146  {
147  return self::_lookupIconPath($this->getId());
148  }
149 
156  function getTinyIconPath()
157  {
158  return self::_lookupIconPath($this->getId());
159  }
160 
166  function getCustomIconPath()
167  {
168  return self::_lookupIconPath($this->getId());
169  }
170 
171 
177  function setHiddenFilesFound($a_hiddenfilesfound)
178  {
179  $this->hiddenfilesfound = $a_hiddenfilesfound;
180  }
181 
188  {
190  }
191 
195  function getStyleSheetId()
196  {
197  return $this->style_id;
198  }
199 
203  function setStyleSheetId($a_style_id)
204  {
205  $this->style_id = $a_style_id;
206  }
207 
216  function _lookupContainerSetting($a_id, $a_keyword, $a_default_value = NULL)
217  {
218  global $ilDB;
219 
220  $q = "SELECT * FROM container_settings WHERE ".
221  " id = ".$ilDB->quote($a_id ,'integer')." AND ".
222  " keyword = ".$ilDB->quote($a_keyword ,'text');
223  $set = $ilDB->query($q);
224  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
225 
226  if(isset($rec['value']))
227  {
228  return $rec["value"];
229  }
230  if($a_default_value === NULL)
231  {
232  return '';
233  }
234  return $a_default_value;
235  }
236 
237  function _writeContainerSetting($a_id, $a_keyword, $a_value)
238  {
239  global $ilDB;
240 
241  $query = "DELETE FROM container_settings WHERE ".
242  "id = ".$ilDB->quote($a_id,'integer')." ".
243  "AND keyword = ".$ilDB->quote($a_keyword,'text');
244  $res = $ilDB->manipulate($query);
245 
246  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (".
247  $ilDB->quote($a_id ,'integer').", ".
248  $ilDB->quote($a_keyword ,'text').", ".
249  $ilDB->quote($a_value ,'text').
250  ")";
251  $res = $ilDB->manipulate($query);
252  }
253 
254  public static function _getContainerSettings($a_id)
255  {
256  global $ilDB;
257 
258  $res = array();
259 
260  $sql = "SELECT * FROM container_settings WHERE ".
261  " id = ".$ilDB->quote($a_id ,'integer');
262  $set = $ilDB->query($sql);
263  while($row = $ilDB->fetchAssoc($set))
264  {
265  $res[$row["keyword"]] = $row["value"];
266  }
267 
268  return $res;
269  }
270 
271  public static function _deleteContainerSettings($a_id, $a_keyword = null, $a_keyword_like = false)
272  {
273  global $ilDB;
274 
275  if(!$a_id)
276  {
277  return;
278  }
279 
280  $sql = "DELETE FROM container_settings WHERE ".
281  " id = ".$ilDB->quote($a_id ,'integer');
282  if($a_keyword)
283  {
284  if(!$a_keyword_like)
285  {
286  $sql .= " AND keyword = ".$ilDB->quote($a_keyword, "text");
287  }
288  else
289  {
290  $sql .= " AND ".$ilDB->like("keyword", "text", $a_keyword);
291  }
292  }
293  $ilDB->manipulate($sql);
294  }
295 
296  public static function _exportContainerSettings(ilXmlWriter $a_xml, $a_obj_id)
297  {
298  // container settings
299  $settings = self::_getContainerSettings($a_obj_id);
300  if(sizeof($settings))
301  {
302  $a_xml->xmlStartTag("ContainerSettings");
303 
304  foreach($settings as $keyword => $value)
305  {
306  // :TODO: proper custom icon export/import
307  if(stristr($keyword, "icon"))
308  {
309  continue;
310  }
311 
312  $a_xml->xmlStartTag(
313  'ContainerSetting',
314  array(
315  'id' => $keyword,
316  )
317  );
318 
319  $a_xml->xmlData($value);
320  $a_xml->xmlEndTag("ContainerSetting");
321  }
322 
323  $a_xml->xmlEndTag("ContainerSettings");
324  }
325  }
326 
333  function _lookupIconPath($a_id, $a_size = "big")
334  {
335  if ($a_size == "")
336  {
337  $a_size = "big";
338  }
339  $size = $a_size;
340 
341  if (ilContainer::_lookupContainerSetting($a_id, "icon_custom"))
342  {
343  $cont_dir = ilContainer::_getContainerDirectory($a_id);
344 
345  $file_name = $cont_dir."/icon_custom.svg";
346  if (is_file($file_name))
347  {
348  return $file_name;
349  }
350  }
351 
352  return "";
353  }
354 
358  function saveIcons($a_custom_icon)
359  {
360  global $ilDB;
361 
362  $this->createContainerDirectory();
363  $cont_dir = $this->getContainerDirectory();
364 
365  $file_name = "";
366  if ($a_custom_icon != "")
367  {
368  $file_name = $cont_dir."/icon_custom.svg";
369  ilUtil::moveUploadedFile($a_custom_icon, "icon_custom.svg", $file_name);
370 
371  if ($file_name != "" && is_file($file_name))
372  {
373  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 1);
374  }
375  else
376  {
377  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 0);
378  }
379  }
380  }
381 
385  function removeCustomIcon()
386  {
387  $cont_dir = $this->getContainerDirectory();
388  $small_file_name = $cont_dir."/icon_custom.svg";
389  @unlink($small_file_name);
390  ilContainer::_writeContainerSetting($this->getId(), "icon_custom", 0);
391  }
392 
401  public function cloneObject($a_target_id,$a_copy_id = 0)
402  {
403  global $ilLog;
404 
405  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
406 
407  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
408  $sorting = new ilContainerSortingSettings($new_obj->getId());
409  $sorting->setSortMode($this->getOrderType());
410  $sorting->update();
411 
412  // copy content page
413  include_once("./Services/Container/classes/class.ilContainerPage.php");
414  if (ilContainerPage::_exists("cont",
415  $this->getId()))
416  {
417  $orig_page = new ilContainerPage($this->getId());
418  $orig_page->copy($new_obj->getId(), "cont", $new_obj->getId());
419  }
420 
421  // #10271 - copy start objects page
422  include_once("./Services/Container/classes/class.ilContainerStartObjectsPage.php");
424  $this->getId()))
425  {
426  $orig_page = new ilContainerStartObjectsPage($this->getId());
427  $orig_page->copy($new_obj->getId(), "cstr", $new_obj->getId());
428  }
429 
430  // #10271
431  foreach(self::_getContainerSettings($this->getId()) as $keyword => $value)
432  {
433  self::_writeContainerSetting($new_obj->getId(), $keyword, $value);
434 
435  // copy custom icons
436  if($keyword == "icon_custom" &&
437  $value)
438  {
439  // see saveIcons()
440  $new_obj->createContainerDirectory();
441  $tgt_dir = $new_obj->getContainerDirectory();
442  $src_dir = $this->getContainerDirectory();
443  $file = "icon_custom.svg";
444  $src_file = $src_dir."/".$file;
445  if(file_exists($src_file))
446  {
447  copy($src_file, $tgt_dir."/".$file);
448  }
449  }
450  }
451 
452  return $new_obj;
453  }
454 
463  public function cloneDependencies($a_target_id,$a_copy_id)
464  {
465  global $ilLog;
466 
467  parent::cloneDependencies($a_target_id, $a_copy_id);
468 
469  include_once('./Services/Container/classes/class.ilContainerSorting.php');
470  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
471 
472  // fix item group references in page content
473  include_once("./Modules/ItemGroup/classes/class.ilObjItemGroup.php");
475 
476  include_once('Services/Object/classes/class.ilObjectLP.php');
477  $olp = ilObjectLP::getInstance($this->getId());
478  $collection = $olp->getCollectionInstance();
479  if($collection)
480  {
481  $collection->cloneCollection($a_target_id, $a_copy_id);
482  }
483 
484  return true;
485  }
486 
498  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
499  {
500  global $ilLog;
501 
502  include_once('./Services/Link/classes/class.ilLink.php');
503  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
504 
505  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
506 
507  // Save wizard options
509  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
510  $wizard_options->saveOwner($ilUser->getId());
511  $wizard_options->saveRoot($clone_source);
512 
513  // add entry for source container
514  $wizard_options->initContainer($clone_source, $ref_id);
515 
516  foreach($options as $source_id => $option)
517  {
518  $wizard_options->addEntry($source_id,$option);
519  }
520  $wizard_options->read();
521  $wizard_options->storeTree($clone_source);
522 
523  // Special handling for course in existing courses
524  if($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs')
525  {
526  $ilLog->write(__METHOD__.': Copy course in course...');
527  $ilLog->write(__METHOD__.': Added mapping, source ID: '.$clone_source.', target ID: '.$ref_id);
528  $wizard_options->read();
529  $wizard_options->dropFirstNode();
530  $wizard_options->appendMapping($clone_source,$ref_id);
531  }
532 
533  #print_r($options);
534  // Duplicate session to avoid logout problems with backgrounded SOAP calls
535  $new_session_id = ilSession::_duplicate($session_id);
536  // Start cloning process using soap call
537  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
538 
539  $soap_client = new ilSoapClient();
540  $soap_client->setResponseTimeout(30);
541  $soap_client->enableWSDL(true);
542 
543  $ilLog->write(__METHOD__.': Trying to call Soap client...');
544  if($soap_client->init())
545  {
546  $ilLog->write(__METHOD__.': Calling soap clone method...');
547  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
548  }
549  else
550  {
551  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
552  $wizard_options->disableSOAP();
553  $wizard_options->read();
554  include_once('./webservice/soap/include/inc.soap_functions.php');
555  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
556  }
557  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
558  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
559  {
560  return $res;
561  }
562  else
563  {
564  return $ref_id;
565  }
566  }
567 
571  function getViewMode()
572  {
574  }
575 
579  function getOrderType()
580  {
581  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
582  }
583 
584  function setOrderType($a_value)
585  {
586  $this->order_type = $a_value;
587  }
588 
597  function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false,
598  $a_get_single = 0)
599  {
600  global $objDefinition, $ilBench, $tree, $ilObjDataCache, $ilUser, $rbacsystem,
601  $ilSetting;
602 
603  // Caching
604  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
605  !$a_get_single)
606  {
607  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
608  }
609 
610  $type_grps = $this->getGroupedObjTypes();
611  $objects = $tree->getChilds($this->getRefId(), "title");
612 
613  $objects = self::getCompleteDescriptions($objects);
614 
615  $found = false;
616  $all_ref_ids = array();
617 
618  if(!self::$data_preloaded)
619  {
620  include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
622  }
623 
624  include_once('Services/Container/classes/class.ilContainerSorting.php');
625  $sort = ilContainerSorting::_getInstance($this->getId());
626 
627  // TODO: check this
628  // get items attached to a session
629  include_once './Modules/Session/classes/class.ilEventItems.php';
630  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
631 
632  foreach ($objects as $key => $object)
633  {
634  if ($a_get_single > 0 && $object["child"] != $a_get_single)
635  {
636  continue;
637  }
638 
639  // hide object types in devmode
640  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
641  || $object["type"] == "rolf")
642  {
643  continue;
644  }
645 
646  // remove inactive plugins
647  if ($objDefinition->isInactivePlugin($object["type"]))
648  {
649  continue;
650  }
651 
652  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
653  if (in_array($object['type'], array('file','fold','cat')))
654  {
655  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
656  if (ilObjFileAccess::_isFileHidden($object['title']))
657  {
658  $this->setHiddenFilesFound(true);
659  if (!$a_admin_panel_enabled)
660  {
661  continue;
662  }
663  }
664  }
665  // END WebDAV: Don't display hidden Files, Folders and Categories
666 
667  // including event items!
668  if (!self::$data_preloaded)
669  {
670  $preloader->addItem($object["obj_id"], $object["type"], $object["child"]);
671  }
672 
673  // filter out items that are attached to an event
674  if (in_array($object['ref_id'],$event_items))
675  {
676  continue;
677  }
678 
679  // filter side block items
680  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
681  {
682  continue;
683  }
684 
685  $all_ref_ids[] = $object["child"];
686  }
687 
688  // data preloader
689  if (!self::$data_preloaded)
690  {
691  $preloader->preload();
692  unset($preloader);
693 
694  self::$data_preloaded = true;
695  }
696 
697  foreach($objects as $key => $object)
698  {
699  // see above, objects were filtered
700  if(!in_array($object["child"], $all_ref_ids))
701  {
702  continue;
703  }
704 
705  // group object type groups together (e.g. learning resources)
706  $type = $objDefinition->getGroupOfObj($object["type"]);
707  if ($type == "")
708  {
709  $type = $object["type"];
710  }
711 
712  // this will add activation properties
713  $this->addAdditionalSubItemInformation($object);
714 
715  $this->items[$type][$key] = $object;
716 
717  $this->items["_all"][$key] = $object;
718  if ($object["type"] != "sess")
719  {
720  $this->items["_non_sess"][$key] = $object;
721  }
722  }
723 
724  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
725  = $sort->sortItems($this->items);
726 
727  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
728  }
729 
733  function gotItems()
734  {
735  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
736  {
737  return true;
738  }
739  return false;
740  }
741 
747  {
748  }
749 
756  {
757  global $objDefinition;
758 
759  if (empty($this->type_grps))
760  {
761  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
762  }
763  return $this->type_grps;
764  }
765 
769  function enablePageEditing()
770  {
771  global $ilSetting;
772 
773  // @todo: this will need a more general approach
774  if ($ilSetting->get("enable_cat_page_edit"))
775  {
776  return true;
777  }
778  }
779 
783  function create()
784  {
785  $ret = parent::create();
786 
787  if (((int) $this->getStyleSheetId()) > 0)
788  {
789  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
791  }
792 
793  return $ret;
794  }
795 
799  function update()
800  {
801  $ret = parent::update();
802 
803  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
805 
806  return $ret;
807  }
808 
809 
817  public function read()
818  {
819  parent::read();
820 
821  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
823 
824  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
826  }
827 
835  public static function getCompleteDescriptions(array $objects)
836  {
837  global $ilSetting, $ilObjDataCache;
838  // using long descriptions?
839  $short_desc = $ilSetting->get("rep_shorten_description");
840  $short_desc_max_length = $ilSetting->get("rep_shorten_description_length");
841  if(!$short_desc || $short_desc_max_length != ilObject::DESC_LENGTH)
842  {
843  // using (part of) shortened description
844  if($short_desc && $short_desc_max_length && $short_desc_max_length < ilObject::DESC_LENGTH)
845  {
846  foreach($objects as $key => $object)
847  {
848  $objects[$key]["description"] = ilUtil::shortenText($object["description"], $short_desc_max_length, true);
849  }
850  }
851  // using (part of) long description
852  else
853  {
854  $obj_ids = array();
855  foreach($objects as $key => $object)
856  {
857  $obj_ids[] = $object["obj_id"];
858  }
859  if(sizeof($obj_ids))
860  {
862  foreach($objects as $key => $object)
863  {
864  // #12166 - keep translation, ignore long description
865  if($ilObjDataCache->isTranslatedDescription($object["obj_id"]))
866  {
867  $long_desc[$object["obj_id"]] = $object["description"];
868  }
869  if($short_desc && $short_desc_max_length)
870  {
871  $long_desc[$object["obj_id"]] = ilUtil::shortenText($long_desc[$object["obj_id"]], $short_desc_max_length, true);
872  }
873  $objects[$key]["description"] = $long_desc[$object["obj_id"]];
874  }
875  }
876  }
877  }
878  return $objects;
879  }
880 
881 } // END class ilContainer
882 ?>