ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebLinkParameter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private int $webr_id;
28 private int $link_id;
29 private int $param_id;
30
32
33 public function __construct(
35 int $webr_id,
36 int $link_id,
37 int $param_id,
38 int $value,
39 string $name
40 ) {
41 $this->user = $user;
42 $this->webr_id = $webr_id;
43 $this->link_id = $link_id;
44 $this->param_id = $param_id;
46 }
47
48 //TODO inject the dependency on DIC->user as an argument into this method
49 public function appendToLink(string $link): string
50 {
51 if (!strpos($link, '?')) {
52 $link .= "?";
53 } else {
54 $link .= "&";
55 }
56 $link .= ($this->getName() . "=");
57 switch ($this->getValue()) {
58 case self::VALUES['login']:
59 $link .= (urlencode(
60 $this->user->getLogin()
61 ));
62 break;
63
64 case self::VALUES['user_id']:
65 $link .= ($this->user->getId());
66 break;
67
68 case self::VALUES['matriculation']:
69 $link .= ($this->user->getMatriculation());
70 break;
71
72 default:
74 'Invalid parameter value'
75 );
76 }
77
78 return $link;
79 }
80
81 public function getInfo(): string
82 {
83 $info = $this->getName();
84
85 switch ($this->getValue()) {
86 case self::VALUES['user_id']:
87 return $info . '=USER_ID';
88
89 case self::VALUES['login']:
90 return $info . '=LOGIN';
91
92 case self::VALUES['matriculation']:
93 return $info . '=MATRICULATION';
94
95 default:
97 'Invalid parameter value'
98 );
99 }
100 }
101
102 public function toXML(ilXmlWriter $writer): void
103 {
104 switch ($this->getValue()) {
105 case self::VALUES['user_id']:
106 $value = 'userId';
107 break;
108
109 case self::VALUES['login']:
110 $value = 'userName';
111 break;
112
113 case self::VALUES['matriculation']:
114 $value = 'matriculation';
115 break;
116
117 default:
118 return;
119 }
120
121 $writer->xmlElement(
122 'DynamicParameter',
123 [
124 'id' => $this->getParamId(),
125 'name' => $this->getName(),
126 'type' => $value
127 ]
128 );
129 }
130
131 public function getWebrId(): int
132 {
133 return $this->webr_id;
134 }
135
136 public function getLinkId(): int
137 {
138 return $this->link_id;
139 }
140
141 public function getParamId(): int
142 {
143 return $this->param_id;
144 }
145}
User class.
Base class for parameters attached to Web Link items.
Immutable class for parameters attached to Web Link items.
toXML(ilXmlWriter $writer)
__construct(ilObjUser $user, int $webr_id, int $link_id, int $param_id, int $value, string $name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$info
Definition: entry_point.php:21
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc