ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilStudyProgrammeAssessmentSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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 = [
31  self::STATUS_DRAFT,
32  self::STATUS_ACTIVE,
33  self::STATUS_OUTDATED
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 
58  public function withPoints(int $points): ilStudyProgrammeAssessmentSettings
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 
74  public function withStatus(int $status): ilStudyProgrammeAssessmentSettings
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,
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 }
Class Factory.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
$lng
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
This describes inputs that can be used in forms.
Definition: FormInput.php:31
toFormInput(Field\Factory $input, ilLanguage $lng, Refinery $refinery)
Refinery Factory $refinery