ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDclSelectionOption.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
11  const DB_TABLE_NAME = "il_dcl_sel_opts";
12 
13  public static function returnDbTableName()
14  {
15  return self::DB_TABLE_NAME;
16  }
17 
29  protected $id;
30 
40  protected $field_id;
41 
51  protected $opt_id;
52 
62  protected $sorting;
63 
72  protected $value;
73 
74 
78  public function getId()
79  {
80  return $this->id;
81  }
82 
83 
87  public function setId($id)
88  {
89  $this->id = $id;
90  }
91 
92 
96  public function getFieldId()
97  {
98  return $this->field_id;
99  }
100 
101 
105  public function setFieldId($field_id)
106  {
107  $this->field_id = $field_id;
108  }
109 
110 
114  public function getOptId()
115  {
116  return (int) $this->opt_id;
117  }
118 
119 
123  public function setOptId($opt_id)
124  {
125  $this->opt_id = $opt_id;
126  }
127 
128 
132  public function getValue()
133  {
134  return $this->value;
135  }
136 
137 
141  public function setValue($value)
142  {
143  $this->value = $value;
144  }
145 
146 
150  public function getSorting()
151  {
152  return $this->sorting;
153  }
154 
155 
159  public function setSorting($sorting)
160  {
161  $this->sorting = $sorting;
162  }
163 
164 
171  public static function storeOption($field_id, $opt_id, $sorting, $value)
172  {
174  $option = self::where(array("field_id" => $field_id, "opt_id" => $opt_id))->first();
175  if (!$option) {
176  $option = new self();
177  }
178  $option->setFieldId($field_id);
179  $option->setOptId($opt_id);
180  $option->setSorting($sorting);
181  $option->setValue($value);
182  $option->store();
183  }
184 
185 
189  public static function flushOptions($field_id)
190  {
191  foreach (self::getAllForField($field_id) as $option) {
192  $option->delete();
193  }
194  }
195 
196 
202  public static function getAllForField($field_id)
203  {
204  return self::where(array("field_id" => $field_id))->orderBy('sorting')->get();
205  }
206 
207  public static function getValues($field_id, $opt_ids)
208  {
209  $operators = array('field_id' => '=');
210  if (is_array($opt_ids)) {
211  if (empty($opt_ids)) {
212  return array();
213  }
214  $operators['opt_id'] = 'IN';
215  } else {
216  $operators['opt_id'] = '=';
217  }
218  $return = array();
219  foreach (self::where(array("field_id" => $field_id, "opt_id" => $opt_ids), $operators)->orderBy('sorting')->get() as $opt) {
220  $return[] = $opt->getValue();
221  }
222  return $return;
223  }
224 
225 
229  public function cloneOption(ilDclSelectionOption $original_option)
230  {
231  $this->setValue($original_option->getValue());
232  $this->setSorting($original_option->getSorting());
233  $this->setOptId($original_option->getOptId());
234  }
235 }
cloneOption(ilDclSelectionOption $original_option)
static getValues($field_id, $opt_ids)
Class ActiveRecord.
Create styles array
The data for the language used.
Class ilDclSelectionOption.
static orderBy($orderBy, $orderDirection='ASC')