Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace App\Mapper;
use App\Entity\News;
use App\Entity\NewsCategory;
use App\Model\File;
use App\Model\NewsDetailElement;
use App\Model\NewsFilterVariants;
use App\Model\NewsList;
use App\Model\NewsListingElement;
use App\Model\NewsCategory as NewsCategoryModel;
use App\Model\Pagination;
use Ramsey\Collection\Collection;
class NewsMapper
{
public static function mapToNewsList(
$news,
$newsCategory,
$page,
$limit,
$count): NewsList
{
return new NewsList(
new Pagination($page, ceil($count / $limit), $limit),
new Collection(NewsListingElement::class, array_map(
function (News $newsOne) {
return self::mapToListingElement($newsOne);
}, $news)
),
new NewsFilterVariants(
new Collection(NewsCategoryModel::class, array_map(
function (NewsCategory $newsCategoryOne) {
return self::mapToNewsCategory($newsCategoryOne);
}, $newsCategory)
)
)
);
}
public static function mapToListingElement(News $newsOne): NewsListingElement
{
$file = new File(
1,
"asd",
"Краткое описание",
1024,
"png",
"/upload/asd.png"
);
return new NewsListingElement(
$newsOne->getId(),
$newsOne->getPreviewText(),
$newsOne->getDetailText(),
$file,
$newsOne->getCreateAt()->format('d.m.Y'),
"/{$newsOne->getCode()}/code/"
);
}
public static function mapToDetailElement(News $newsOne): NewsDetailElement
{
$file = new File(
1,
"asd",
"Краткое описание",
1024,
"png",
"/upload/asd.png"
);
return new NewsDetailElement(
$newsOne->getId(),
$newsOne->getPreviewText(),
$newsOne->getDetailText(),
$newsOne->getDetailText(),
$file,
$newsOne->getCreateAt()->format('d.m.Y'),
"Отель «Арктика»",
"otel-arktika",
"otel-arktika"
);
}
public static function mapToNewsCategory(NewsCategory $newsCategory): NewsCategoryModel
{
return new NewsCategoryModel(
$newsCategory->getId(),
$newsCategory->getName(),
$newsCategory->getCode(),
);
}
}