69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Inf;
|
|
|
|
use Core\Config;
|
|
|
|
class Zodiac
|
|
{
|
|
private const ZODIAC = [
|
|
1 => 'Овен',
|
|
2 => 'Телец',
|
|
3 => 'Близнецы',
|
|
4 => 'Рак',
|
|
5 => 'Лев',
|
|
6 => 'Дева',
|
|
7 => 'Весы',
|
|
8 => 'Скорпион',
|
|
9 => 'Стрелец',
|
|
10 => 'Козерог',
|
|
11 => 'Водолей',
|
|
12 => 'Рыбы',
|
|
];
|
|
private int $day = 0;
|
|
private int $month = 0;
|
|
|
|
public function __construct(string $date)
|
|
{
|
|
[$d, $m, $y] = explode('.', $date);
|
|
if (!checkdate($d, $m, $y)) {
|
|
return;
|
|
}
|
|
$this->day = (int)$d;
|
|
$this->month = (int)$m;
|
|
}
|
|
|
|
public function getImageLink(): string
|
|
{
|
|
if (empty($this->getName())) {
|
|
return '#';
|
|
}
|
|
$id = array_flip(self::ZODIAC);
|
|
return Config::img() . '/i/zodiac/' . $id[$this->getName()] . '.gif';
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
if (empty($this->day) || empty($this->month)) {
|
|
return '';
|
|
}
|
|
$z = [
|
|
1 => self::ZODIAC[10],
|
|
self::ZODIAC[11],
|
|
self::ZODIAC[12],
|
|
self::ZODIAC[1],
|
|
self::ZODIAC[2],
|
|
self::ZODIAC[3],
|
|
self::ZODIAC[4],
|
|
self::ZODIAC[5],
|
|
self::ZODIAC[6],
|
|
self::ZODIAC[7],
|
|
self::ZODIAC[8],
|
|
self::ZODIAC[9],
|
|
self::ZODIAC[10],
|
|
];
|
|
$lastDay = [1 => 19, 18, 20, 20, 21, 21, 22, 22, 21, 22, 21, 20, 19];
|
|
return $this->day > $lastDay[$this->month] ? $z[$this->month + 1] : $z[$this->month];
|
|
}
|
|
}
|