ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
14  public static function returnDbTableName()
15  {
16  return self::DB_TABLE_NAME;
17  }
18 
19 
31  protected $id;
41  protected $field_id;
51  protected $opt_id;
61  protected $sorting;
70  protected $value;
71 
72 
76  public function getId()
77  {
78  return $this->id;
79  }
80 
81 
85  public function setId($id)
86  {
87  $this->id = $id;
88  }
89 
90 
94  public function getFieldId()
95  {
96  return $this->field_id;
97  }
98 
99 
103  public function setFieldId($field_id)
104  {
105  $this->field_id = $field_id;
106  }
107 
108 
112  public function getOptId()
113  {
114  return (int) $this->opt_id;
115  }
116 
117 
121  public function setOptId($opt_id)
122  {
123  $this->opt_id = $opt_id;
124  }
125 
126 
130  public function getValue()
131  {
132  return $this->value;
133  }
134 
135 
139  public function setValue($value)
140  {
141  $this->value = $value;
142  }
143 
144 
148  public function getSorting()
149  {
150  return $this->sorting;
151  }
152 
153 
157  public function setSorting($sorting)
158  {
159  $this->sorting = $sorting;
160  }
161 
162 
169  public static function storeOption($field_id, $opt_id, $sorting, $value)
170  {
172  $option = self::where(array("field_id" => $field_id, "opt_id" => $opt_id))->first();
173  if (!$option) {
174  $option = new self();
175  }
176  $option->setFieldId($field_id);
177  $option->setOptId($opt_id);
178  $option->setSorting($sorting);
179  $option->setValue($value);
180  $option->store();
181  }
182 
183 
187  public static function flushOptions($field_id)
188  {
189  foreach (self::getAllForField($field_id) as $option) {
190  $option->delete();
191  }
192  }
193 
194 
200  public static function getAllForField($field_id)
201  {
202  return self::where(array("field_id" => $field_id))->orderBy('sorting')->get();
203  }
204 
205 
206  public static function getValues($field_id, $opt_ids)
207  {
208  $operators = array('field_id' => '=');
209  if (is_array($opt_ids)) {
210  if (empty($opt_ids)) {
211  return array();
212  }
213  $operators['opt_id'] = 'IN';
214  } else {
215  $operators['opt_id'] = '=';
216  }
217  $return = array();
218  foreach (self::where(array("field_id" => $field_id, "opt_id" => $opt_ids), $operators)->orderBy('sorting')->get() as $opt) {
219  $return[] = $opt->getValue();
220  }
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.
Class ilDclSelectionOption.
static orderBy($orderBy, $orderDirection='ASC')