File.php 3.12 KB
Newer Older
keven's avatar
keven committed
1
2
3
4
5
<?php

namespace Libcast\Client\Entity;

use Libcast\Client\Model\FileInterface;
Keven's avatar
Keven committed
6
7
use Libcast\Client\Model\ResourceInterface;
use Libcast\Client\Model\StreamInterface;
keven's avatar
keven committed
8
9
10

use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\XmlRoot;
Keven's avatar
Keven committed
11
use JMS\Serializer\Annotation\SerializedName;
keven's avatar
keven committed
12
13

/**
14
 *
keven's avatar
keven committed
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
 * @XmlRoot("file")
 */
class File extends Entity implements FileInterface
{
    /**
     *
     * @Type("string")
     * @var string
     */
    protected $name;

    /**
     *
     * @Type("integer")
     * @var int
     */
    protected $size;

    /**
     *
     * @Type("string")
     * @var string
     */
    protected $embed;

    /**
     *
     * @Type("string")
     * @var string
     */
    protected $encodingStatus;

    /**
     *
     * @Type("string")
     * @var string
     */
    protected $thumbnail;

54
55
56
57
58
59
60
    /**
     *
     * @Type("double")
     * @var float
     */
    protected $duration;

Keven's avatar
Keven committed
61
62
63
64
65
66
67
68
    /**
     *
     * @Type("Libcast\Client\Entity\KeyValuePairs")
     * @SerializedName("metadata")
     * @var array
     */
    protected $metadata = [];

keven's avatar
keven committed
69
    /**
Keven's avatar
Keven committed
70
71
72
73
74
75
76
77
78
     * URL of the thumbnail
     *
     * You can change the size of pointed thumbnail py providing width and height parameters
     *
     * @param int $width The width of the thumbnail
     * @param int $height The height of the thumbnail
     *
     * @return string
     */
79
    public function getThumbnail($height = null, $width = null)
Keven's avatar
Keven committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    {
        if ($height)
        {
            $this->thumbnail = substr($this->thumbnail, 0, strrpos($this->thumbnail, "/")).'/height/'.$height.substr($this->thumbnail, strrpos($this->thumbnail, "/"));
        }
        if ($width)
        {
            $this->thumbnail = substr($this->thumbnail, 0, strrpos($this->thumbnail, "/")).'/width/'.$width.substr($this->thumbnail, strrpos($this->thumbnail, "/"));
        }

        return $this->thumbnail;
    }
    /**
     *
     * @param \Libcast\Client\Model\StreamInterface $stream
     * @param array $properties Array of Resource properties
     *
     * @return \Libcast\Client\Model\ResourceInterface
     */
    public function publishTo($stream, $properties = [])
    {
        $resource = new Resource($this);
        foreach ($properties as $property => $value) {
            $resource->$property = $value;
        }

        return $this->client->createResource($resource, $stream);
    }

    // Deprecated API

    /**
     *
     * @deprecated since 2.1.16
     * @see File->name
115
     *
keven's avatar
keven committed
116
117
118
119
120
121
122
123
124
125
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Size in bytes
     *
Keven's avatar
Keven committed
126
127
128
     * @deprecated since 2.1.16
     * @see File->size
     *
keven's avatar
keven committed
129
130
131
132
133
134
135
136
     * @return int
     */
    public function getSize()
    {
        return $this->size;
    }

    /**
Keven's avatar
Keven committed
137
138
139
     *
     * @deprecated since 2.1.16
     * @see File->encodingStatus
140
     *
keven's avatar
keven committed
141
142
143
144
145
146
147
148
149
     * @return ???
     */
    public function getEncodingStatus()
    {
        return $this->encodingStatus;
    }

    /**
     * Code of the embed (URL encoded)
150
     *
Keven's avatar
Keven committed
151
152
153
     * @deprecated since 2.1.16
     * @see File->embed
     *
keven's avatar
keven committed
154
155
156
157
158
159
     * @return string
     */
    public function getEmbed()
    {
        return $this->embed;
    }
Keven's avatar
Keven committed
160
}