ILIAS  release_8 Revision v8.24
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,
88 Refinery $refinery
89 ): \ILIAS\UI\Component\Input\Container\Form\FormInput {
90 $num = $input
91 ->numeric($lng->txt('prg_points'), $lng->txt('prg_points_byline'))
92 ->withValue($this->getPoints())
93 ->withAdditionalTransformation($refinery->int()->isGreaterThanOrEqual(0))
94 ;
95 $select = $input
96 ->select(
97 $lng->txt('prg_status'),
98 $this->getStatusOptions($lng),
99 $lng->txt('prg_status_byline')
100 )
101 ->withValue($this->getStatus())
102 ->withRequired(true)
103 ;
104
105 return $input->section(
106 [
107 'points' => $num,
108 'status' => $select
109 ],
110 $lng->txt('prg_assessment')
111 )
112 ->withAdditionalTransformation($refinery->custom()->transformation(function ($vals) {
114 (int) $vals['points'],
115 (int) $vals['status']
116 );
117 }));
118 }
119
120 protected function getStatusOptions(ilLanguage $lng): array
121 {
122 return [
123 ilStudyProgrammeSettings::STATUS_DRAFT => $lng->txt("prg_status_draft"),
124 ilStudyProgrammeSettings::STATUS_ACTIVE => $lng->txt("prg_status_active"),
125 ilStudyProgrammeSettings::STATUS_OUTDATED => $lng->txt("prg_status_outdated")
126 ];
127 }
128}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
language handling
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery)
This describes inputs that can be used in forms.
Definition: FormInput.php:32
This is what a factory for input fields looks like.
Definition: Factory.php:29
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$lng