ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilParameterAppender.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
24define("LINKS_USER_ID", 1);
25define("LINKS_SESSION_ID", 2);
26define("LINKS_LOGIN", 3);
27define('LINKS_MATRICULATION', 4);
28
29// Errors
30define("LINKS_ERR_NO_NAME", 1);
31define("LINKS_ERR_NO_VALUE", 2);
32define("LINKS_ERR_NO_NAME_VALUE", 3);
33
43{
44 public $webr_id = null;
45 public $db = null;
46
47 public $err = null;
48
49
54 public function __construct($webr_id)
55 {
56 global $ilDB;
57
58 $this->webr_id = $webr_id;
59 $this->db = $ilDB;
60 }
61
68 public static function getParameterIds($a_webr_id, $a_link_id)
69 {
70 global $ilDB;
71
72 $query = "SELECT * FROM webr_params " .
73 "WHERE webr_id = " . $ilDB->quote($a_webr_id, 'integer') . " " .
74 "AND link_id = " . $ilDB->quote($a_link_id, 'integer');
75 $res = $ilDB->query($query);
76 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
77 $params[] = $row['param_id'];
78 }
79 return (array) $params;
80 }
81
82 public function getErrorCode()
83 {
84 return $this->err;
85 }
86
87 // SET GET
88 public function setObjId($a_obj_id)
89 {
90 $this->webr_id = $a_obj_id;
91 }
92
93 public function getObjId()
94 {
95 return $this->webr_id;
96 }
97
98 public function setName($a_name)
99 {
100 $this->name = $a_name;
101 }
102 public function getName()
103 {
104 return $this->name;
105 }
106 public function setValue($a_value)
107 {
108 $this->value = $a_value;
109 }
110 public function getValue()
111 {
112 return $this->value;
113 }
114
115 public function validate()
116 {
117 if (!strlen($this->getName()) and !$this->getValue()) {
118 $this->err = LINKS_ERR_NO_NAME_VALUE;
119 return false;
120 }
121 if (!strlen($this->getName())) {
122 $this->err = LINKS_ERR_NO_NAME;
123 return false;
124 }
125 if (!$this->getValue()) {
126 $this->err = LINKS_ERR_NO_VALUE;
127 return false;
128 }
129 return true;
130 }
131
132
133 public function add($a_link_id)
134 {
135 global $ilDB;
136
137 if (!$a_link_id) {
138 return false;
139 }
140 if (!strlen($this->getName() or !strlen($this->getValue()))) {
141 return false;
142 }
143
144 $next_id = $ilDB->nextId('webr_params');
145 $query = "INSERT INTO webr_params (param_id,webr_id,link_id,name,value) " .
146 "VALUES( " .
147 $ilDB->quote($next_id, 'integer') . ", " .
148 $ilDB->quote($this->getObjId(), 'integer') . ", " .
149 $ilDB->quote($a_link_id, 'integer') . ", " .
150 $ilDB->quote($this->getName(), 'text') . ", " .
151 $ilDB->quote($this->getValue(), 'integer') .
152 ")";
153 $res = $ilDB->manipulate($query);
154
155 return $next_id;
156 }
157
158 public function delete($a_param_id)
159 {
160 global $ilDB;
161
162 $query = "DELETE FROM webr_params " .
163 "WHERE param_id = " . $ilDB->quote($a_param_id, 'integer') . " " .
164 "AND webr_id = " . $ilDB->quote($this->getObjId(), 'integer');
165 $res = $ilDB->manipulate($query);
166 return true;
167 }
168
173 public static function _isEnabled()
174 {
175 global $ilSetting;
176
177 return $ilSetting->get('links_dynamic', false) ? true : false;
178 }
179
180 public static function _append($a_link_data)
181 {
182 global $ilUser;
183
184 if (!is_array($a_link_data)) {
185 return false;
186 }
187 if (count($params = ilParameterAppender::_getParams($a_link_data['link_id']))) {
188 // Check for prefix
189 foreach ($params as $param_data) {
190 if (!strpos($a_link_data['target'], '?')) {
191 $a_link_data['target'] .= "?";
192 } else {
193 $a_link_data['target'] .= "&";
194 }
195 $a_link_data['target'] .= ($param_data['name'] . "=");
196 switch ($param_data['value']) {
197 case LINKS_LOGIN:
198 $a_link_data['target'] .= (urlencode($ilUser->getLogin()));
199 break;
200
201 case LINKS_SESSION_ID:
202 $a_link_data['target'] .= (session_id());
203 break;
204
205 case LINKS_USER_ID:
206 $a_link_data['target'] .= ($ilUser->getId());
207 break;
208
210 $a_link_data['target'] .= ($ilUser->getMatriculation());
211 break;
212 }
213 }
214 }
215 return $a_link_data;
216 }
217
223 public static function _getParams($a_link_id)
224 {
225 global $ilDB;
226
227 $params = [];
228
229 $res = $ilDB->query("SELECT * FROM webr_params WHERE link_id = " .
230 $ilDB->quote((int) $a_link_id, 'integer'));
231 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
232 $params[$row->param_id]['name'] = $row->name;
233 $params[$row->param_id]['value'] = $row->value;
234 }
235
236 return $params;
237 }
238
245 public static function parameterToInfo($a_name, $a_value)
246 {
247 $info = $a_name;
248
249 switch ($a_value) {
250 case LINKS_USER_ID:
251 return $info . '=USER_ID';
252
253 case LINKS_SESSION_ID:
254 return $info . '=SESSION_ID';
255
256 case LINKS_LOGIN:
257 return $info . '=LOGIN';
258
260 return $info . '=MATRICULATION';
261 }
262 return '';
263 }
264
265 public static function _deleteAll($a_webr_id)
266 {
267 global $ilDB;
268
269 $query = "DELETE FROM webr_params WHERE webr_id = " .
270 $ilDB->quote((int) $a_webr_id, 'integer');
271 $res = $ilDB->manipulate($query);
272
273 return true;
274 }
275
280 public static function _getOptionSelect()
281 {
282 global $lng;
283
284 return array(0 => $lng->txt('links_select_one'),
285 LINKS_USER_ID => $lng->txt('links_user_id'),
286 LINKS_LOGIN => $lng->txt('links_user_name'),
287 LINKS_SESSION_ID => $lng->txt('links_session_id'),
288 LINKS_MATRICULATION => $lng->txt('matriculation')
289 );
290 }
291}
An exception for terminatinating execution or to throw for unit testing.
const LINKS_SESSION_ID
const LINKS_USER_ID
const LINKS_ERR_NO_NAME
const LINKS_LOGIN
const LINKS_MATRICULATION
const LINKS_ERR_NO_VALUE
const LINKS_ERR_NO_NAME_VALUE
Class ilParameterAppender.
static getParameterIds($a_webr_id, $a_link_id)
Get Parameter ids of link.
__construct($webr_id)
Constructor @access public.
static parameterToInfo($a_name, $a_value)
Get info text describing an existing dynamic link.
static _append($a_link_data)
static _getOptionSelect()
Get options as array.
static _getParams($a_link_id)
Get dynamic parameter definitions.
static _isEnabled()
Check if dynamic parameters are enabled.
if($format !==null) $name
Definition: metadata.php:146
$info
Definition: index.php:5
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$params
Definition: disable.php:11