1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Common\Records\Media\Images; |
4
|
|
|
|
5
|
|
|
use Nip\Filesystem\Image; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Model |
9
|
|
|
* @package ByTIC\Common\Records\Media\Images |
10
|
|
|
*/ |
11
|
|
|
class Model extends Image |
12
|
|
|
{ |
13
|
|
|
use \ByTIC\Common\Records\Media\Traits\HasModels; |
14
|
|
|
use \ByTIC\Common\Records\Media\Traits\HydrateCollection; |
15
|
|
|
|
16
|
|
|
public $basePath; |
17
|
|
|
public $baseURL; |
18
|
|
|
public $cropWidth; |
19
|
|
|
public $cropHeight; |
20
|
|
|
|
21
|
|
|
protected $_type; |
22
|
|
|
protected $mediaCollection = 'images'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return Model |
26
|
|
|
*/ |
27
|
|
|
public function getSmall() |
28
|
|
|
{ |
29
|
|
|
return $this->getImageSize("small"); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $type |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
|
|
public function getImageSize($type) |
37
|
|
|
{ |
38
|
|
|
if ($type == $this->_type) { |
39
|
|
|
return $this; |
40
|
|
|
} else { |
41
|
|
|
$image = $this->_model->getNewImage($type); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$image->setName($this->name); |
44
|
|
|
|
45
|
|
|
return $image; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return Model |
51
|
|
|
*/ |
52
|
|
|
public function getMedium() |
53
|
|
|
{ |
54
|
|
|
return $this->getImageSize("medium"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return Model |
59
|
|
|
*/ |
60
|
|
|
public function getLarge() |
61
|
|
|
{ |
62
|
|
|
return $this->getImageSize("large"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return Model |
67
|
|
|
*/ |
68
|
|
|
public function getFull() |
69
|
|
|
{ |
70
|
|
|
return $this->getImageSize("full"); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $path |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function setResourceFromFile($path) |
78
|
|
|
{ |
79
|
|
|
parent::setResourceFromFile($path); |
80
|
|
|
$this->setName(pathinfo($path, PATHINFO_BASENAME)); |
81
|
|
|
|
82
|
|
|
return $this; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// /** |
|
|
|
|
86
|
|
|
// * @param string $name |
87
|
|
|
// */ |
88
|
|
|
// public function setName($name) |
89
|
|
|
// { |
90
|
|
|
// parent::setName($name); |
91
|
|
|
// $this->url = $this->getModel()->getImageURL($this->_type, $this->name); |
92
|
|
|
// $this->path = $this->getModel()->getImagePath($this->_type, $this->name); |
93
|
|
|
// } |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param Image $image |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function copyResource($image) |
100
|
|
|
{ |
101
|
|
|
parent::copyResource($image); |
102
|
|
|
$this->setName($image->name); |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
|
|
public function getDefaultWidth() |
111
|
|
|
{ |
112
|
|
|
$option = "images_" . $this->getModel()->getManager()->getTable() . "_" . $this->_type . "_width"; |
113
|
|
|
return Options::instance()->$option; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
public function getDefaultHeight() |
120
|
|
|
{ |
121
|
|
|
$option = "images_" . $this->getManager()->getTable() . "_" . $this->_type . "_height"; |
|
|
|
|
122
|
|
|
return Options::instance()->$option; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return mixed |
127
|
|
|
*/ |
128
|
|
|
public function getImageType() |
129
|
|
|
{ |
130
|
|
|
return $this->_type; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function save() |
137
|
|
|
{ |
138
|
|
|
$this->path = $this->path ? $this->path : $this->basePath . $this->name; |
139
|
|
|
parent::save(); |
140
|
|
|
|
141
|
|
|
return $this; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param bool $bubble |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
|
|
public function delete($bubble = false) |
149
|
|
|
{ |
150
|
|
|
if ($bubble) { |
151
|
|
|
return parent::delete(); |
|
|
|
|
152
|
|
|
} else { |
153
|
|
|
return $this->getModel()->deleteImage($this->name); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.