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