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