• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 3717593689

pending completion
3717593689

Pull #1287

github

GitHub
Merge 42fe701e4 into ff8c1edaf
Pull Request #1287: [stable25] Bump packages

2548 of 4384 relevant lines covered (58.12%)

4.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.38
/lib/Db/FileMapper.php
1
<?php
2

3
namespace OCA\Libresign\Db;
4

5
use OCP\AppFramework\Db\QBMapper;
6
use OCP\DB\QueryBuilder\IQueryBuilder;
7
use OCP\IDBConnection;
8
use OCP\IL10N;
9

10
/**
11
 * Class FileMapper
12
 *
13
 * @package OCA\Libresign\DB
14
 */
15
class FileMapper extends QBMapper {
16
        /** @var IL10N */
17
        private $l;
18
        /** @var File[] */
19
        private $file;
20

21
        /**
22
         * @param IDBConnection $db
23
         */
24
        public function __construct(
25
                IDBConnection $db,
26
                IL10N $l
27
        ) {
28
                $this->l = $l;
38✔
29
                parent::__construct($db, 'libresign_file');
38✔
30
        }
31

32
        /**
33
         * Return LibreSign file by ID
34
         *
35
         * @return File Row of table libresign_file
36
         */
37
        public function getById(int $id): File {
38
                if (empty($this->file['id'][$id])) {
6✔
39
                        $qb = $this->db->getQueryBuilder();
6✔
40

41
                        $qb->select('*')
6✔
42
                                ->from($this->getTableName())
6✔
43
                                ->where(
6✔
44
                                        $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
6✔
45
                                );
6✔
46

47
                        $this->file['id'][$id] = $this->findEntity($qb);
6✔
48
                        $this->file['uuid'][$this->file['id'][$id]->getUuid()] = $this->file['id'][$id];
6✔
49
                }
50
                return $this->file['id'][$id];
6✔
51
        }
52

53
        /**
54
         * Return LibreSign file by UUID
55
         */
56
        public function getByUuid(?string $uuid = null): File {
57
                if (!$uuid) {
9✔
58
                        return array_values($this->file)[0];
×
59
                }
60
                if (empty($this->file[$uuid]) || ($this->file[$uuid]->getUuid() !== $uuid)) {
9✔
61
                        $qb = $this->db->getQueryBuilder();
9✔
62

63
                        $qb->select('*')
9✔
64
                                ->from($this->getTableName())
9✔
65
                                ->where(
9✔
66
                                        $qb->expr()->eq('uuid', $qb->createNamedParameter($uuid))
9✔
67
                                );
9✔
68

69
                        $this->file[$uuid] = $this->findEntity($qb);
9✔
70
                        $this->file['id'][$this->file[$uuid]->getId()] = $this->file[$uuid];
8✔
71
                }
72
                return $this->file[$uuid];
8✔
73
        }
74

75
        /**
76
         * Return LibreSign file by fileId
77
         */
78
        public function getByFileId(?int $fileId = null): File {
79
                if (!$fileId) {
11✔
80
                        return array_values($this->file)[0];
1✔
81
                }
82
                if (empty($this->file[$fileId]) || ($this->file[$fileId]->getNodeId() !== $fileId)) {
11✔
83
                        $qb = $this->db->getQueryBuilder();
11✔
84

85
                        $qb->select('*')
11✔
86
                                ->from($this->getTableName())
11✔
87
                                ->where(
11✔
88
                                        $qb->expr()->orX(
11✔
89
                                                $qb->expr()->eq('node_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)),
11✔
90
                                                $qb->expr()->eq('signed_node_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
11✔
91
                                        )
11✔
92
                                );
11✔
93

94
                        $this->file[$fileId] = $this->findEntity($qb);
11✔
95
                }
96
                return $this->file[$fileId];
9✔
97
        }
98

99
        /**
100
         * @param string $userId
101
         * @return File[]
102
         */
103
        public function getFilesOfAccount(string $userId): array {
104
                $qb = $this->db->getQueryBuilder();
×
105

106
                $qb->select('lf.*')
×
107
                        ->from($this->getTableName(), 'lf')
×
108
                        ->join('lf', 'libresign_account_file', 'laf', 'laf.file_id = lf.id')
×
109
                        ->where(
×
110
                                $qb->expr()->eq('laf.user_id', $qb->createNamedParameter($userId))
×
111
                        );
×
112

113
                $cursor = $qb->executeQuery();
×
114
                $return = [];
×
115
                while ($row = $cursor->fetch()) {
×
116
                        $return[] = $this->file[$row['id']] = $this->mapRowToEntity($row);
×
117
                }
118
                return $return;
×
119
        }
120

121
        public function getFileType(int $id): string {
122
                $fullOuterJoin = $this->db->getQueryBuilder();
×
123
                $fullOuterJoin->select($fullOuterJoin->expr()->literal(1));
×
124

125
                $qb = $this->db->getQueryBuilder();
×
126
                $qb
×
127
                        ->selectAlias('f.id', 'file')
×
128
                        ->selectAlias('sf.signed_node_id', 'signed_file')
×
129
                        ->selectAlias('ue.id', 'user_element')
×
130
                        ->selectAlias('fe.id', 'file_element')
×
131
                        ->from($qb->createFunction('(' . $fullOuterJoin->getSQL() . ')'), 'foj')
×
132
                        ->leftJoin('foj', 'libresign_file', 'f', $qb->expr()->eq('f.node_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
×
133
                        ->leftJoin('foj', 'libresign_file', 'sf', $qb->expr()->eq('sf.signed_node_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
×
134
                        ->leftJoin('foj', 'libresign_user_element', 'ue', $qb->expr()->eq('ue.file_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
×
135
                        ->leftJoin('foj', 'libresign_file_element', 'fe', $qb->expr()->eq('fe.file_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
×
136
                $cursor = $qb->executeQuery();
×
137
                $row = $cursor->fetch();
×
138
                if ($row) {
×
139
                        foreach ($row as $key => $value) {
×
140
                                if ($value) {
×
141
                                        return $key;
×
142
                                }
143
                        }
144
                }
145
                return 'not_libresign_file';
×
146
        }
147

148
        public function getTextOfStatus(int $status): ?string {
149
                switch ($status) {
150
                        case File::STATUS_DRAFT:
2✔
151
                                return $this->l->t('draft');
×
152
                        case File::STATUS_ABLE_TO_SIGN:
2✔
153
                                return $this->l->t('able to sign');
2✔
154
                        case File::STATUS_PARTIAL_SIGNED:
×
155
                                return $this->l->t('partially signed');
×
156
                        case File::STATUS_SIGNED:
×
157
                                return $this->l->t('signed');
×
158
                        case File::STATUS_DELETED:
×
159
                                return $this->l->t('deleted');
×
160
                }
161
                return '';
×
162
        }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc