ILIAS  release_8 Revision v8.24
class.ilDclSelectionOption.php
Go to the documentation of this file.
1<?php
2
20{
21 public const DB_TABLE_NAME = "il_dcl_sel_opts";
22
23 public static function returnDbTableName(): string
24 {
26 }
27
38 protected ?int $id;
46 protected int $field_id;
54 protected int $opt_id;
62 protected int $sorting;
70 protected string $value;
71
72 public function getId(): int
73 {
74 return $this->id;
75 }
76
77 public function setId(int $id): void
78 {
79 $this->id = $id;
80 }
81
82 public function getFieldId(): int
83 {
84 return $this->field_id;
85 }
86
87 public function setFieldId(int $field_id): void
88 {
89 $this->field_id = $field_id;
90 }
91
92 public function getOptId(): int
93 {
94 return $this->opt_id;
95 }
96
97 public function setOptId(int $opt_id): void
98 {
99 $this->opt_id = $opt_id;
100 }
101
102 public function getValue(): string
103 {
104 return $this->value;
105 }
106
107 public function setValue(string $value): void
108 {
109 $this->value = $value;
110 }
111
112 public function getSorting(): int
113 {
114 return $this->sorting;
115 }
116
117 public function setSorting(int $sorting): void
118 {
119 $this->sorting = $sorting;
120 }
121
122 public static function storeOption(int $field_id, int $opt_id, int $sorting, string $value): void
123 {
125 $option = self::where(array("field_id" => $field_id, "opt_id" => $opt_id))->first();
126 if (!$option) {
127 $option = new self();
128 }
129 $option->setFieldId($field_id);
130 $option->setOptId($opt_id);
131 $option->setSorting($sorting);
132 $option->setValue($value);
133 $option->store();
134 }
135
136 public static function flushOptions(int $field_id): void
137 {
138 foreach (self::getAllForField($field_id) as $option) {
139 $option->delete();
140 }
141 }
142
146 public static function getAllForField(int $field_id): array
147 {
148 return self::where(array("field_id" => $field_id))->orderBy('sorting')->get();
149 }
150
155 public static function getValues(int $field_id, $opt_ids): array
156 {
157 $operators = array('field_id' => '=');
158 if (is_array($opt_ids)) {
159 if (empty($opt_ids)) {
160 return array();
161 }
162 $operators['opt_id'] = 'IN';
163 } else {
164 $operators['opt_id'] = '=';
165 }
166 $return = array();
167 foreach (self::where(
168 array("field_id" => $field_id, "opt_id" => $opt_ids),
169 $operators
170 )->orderBy('sorting')->get() as $opt) {
171 $return[] = $opt->getValue();
172 }
173
174 return $return;
175 }
176
180 public function cloneOption(ilDclSelectionOption $original_option): void
181 {
182 $this->setValue($original_option->getValue());
183 $this->setSorting($original_option->getSorting());
184 $this->setOptId($original_option->getOptId());
185 }
186}
Class ActiveRecord.
static orderBy($orderBy, string $orderDirection='ASC')
static where($where, $operator=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllForField(int $field_id)
cloneOption(ilDclSelectionOption $original_option)
static getValues(int $field_id, $opt_ids)
static flushOptions(int $field_id)