ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjTestSettingsScoring.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  protected int $count_system = 0;
28  protected int $score_cutting = 0;
29  protected int $pass_scoring = 0;
30 
31 
32  public function __construct(int $test_id)
33  {
34  parent::__construct($test_id);
35  }
36 
37  public function toForm(
41  array $environment = null
42  ): FormInput {
43  $trafo = $refinery->kindlyTo()->Int();
44  $fields = [
45  'count_system' => $f->radio($lng->txt('tst_text_count_system'), "")
46  ->withOption('0', $lng->txt('tst_count_partial_solutions'), $lng->txt('tst_count_partial_solutions_desc'))
47  ->withOption('1', $lng->txt('tst_count_correct_solutions'), $lng->txt('tst_count_correct_solutions_desc'))
48  ->withValue($this->getCountSystem())
50  'score_cutting' => $f->radio($lng->txt('tst_score_cutting'), "")
51  ->withOption('0', $lng->txt('tst_score_cut_question'), $lng->txt('tst_score_cut_question_desc'))
52  ->withOption('1', $lng->txt('tst_score_cut_test'), $lng->txt('tst_score_cut_test_desc'))
53  ->withValue($this->getScoreCutting())
55  'pass_scoring' => $f->radio($lng->txt('tst_pass_scoring'), "")
56  ->withOption('0', $lng->txt('tst_pass_last_pass'), $lng->txt('tst_pass_last_pass_desc'))
57  ->withOption('1', $lng->txt('tst_pass_best_pass'), $lng->txt('tst_pass_best_pass_desc'))
58  ->withValue($this->getPassScoring())
60  ];
61  return $f->section($fields, $lng->txt('test_scoring'))
63  $refinery->custom()->transformation(
64  function ($v) {
65  return (clone $this)
66  ->withCountSystem($v['count_system'])
67  ->withScoreCutting($v['score_cutting'])
68  ->withPassScoring($v['pass_scoring']);
69  }
70  )
71  );
72  }
73 
74  public function toStorage(): array
75  {
76  return [
77  'count_system' => ['text', $this->getCountSystem()],
78  'score_cutting' => ['text', $this->getScoreCutting()],
79  'pass_scoring' => ['text', $this->getPassScoring()]
80  ];
81  }
82 
83 
84  public function getCountSystem(): int
85  {
86  return $this->count_system;
87  }
88  public function withCountSystem(int $count_system): self
89  {
90  $clone = clone $this;
91  $clone->count_system = $count_system;
92  return $clone;
93  }
94 
95  public function getScoreCutting(): int
96  {
97  return $this->score_cutting;
98  }
99  public function withScoreCutting(int $score_cutting): self
100  {
101  $clone = clone $this;
102  $clone->score_cutting = $score_cutting;
103  return $clone;
104  }
105 
106  public function getPassScoring(): int
107  {
108  return $this->pass_scoring;
109  }
110  public function withPassScoring(int $pass_scoring): self
111  {
112  $clone = clone $this;
113  $clone->pass_scoring = $pass_scoring;
114  return $clone;
115  }
116 }
This is what a factory for input fields looks like.
Definition: Factory.php:28
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
toForm(\ilLanguage $lng, FieldFactory $f, Refinery $refinery, array $environment=null)
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
__construct(Container $dic, ilPlugin $plugin)
This describes inputs that can be used in forms.
Definition: FormInput.php:31
withScoreCutting(int $score_cutting)
Refinery Factory $refinery