ILIAS  Release_3_10_x_branch Revision 61812
 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 
170  function _lookupContainerSetting($a_id, $a_keyword)
171  {
172  global $ilDB;
173 
174  $q = "SELECT * FROM container_settings WHERE ".
175  " id = ".$ilDB->quote($a_id)." AND ".
176  " keyword = ".$ilDB->quote($a_keyword);
177  $set = $ilDB->query($q);
178  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
179 
180  return $rec["value"];
181  }
182 
183  function _writeContainerSetting($a_id, $a_keyword, $a_value)
184  {
185  global $ilDB;
186 
187  $q = "REPLACE INTO container_settings (id, keyword, value) VALUES".
188  " (".$ilDB->quote($a_id).", ".
189  $ilDB->quote($a_keyword).", ".
190  $ilDB->quote($a_value).")";
191 
192  $ilDB->query($q);
193  }
194 
201  function _lookupIconPath($a_id, $a_size = "big")
202  {
203  if ($a_size == "")
204  {
205  $a_size = "big";
206  }
207 
208  $size = $a_size;
209 
210  if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
211  {
212  $cont_dir = ilContainer::_getContainerDirectory($a_id);
213  $file_name = $cont_dir."/icon_".$a_size.".gif";
214 
215  if (is_file($file_name))
216  {
217  return $file_name;
218  }
219  }
220 
221  return "";
222  }
223 
227  function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
228  {
229  global $ilDB;
230 
231  $this->createContainerDirectory();
232  $cont_dir = $this->getContainerDirectory();
233 
234  // save big icon
235  $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
236  $this->ilias->getSetting("custom_icon_big_height");
237  $big_file_name = $cont_dir."/icon_big.gif";
238 
239  if (is_file($a_big_icon))
240  {
241  $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
242  $big_file_name = ilUtil::escapeShellArg($big_file_name);
243  $cmd = ilUtil::getConvertCmd()." ".$a_big_icon."[0] -geometry $big_geom GIF:$big_file_name";
244  system($cmd);
245  }
246 
247  if (is_file($cont_dir."/icon_big.gif"))
248  {
249  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
250  }
251  else
252  {
253  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
254  }
255 
256  // save small icon
257  $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
258  $this->ilias->getSetting("custom_icon_small_height");
259  $small_file_name = $cont_dir."/icon_small.gif";
260 
261  if (is_file($a_small_icon))
262  {
263  $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
264  $small_file_name = ilUtil::escapeShellArg($small_file_name);
265  $cmd = ilUtil::getConvertCmd()." ".$a_small_icon."[0] -geometry $small_geom GIF:$small_file_name";
266  system($cmd);
267  }
268  if (is_file($cont_dir."/icon_small.gif"))
269  {
270  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
271  }
272  else
273  {
274  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
275  }
276 
277  // save tiny icon
278  $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
279  $this->ilias->getSetting("custom_icon_tiny_height");
280  $tiny_file_name = $cont_dir."/icon_tiny.gif";
281 
282  if (is_file($a_tiny_icon))
283  {
284  $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
285  $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
286  $cmd = ilUtil::getConvertCmd()." ".$a_tiny_icon."[0] -geometry $tiny_geom GIF:$tiny_file_name";
287  system($cmd);
288  }
289  if (is_file($cont_dir."/icon_tiny.gif"))
290  {
291  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
292  }
293  else
294  {
295  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
296  }
297 
298  }
299 
303  function removeBigIcon()
304  {
305  $cont_dir = $this->getContainerDirectory();
306  $big_file_name = $cont_dir."/icon_big.gif";
307  @unlink($big_file_name);
308  ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
309  }
310 
314  function removeSmallIcon()
315  {
316  $cont_dir = $this->getContainerDirectory();
317  $small_file_name = $cont_dir."/icon_small.gif";
318  @unlink($small_file_name);
319  ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
320  }
321 
325  function removeTinyIcon()
326  {
327  $cont_dir = $this->getContainerDirectory();
328  $tiny_file_name = $cont_dir."/icon_tiny.gif";
329  @unlink($tiny_file_name);
330  ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
331  }
332 
338  function getFirstColumn()
339  {
340  $col_id = ilContainer::_lookupContainerSetting($this->getId(), "first_column");
341  if ($col_id > 0)
342  {
343  include_once("./Services/Blocks/class.ilBlockColumn.php");
344  $block_column = new ilBlockColumn($col_id);
345  return $block_column;
346  }
347  return false;
348  }
349 
358  public function cloneObject($a_target_id,$a_copy_id = 0)
359  {
360  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
361 
362  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
363  $sorting = new ilContainerSortingSettings($new_obj->getId());
364  $sorting->setSortMode($this->getOrderType());
365  $sorting->update();
366 
367  // copy content page
368  include_once("./Services/COPage/classes/class.ilPageObject.php");
369  if (ilPageObject::_exists($this->getType(),
370  $this->getId()))
371  {
372  $orig_page = new ilPageObject($this->getType(), $this->getId());
373  $new_page_object = new ilPageObject($this->getType());
374  $new_page_object->setParentId($new_obj->getId());
375  $new_page_object->setId($new_obj->getId());
376  $new_page_object->createFromXML();
377  $new_page_object->setXMLContent($orig_page->getXMLContent());
378  $new_page_object->buildDom();
379  $new_page_object->update();
380  }
381 
382  return $new_obj;
383  }
384 
393  public function cloneDependencies($a_target_id,$a_copy_id)
394  {
395  include_once('./Services/Container/classes/class.ilContainerSorting.php');
396  ilContainerSorting::_getInstance($this->getId())->cloneSorting($a_target_id,$a_copy_id);
397  return true;
398  }
399 
411  public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options, $soap_call = false)
412  {
413  global $ilLog;
414 
415  include_once('classes/class.ilLink.php');
416  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
417 
418  global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
419 
420  // Save wizard options
422  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
423  $wizard_options->saveOwner($ilUser->getId());
424  $wizard_options->saveRoot($clone_source);
425 
426  // add entry for source container
427  $wizard_options->initContainer($clone_source, $ref_id);
428 
429  foreach($options as $source_id => $option)
430  {
431  $wizard_options->addEntry($source_id,$option);
432  }
433  $wizard_options->read();
434  $wizard_options->storeTree($clone_source);
435  #print_r($options);
436  // Duplicate session to avoid logout problems with backgrounded SOAP calls
437  $new_session_id = duplicate_session($session_id);
438  // Start cloning process using soap call
439  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
440 
441  $soap_client = new ilSoapClient();
442  $soap_client->setTimeout(30);
443  $soap_client->setResponseTimeout(30);
444  $soap_client->enableWSDL(true);
445 
446  $ilLog->write(__METHOD__.': Trying to call Soap client...');
447  if($soap_client->init())
448  {
449  $ilLog->write(__METHOD__.': Calling soap clone method...');
450  $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
451  }
452  else
453  {
454  $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
455  $wizard_options->disableSOAP();
456  $wizard_options->read();
457  include_once('./webservice/soap/include/inc.soap_functions.php');
458  $res = ilSoapFunctions::ilClone($new_session_id.'::'.$client_id, $copy_id);
459  }
460  // Check if copy is in progress or if this has been called by soap (don't wait for finishing)
461  if($soap_call || ilCopyWizardOptions::_isFinished($copy_id))
462  {
463  return $res;
464  }
465  else
466  {
467  return $ref_id;
468  }
469  }
470 
474  function getViewMode()
475  {
477  }
478 
482  function getOrderType()
483  {
484  return $this->order_type ? $this->order_type : ilContainer::SORT_TITLE;
485  }
486 
487  function setOrderType($a_value)
488  {
489  $this->order_type = $a_value;
490  }
491 
497  function getSubItems($a_include_hidden_files = false, $a_include_side_block = false)
498  {
499  global $objDefinition, $ilBench, $tree;
500 
501  // Caching
502  if (is_array($this->items[(int) $a_include_hidden_files][(int) $a_include_side_block]))
503  {
504  return $this->items[(int) $a_include_hidden_files][(int) $a_include_side_block];
505  }
506 
507  $type_grps = $this->getGroupedObjTypes();
508  $objects = $tree->getChilds($this->getRefId(), "title");
509 
510  $found = false;
511 
512  include_once('Services/Container/classes/class.ilContainerSorting.php');
513  $sort = ilContainerSorting::_getInstance($this->getId());
514 
515  // TODO: check this
516  // get items attached to a session
517  include_once './Modules/Session/classes/class.ilEventItems.php';
518  $event_items = ilEventItems::_getItemsOfContainer($this->getRefId());
519 
520  foreach ($objects as $key => $object)
521  {
522  // hide object types in devmode
523  if ($objDefinition->getDevMode($object["type"]) || $object["type"] == "adm"
524  || $object["type"] == "rolf")
525  {
526  continue;
527  }
528 
529  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
530  if (in_array($object['type'], array('file','fold','cat')))
531  {
532  include_once 'Modules/File/classes/class.ilObjFileAccess.php';
533  if (ilObjFileAccess::_isFileHidden($object['title']))
534  {
535  $this->setHiddenFilesFound(true);
536  if (!$a_include_hidden_files)
537  {
538  continue;
539  }
540  }
541  }
542  // END WebDAV: Don't display hidden Files, Folders and Categories
543 
544  // filter out items that are attached to an event
545  if (in_array($object['ref_id'],$event_items))
546  {
547  continue;
548  }
549 
550  // filter side block items
551  if(!$a_include_side_block && $objDefinition->isSideBlock($object['type']))
552  {
553  continue;
554  }
555 
556  // group object type groups together (e.g. learning resources)
557  $type = $objDefinition->getGroupOfObj($object["type"]);
558  if ($type == "")
559  {
560  $type = $object["type"];
561  }
562 
563  $this->addAdditionalSubItemInformation($object);
564 
565  $this->items[$type][$key] = $object;
566  $this->items["_all"][$key] = $object;
567  if ($object["type"] != "sess")
568  {
569  $this->items["_non_sess"][$key] = $object;
570  }
571  }
572 
573  $this->items[(int) $a_include_hidden_files][(int) $a_include_side_block]
574  = $sort->sortItems($this->items);
575 
576  return $this->items[(int) $a_include_hidden_files][(int) $a_include_side_block];
577  }
578 
582  function gotItems()
583  {
584  if (is_array($this->items["_all"]) && count($this->items["_all"]) > 0)
585  {
586  return true;
587  }
588  return false;
589  }
590 
596  {
597  }
598 
605  {
606  global $objDefinition;
607 
608  if (empty($this->type_grps))
609  {
610  $this->type_grps = $objDefinition->getGroupedRepositoryObjectTypes($this->getType());
611  }
612  return $this->type_grps;
613  }
614 
618  function enablePageEditing()
619  {
620  global $ilSetting;
621 
622  // @todo: this will need a more general approach
623  if ($ilSetting->get("enable_cat_page_edit"))
624  {
625  return true;
626  }
627  }
628 
636  public function read()
637  {
638  parent::read();
639 
640  include_once("./Services/Container/classes/class.ilContainerSortingSettings.php");
642  }
643 
644 } // END class ilContainer
645 ?>