ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionSkillAssignmentRegistry.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Utilities/classes/class.ilStr.php';
5
10{
11 const DEFAULT_CHUNK_SIZE = 1000;
12
16 protected $settings;
17
22
27 public function __construct(\ilSetting $setting)
28 {
29 $this->settings = $setting;
30 }
31
35 public function getChunkSize()
36 {
37 return $this->chunkSize;
38 }
39
44 public function setChunkSize($chunkSize)
45 {
46 if(!is_numeric($chunkSize) || $chunkSize <= 0)
47 {
48 throw new \InvalidArgumentException(sprintf("The passed chunk size is not a valid/supported integer: %s", var_export($chunkSize, true)));
49 }
50
51 $this->chunkSize = $chunkSize;
52 }
53
58 protected function getNumberOfChunksByKey($key)
59 {
60 return (int)$this->settings->get($key . '_num', 0);
61 }
62
68 public function getStringifiedImports($key, $default = null)
69 {
70 $value = '';
71
72 for($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++)
73 {
74 $value .= $this->settings->get($key . '_' . $i);
75 }
76
77 return \ilStr::strLen($value) > 0 ? $value : $default;
78 }
79
84 public function setStringifiedImports($key, $value)
85 {
86 $i = 0;
87
88 while(\ilStr::strLen($value) > 0)
89 {
90 ++$i;
91
92 $valueToStore = \ilStr::subStr($value, 0, $this->getChunkSize());
93 $this->settings->set($key . '_' . $i, $valueToStore);
94
95 $truncatedValue = \ilStr::subStr($value, $this->getChunkSize(), \ilStr::strLen($value) - $this->getChunkSize());
96
97 $value = $truncatedValue;
98 }
99
100 if($i > 0)
101 {
102 $this->settings->set($key . '_num', $i);
103 }
104 }
105
109 public function deleteStringifiedImports($key)
110 {
111 for($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++)
112 {
113 $this->settings->delete($key . '_' . $i);
114 }
115
116 $this->settings->delete($key . '_num');
117 }
118}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
__construct(\ilSetting $setting)
ilAssQuestionSkillAssignmentRegistry constructor.
ILIAS Setting Class.
static strLen($a_string)
Definition: class.ilStr.php:91
static subStr($a_str, $a_start, $a_length=NULL)
Definition: class.ilStr.php:15
settings()
Definition: settings.php:2