ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTExternalLinkSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
13 const SQL_STRICT = 1;
14 const SQL_LIKE = 2;
15 const SQL_LIKE_END = 3;
16 const SQL_LIKE_START = 4;
17
18
24 protected function isValidADTDefinition(\ilADTDefinition $a_adt_def)
25 {
26 return $a_adt_def instanceof ilADTExternalLinkDefinition;
27 }
28
29
33 public function loadFilter()
34 {
35 $value = $this->readFilter();
36 if ($value !== null) {
37 $this->getADT()->setUrl($value);
38 }
39 }
40
44 public function addToForm()
45 {
46 $def = $this->getADT()->getCopyOfDefinition();
47
48 $url = new ilTextInputGUI($this->getTitle(), $this->getElementId());
49 $url->setSize(255);
50 $url->setValue($this->getADT()->getUrl());
52 }
53
58 public function importFromPost(array $a_post = null)
59 {
60 $post = $this->extractPostValues($a_post);
61
62 if ($post && $this->shouldBeImportedFromPost($post)) {
63
64 if ($this->getForm() instanceof ilPropertyFormGUI) {
65 $item = $this->getForm()->getItemByPostVar($this->getElementId());
66 $item->setValue($post);
67 $this->getADT()->setUrl($post);
68 } elseif (array_key_exists($this->getElementId(), $this->table_filter_fields)) {
69 $this->table_filter_fields[$this->getElementId()]->setValue($post);
70 $this->writeFilter($post);
71 $this->getADT()->setUrl($post);
72 }
73 } else {
74 $this->getADT()->setUrl(null);
75 $this->writeFilter();
76 }
77 }
78
84 public function getSQLCondition($a_element_id, $a_mode = self::SQL_LIKE, $a_value = null)
85 {
86 $db = $GLOBALS['DIC']->database();
87
88 if (!$a_value) {
89 if ($this->isNull() || !$this->isValid()) {
90 return;
91 }
92 $a_value = $this->getADT()->getUrl();
93 }
94
95 switch ($a_mode) {
97 if (!is_array($a_value)) {
98 return $a_element_id . " = " . $db->quote($a_value, "text");
99 } else {
100 return $db->in($a_element_id, $a_value, "", "text");
101 }
102 break;
103
104 case self::SQL_LIKE:
105 if (!is_array($a_value)) {
106 return $db->like($a_element_id, "text", "%" . $a_value . "%");
107 } else {
108 $tmp = array();
109 foreach ($a_value as $word) {
110 if ($word) {
111 $tmp[] = $db->like($a_element_id, "text", "%" . $word . "%");
112 }
113 }
114 if (sizeof($tmp)) {
115 return "(" . implode(" OR ", $tmp) . ")";
116 }
117 }
118 break;
119
121 if (!is_array($a_value)) {
122 return $db->like($a_element_id, "text", $a_value . "%");
123 }
124 break;
125
127 if (!is_array($a_value)) {
128 return $db->like($a_element_id, "text", "%" . $a_value);
129 }
130 break;
131 }
132 }
133
139 public function isInCondition(ilADT $a_adt)
140 {
141 if ($this->getADT()->getCopyOfDefinition()->isComparableTo($a_adt)) {
142 return
143 strcasecmp(trim($this->getADT()->getUrl()), trim($a_adt->getUrl())) === 0 ||
144 strcasecmp(trim($this->getADT()->getUrl()), trim($a_adt->getTitle())) === 0;
145 }
146 return false;
147 }
148
153 public function getSerializedValue()
154 {
155 if (!$this->isNull() && $this->isValid()) {
156 return serialize(array($this->getADT()->getUrl()));
157 }
158 }
159
164 public function setSerializedValue($a_value)
165 {
166 $a_value = unserialize($a_value);
167 if (is_array($a_value)) {
168 $this->getADT()->setUrl($a_value[0]);
169 }
170 }
171}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
isValidADTDefinition(\ilADTDefinition $a_adt_def)
Is valid type.
getSQLCondition($a_element_id, $a_mode=self::SQL_LIKE, $a_value=null)
Get sql condition.
readFilter()
Load value(s) from filter store (in session)
extractPostValues(array $a_post=null)
Extract data from (post) values.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
getElementId()
Get element id.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
writeFilter($a_value=null)
Write value(s) to filter store (in session)
ADT base class.
Definition: class.ilADT.php:12
This class represents a property form user interface.
This class represents a text property in a property form.
$url