|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\System\Model\Image; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Contracts\System\Model\Image\ImageCollectionInterface; |
|
6
|
|
|
use Leonidas\Contracts\System\Model\Image\ImageInterface; |
|
7
|
|
|
use Leonidas\Contracts\System\Model\Image\ImageRepositoryInterface; |
|
8
|
|
|
use Leonidas\Contracts\System\Model\Post\PostInterface; |
|
9
|
|
|
use Leonidas\Library\System\Model\Abstracts\Attachment\AbstractAttachmentEntityRepository; |
|
10
|
|
|
|
|
11
|
|
|
class ImageRepository extends AbstractAttachmentEntityRepository implements ImageRepositoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
public function select(int $id): ?ImageInterface |
|
14
|
|
|
{ |
|
15
|
|
|
return $this->manager->select($id); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function whereIds(int ...$ids): ImageCollectionInterface |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->manager->whereIds(...$ids); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function whereAttachedToPost(PostInterface $post): ImageCollectionInterface |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->manager->whereAttachedToPost($post->getId()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function query(array $args): ImageCollectionInterface |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->manager->query($args); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function all(): ImageCollectionInterface |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->manager->all(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function insert(ImageInterface $image): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->manager->insert($this->extractData($image)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function update(ImageInterface $image): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->manager->update($image->getId(), $this->extractData($image)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function extractData(ImageInterface $image): array |
|
49
|
|
|
{ |
|
50
|
|
|
$dateFormat = $image::DATE_FORMAT; |
|
51
|
|
|
|
|
52
|
|
|
$image->applyFilter('db'); |
|
53
|
|
|
|
|
54
|
|
|
return [ |
|
55
|
|
|
'post_author' => $image->getAuthor()->getId(), |
|
56
|
|
|
'post_date' => $image->getDate()->format($dateFormat), |
|
57
|
|
|
'post_date_gmt' => $image->getDate()->format($dateFormat), |
|
58
|
|
|
'post_content' => $image->getDescription(), |
|
59
|
|
|
'post_title' => $image->getTitle(), |
|
60
|
|
|
'post_excerpt' => $image->getCaption(), |
|
61
|
|
|
'comment_status' => $image->getCommentStatus(), |
|
62
|
|
|
'ping_status' => $image->getPingStatus(), |
|
63
|
|
|
'pinged' => $image->getPinged(), |
|
64
|
|
|
'to_ping' => $image->getToBePinged(), |
|
65
|
|
|
'post_password' => $image->getPassword(), |
|
66
|
|
|
'post_name' => $image->getName(), |
|
67
|
|
|
'post_modified' => $image->getDate()->format($dateFormat), |
|
68
|
|
|
'post_modified_gmt' => $image->getDate()->format($dateFormat), |
|
69
|
|
|
'post_mime_type' => $image->getMimeType(), |
|
70
|
|
|
'menu_order' => $image->getMenuOrder(), |
|
71
|
|
|
'guid' => $image->getGuid()->getHref(), |
|
72
|
|
|
'tax_input' => $this->extractTaxInput($image), |
|
73
|
|
|
'meta_input' => $this->extractMetaInput($image), |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function extractMetaInput(ImageInterface $post): array |
|
78
|
|
|
{ |
|
79
|
|
|
return [ |
|
80
|
|
|
'_wp_attachment_image_alt' => $post->getAlt(), |
|
81
|
|
|
]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function extractTaxInput(ImageInterface $post): array |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
return []; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.