ILIAS  eassessment Revision 61809
 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 
54 
55  const SORT_TITLE = 0;
56  const SORT_MANUAL = 1;
57  const SORT_ACTIVATION = 2;
58  const SORT_INHERIT = 3;
59 
60  static $data_preloaded = false;
61 
68  function ilContainer($a_id = 0, $a_call_by_reference = true)
69  {
70  parent::__construct($a_id, $a_call_by_reference);
71  }
72 
73 
74 
80  {
81  $webspace_dir = ilUtil::getWebspaceDir();
82  $cont_dir = $webspace_dir."/container_data";
83  if (!is_dir($cont_dir))
84  {
85  ilUtil::makeDir($cont_dir);
86  }
87  $obj_dir = $cont_dir."/obj_".$this->getId();
88  if (!is_dir($obj_dir))
89  {
90  ilUtil::makeDir($obj_dir);
91  }
92  }
93 
100  {
101  return $this->_getContainerDirectory($this->getId());
102  }
103 
109  function _getContainerDirectory($a_id)
110  {
111  return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
112  }
113 
119  function getBigIconPath()
120  {
121  return ilContainer::_lookupIconPath($this->getId(), "big");
122  }
123 
129  function getSmallIconPath()
130  {
131  return ilContainer::_lookupIconPath($this->getId(), "small");
132  }
133 
139  function getTinyIconPath()
140  {
141  return ilContainer::_lookupIconPath($this->getId(), "tiny");
142  }
143 
144 
150  function setHiddenFilesFound($a_hiddenfilesfound)
151  {
152  $this->hiddenfilesfound = $a_hiddenfilesfound;
153  }
154 
161  {
163  }
164 
168  function getStyleSheetId()
169  {
170  return $this->style_id;
171  }
172 
176  function setStyleSheetId($a_style_id)
177  {
178  $this->style_id = $a_style_id;
179  }
180 
189  function _lookupContainerSetting($a_id, $a_keyword)
190  {
191  global $ilDB;
192 
193  $q = "SELECT * FROM container_settings WHERE ".
194  " id = ".$ilDB->quote($a_id ,'integer')." AND ".
195  " keyword = ".$ilDB->quote($a_keyword ,'text');
196  $set = $ilDB->query($q);
197  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
198 
199  return $rec["value"];
200  }
201 
202  function _writeContainerSetting($a_id, $a_keyword, $a_value)
203  {
204  global $ilDB;
205 
206  $query = "DELETE FROM container_settings WHERE ".
207  "id = ".$ilDB->quote($a_id,'integer')." ".
208  "AND keyword = ".$ilDB->quote($a_keyword,'text');
209  $res = $ilDB->manipulate($query);
210 
211  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (".
212  $ilDB->quote($a_id ,'integer').", ".
213  $ilDB->quote($a_keyword ,'text').", ".
214  $ilDB->quote($a_value ,'text').
215  ")";
216  $res = $ilDB->manipulate($query);
217  }
218 
225  function _lookupIconPath($a_id, $a_size = "big")
226  {
227  if ($a_size == "")
228  {
229  $a_size = "big";
230  }
231 
232  $size = $a_size;
233 
234  if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
235  {
236  $cont_dir = ilContainer::_getContainerDirectory($a_id);
237  $file_name = $cont_dir."/icon_".$a_size.".gif";
238 
239  if (is_file($file_name))
240  {
241  return $file_name;
242  }
243  }
244 
245  return "";
246  }
247 
251  function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
252  {
253  global $ilDB;
254 
255  $this->createContainerDirectory();
256  $cont_dir = $this->getContainerDirectory();
257 
258  // save big icon
259  $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
260  $this->ilias->getSetting("custom_icon_big_height");
261  $big_file_name = $cont_dir."/icon_big.gif";
262 
263  if (is_file($a_big_icon))
264  {
265  $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
266  $big_file_name = ilUtil::escapeShellArg($big_file_name);
267  ilUtil::execConvert($a_big_icon."[0] -geometry ".$big_geom." GIF:".$big_file_name);
268  }
269 
270  if (is_file($cont_dir."/icon_big.gif"))
271  {
272  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
273  }
274  else
275  {
276  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
277  }
278 
279  // save small icon
280  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
281  $this->ilias->getSetting("custom_icon_small_height");
282  $small_file_name = $cont_dir."/icon_small.gif";
283 
284  if (is_file($a_small_icon))
285  {
286  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
287  $small_file_name = ilUtil::escapeShellArg($small_file_name);
288  ilUtil::execConvert($a_small_icon."[0] -geometry ".$small_geom." GIF:".$small_file_name);
289  }
290  if (is_file($cont_dir."/icon_small.gif"))
291  {
292  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
293  }
294  else
295  {
296  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
297  }
298 
299  // save tiny icon
300  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
301  $this->ilias->getSetting("custom_icon_tiny_height");
302  $tiny_file_name = $cont_dir."/icon_tiny.gif";
303 
304  if (is_file($a_tiny_icon))
305  {
306  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
307  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
308  ilUtil::execConvert($a_tiny_icon."[0] -geometry ".$tiny_geom." GIF:".$tiny_file_name);
309  }
310  if (is_file($cont_dir."/icon_tiny.gif"))
311  {
312  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
313  }
314  else
315  {
316  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
317  }
318 
319  }
320 
324  function removeBigIcon()
325  {
326  $cont_dir = $this->getContainerDirectory();
327  $big_file_name = $cont_dir."/icon_big.gif";
328  @unlink($big_file_name);
329  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
330  }
331 
335  function removeSmallIcon()
336  {
337  $cont_dir = $this->getContainerDirectory();
338  $small_file_name = $cont_dir."/icon_small.gif";
339  @unlink($small_file_name);
340  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
341  }
342 
346  function removeTinyIcon()
347  {
348  $cont_dir = $this->getContainerDirectory();
349  $tiny_file_name = $cont_dir."/icon_tiny.gif";
350  @unlink($tiny_file_name);
351  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
352  }
353 
359  function getFirstColumn()
360  {
361  $col_id = ilContainer::_lookupContainerSetting($this->getId(), "first_column");
362  if ($col_id > 0)
363  {
364  include_once("./Services/Blocks/class.ilBlockColumn.php");
365  $block_column = new ilBlockColumn($col_id);
366  return $block_column;
367  }
368  return false;
369  }
370 
379  public function cloneObject($a_target_id,$a_copy_id = 0)
380  {
381  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
382 
383  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
384  $sorting = new ilContainerSortingSettings($new_obj->getId());
385  $sorting->setSortMode($this->getOrderType());
386  $sorting->update();
387 
388  // copy content page
389  include_once("./Services/COPage/classes/class.ilPageObject.php");
390  if (ilPageObject::_exists($this->getType(),
391  $this->getId()))
392  {
393  $orig_page = new ilPageObject($this->getType(), $this->getId());
394  $new_page_object = new ilPageObject($this->getType());
395  $new_page_object->setParentId($new_obj->getId());
396  $new_page_object->setId($new_obj->getId());
397  $new_page_object->createFromXML();
398  $new_page_object->setXMLContent($orig_page->getXMLContent());
399  $new_page_object->buildDom();
400  $new_page_object->update();
401  }
402 
403  return $new_obj;
404  }
405 
414  public function cloneDependencies($a_target_id,$a_copy_id)
415  {
416  include_once('./Services/Container/classes/class.ilContainerSorting.php');
417  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
418  return true;
419  }
420 
432  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
433  {
434  global $ilLog;
435 
436  include_once('classes/class.ilLink.php');
437  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
438 
439  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
440 
441  // Save wizard options
443  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
444  $wizard_options->saveOwner($ilUser->getId());
445  $wizard_options->saveRoot($clone_source);
446 
447  // add entry for source container
448  $wizard_options->initContainer($clone_source, $ref_id);
449 
450  foreach($options as $source_id => $option)
451  {
452  $wizard_options->addEntry($source_id,$option);
453  }
454  $wizard_options->read();
455  $wizard_options->storeTree($clone_source);
456 
457  // Special handling for course in existing courses
458  if($new_type == 'crs' and ilObject::_lookupType(ilObject::_lookupObjId($ref_id)) == 'crs')
459  {
460  $ilLog->write(__METHOD__.': Copy course in course...');
461  $ilLog->write(__METHOD__.': Added mapping, source ID: '.$clone_source.', target ID: '.$ref_id);
462  $wizard_options->read();
463  $wizard_options->dropFirstNode();
464  $wizard_options->appendMapping($clone_source,$ref_id);
465  }
466 
467  #print_r($options);
468  // Duplicate session to avoid logout problems with backgrounded SOAP calls
469  $new_session_id = duplicate_session($session_id);
470  // Start cloning process using soap call
471  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
472 
473  $soap_client = new ilSoapClient();
474  $soap_client->setTimeout(30);
475  $soap_client->setResponseTimeout(30);
476  $soap_client->enableWSDL(true);
477 
478  $ilLog->write(__METHOD__.': Trying to call Soap client...');
479  if($soap_client->init())
480  {
481  $ilLog->write(__METHOD__.': Calling soap clone method...');
482  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
483  }
484  else
485  {
486  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
487  $wizard_options->disableSOAP();
488  $wizard_options->read();
489  include_once('./webservice/soap/include/inc.soap_functions.php');
490  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
491  }
492  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
493  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
494  {
495  return $res;
496  }
497  else
498  {
499  return $ref_id;
500  }
501  }
502 
506  function getViewMode()
507  {
509  }
510 
514  function getOrderType()
515  {
516  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
517  }
518 
519  function setOrderType($a_value)
520  {
521  $this->order_type = $a_value;
522  }
523 
532  function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
533  {
534  global $objDefinition, $ilBench, $tree, $ilObjDataCache, $ilUser, $rbacsystem;
535 
536  // Caching
537  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]))
538  {
539  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
540  }
541 
542  $type_grps = $this->getGroupedObjTypes();
543  $objects = $tree->getChilds($this->getRefId(), "title");
544 
545  $found = false;
546 
547  include_once('Services/Container/classes/class.ilContainerSorting.php');
548  $sort = ilContainerSorting::_getInstance($this->getId());
549 
550  // TODO: check this
551  // get items attached to a session
552  include_once './Modules/Session/classes/class.ilEventItems.php';
553  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
554 
555  foreach ($objects as $key => $object)
556  {
557  // hide object types in devmode
558  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
559  || $object["type"] == "rolf")
560  {
561  continue;
562  }
563 
564  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
565  if (in_array($object['type'], array('file','fold','cat')))
566  {
567  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
568  if (ilObjFileAccess::_isFileHidden($object['title']))
569  {
570  $this->setHiddenFilesFound(true);
571  if (!$a_admin_panel_enabled)
572  {
573  continue;
574  }
575  }
576  }
577  // END WebDAV: Don't display hidden Files, Folders and Categories
578 
579  // filter out items that are attached to an event
580  if (in_array($object['ref_id'],$event_items))
581  {
582  continue;
583  }
584 
585  // filter side block items
586  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
587  {
588  continue;
589  }
590 
591  // group object type groups together (e.g. learning resources)
592  $type = $objDefinition->getGroupOfObj($object["type"]);
593  if ($type == "")
594  {
595  $type = $object["type"];
596  }
597 
598  $this->addAdditionalSubItemInformation($object);
599 
600  $this->items[$type][$key] = $object;
601 
602  $obj_ids_of_type[$type][] = $object["obj_id"];
603  $ref_ids_of_type[$type][] = $object["child"];
604  $all_ref_ids[] = $object["child"];
605  $all_obj_ids[] = $object["obj_id"];
606 
607  $this->items["_all"][$key] = $object;
608  if ($object["type"] != "sess")
609  {
610  $this->items["_non_sess"][$key] = $object;
611  }
612  }
613 
614  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
615  = $sort->sortItems($this->items);
616 
617  // data preloader
618  if (!self::$data_preloaded && is_array($this->items))
619  {
620  // type specific preloads
621  foreach ($this->items as $t => $items)
622  {
623  if (!in_array($t, array("_all", "_non_sess")) && !is_numeric($t))
624  {
625  // condition handler: preload conditions
626  include_once("./classes/class.ilConditionHandler.php");
628  $obj_ids_of_type[$t]);
629  }
630  }
631 
632  // general preloads
633  $tree->preloadDeleted($all_ref_ids);
634  $tree->preloadDepthParent($all_ref_ids);
635  $ilObjDataCache->preloadReferenceCache($all_ref_ids, false);
636  ilObjUser::preloadIsDesktopItem($ilUser->getId(), $all_ref_ids);
637  $rbacsystem->preloadRbacPaCache($all_ref_ids, $ilUser->getId());
638 
639  self::$data_preloaded = true;
640  }
641 
642  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
643  }
644 
648  function gotItems()
649  {
650  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
651  {
652  return true;
653  }
654  return false;
655  }
656 
662  {
663  }
664 
671  {
672  global $objDefinition;
673 
674  if (empty($this->type_grps))
675  {
676  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
677  }
678  return $this->type_grps;
679  }
680 
684  function enablePageEditing()
685  {
686  global $ilSetting;
687 
688  // @todo: this will need a more general approach
689  if ($ilSetting->get("enable_cat_page_edit"))
690  {
691  return true;
692  }
693  }
694 
698  function create()
699  {
700  $ret = parent::create();
701 
702  if (((int) $this->getStyleSheetId()) > 0)
703  {
704  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
706  }
707 
708  return $ret;
709  }
710 
714  function update()
715  {
716  $ret = parent::update();
717 
718  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
720 
721  return $ret;
722  }
723 
724 
732  public function read()
733  {
734  parent::read();
735 
736  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
738 
739  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
741  }
742 
743 } // END class ilContainer
744 ?>