|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Model; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Task File Model. |
|
16
|
|
|
*/ |
|
17
|
|
|
class TaskFileModel extends FileModel |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Table name. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
const TABLE = 'task_has_files'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Events. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
const EVENT_CREATE = 'task.file.create'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get the table. |
|
35
|
|
|
* |
|
36
|
|
|
* @abstract |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getTable() |
|
41
|
|
|
{ |
|
42
|
|
|
return self::TABLE; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Define the foreign key. |
|
47
|
|
|
* |
|
48
|
|
|
* @abstract |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getForeignKey() |
|
53
|
|
|
{ |
|
54
|
|
|
return 'task_id'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Define the path prefix. |
|
59
|
|
|
* |
|
60
|
|
|
* @abstract |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getPathPrefix() |
|
65
|
|
|
{ |
|
66
|
|
|
return 'tasks'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get projectId from fileId. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $file_id |
|
73
|
|
|
* |
|
74
|
|
|
* @return int |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getProjectId($file_id) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->db |
|
|
|
|
|
|
79
|
|
|
->table(self::TABLE) |
|
80
|
|
|
->eq(self::TABLE.'.id', $file_id) |
|
81
|
|
|
->join(TaskModel::TABLE, 'id', 'task_id') |
|
82
|
|
|
->findOneColumn(TaskModel::TABLE.'.project_id') ?: 0; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Handle screenshot upload. |
|
87
|
|
|
* |
|
88
|
|
|
* @param int $task_id Task id |
|
89
|
|
|
* @param string $blob Base64 encoded image |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool|int |
|
92
|
|
|
*/ |
|
93
|
|
|
public function uploadScreenshot($task_id, $blob) |
|
94
|
|
|
{ |
|
95
|
|
|
$original_filename = l('Screenshot taken %s', $this->helper->dt->datetime(time())).'.png'; |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
return $this->uploadContent($task_id, $original_filename, $blob); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Fire file creation event. |
|
102
|
|
|
* |
|
103
|
|
|
* @param int $file_id |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function fireCreationEvent($file_id) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->queueManager->push($this->taskFileEventJob->withParams($file_id, self::EVENT_CREATE)); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.