ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjLinkResource.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 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 include_once "./Services/Object/classes/class.ilObject.php";
25 
38 {
45  public function __construct($a_id = 0,$a_call_by_reference = true)
46  {
47  $this->type = "webr";
48  parent::__construct($a_id,$a_call_by_reference);
49  }
50 
56  function create($a_upload = false)
57  {
58  $new_id = parent::create();
59 
60  if(!$a_upload)
61  {
62  $this->createMetaData();
63  }
64 
65  return $new_id;
66  }
67 
71  function update()
72  {
73  $this->updateMetaData();
74  parent::update();
75  }
76 
83  public function MDUpdateListener($a_element)
84  {
85  global $ilLog;
86 
87  parent::MDUpdateListener($a_element);
88 
89  $md = new ilMD($this->getId(),0, $this->getType());
90  if(!is_object($md_gen = $md->getGeneral()))
91  {
92  return false;
93  }
94  $title = $md_gen->getTitle();
95  foreach($md_gen->getDescriptionIds() as $id)
96  {
97  $md_des = $md_gen->getDescription($id);
98  $description = $md_des->getDescription();
99  break;
100  }
101  switch($a_element)
102  {
103  case 'General':
104  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
106  {
107  $link_arr = ilLinkResourceItems::_getFirstLink($this->getId());
108  $link = new ilLinkResourceItems($this->getId());
109  $link->readItem($link_arr['link_id']);
110  $link->setTitle($title);
111  $link->setDescription($description);
112  $link->update();
113  }
114  break;
115  default:
116  return true;
117  }
118  return true;
119  }
120 
121 
122 
129  function delete()
130  {
131  // always call parent delete function first!!
132  if (!parent::delete())
133  {
134  return false;
135  }
136 
137  // delete items
138  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
140 
141 
142  // Delete notify entries
143  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
145 
146  // delete meta data
147  $this->deleteMetaData();
148 
149  return true;
150  }
151 
153  {
154  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
155 
156  $this->items_obj = new ilLinkResourceItems($this->getId());
157 
158  return true;
159  }
160 
169  public function cloneObject($a_target_id,$a_copy_id = 0, $a_omit_tree = false)
170  {
171  $new_obj = parent::cloneObject($a_target_id,$a_copy_id, $a_omit_tree);
172  $this->cloneMetaData($new_obj);
173 
174  // object created now copy other settings
175  include_once('Modules/WebResource/classes/class.ilLinkResourceItems.php');
176  $links = new ilLinkResourceItems($this->getId());
177  $links->cloneItems($new_obj->getId());
178 
179  // append copy info weblink title
180  if(ilLinkResourceItems::_isSingular($new_obj->getId()))
181  {
182  $first = ilLinkResourceItems::_getFirstLink($new_obj->getId());
183  ilLinkResourceItems::updateTitle($first['link_id'], $new_obj->getTitle());
184  }
185 
186  return $new_obj;
187  }
188 
194  public function toXML(ilXmlWriter $writer)
195  {
196  $attribs = array("obj_id" => "il_".IL_INST_ID."_webr_".$this->getId());
197 
198  $writer->xmlStartTag('WebLinks',$attribs);
199 
200  // LOM MetaData
201  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
202  $md2xml = new ilMD2XML($this->getId(),$this->getId(),'webr');
203  $md2xml->startExport();
204  $writer->appendXML($md2xml->getXML());
205 
206  // Sorting
207  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
209  {
211  $writer->xmlElement(
212  'Sorting',
213  array('type' => 'Manual')
214  );
215  break;
216 
218  default:
219  $writer->xmlElement(
220  'Sorting',
221  array('type' => 'Title')
222  );
223  break;
224  }
225 
226  // All links
227  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
228  $links = new ilLinkResourceItems($this->getId());
229  $links->toXML($writer);
230 
231 
232  $writer->xmlEndTag('WebLinks');
233  return true;
234  }
235 
236 
237  // PRIVATE
238 
239 
240 } // END class.ilObjLinkResource
241 ?>
static _isSingular($a_webr_id)
Check whether there is only one active link in the web resource.
toXML(ilXmlWriter $writer)
Write webresource xml.
static updateTitle($a_link_id, $a_title)
Update title.
updateMetaData()
update meta data entry
Class ilObject Basic functions for all objects.
static lookupNumberOfLinks($a_webr_id)
Get number of assigned links.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
createMetaData()
create meta data entry
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static _deleteObject($a_obj_id)
MDUpdateListener($a_element)
Overwriten Metadata update listener for ECS functionalities.
xmlEndTag($tag)
Writes an endtag.
getId()
get object id public
cloneMetaData($target_obj)
Copy meta data.
getType()
get object type public
Create styles array
The data for the language used.
static _getFirstLink($a_webr_id)
Get first link item Check before with _isSingular() if there is more or less than one...
create($a_upload=false)
create object
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone.
Class ilObjLinkResourceGUI.
deleteMetaData()
delete meta data entry
appendXML($a_str)
append xml string to document
static _lookupSortMode($a_obj_id)
lookup sort mode
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
Class ilObjLinkResource.