Page MenuHomeCode

TryAutoSelect.php
No OneTemporary

TryAutoSelect.php

<?php
namespace Zed\Engines\Perso\Events;
use Zed\Models\Objects\Perso;
class TryAutoSelect extends BaseEvent {
/**
* @var Perso[]
*/
private array $persos;
public function isTriggered (): bool {
return !$this->selector->hasPerso;
}
public function handle () : void {
$this->persos = Perso::get_persos(
$this->getDatabase(),
$this->selector->user
);
$count = count($this->persos);
if ($count === 0) {
$this->askUserToCreatePerso();
} elseif ($count === 1) {
$this->autoselect();
} else {
$this->askUserToSelectPerso();
}
}
private function askUserToCreatePerso () : never {
$this->selector->smarty
->display("perso_create.tpl");
exit;
}
private function autoselect () : void {
$this->selector->selectAndSetPerso($this->persos[0]);
}
private function askUserToSelectPerso () : never {
$this->selector->smarty
->assign("PERSOS", $this->persos)
->display("perso_select.tpl");
$_SESSION['UserWithSeveralPersos'] = true;
exit;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Nov 16, 14:27 (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21428
Default Alt Text
TryAutoSelect.php (1 KB)

Event Timeline