|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\MediaLibraryModule\Controllers\Traits\Async; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Images |
|
7
|
|
|
* @package ByTIC\MediaLibraryModule\Controllers\Traits\Async |
|
8
|
|
|
*/ |
|
9
|
|
|
trait Images |
|
10
|
|
|
{ |
|
11
|
|
|
public function uploadImage() |
|
12
|
|
|
{ |
|
13
|
|
|
$item = $this->getModelFromRequest(); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
$image = $item->uploadImage(); |
|
16
|
|
|
|
|
17
|
|
|
if (is_object($image)) { |
|
18
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
19
|
|
|
$response['url'] = $image->url; |
|
20
|
|
|
$response['path'] = $image->name; |
|
21
|
|
|
$response['width'] = $item->getImageWidth("default"); |
|
22
|
|
|
$response['height'] = $item->getImageHeight("default"); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$response['message'] = $item->errors['upload']; |
|
26
|
|
|
$this->setResponseValues($response); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param $values |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract public function setResponseValues($values); |
|
34
|
|
|
|
|
35
|
|
|
public function cropImage() |
|
36
|
|
|
{ |
|
37
|
|
|
$item = $this->checkItem($_POST); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$image = $item->cropImages($_POST); |
|
40
|
|
|
|
|
41
|
|
|
if ($image) { |
|
42
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
43
|
|
|
$response['url'] = $image->url; |
|
44
|
|
|
$response['name'] = $image->name; |
|
45
|
|
|
} |
|
46
|
|
|
$this->setResponseValues($response); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setDefaultImage() |
|
50
|
|
|
{ |
|
51
|
|
|
$item = $this->getModelFromRequest(); |
|
52
|
|
|
|
|
53
|
|
|
if ($item->setDefaultImage($_POST)) { |
|
54
|
|
|
$item->update(); |
|
55
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function removeImage() |
|
60
|
|
|
{ |
|
61
|
|
|
$item = $this->getModelFromRequest(); |
|
62
|
|
|
|
|
63
|
|
|
if ($item->removeImage($_POST)) { |
|
64
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
$this->setResponseValues($response); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|