ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAssQuestionSkillAssignmentRegistry.php
Go to the documentation of this file.
1<?php
2
23{
24 public const DEFAULT_CHUNK_SIZE = 1000;
25
29 protected $settings;
30
35
40 public function __construct(\ilSetting $setting)
41 {
42 $this->settings = $setting;
43 }
44
48 public function getChunkSize(): int
49 {
50 return $this->chunkSize;
51 }
52
57 public function setChunkSize($chunkSize): void
58 {
59 if (!is_numeric($chunkSize) || $chunkSize <= 0) {
60 throw new \InvalidArgumentException(sprintf("The passed chunk size is not a valid/supported integer: %s", var_export($chunkSize, true)));
61 }
62
63 $this->chunkSize = $chunkSize;
64 }
65
70 protected function getNumberOfChunksByKey($key): int
71 {
72 return (int) $this->settings->get($key . '_num', '0');
73 }
74
80 public function getStringifiedImports($key, $default = null)
81 {
82 $value = '';
83
84 for ($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++) {
85 $value .= $this->settings->get($key . '_' . $i);
86 }
87
88 return \ilStr::strLen($value) > 0 ? $value : $default;
89 }
90
95 public function setStringifiedImports($key, $value): void
96 {
97 $i = 0;
98
99 while (\ilStr::strLen($value) > 0) {
100 ++$i;
101
102 $valueToStore = \ilStr::subStr($value, 0, $this->getChunkSize());
103 $this->settings->set($key . '_' . $i, $valueToStore);
104
105 $truncatedValue = \ilStr::subStr($value, $this->getChunkSize(), \ilStr::strLen($value) - $this->getChunkSize());
106
107 $value = $truncatedValue;
108 }
109
110 if ($i > 0) {
111 $this->settings->set($key . '_num', $i);
112 }
113 }
114
118 public function deleteStringifiedImports($key): void
119 {
120 for ($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++) {
121 $this->settings->delete($key . '_' . $i);
122 }
123
124 $this->settings->delete($key . '_num');
125 }
126}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(\ilSetting $setting)
ilAssQuestionSkillAssignmentRegistry constructor.
ILIAS Setting Class.
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:21
static strLen(string $a_string)
Definition: class.ilStr.php:60