1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nextcloud - OCR |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. |
7
|
|
|
* See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Janis Koehr <[email protected]> |
10
|
|
|
* @copyright Janis Koehr 2017 |
11
|
|
|
*/ |
12
|
|
|
namespace OCA\Ocr\Db; |
13
|
|
|
|
14
|
|
|
use OCP\AppFramework\Db\Mapper; |
15
|
|
|
use OCP\IDBConnection; |
16
|
|
|
use OCA\Ocr\Constants\OcrConstants; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class OcrJobMapper |
21
|
|
|
* |
22
|
|
|
* @package OCA\Ocr\Db |
23
|
|
|
*/ |
24
|
|
|
class OcrJobMapper extends Mapper { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* OcrJobMapper constructor. |
28
|
|
|
* |
29
|
|
|
* @param IDBConnection $db |
30
|
|
|
*/ |
31
|
15 |
|
public function __construct(IDBConnection $db) { |
32
|
15 |
|
parent::__construct($db, 'ocr_jobs', 'OCA\Ocr\Db\OcrJob'); |
33
|
15 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Find a specific job entity |
37
|
|
|
* |
38
|
|
|
* @param |
39
|
|
|
* $id |
40
|
|
|
* @return OcrJob |
41
|
|
|
*/ |
42
|
3 |
|
public function find($id) { |
43
|
3 |
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE id = ?'; |
44
|
3 |
|
return $this->findEntity($sql, [ |
45
|
3 |
|
$id |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Finds all user specific jobs entities |
51
|
|
|
* |
52
|
|
|
* @param |
53
|
|
|
* $userId |
54
|
|
|
* @return OcrJob[] |
55
|
|
|
*/ |
56
|
1 |
|
public function findAll($userId) { |
57
|
1 |
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ?'; |
58
|
1 |
|
return $this->findEntities($sql, [ |
59
|
1 |
|
$userId |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Finds all jobs PROCESSED entities for a given userid |
65
|
|
|
* |
66
|
|
|
* @param |
67
|
|
|
* $userId |
68
|
|
|
* @return OcrJob[] |
69
|
|
|
*/ |
70
|
1 |
|
public function findAllProcessed($userId) { |
71
|
1 |
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
72
|
1 |
|
return $this->findEntities($sql, |
73
|
|
|
[ |
74
|
1 |
|
$userId, |
75
|
1 |
|
OcrConstants::STATUS_PROCESSED |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Finds all jobs PENDING entities for a given userid. |
81
|
|
|
* |
82
|
|
|
* @param |
83
|
|
|
* $userId |
84
|
|
|
* @return OcrJob[] |
85
|
|
|
*/ |
86
|
1 |
|
public function findAllPending($userId) { |
87
|
1 |
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
88
|
1 |
|
return $this->findEntities($sql, |
89
|
|
|
[ |
90
|
1 |
|
$userId, |
91
|
1 |
|
OcrConstants::STATUS_PENDING |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Finds all jobs FAILED entities for a given userid, which were not displayed yet. |
97
|
|
|
* |
98
|
|
|
* @param |
99
|
|
|
* $userId |
100
|
|
|
* @return OcrJob[] |
101
|
|
|
*/ |
102
|
1 |
|
public function findAllFailed($userId) { |
103
|
1 |
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ? AND error_displayed = ?'; |
104
|
1 |
|
return $this->findEntities($sql, |
105
|
|
|
[ |
106
|
1 |
|
$userId, |
107
|
1 |
|
OcrConstants::STATUS_FAILED, |
108
|
|
|
false |
109
|
|
|
]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Deletes all jobs for a given userid. |
114
|
|
|
* (For example after user deletion) |
115
|
|
|
* |
116
|
|
|
* @param unknown $userId |
117
|
|
|
* @return OcrJob[] |
118
|
|
|
*/ |
119
|
1 |
|
public function deleteAllForUser($userId) { |
120
|
1 |
|
$sql = 'DELETE FROM *PREFIX*ocr_jobs WHERE user_id = ?'; |
121
|
1 |
|
return $this->findEntities($sql, [ |
122
|
1 |
|
$userId |
123
|
|
|
]); |
124
|
|
|
} |
125
|
|
|
} |