Completed
Pull Request — master (#93)
by Janis
04:18
created

OcrJobMapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
}