1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/** @defgroup ServicesPermanentLink Services/PermanentLink
6 */
7
8/**
9* Class for permanent links
10*
11* @version $Id$
12*
13* @ilCtrl_Calls ilPermanentLinkGUI: ilNoteGUI, ilColumnGUI, ilPublicUserProfileGUI
14*
15* @ingroup ServicesPermanentLink
16*/
17class ilPermanentLinkGUI
18{
19    /**
20     * @var ilLanguage
21     */
22    protected $lng;
23
24    /**
25     * @var ilCtrl
26     */
27    protected $ctrl;
28
29    /**
30     * @var ilObjectDataCache
31     */
32    protected $obj_data_cache;
33
34    protected $align_center = true;
35
36    /**
37    * Example: type = "wiki", id (ref_id) = "234", append = "_Start_Page"
38    */
39    public function __construct($a_type, $a_id, $a_append = "", $a_target = "")
40    {
41        global $DIC;
42
43        $this->lng = $DIC->language();
44        $this->ctrl = $DIC->ctrl();
45        $this->obj_data_cache = $DIC["ilObjDataCache"];
46        $this->setType($a_type);
47        $this->setId($a_id);
48        $this->setAppend($a_append);
49        $this->setIncludePermanentLinkText(true);
50        $this->setTarget($a_target);
51    }
52
53    /**
54    * Set Include permanent link text.
55    *
56    * @param	boolean	$a_includepermanentlinktext	Include permanent link text
57    */
58    public function setIncludePermanentLinkText($a_includepermanentlinktext)
59    {
60        $this->includepermanentlinktext = $a_includepermanentlinktext;
61    }
62
63    /**
64    * Get Include permanent link text.
65    *
66    * @return	boolean	Include permanent link text
67    */
68    public function getIncludePermanentLinkText()
69    {
70        return $this->includepermanentlinktext;
71    }
72
73    /**
74    * Set Type.
75    *
76    * @param	string	$a_type	Type
77    */
78    public function setType($a_type)
79    {
80        $this->type = $a_type;
81    }
82
83    /**
84    * Get Type.
85    *
86    * @return	string	Type
87    */
88    public function getType()
89    {
90        return $this->type;
91    }
92
93    /**
94    * Set Id.
95    *
96    * @param	string	$a_id	Id
97    */
98    public function setId($a_id)
99    {
100        $this->id = $a_id;
101    }
102
103    /**
104    * Get Id.
105    *
106    * @return	string	Id
107    */
108    public function getId()
109    {
110        return $this->id;
111    }
112
113    /**
114    * Set Append.
115    *
116    * @param	string	$a_append	Append
117    */
118    public function setAppend($a_append)
119    {
120        $this->append = $a_append;
121    }
122
123    /**
124    * Get Append.
125    *
126    * @return	string	Append
127    */
128    public function getAppend()
129    {
130        return $this->append;
131    }
132
133    /**
134    * Set Target.
135    *
136    * @param	string	$a_target	Target
137    */
138    public function setTarget($a_target)
139    {
140        $this->target = $a_target;
141    }
142
143    /**
144    * Get Target.
145    *
146    * @return	string	Target
147    */
148    public function getTarget()
149    {
150        return $this->target;
151    }
152
153    /**
154     * Set title
155     *
156     * @param	string	title
157     */
158    public function setTitle($a_val)
159    {
160        $this->title = $a_val;
161    }
162
163    /**
164     * Get title
165     *
166     * @return	string	title
167     */
168    public function getTitle()
169    {
170        return $this->title;
171    }
172
173    /**
174     * Set center alignment
175     *
176     * @param	boolean	align the link at center
177     */
178    public function setAlignCenter($a_val)
179    {
180        $this->align_center = $a_val;
181    }
182
183    /**
184     * Get center alignment
185     *
186     * @return	boolean	align the link at center
187     */
188    public function getAlignCenter()
189    {
190        return $this->align_center;
191    }
192
193    /**
194    * Get HTML for link
195    */
196    public function getHTML()
197    {
198        $lng = $this->lng;
199        $ilCtrl = $this->ctrl;
200        $ilObjDataCache = $this->obj_data_cache;
201
202        $tpl = new ilTemplate(
203            "tpl.permanent_link.html",
204            true,
205            true,
206            "Services/PermanentLink"
207        );
208
209        include_once('./Services/Link/classes/class.ilLink.php');
210        $href = ilLink::_getStaticLink(
211            $this->getId(),
212            $this->getType(),
213            true,
214            $this->getAppend()
215        );
216        if ($this->getIncludePermanentLinkText()) {
217            $tpl->setVariable("TXT_PERMA", $lng->txt("perma_link") . ":");
218        }
219
220        $title = '';
221
222        if ($this->getTitle() != "") {
223            $title = $this->getTitle();
224        } elseif (is_numeric($this->getId())) {
225            $obj_id = $ilObjDataCache->lookupObjId($this->getId());
226            $title = $ilObjDataCache->lookupTitle($obj_id);
227        }
228
229        $tpl->setVariable("TXT_BOOKMARK_DEFAULT", $title);
230
231        $tpl->setVariable("LINK", $href);
232
233        if ($this->getAlignCenter()) {
234            $tpl->setVariable("ALIGN", "center");
235        } else {
236            $tpl->setVariable("ALIGN", "left");
237        }
238
239        if ($this->getTarget() != "") {
240            $tpl->setVariable("TARGET", 'target="' . $this->getTarget() . '"');
241        }
242
243        return $tpl->get();
244    }
245}
246