|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\MediaLibraryModule\Controllers\Traits\Async; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Covers |
|
7
|
|
|
* @package ByTIC\MediaLibraryModule\Controllers\Traits\Async |
|
8
|
|
|
*/ |
|
9
|
|
|
trait Covers |
|
10
|
|
|
{ |
|
11
|
|
|
public function uploadCover() |
|
12
|
|
|
{ |
|
13
|
|
|
$item = $this->getModelFromRequest(); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
$cover = $item->uploadCover(); |
|
16
|
|
|
|
|
17
|
|
|
if (is_object($cover)) { |
|
18
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
19
|
|
|
$response['url'] = $cover->url; |
|
20
|
|
|
$response['path'] = $cover->name; |
|
21
|
|
|
$response['width'] = $cover->cropWidth; |
|
22
|
|
|
$response['height'] = $cover->cropHeight; |
|
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 cropCover() |
|
36
|
|
|
{ |
|
37
|
|
|
$item = $this->checkItem($_POST); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$cover = $item->cropCovers($_POST); |
|
40
|
|
|
|
|
41
|
|
|
if ($cover) { |
|
42
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
43
|
|
|
$response['url'] = $cover->url; |
|
44
|
|
|
$response['name'] = $cover->name; |
|
45
|
|
|
} |
|
46
|
|
|
$this->setResponseValues($response); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setDefaultCover() |
|
50
|
|
|
{ |
|
51
|
|
|
$item = $this->getModelFromRequest(); |
|
52
|
|
|
|
|
53
|
|
|
if ($item->setDefaultCover($_POST)) { |
|
54
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
$this->setResponseValues($response); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function removeCover() |
|
60
|
|
|
{ |
|
61
|
|
|
$item = $this->getModelFromRequest(); |
|
62
|
|
|
|
|
63
|
|
|
if ($item->removeCover($_POST)) { |
|
64
|
|
|
$response['type'] = 'success'; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
$this->setResponseValues($response); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|