1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| function toString() {
$objectString='';
$items=$this->children;
$bufferLimit=(count($items)==0)?1:$this->getBufferLimit()+1;
do {
$bufferLimit-=1;
$objectString=$this->recurseMenu($items,$bufferLimit);
} while(strlen($objectString>160));
$this->index=$bufferLimit;
return $objectString;
}
function getBufferLimit() {
$len=count($this->children);
$margin=$len-$this->index;
if($margin<5)
return $this->index+$margin;
else
return $this->index+5; //Permet de définir le Nombre de Menu à afficher au niveau de l'index "/ussd/receiver.php" dont le Menu est "/ussd/MyTree.php".
}
function recurseMenu($items,$bufferLimit) {
$objectString="<strong>". $this->getTitle() . "</strong>" . PHP_EOL;
$lastMenu=false;
if(count($items)>0) {
foreach ($items as $i => $item) {
$num = $i + 1;
//get node by name
$userSessions = $_SESSION['userSessions'];
$currUserSession = $userSessions[$this->address];
$node = $currUserSession->getNode($item);
$title = $node->getTitle();
$objectString .= PHP_EOL . $num . '. ' . $title;
}
} else {
$objectString=$objectString.PHP_EOL . 'NO DATA AVAILABLE, TRY AGAIN LATER';
}
$lastMenu=$bufferLimit==count($items);
$objectString=$objectString . PHP_EOL . PHP_EOL . "<strong>0. Exit</strong>";
if($this->getParent() != '0'){
$objectString=$objectString . PHP_EOL . "<strong>#. Back</strong>";
}
if($lastMenu===false){
$rem=count($items)-$this->index;
$objectString=$objectString . PHP_EOL . "<strong>99. Next (".$rem.")</strong>";
}
return $objectString;
} |
Partager