diff --git a/src/Action/Functions.php b/src/Action/Functions.php index e2ee60a3bdb67c7c48ce9c09017318732b12ae8e..6c8ca262ed339b3ef680a24395873ffad7857dd4 100644 --- a/src/Action/Functions.php +++ b/src/Action/Functions.php @@ -17,6 +17,7 @@ class Functions * @param array $array * @return array */ + public function sortPrice(array $array): array { $prices = array_column($array, 'price'); @@ -70,13 +71,13 @@ class Functions } /** - * Выходной маÑÑив: - * Array ( - * [0] => Array([0] => laravel, [1] => php) - * [1] => Array([0] => codeigniter, [1] => php) - * [3] => Array([0] => c++, [1] => java)) - * ) - */ + * Выходной маÑÑив: + * Array ( + * [0] => Array([0] => laravel, [1] => php) + * [1] => Array([0] => codeigniter, [1] => php) + * [3] => Array([0] => c++, [1] => java)) + * ) + */ /** * Сгруппировать подразедлы в верхние разделы меню @@ -157,7 +158,6 @@ class Functions return (int)$dateInterval->format("%a") + 1; } - /** * Вернет вÑе пÑтницы 13 в году * @param int $year год, в котором необходимо произвеÑти раÑчет @@ -187,5 +187,4 @@ class Functions $dateInterval = date_diff($dateStart, $dateEnd); return (int)$dateInterval->format("%a") ; } -} - +} \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 836c0f0dc7c130ec043a35d373f8992a00566160..d1d2d6873f92f881d90643a9392f926181d2bc3a 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -2,20 +2,36 @@ namespace App\Controller; -use App\Action\Functions; -use App\Validation\DateValidation; +use DateInterval; +use DatePeriod; +use DateTime; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private Functions $functions; + private function countFriday13(int $year): iterable { + $stardDate = new DateTime("{$year}-01-01 Friday"); + $year += 1; + $endDate = new DateTime("{$year}-01-01"); + $interval = new DateInterval('P7D'); + foreach(new DatePeriod($stardDate, $interval, $endDate) as $day) { + yield new DateTimeImmutable($day->format("Y-m-d")); + } + } - public function __construct(Functions $functions) + + #[Route('/{year}', name: 'home')] + public function home(int $year): Response { - $this->functions = $functions; + $fridays = array(); + foreach($this->countFriday13($year) as $date) { + $fridays[] = $date->format("Y-m-d l"); + } + return $this->render('home.html.twig', ['fridays' => $fridays]); } #[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024 diff --git a/src/Validation/ArrayValidation.php b/src/Validation/ArrayValidation.php new file mode 100644 index 0000000000000000000000000000000000000000..5807a447814593f64ecf069980c81099b8be861d --- /dev/null +++ b/src/Validation/ArrayValidation.php @@ -0,0 +1,26 @@ +<?php + +namespace App\Validation; + +class ArrayValidation +{ + public static function validateFunc1(array $array): bool + { + $prices = array_column($array, 'price'); + $counts = array_column($array, 'count'); + return ctype_digit(implode('',$prices)) && ctype_digit(implode('', $counts)); + } + + public static function validateFunc2(array $array): bool + { + $ids = array_column($array, 'id'); + $ages = array_column($array, 'age'); + return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); + } + + public static function validateFunc4(array $array): bool + { + $depths = array_column($array, 'depth'); + return ctype_digit(implode('', $depths)); + } +} \ No newline at end of file