ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\TestQuestionPool\ilTestLegacyFormsHelper Class Reference
+ Collaboration diagram for ILIAS\TestQuestionPool\ilTestLegacyFormsHelper:

Public Member Functions

 __construct ()
 
 checkPointsInput ($data, bool $required, string $key='points')
 Checks if the provides points of an input are valid. More...
 
 checkPointsInputEnoughPositive ($data, bool $required, string $key='points')
 Extends the checkPointsInput function by checking if at least one point is greater than 0.0. More...
 
 transformArray ($data, string $key, Transformation $transformation)
 
 transformPoints ($data, string $key='points')
 
 inArray ($array, $key)
 Returns true if the given key is set in the array and the value is not empty. More...
 

Protected Attributes

Refinery $refinery
 

Detailed Description

Deprecated:
This class is no longer needed when using the ks input components.

Definition at line 28 of file ilTestLegacyFormsHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::__construct ( )

Definition at line 32 of file ilTestLegacyFormsHelper.php.

34 {
35 global $DIC;
36 $this->refinery = $DIC['refinery'];
37 }
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkPointsInput()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::checkPointsInput (   $data,
bool  $required,
string  $key = 'points' 
)

Checks if the provides points of an input are valid.

The function returns the language key of the error message if either the input is not an array or one of the points are not numeric. If the input is valid, the function returns the points as an array of floats.

Returns
string|float[]

Definition at line 46 of file ilTestLegacyFormsHelper.php.

46 : string|array
47 {
48 if (!is_array($data) || !$this->inArray($data, $key)) {
49 return $required ? 'msg_input_is_required' : [];
50 }
51
52 try {
53 $points = $this->refinery->to()->listOf($this->refinery->kindlyTo()->float())->transform($data[$key]);
54 } catch (ConstraintViolationException $e) {
55 return 'form_msg_numeric_value_required';
56 }
57
58 if (count($points) === 0) {
59 return $required ? 'msg_input_is_required' : [];
60 }
61
62 return $points;
63 }
inArray($array, $key)
Returns true if the given key is set in the array and the value is not empty.

References $data, Vendor\Package\$e, ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\inArray(), and ILIAS\Repository\refinery().

Referenced by ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\checkPointsInputEnoughPositive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkPointsInputEnoughPositive()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::checkPointsInputEnoughPositive (   $data,
bool  $required,
string  $key = 'points' 
)

Extends the checkPointsInput function by checking if at least one point is greater than 0.0.

If not, the function returns the language key of the error message.

Returns
string|float[]

Definition at line 71 of file ilTestLegacyFormsHelper.php.

71 : string|array
72 {
73 $points = $this->checkPointsInput($data, $required, $key);
74 if (!is_array($points)) {
75 return $points;
76 }
77
78 return max($points) <= 0 ? 'enter_enough_positive_points' : $points;
79 }
checkPointsInput($data, bool $required, string $key='points')
Checks if the provides points of an input are valid.

References $data, and ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\checkPointsInput().

+ Here is the call graph for this function:

◆ inArray()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::inArray (   $array,
  $key 
)

Returns true if the given key is set in the array and the value is not empty.

Definition at line 111 of file ilTestLegacyFormsHelper.php.

111 : bool
112 {
113 return is_array($array)
114 && array_key_exists($key, $array)
115 && $array[$key] !== null
116 && $array[$key] !== false
117 && $array[$key] !== ''
118 && $array[$key] !== []
119 && $array[$key] !== 0
120 && $array[$key] !== 0.0;
121 }

Referenced by ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\checkPointsInput(), ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\transformArray(), and ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\transformPoints().

+ Here is the caller graph for this function:

◆ transformArray()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::transformArray (   $data,
string  $key,
Transformation  $transformation 
)

Definition at line 81 of file ilTestLegacyFormsHelper.php.

81 : array
82 {
83 if (!$this->inArray($data, $key)) {
84 return [];
85 }
86
87 return $this->refinery->byTrying([
88 $this->refinery->kindlyTo()->listOf($transformation),
89 $this->refinery->always([])
90 ])->transform($data[$key]);
91 }

References $data, ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\inArray(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ transformPoints()

ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::transformPoints (   $data,
string  $key = 'points' 
)
Returns
array<float>

Definition at line 96 of file ilTestLegacyFormsHelper.php.

96 : array
97 {
98 if (!$this->inArray($data, $key)) {
99 return [];
100 }
101
102 return array_map(
103 fn($v): ?float => $this->refinery->byTrying([$this->refinery->kindlyTo()->float(), $this->refinery->always(null)])->transform($v),
104 $data[$key]
105 );
106 }

References $data, ILIAS\TestQuestionPool\ilTestLegacyFormsHelper\inArray(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Field Documentation

◆ $refinery

Refinery ILIAS\TestQuestionPool\ilTestLegacyFormsHelper::$refinery
protected

Definition at line 30 of file ilTestLegacyFormsHelper.php.


The documentation for this class was generated from the following file: