ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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.

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

34  {
35  global $DIC;
36  $this->refinery = $DIC['refinery'];
37  }
global $DIC
Definition: shib_login.php:22
+ 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.

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

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

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.
+ 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.

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

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.
+ 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.

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

111  : bool
112  {
113  return is_array($array) && array_key_exists($key, $array) && !empty($array[$key]);
114  }
+ 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.

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

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  }
inArray($array, $key)
Returns true if the given key is set in the array and the value is not empty.
+ 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.

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

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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
inArray($array, $key)
Returns true if the given key is set in the array and the value is not empty.
+ 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: