Code Duplication    Length = 188-212 lines in 14 locations

local/devel/Repositories/CacheListBookmarksRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class CacheListBookmarksRepository
10
{
11
    const TABLE = 'cache_list_bookmarks';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeoCacheListBookmarksEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return GeoCacheListBookmarksEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return GeoCacheListBookmarksEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return GeoCacheListBookmarksEntity
107
     */
108
    public function create(GeoCacheListBookmarksEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->cacheListId = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return GeoCacheListBookmarksEntity
128
     */
129
    public function update(GeoCacheListBookmarksEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['cache_list_id' => $entity->cacheListId]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return GeoCacheListBookmarksEntity
148
     */
149
    public function remove(GeoCacheListBookmarksEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['cache_list_id' => $entity->cacheListId]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(GeoCacheListBookmarksEntity $entity)
169
    {
170
        return [
171
            'cache_list_id' => $entity->cacheListId,
172
            'user_id' => $entity->userId,
173
            'password' => $entity->password,
174
        ];
175
    }
176
177
    /**
178
     * @return GeoCacheListBookmarksEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new GeoCacheListBookmarksEntity();
183
        $entity->cacheListId = (int) $data['cache_list_id'];
184
        $entity->userId = (int) $data['user_id'];
185
        $entity->password = (string) $data['password'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/CacheReportStatusRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class CacheReportStatusRepository
10
{
11
    const TABLE = 'cache_report_status';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeoCacheReportStatusEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return GeoCacheReportStatusEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return GeoCacheReportStatusEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return GeoCacheReportStatusEntity
107
     */
108
    public function create(GeoCacheReportStatusEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->id = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return GeoCacheReportStatusEntity
128
     */
129
    public function update(GeoCacheReportStatusEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['id' => $entity->id]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return GeoCacheReportStatusEntity
148
     */
149
    public function remove(GeoCacheReportStatusEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['id' => $entity->id]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(GeoCacheReportStatusEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'name' => $entity->name,
173
            'trans_id' => $entity->transId,
174
        ];
175
    }
176
177
    /**
178
     * @return GeoCacheReportStatusEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new GeoCacheReportStatusEntity();
183
        $entity->id = (int) $data['id'];
184
        $entity->name = (string) $data['name'];
185
        $entity->transId = (int) $data['trans_id'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/GeodbTypeNamesRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class GeodbTypeNamesRepository
10
{
11
    const TABLE = 'geodb_type_names';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeodbTypeNamesEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return GeodbTypeNamesEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return GeodbTypeNamesEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return GeodbTypeNamesEntity
107
     */
108
    public function create(GeodbTypeNamesEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->typeId = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return GeodbTypeNamesEntity
128
     */
129
    public function update(GeodbTypeNamesEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['type_id' => $entity->typeId]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return GeodbTypeNamesEntity
148
     */
149
    public function remove(GeodbTypeNamesEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['type_id' => $entity->typeId]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(GeodbTypeNamesEntity $entity)
169
    {
170
        return [
171
            'type_id' => $entity->typeId,
172
            'type_locale' => $entity->typeLocale,
173
            'name' => $entity->name,
174
        ];
175
    }
176
177
    /**
178
     * @return GeodbTypeNamesEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new GeodbTypeNamesEntity();
183
        $entity->typeId = (int) $data['type_id'];
184
        $entity->typeLocale = (string) $data['type_locale'];
185
        $entity->name = (string) $data['name'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/HelppagesRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class HelppagesRepository
10
{
11
    const TABLE = 'helppages';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return HelppagesEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return HelppagesEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return HelppagesEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return HelppagesEntity
107
     */
108
    public function create(HelppagesEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->ocpage = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return HelppagesEntity
128
     */
129
    public function update(HelppagesEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['ocpage' => $entity->ocpage]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return HelppagesEntity
148
     */
149
    public function remove(HelppagesEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['ocpage' => $entity->ocpage]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(HelppagesEntity $entity)
169
    {
170
        return [
171
            'ocpage' => $entity->ocpage,
172
            'language' => $entity->language,
173
            'helppage' => $entity->helppage,
174
        ];
175
    }
176
177
    /**
178
     * @return HelppagesEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new HelppagesEntity();
183
        $entity->ocpage = (string) $data['ocpage'];
184
        $entity->language = (string) $data['language'];
185
        $entity->helppage = (string) $data['helppage'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/LogentriesTypesRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class LogentriesTypesRepository
10
{
11
    const TABLE = 'logentries_types';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return LogentriesTypesEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return LogentriesTypesEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return LogentriesTypesEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return LogentriesTypesEntity
107
     */
108
    public function create(LogentriesTypesEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->id = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return LogentriesTypesEntity
128
     */
129
    public function update(LogentriesTypesEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['id' => $entity->id]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return LogentriesTypesEntity
148
     */
149
    public function remove(LogentriesTypesEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['id' => $entity->id]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(LogentriesTypesEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'module' => $entity->module,
173
            'eventname' => $entity->eventname,
174
        ];
175
    }
176
177
    /**
178
     * @return LogentriesTypesEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new LogentriesTypesEntity();
183
        $entity->id = (int) $data['id'];
184
        $entity->module = (string) $data['module'];
185
        $entity->eventname = (string) $data['eventname'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/OkapiAuthorizationsRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiAuthorizationsRepository
10
{
11
    const TABLE = 'okapi_authorizations';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiAuthorizationsEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return OkapiAuthorizationsEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return OkapiAuthorizationsEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return OkapiAuthorizationsEntity
107
     */
108
    public function create(OkapiAuthorizationsEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->consumerKey = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return OkapiAuthorizationsEntity
128
     */
129
    public function update(OkapiAuthorizationsEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['consumer_key' => $entity->consumerKey]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return OkapiAuthorizationsEntity
148
     */
149
    public function remove(OkapiAuthorizationsEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['consumer_key' => $entity->consumerKey]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(OkapiAuthorizationsEntity $entity)
169
    {
170
        return [
171
            'consumer_key' => $entity->consumerKey,
172
            'user_id' => $entity->userId,
173
            'last_access_token' => $entity->lastAccessToken,
174
        ];
175
    }
176
177
    /**
178
     * @return OkapiAuthorizationsEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new OkapiAuthorizationsEntity();
183
        $entity->consumerKey = (string) $data['consumer_key'];
184
        $entity->userId = (int) $data['user_id'];
185
        $entity->lastAccessToken = new DateTime($data['last_access_token']);
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/OkapiNoncesRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiNoncesRepository
10
{
11
    const TABLE = 'okapi_nonces';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiNoncesEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return OkapiNoncesEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return OkapiNoncesEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return OkapiNoncesEntity
107
     */
108
    public function create(OkapiNoncesEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->consumerKey = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return OkapiNoncesEntity
128
     */
129
    public function update(OkapiNoncesEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['consumer_key' => $entity->consumerKey]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return OkapiNoncesEntity
148
     */
149
    public function remove(OkapiNoncesEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['consumer_key' => $entity->consumerKey]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(OkapiNoncesEntity $entity)
169
    {
170
        return [
171
            'consumer_key' => $entity->consumerKey,
172
            'nonce_hash' => $entity->nonceHash,
173
            'timestamp' => $entity->timestamp,
174
        ];
175
    }
176
177
    /**
178
     * @return OkapiNoncesEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new OkapiNoncesEntity();
183
        $entity->consumerKey = (string) $data['consumer_key'];
184
        $entity->nonceHash = (string) $data['nonce_hash'];
185
        $entity->timestamp = (int) $data['timestamp'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/OkapiSubmittedObjectsRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiSubmittedObjectsRepository
10
{
11
    const TABLE = 'okapi_submitted_objects';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiSubmittedObjectsEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return OkapiSubmittedObjectsEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return OkapiSubmittedObjectsEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return OkapiSubmittedObjectsEntity
107
     */
108
    public function create(OkapiSubmittedObjectsEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->objectType = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return OkapiSubmittedObjectsEntity
128
     */
129
    public function update(OkapiSubmittedObjectsEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['object_type' => $entity->objectType]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return OkapiSubmittedObjectsEntity
148
     */
149
    public function remove(OkapiSubmittedObjectsEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['object_type' => $entity->objectType]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(OkapiSubmittedObjectsEntity $entity)
169
    {
170
        return [
171
            'object_type' => $entity->objectType,
172
            'object_id' => $entity->objectId,
173
            'consumer_key' => $entity->consumerKey,
174
        ];
175
    }
176
177
    /**
178
     * @return OkapiSubmittedObjectsEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new OkapiSubmittedObjectsEntity();
183
        $entity->objectType = (int) $data['object_type'];
184
        $entity->objectId = (int) $data['object_id'];
185
        $entity->consumerKey = (string) $data['consumer_key'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/ReplicationNotimportedRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class ReplicationNotimportedRepository
10
{
11
    const TABLE = 'replication_notimported';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return ReplicationNotimportedEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return ReplicationNotimportedEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return ReplicationNotimportedEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return ReplicationNotimportedEntity
107
     */
108
    public function create(ReplicationNotimportedEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->id = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return ReplicationNotimportedEntity
128
     */
129
    public function update(ReplicationNotimportedEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['id' => $entity->id]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return ReplicationNotimportedEntity
148
     */
149
    public function remove(ReplicationNotimportedEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['id' => $entity->id]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(ReplicationNotimportedEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'object_uuid' => $entity->objectUuid,
173
            'object_type' => $entity->objectType,
174
        ];
175
    }
176
177
    /**
178
     * @return ReplicationNotimportedEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new ReplicationNotimportedEntity();
183
        $entity->id = (int) $data['id'];
184
        $entity->objectUuid = (string) $data['object_uuid'];
185
        $entity->objectType = (int) $data['object_type'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/SearchDoublesRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SearchDoublesRepository
10
{
11
    const TABLE = 'search_doubles';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SearchDoublesEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return SearchDoublesEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return SearchDoublesEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return SearchDoublesEntity
107
     */
108
    public function create(SearchDoublesEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->hash = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return SearchDoublesEntity
128
     */
129
    public function update(SearchDoublesEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['hash' => $entity->hash]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return SearchDoublesEntity
148
     */
149
    public function remove(SearchDoublesEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['hash' => $entity->hash]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(SearchDoublesEntity $entity)
169
    {
170
        return [
171
            'hash' => $entity->hash,
172
            'word' => $entity->word,
173
            'simple' => $entity->simple,
174
        ];
175
    }
176
177
    /**
178
     * @return SearchDoublesEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new SearchDoublesEntity();
183
        $entity->hash = (int) $data['hash'];
184
        $entity->word = (string) $data['word'];
185
        $entity->simple = (string) $data['simple'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/SysTransRefRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysTransRefRepository
10
{
11
    const TABLE = 'sys_trans_ref';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysTransRefEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return SysTransRefEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return SysTransRefEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return SysTransRefEntity
107
     */
108
    public function create(SysTransRefEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->transId = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return SysTransRefEntity
128
     */
129
    public function update(SysTransRefEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['trans_id' => $entity->transId]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return SysTransRefEntity
148
     */
149
    public function remove(SysTransRefEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['trans_id' => $entity->transId]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(SysTransRefEntity $entity)
169
    {
170
        return [
171
            'trans_id' => $entity->transId,
172
            'resource_name' => $entity->resourceName,
173
            'line' => $entity->line,
174
        ];
175
    }
176
177
    /**
178
     * @return SysTransRefEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new SysTransRefEntity();
183
        $entity->transId = (int) $data['trans_id'];
184
        $entity->resourceName = (string) $data['resource_name'];
185
        $entity->line = (int) $data['line'];
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/SysTransRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysTransRepository
10
{
11
    const TABLE = 'sys_trans';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysTransEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return SysTransEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return SysTransEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return SysTransEntity
107
     */
108
    public function create(SysTransEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->id = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return SysTransEntity
128
     */
129
    public function update(SysTransEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['id' => $entity->id]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return SysTransEntity
148
     */
149
    public function remove(SysTransEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['id' => $entity->id]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(SysTransEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'text' => $entity->text,
173
            'last_modified' => $entity->lastModified,
174
        ];
175
    }
176
177
    /**
178
     * @return SysTransEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new SysTransEntity();
183
        $entity->id = (int) $data['id'];
184
        $entity->text = (string) $data['text'];
185
        $entity->lastModified = new DateTime($data['last_modified']);
186
187
        return $entity;
188
    }
189
}
190

local/devel/Repositories/UserStatpicRepository.php 1 location

@@ 9-196 (lines=188) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class UserStatpicRepository
10
{
11
    const TABLE = 'user_statpic';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return UserStatpicEntity[]
23
     */
24
    public function fetchAll()
25
    {
26
        $statement = $this->connection->createQueryBuilder()
27
            ->select('*')
28
            ->from(self::TABLE)
29
            ->execute();
30
31
        $result = $statement->fetchAll();
32
33
        if ($statement->rowCount() === 0) {
34
            throw new RecordsNotFoundException('No records found');
35
        }
36
37
        $records = [];
38
39
        foreach ($result as $item) {
40
            $records[] = $this->getEntityFromDatabaseArray($item);
41
        }
42
43
        return $records;
44
    }
45
46
    /**
47
     * @return UserStatpicEntity
48
     */
49
    public function fetchOneBy(array $where = [])
50
    {
51
        $queryBuilder = $this->connection->createQueryBuilder()
52
            ->select('*')
53
            ->from(self::TABLE)
54
            ->setMaxResults(1);
55
56
        if (count($where) > 0) {
57
            foreach ($where as $column => $value) {
58
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
59
            }
60
        }
61
62
        $statement = $queryBuilder->execute();
63
64
        $result = $statement->fetch();
65
66
        if ($statement->rowCount() === 0) {
67
            throw new RecordNotFoundException('Record with given where clause not found');
68
        }
69
70
        return $this->getEntityFromDatabaseArray($result);
71
    }
72
73
    /**
74
     * @return UserStatpicEntity[]
75
     */
76
    public function fetchBy(array $where = [])
77
    {
78
        $queryBuilder = $this->connection->createQueryBuilder()
79
            ->select('*')
80
            ->from(self::TABLE);
81
82
        if (count($where) > 0) {
83
            foreach ($where as $column => $value) {
84
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
85
            }
86
        }
87
88
        $statement = $queryBuilder->execute();
89
90
        $result = $statement->fetchAll();
91
92
        if ($statement->rowCount() === 0) {
93
            throw new RecordsNotFoundException('No records with given where clause found');
94
        }
95
96
        $entities = [];
97
98
        foreach ($result as $item) {
99
            $entities[] = $this->getEntityFromDatabaseArray($item);
100
        }
101
102
        return $entities;
103
    }
104
105
    /**
106
     * @return UserStatpicEntity
107
     */
108
    public function create(UserStatpicEntity $entity)
109
    {
110
        if (!$entity->isNew()) {
111
            throw new RecordAlreadyExistsException('The entity does already exist.');
112
        }
113
114
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
115
116
        $this->connection->insert(
117
            self::TABLE,
118
            $databaseArray
119
        );
120
121
        $entity->userId = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return UserStatpicEntity
128
     */
129
    public function update(UserStatpicEntity $entity)
130
    {
131
        if ($entity->isNew()) {
132
            throw new RecordNotPersistedException('The entity does not exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->update(
138
            self::TABLE,
139
            $databaseArray,
140
            ['user_id' => $entity->userId]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return UserStatpicEntity
148
     */
149
    public function remove(UserStatpicEntity $entity)
150
    {
151
        if ($entity->isNew()) {
152
            throw new RecordNotPersistedException('The entity does not exist.');
153
        }
154
155
        $this->connection->delete(
156
            self::TABLE,
157
            ['user_id' => $entity->userId]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(UserStatpicEntity $entity)
169
    {
170
        return [
171
            'user_id' => $entity->userId,
172
            'lang' => $entity->lang,
173
            'date_created' => $entity->dateCreated,
174
        ];
175
    }
176
177
    /**
178
     * @return UserStatpicEntity
179
     */
180
    public function getEntityFromDatabaseArray(array $data)
181
    {
182
        $entity = new UserStatpicEntity();
183
        $entity->userId = (int) $data['user_id'];
184
        $entity->lang = (string) $data['lang'];
185
        $entity->dateCreated = new DateTime($data['date_created']);
186
187
        return $entity;
188
    }
189
}
190

htdocs_symfony/src/Repository/CacheReportStatusRepository.php 1 location

@@ 12-223 (lines=212) @@
9
use Oc\Repository\Exception\RecordNotPersistedException;
10
use Oc\Repository\Exception\RecordsNotFoundException;
11
12
class CacheReportStatusRepository
13
{
14
    const TABLE = 'cache_report_status';
15
16
    /**
17
     * @var Connection
18
     */
19
    private $connection;
20
21
    /**
22
     * CacheReportStatusRepository constructor.
23
     *
24
     * @param Connection $connection
25
     */
26
    public function __construct(Connection $connection)
27
    {
28
        $this->connection = $connection;
29
    }
30
31
    /**
32
     * @return array
33
     * @throws RecordsNotFoundException
34
     */
35
    public function fetchAll()
36
    {
37
        $statement = $this->connection->createQueryBuilder()
38
            ->select('*')
39
            ->from(self::TABLE)
40
            ->execute();
41
42
        $result = $statement->fetchAll();
43
44
        if ($statement->rowCount() === 0) {
45
            throw new RecordsNotFoundException('No records found');
46
        }
47
48
        $records = [];
49
50
        foreach ($result as $item) {
51
            $records[] = $this->getEntityFromDatabaseArray($item);
52
        }
53
54
        return $records;
55
    }
56
57
    /**
58
     * @param array $where
59
     *
60
     * @return GeoCacheReportStatusEntity
61
     * @throws RecordNotFoundException
62
     */
63
    public function fetchOneBy(array $where = [])
64
    {
65
        $queryBuilder = $this->connection->createQueryBuilder()
66
            ->select('*')
67
            ->from(self::TABLE)
68
            ->setMaxResults(1);
69
70
        if (count($where) > 0) {
71
            foreach ($where as $column => $value) {
72
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
73
            }
74
        }
75
76
        $statement = $queryBuilder->execute();
77
78
        $result = $statement->fetch();
79
80
        if ($statement->rowCount() === 0) {
81
            throw new RecordNotFoundException('Record with given where clause not found');
82
        }
83
84
        return $this->getEntityFromDatabaseArray($result);
85
    }
86
87
    /**
88
     * @param array $where
89
     *
90
     * @return array
91
     * @throws RecordsNotFoundException
92
     */
93
    public function fetchBy(array $where = [])
94
    {
95
        $queryBuilder = $this->connection->createQueryBuilder()
96
            ->select('*')
97
            ->from(self::TABLE);
98
99
        if (count($where) > 0) {
100
            foreach ($where as $column => $value) {
101
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
102
            }
103
        }
104
105
        $statement = $queryBuilder->execute();
106
107
        $result = $statement->fetchAll();
108
109
        if ($statement->rowCount() === 0) {
110
            throw new RecordsNotFoundException('No records with given where clause found');
111
        }
112
113
        $entities = [];
114
115
        foreach ($result as $item) {
116
            $entities[] = $this->getEntityFromDatabaseArray($item);
117
        }
118
119
        return $entities;
120
    }
121
122
    /**
123
     * @param GeoCacheReportStatusEntity $entity
124
     *
125
     * @return GeoCacheReportStatusEntity
126
     * @throws RecordAlreadyExistsException
127
     * @throws \Doctrine\DBAL\DBALException
128
     */
129
    public function create(GeoCacheReportStatusEntity $entity)
130
    {
131
        if (!$entity->isNew()) {
132
            throw new RecordAlreadyExistsException('The entity does already exist.');
133
        }
134
135
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
136
137
        $this->connection->insert(
138
            self::TABLE,
139
            $databaseArray
140
        );
141
142
        $entity->id = (int) $this->connection->lastInsertId();
143
144
        return $entity;
145
    }
146
147
    /**
148
     * @param GeoCacheReportStatusEntity $entity
149
     *
150
     * @return GeoCacheReportStatusEntity
151
     * @throws RecordNotPersistedException
152
     * @throws \Doctrine\DBAL\DBALException
153
     */
154
    public function update(GeoCacheReportStatusEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
161
162
        $this->connection->update(
163
            self::TABLE,
164
            $databaseArray,
165
            ['id' => $entity->id]
166
        );
167
168
        return $entity;
169
    }
170
171
    /**
172
     * @param GeoCacheReportStatusEntity $entity
173
     *
174
     * @return GeoCacheReportStatusEntity
175
     * @throws RecordNotPersistedException
176
     * @throws \Doctrine\DBAL\DBALException
177
     * @throws \Doctrine\DBAL\Exception\InvalidArgumentException
178
     */
179
    public function remove(GeoCacheReportStatusEntity $entity)
180
    {
181
        if ($entity->isNew()) {
182
            throw new RecordNotPersistedException('The entity does not exist.');
183
        }
184
185
        $this->connection->delete(
186
            self::TABLE,
187
            ['id' => $entity->id]
188
        );
189
190
        $entity->cacheId = null;
191
192
        return $entity;
193
    }
194
195
    /**
196
     * @param GeoCacheReportStatusEntity $entity
197
     *
198
     * @return array
199
     */
200
    public function getDatabaseArrayFromEntity(GeoCacheReportStatusEntity $entity)
201
    {
202
        return [
203
            'id' => $entity->id,
204
            'name' => $entity->name,
205
            'trans_id' => $entity->transId,
206
        ];
207
    }
208
209
    /**
210
     * @param array $data
211
     *
212
     * @return GeoCacheReportStatusEntity
213
     */
214
    public function getEntityFromDatabaseArray(array $data)
215
    {
216
        $entity = new GeoCacheReportStatusEntity();
217
        $entity->id = (int) $data['id'];
218
        $entity->name = (string) $data['name'];
219
        $entity->transId = (int) $data['trans_id'];
220
221
        return $entity;
222
    }
223
}
224