ILIAS  Release_4_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 "./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 
65  function ilContainer($a_id = 0, $a_call_by_reference = true)
66  {
67  parent::__construct($a_id, $a_call_by_reference);
68  }
69 
70 
71 
77  {
78  $webspace_dir = ilUtil::getWebspaceDir();
79  $cont_dir = $webspace_dir."/container_data";
80  if (!is_dir($cont_dir))
81  {
82  ilUtil::makeDir($cont_dir);
83  }
84  $obj_dir = $cont_dir."/obj_".$this->getId();
85  if (!is_dir($obj_dir))
86  {
87  ilUtil::makeDir($obj_dir);
88  }
89  }
90 
97  {
98  return $this->_getContainerDirectory($this->getId());
99  }
100 
106  function _getContainerDirectory($a_id)
107  {
108  return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
109  }
110 
116  function getBigIconPath()
117  {
118  return ilContainer::_lookupIconPath($this->getId(), "big");
119  }
120 
126  function getSmallIconPath()
127  {
128  return ilContainer::_lookupIconPath($this->getId(), "small");
129  }
130 
136  function getTinyIconPath()
137  {
138  return ilContainer::_lookupIconPath($this->getId(), "tiny");
139  }
140 
141 
147  function setHiddenFilesFound($a_hiddenfilesfound)
148  {
149  $this->hiddenfilesfound = $a_hiddenfilesfound;
150  }
151 
158  {
160  }
161 
165  function getStyleSheetId()
166  {
167  return $this->style_id;
168  }
169 
173  function setStyleSheetId($a_style_id)
174  {
175  $this->style_id = $a_style_id;
176  }
177 
186  function _lookupContainerSetting($a_id, $a_keyword)
187  {
188  global $ilDB;
189 
190  $q = "SELECT * FROM container_settings WHERE ".
191  " id = ".$ilDB->quote($a_id ,'integer')." AND ".
192  " keyword = ".$ilDB->quote($a_keyword ,'text');
193  $set = $ilDB->query($q);
194  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
195 
196  return $rec["value"];
197  }
198 
199  function _writeContainerSetting($a_id, $a_keyword, $a_value)
200  {
201  global $ilDB;
202 
203  $query = "DELETE FROM container_settings WHERE ".
204  "id = ".$ilDB->quote($a_id,'integer')." ".
205  "AND keyword = ".$ilDB->quote($a_keyword,'text');
206  $res = $ilDB->manipulate($query);
207 
208  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (".
209  $ilDB->quote($a_id ,'integer').", ".
210  $ilDB->quote($a_keyword ,'text').", ".
211  $ilDB->quote($a_value ,'text').
212  ")";
213  $res = $ilDB->manipulate($query);
214  }
215 
222  function _lookupIconPath($a_id, $a_size = "big")
223  {
224  if ($a_size == "")
225  {
226  $a_size = "big";
227  }
228 
229  $size = $a_size;
230 
231  if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
232  {
233  $cont_dir = ilContainer::_getContainerDirectory($a_id);
234  $file_name = $cont_dir."/icon_".$a_size.".gif";
235 
236  if (is_file($file_name))
237  {
238  return $file_name;
239  }
240  }
241 
242  return "";
243  }
244 
248  function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
249  {
250  global $ilDB;
251 
252  $this->createContainerDirectory();
253  $cont_dir = $this->getContainerDirectory();
254 
255  // save big icon
256  $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
257  $this->ilias->getSetting("custom_icon_big_height");
258  $big_file_name = $cont_dir."/icon_big.gif";
259 
260  if (is_file($a_big_icon))
261  {
262  $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
263  $big_file_name = ilUtil::escapeShellArg($big_file_name);
264  $cmd = ilUtil::getConvertCmd()." ".$a_big_icon."[0] -geometry $big_geom GIF:$big_file_name";
265  system($cmd);
266  }
267 
268  if (is_file($cont_dir."/icon_big.gif"))
269  {
270  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
271  }
272  else
273  {
274  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
275  }
276 
277  // save small icon
278  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
279  $this->ilias->getSetting("custom_icon_small_height");
280  $small_file_name = $cont_dir."/icon_small.gif";
281 
282  if (is_file($a_small_icon))
283  {
284  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
285  $small_file_name = ilUtil::escapeShellArg($small_file_name);
286  $cmd = ilUtil::getConvertCmd()." ".$a_small_icon."[0] -geometry $small_geom GIF:$small_file_name";
287  system($cmd);
288  }
289  if (is_file($cont_dir."/icon_small.gif"))
290  {
291  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
292  }
293  else
294  {
295  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
296  }
297 
298  // save tiny icon
299  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
300  $this->ilias->getSetting("custom_icon_tiny_height");
301  $tiny_file_name = $cont_dir."/icon_tiny.gif";
302 
303  if (is_file($a_tiny_icon))
304  {
305  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
306  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
307  $cmd = ilUtil::getConvertCmd()." ".$a_tiny_icon."[0] -geometry $tiny_geom GIF:$tiny_file_name";
308  system($cmd);
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;
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  $this->items["_all"][$key] = $object;
602  if ($object["type"] != "sess")
603  {
604  $this->items["_non_sess"][$key] = $object;
605  }
606  }
607 
608  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
609  = $sort->sortItems($this->items);
610 
611  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
612  }
613 
617  function gotItems()
618  {
619  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
620  {
621  return true;
622  }
623  return false;
624  }
625 
631  {
632  }
633 
640  {
641  global $objDefinition;
642 
643  if (empty($this->type_grps))
644  {
645  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
646  }
647  return $this->type_grps;
648  }
649 
653  function enablePageEditing()
654  {
655  global $ilSetting;
656 
657  // @todo: this will need a more general approach
658  if ($ilSetting->get("enable_cat_page_edit"))
659  {
660  return true;
661  }
662  }
663 
667  function create()
668  {
669  $ret = parent::create();
670 
671  if (((int) $this->getStyleSheetId()) > 0)
672  {
673  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
675  }
676 
677  return $ret;
678  }
679 
683  function update()
684  {
685  $ret = parent::update();
686 
687  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
689 
690  return $ret;
691  }
692 
693 
701  public function read()
702  {
703  parent::read();
704 
705  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
707 
708  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
710  }
711 
712 } // END class ilContainer
713 ?>