ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStudyProgrammeAssessmentSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23
25{
26 public const STATUS_DRAFT = 10;
27 public const STATUS_ACTIVE = 20;
28 public const STATUS_OUTDATED = 30;
29
30 public static array $STATUS = [
34 ];
35
36 protected int $points;
37 protected int $status;
38
39 public function __construct(int $points, int $status)
40 {
41 if (0 > $points) {
42 throw new InvalidArgumentException('Numbers less than 0 are not allowed');
43 }
44
45 if (!in_array($status, self::$STATUS)) {
46 throw new InvalidArgumentException("No valid status: '$status'");
47 }
48
49 $this->points = $points;
50 $this->status = $status;
51 }
52
53 public function getPoints(): int
54 {
55 return $this->points;
56 }
57
59 {
60 if (0 > $points) {
61 throw new InvalidArgumentException('Numbers less than 0 are not allowed');
62 }
63
64 $clone = clone $this;
65 $clone->points = $points;
66 return $clone;
67 }
68
69 public function getStatus(): int
70 {
71 return $this->status;
72 }
73
75 {
76 if (!in_array($status, self::$STATUS)) {
77 throw new InvalidArgumentException("No valid status: '$status'");
78 }
79
80 $clone = clone $this;
81 $clone->status = $status;
82 return $clone;
83 }
84
85 public function toFormInput(
86 Field\Factory $input,
90 $num = $input
91 ->numeric($lng->txt('prg_points'), $lng->txt('prg_points_byline'))
92 ->withAdditionalTransformation($refinery->int()->isGreaterThanOrEqual(0))
93 ->withAdditionalTransformation($refinery->int()->isLessThanOrEqual(2147483647))
94 ->withRequired(true)
95 ->withValue($this->getPoints())
96 ;
97 $select = $input
98 ->select(
99 $lng->txt('prg_status'),
100 $this->getStatusOptions($lng),
101 $lng->txt('prg_status_byline')
102 )
103 ->withValue($this->getStatus())
104 ->withRequired(true)
105 ;
106
107 return $input->section(
108 [
109 'points' => $num,
110 'status' => $select
111 ],
112 $lng->txt('prg_assessment')
113 )
114 ->withAdditionalTransformation($refinery->custom()->transformation(function ($vals) {
116 (int) $vals['points'],
117 (int) $vals['status']
118 );
119 }));
120 }
121
122 protected function getStatusOptions(ilLanguage $lng): array
123 {
124 return [
125 ilStudyProgrammeSettings::STATUS_DRAFT => $lng->txt("prg_status_draft"),
126 ilStudyProgrammeSettings::STATUS_ACTIVE => $lng->txt("prg_status_active"),
127 ilStudyProgrammeSettings::STATUS_OUTDATED => $lng->txt("prg_status_outdated")
128 ];
129 }
130}
Builds data types.
Definition: Factory.php:36
Definition: UI.php:24
return true
language handling
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery)
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31