ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once 'Services/Utilities/classes/class.ilStr.php';
5 
10 {
11  const DEFAULT_CHUNK_SIZE = 1000;
12 
16  protected $settings;
17 
21  protected $chunkSize = self::DEFAULT_CHUNK_SIZE;
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  throw new \InvalidArgumentException(sprintf("The passed chunk size is not a valid/supported integer: %s", var_export($chunkSize, true)));
48  }
49 
50  $this->chunkSize = $chunkSize;
51  }
52 
57  protected function getNumberOfChunksByKey($key)
58  {
59  return (int) $this->settings->get($key . '_num', 0);
60  }
61 
67  public function getStringifiedImports($key, $default = null)
68  {
69  $value = '';
70 
71  for ($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++) {
72  $value .= $this->settings->get($key . '_' . $i);
73  }
74 
75  return \ilStr::strLen($value) > 0 ? $value : $default;
76  }
77 
82  public function setStringifiedImports($key, $value)
83  {
84  $i = 0;
85 
86  while (\ilStr::strLen($value) > 0) {
87  ++$i;
88 
89  $valueToStore = \ilStr::subStr($value, 0, $this->getChunkSize());
90  $this->settings->set($key . '_' . $i, $valueToStore);
91 
92  $truncatedValue = \ilStr::subStr($value, $this->getChunkSize(), \ilStr::strLen($value) - $this->getChunkSize());
93 
94  $value = $truncatedValue;
95  }
96 
97  if ($i > 0) {
98  $this->settings->set($key . '_num', $i);
99  }
100  }
101 
106  {
107  for ($i = 1, $numberOfChunks = $this->getNumberOfChunksByKey($key); $i <= $numberOfChunks; $i++) {
108  $this->settings->delete($key . '_' . $i);
109  }
110 
111  $this->settings->delete($key . '_num');
112  }
113 }
settings()
Definition: settings.php:2
static strLen($a_string)
Definition: class.ilStr.php:78
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
__construct(\ilSetting $setting)
ilAssQuestionSkillAssignmentRegistry constructor.
Class ilAssQuestionSkillAssignmentRegistry.
$default
Definition: build.php:20
$i
Definition: disco.tpl.php:19
$key
Definition: croninfo.php:18