ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilStudyProgrammeAssessmentSettings.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5declare(strict_types=1);
6
7use \ILIAS\UI\Component\Input\Field;
8use \ILIAS\Refinery\Factory as Refinery;
9
11{
12 const STATUS_DRAFT = 10;
13 const STATUS_ACTIVE = 20;
14 const STATUS_OUTDATED = 30;
15
16 public static $STATUS = array(
17 self::STATUS_DRAFT,
18 self::STATUS_ACTIVE,
19 self::STATUS_OUTDATED
20 );
21
25 protected $points;
26
30 protected $status;
31
32 public function __construct(int $points, int $status)
33 {
34 if (0 > $points) {
35 throw new InvalidArgumentException(
36 'Numbers less than 0 are not allowed'
37 );
38 }
39
40 if (!in_array($status, self::$STATUS)) {
41 throw new InvalidArgumentException(
42 'No valid status: ' . '\'$status\''
43 );
44 }
45
46 $this->points = $points;
47 $this->status = $status;
48 }
49
50 public function getPoints() : int
51 {
52 return $this->points;
53 }
54
56 {
57 if (0 > $points) {
58 throw new InvalidArgumentException(
59 'Numbers less than 0 are not allowed'
60 );
61 }
62
63 $clone = clone $this;
64 $clone->points = $points;
65 return $clone;
66 }
67
68 public function getStatus() : int
69 {
70 return $this->status;
71 }
72
74 {
75 if (!in_array($status, self::$STATUS)) {
76 throw new InvalidArgumentException(
77 'No valid status: ' . '\'$status\''
78 );
79 }
80
81 $clone = clone $this;
82 $clone->status = $status;
83 return $clone;
84 }
85
86 public function toFormInput(
87 Field\Factory $input,
89 Refinery $refinery
90 ) : Field\Input {
91 $num = $input
92 ->numeric($lng->txt('prg_points'), $lng->txt('prg_points_byline'))
93 ->withValue($this->getPoints())
94 ->withAdditionalTransformation($refinery->int()->isGreaterThan(-1))
95 ;
96 $select = $input
97 ->select(
98 $lng->txt('prg_status'),
99 $this->getStatusOptions($lng),
100 $lng->txt('prg_status_byline')
101 )
102 ->withValue($this->getStatus())
103 ->withRequired(true)
104 ;
105
106 return $input->section(
107 [
108 'points' => $num,
109 'status' => $select
110 ],
111 $lng->txt('prg_assessment')
112 )
113 ->withAdditionalTransformation($refinery->custom()->transformation(function ($vals) {
115 (int) $vals['points'],
116 (int) $vals['status']
117 );
118 }));
119 }
120
121 protected function getStatusOptions(ilLanguage $lng) : array
122 {
123 return [
124 ilStudyProgrammeSettings::STATUS_DRAFT => $lng->txt("prg_status_draft"),
125 ilStudyProgrammeSettings::STATUS_ACTIVE => $lng->txt("prg_status_active"),
126 ilStudyProgrammeSettings::STATUS_OUTDATED => $lng->txt("prg_status_outdated")
127 ];
128 }
129}
An exception for terminatinating execution or to throw for unit testing.
language handling
toFormInput(Field\Factory $input, \ilLanguage $lng, Refinery $refinery)
This is what a factory for input fields looks like.
Definition: Factory.php:11
This describes commonalities between all inputs.
Definition: Input.php:32
withValue($value)
Get an input like this with another value displayed on the client side.
$lng