PluginProbe
Assistant – Every Day Productivity Apps / 0.3.1
Assistant – Every Day Productivity Apps v0.3.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / Data / Transformers / AttachmentTransformer.php

AttachmentTransformer.php in Assistant – Every Day Productivity Apps 0.3.1, at backend/src/Data/Transformers/AttachmentTransformer.php

63 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FL\Assistant\Data\Transformers;
5
6 use FL\Assistant\Data\Repository\NotationsRepository;
7
8
9 class AttachmentTransformer {
10
11 protected $notations;
12
13 public function __construct(
14 NotationsRepository $notations
15 ) {
16 $this->notations = $notations;
17 }
18
19 public function __invoke( \WP_Post $attachment ) {
20 $size = wp_get_attachment_image_src( $attachment->ID, 'medium' );
21 $meta = wp_prepare_attachment_for_js( $attachment->ID );
22 $thumb_src = wp_get_attachment_image_src( $attachment->ID, 'thumbnail' );
23 $thumb = $thumb_src ? $thumb_src[0] : null;
24
25 $response = [
26 'alt' => $meta['alt'],
27 'author' => get_the_author_meta( 'display_name', $attachment->post_author ),
28 'commentsAllowed' => 'open' === $attachment->comment_status ? true : false,
29 'date' => get_the_date( '', $attachment ),
30 'description' => $meta['description'],
31 'editUrl' => get_edit_post_link( $attachment->ID, '' ),
32 'filesize' => $meta['filesizeHumanReadable'],
33 'filename' => $meta['filename'],
34 'id' => $attachment->ID,
35 'labels' => [],
36 'mime' => $meta['mime'],
37 'permalink' => get_permalink( $attachment ),
38 'sizes' => isset( $meta['sizes'] ) ? $meta['sizes'] : [],
39 'slug' => $attachment->post_name,
40 'subtype' => $meta['subtype'],
41 'thumbnail' => $thumb,
42 'title' => $meta['title'],
43 'type' => $meta['type'],
44 'url' => $meta['url'],
45 'urls' => [
46 'medium' => $size ? $size[0] : null,
47 ],
48 'height' => $meta['height'],
49 'width' => $meta['width'],
50 'orientation' => isset( $meta['orientation'] ) ? $meta['orientation'] : null,
51 ];
52
53 // Labels
54 $labels = $this->notations->get_labels( 'post', $attachment->ID );
55 foreach ( $labels as $label ) {
56 $response['labels'][] = $label['label_id'];
57 }
58
59 return $response;
60 }
61
62 }
63