ILIAS  release_8 Revision v8.24
class.ilCtrlStructureCidGenerator.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6
13{
17 private int $index;
18
24 public function __construct(int $starting_index = 0)
25 {
26 $this->index = $starting_index;
27 }
28
35 public function getIndexByCid(string $cid): int
36 {
37 if (strpos($cid, '-') === 0) {
38 $inverted_cid = str_replace('-', '', $cid);
39 $index = (int) base_convert($inverted_cid, 36, 10);
40
41 return $this->invertIndex($index);
42 }
43
44 return (int) base_convert($cid, 36, 10);
45 }
46
53 public function getCidByIndex(int $index): string
54 {
55 if (0 > $index) {
56 return '-' . base_convert((string) $this->invertIndex($index), 10, 36);
57 }
58
59 return base_convert((string) $index, 10, 36);
60 }
61
67 public function getCid(): string
68 {
69 return $this->getCidByIndex($this->index++);
70 }
71
78 private function invertIndex(int $index): int
79 {
80 return (-1 * $index);
81 }
82}
Class ilCtrlStructureCidGenerator.
getCidByIndex(int $index)
Returns the cid for a given index.
invertIndex(int $index)
Helper function that inverts an integer value.
__construct(int $starting_index=0)
ilCtrlStructureCidGenerator Constructor
getIndexByCid(string $cid)
Returns the index of a given cid.
getCid()
Returns the next available cid.