1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nextcloud - OCR |
4
|
|
|
* |
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
|
|
|
|
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
|
|
|
* 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
|
|
|
public function __construct(IDBConnection $db) { |
31
|
|
|
parent::__construct($db, 'ocr_jobs', 'OCA\Ocr\Db\OcrJob'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Find a specific job entity |
36
|
|
|
* |
37
|
|
|
* @param $id |
38
|
|
|
* @return OcrJob |
39
|
|
|
*/ |
40
|
|
|
public function find($id) { |
41
|
|
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE id = ?'; |
42
|
|
|
return $this->findEntity($sql, [$id]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Finds all user specific jobs entities |
47
|
|
|
* |
48
|
|
|
* @param $userId |
49
|
|
|
* @return OcrJob[] |
50
|
|
|
*/ |
51
|
|
|
public function findAll($userId) { |
52
|
|
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ?'; |
53
|
|
|
return $this->findEntities($sql, [$userId]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Finds all jobs PROCESSED entities for a given userid |
58
|
|
|
* @param $userId |
59
|
|
|
* @return OcrJob[] |
60
|
|
|
*/ |
61
|
|
|
public function findAllProcessed($userId) { |
62
|
|
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
63
|
|
|
return $this->findEntities($sql, [$userId, OcrConstants::STATUS_PROCESSED]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Finds all jobs PENDING entities for a given userid. |
68
|
|
|
* @param $userId |
69
|
|
|
* @return OcrJob[] |
70
|
|
|
*/ |
71
|
|
|
public function findAllPending($userId) { |
72
|
|
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ?'; |
73
|
|
|
return $this->findEntities($sql, [$userId, OcrConstants::STATUS_PENDING]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Finds all jobs FAILED entities for a given userid, which were not displayed yet. |
78
|
|
|
* @param $userId |
79
|
|
|
* @return OcrJob[] |
80
|
|
|
*/ |
81
|
|
|
public function findAllFailed($userId) { |
82
|
|
|
$sql = 'SELECT * FROM *PREFIX*ocr_jobs WHERE user_id = ? AND status = ? AND error_displayed = ?'; |
83
|
|
|
return $this->findEntities($sql, [$userId, OcrConstants::STATUS_FAILED, false]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |