refactor
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Inf;
|
||||
|
||||
use Core\Db;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class LastNames
|
||||
{
|
||||
private array $lastnames = [];
|
||||
|
||||
/** История имён
|
||||
* @param int $userid
|
||||
*/
|
||||
public function __construct(int $userid)
|
||||
{
|
||||
$names = Db::getRows('select * from lastnames where uid = ? order by time desc', [$userid]);
|
||||
$dt = new DateTimeImmutable();
|
||||
|
||||
foreach ($names as $name) {
|
||||
$dt->setTimestamp($name['time']);
|
||||
$this->lastnames[] = "«{$name['login']}» до " . $dt->format('d.m.Y H:i');
|
||||
}
|
||||
}
|
||||
|
||||
public function print(): void
|
||||
{
|
||||
echo $this->get();
|
||||
}
|
||||
|
||||
private function get(): string
|
||||
{
|
||||
if (empty($this->lastnames)) {
|
||||
return '';
|
||||
}
|
||||
return 'История имен:<br>' . implode('<br>', $this->lastnames);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user