ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function create($a_upload = false)
57  {
58  $new_id = parent::create();
59 
60  if (!$a_upload) {
61  $this->createMetaData();
62  }
63 
64  return $new_id;
65  }
66 
70  public function update()
71  {
72  $this->updateMetaData();
74  }
75 
82  public function MDUpdateListener($a_element)
83  {
84  global $ilLog;
85 
86  parent::MDUpdateListener($a_element);
87 
88  $md = new ilMD($this->getId(), 0, $this->getType());
89  if (!is_object($md_gen = $md->getGeneral())) {
90  return false;
91  }
92  $title = $md_gen->getTitle();
93  foreach ($md_gen->getDescriptionIds() as $id) {
94  $md_des = $md_gen->getDescription($id);
95  $description = $md_des->getDescription();
96  break;
97  }
98  switch ($a_element) {
99  case 'General':
100  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
101  if (ilLinkResourceItems::lookupNumberOfLinks($this->getId()) == 1) {
102  $link_arr = ilLinkResourceItems::_getFirstLink($this->getId());
103  $link = new ilLinkResourceItems($this->getId());
104  $link->readItem($link_arr['link_id']);
105  $link->setTitle($title);
106  $link->setDescription($description);
107  $link->update();
108  }
109  break;
110  default:
111  return true;
112  }
113  return true;
114  }
115 
116 
117 
124  public function delete()
125  {
126  // always call parent delete function first!!
127  if (!parent::delete()) {
128  return false;
129  }
130 
131  // delete items
132  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
134 
135 
136  // Delete notify entries
137  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
139 
140  // delete meta data
141  $this->deleteMetaData();
142 
143  return true;
144  }
145 
146  public function initLinkResourceItemsObject()
147  {
148  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
149 
150  $this->items_obj = new ilLinkResourceItems($this->getId());
151 
152  return true;
153  }
154 
163  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
164  {
165  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
166  $this->cloneMetaData($new_obj);
167 
168  // object created now copy other settings
169  include_once('Modules/WebResource/classes/class.ilLinkResourceItems.php');
170  $links = new ilLinkResourceItems($this->getId());
171  $links->cloneItems($new_obj->getId());
172 
173  // append copy info weblink title
174  if (ilLinkResourceItems::_isSingular($new_obj->getId())) {
175  $first = ilLinkResourceItems::_getFirstLink($new_obj->getId());
176  ilLinkResourceItems::updateTitle($first['link_id'], $new_obj->getTitle());
177  }
178 
179  return $new_obj;
180  }
181 
187  public function toXML(ilXmlWriter $writer)
188  {
189  $attribs = array("obj_id" => "il_" . IL_INST_ID . "_webr_" . $this->getId());
190 
191  $writer->xmlStartTag('WebLinks', $attribs);
192 
193  // LOM MetaData
194  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
195  $md2xml = new ilMD2XML($this->getId(), $this->getId(), 'webr');
196  $md2xml->startExport();
197  $writer->appendXML($md2xml->getXML());
198 
199  // Sorting
200  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
203  $writer->xmlElement(
204  'Sorting',
205  array('type' => 'Manual')
206  );
207  break;
208 
210  default:
211  $writer->xmlElement(
212  'Sorting',
213  array('type' => 'Title')
214  );
215  break;
216  }
217 
218  // All links
219  include_once './Modules/WebResource/classes/class.ilLinkResourceItems.php';
220  $links = new ilLinkResourceItems($this->getId());
221  $links->toXML($writer);
222 
223 
224  $writer->xmlEndTag('WebLinks');
225  return true;
226  }
227 
228 
229  // PRIVATE
230 } // END class.ilObjLinkResource
static _isSingular($a_webr_id)
Check whether there is only one active link in the web resource.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
toXML(ilXmlWriter $writer)
Write webresource xml.
static updateTitle($a_link_id, $a_title)
Update title.
updateMetaData()
update meta data entry
static lookupNumberOfLinks($a_webr_id)
Get number of assigned links.
createMetaData()
create meta data entry
XML writer class.
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...
update($pash, $contents, Config $config)
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
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.
$links
Class ilObjLinkResource.