ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCtrlStructureCidGenerator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
31 private int $index;
32
38 public function __construct(int $starting_index = 0)
39 {
40 $this->index = $starting_index;
41 }
42
49 public function getIndexByCid(string $cid): int
50 {
51 if (strpos($cid, '-') === 0) {
52 $inverted_cid = str_replace('-', '', $cid);
53 $index = (int) base_convert($inverted_cid, 36, 10);
54
55 return $this->invertIndex($index);
56 }
57
58 return (int) base_convert($cid, 36, 10);
59 }
60
67 public function getCidByIndex(int $index): string
68 {
69 if (0 > $index) {
70 return '-' . base_convert((string) $this->invertIndex($index), 10, 36);
71 }
72
73 return base_convert((string) $index, 10, 36);
74 }
75
81 public function getCid(): string
82 {
83 return $this->getCidByIndex($this->index++);
84 }
85
92 private function invertIndex(int $index): int
93 {
94 return (-1 * $index);
95 }
96}
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.