Skip to content
Snippets Groups Projects
Commit b6294936 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

Merge branch 'PTPS_Controller_6' into PTPS_Controller_7

parents 512b4a2c ecb2ff0f
No related branches found
No related tags found
1 merge request!7Ptps controller 7
...@@ -17,6 +17,7 @@ class Functions ...@@ -17,6 +17,7 @@ class Functions
* @param array $array * @param array $array
* @return array * @return array
*/ */
public function sortPrice(array $array): array public function sortPrice(array $array): array
{ {
$prices = array_column($array, 'price'); $prices = array_column($array, 'price');
...@@ -70,13 +71,13 @@ class Functions ...@@ -70,13 +71,13 @@ class Functions
} }
/** /**
* Выходной массив: * Выходной массив:
* Array ( * Array (
* [0] => Array([0] => laravel, [1] => php) * [0] => Array([0] => laravel, [1] => php)
* [1] => Array([0] => codeigniter, [1] => php) * [1] => Array([0] => codeigniter, [1] => php)
* [3] => Array([0] => c++, [1] => java)) * [3] => Array([0] => c++, [1] => java))
* ) * )
*/ */
/** /**
* Сгруппировать подразедлы в верхние разделы меню * Сгруппировать подразедлы в верхние разделы меню
...@@ -157,7 +158,6 @@ class Functions ...@@ -157,7 +158,6 @@ class Functions
return (int)$dateInterval->format("%a") + 1; return (int)$dateInterval->format("%a") + 1;
} }
/** /**
* Вернет все пятницы 13 в году * Вернет все пятницы 13 в году
* @param int $year год, в котором необходимо произвести расчет * @param int $year год, в котором необходимо произвести расчет
...@@ -187,5 +187,4 @@ class Functions ...@@ -187,5 +187,4 @@ class Functions
$dateInterval = date_diff($dateStart, $dateEnd); $dateInterval = date_diff($dateStart, $dateEnd);
return (int)$dateInterval->format("%a") ; return (int)$dateInterval->format("%a") ;
} }
} }
\ No newline at end of file
...@@ -2,20 +2,36 @@ ...@@ -2,20 +2,36 @@
namespace App\Controller; namespace App\Controller;
use App\Action\Functions; use DateInterval;
use App\Validation\DateValidation; use DatePeriod;
use DateTime;
use DateTimeImmutable; use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController 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 #[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
......
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment