Code Duplication    Length = 190-214 lines in 8 locations

local/devel/Repositories/CacheVisitsRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class CacheVisitsRepository
10
{
11
    const TABLE = 'cache_visits';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeoCacheVisitsEntity[]
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 GeoCacheVisitsEntity
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 GeoCacheVisitsEntity[]
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 GeoCacheVisitsEntity
107
     */
108
    public function create(GeoCacheVisitsEntity $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->cacheId = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return GeoCacheVisitsEntity
128
     */
129
    public function update(GeoCacheVisitsEntity $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_id' => $entity->cacheId]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return GeoCacheVisitsEntity
148
     */
149
    public function remove(GeoCacheVisitsEntity $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_id' => $entity->cacheId]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(GeoCacheVisitsEntity $entity)
169
    {
170
        return [
171
            'cache_id' => $entity->cacheId,
172
            'user_id_ip' => $entity->userIdIp,
173
            'count' => $entity->count,
174
            'last_modified' => $entity->lastModified,
175
        ];
176
    }
177
178
    /**
179
     * @return GeoCacheVisitsEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new GeoCacheVisitsEntity();
184
        $entity->cacheId = (int) $data['cache_id'];
185
        $entity->userIdIp = (string) $data['user_id_ip'];
186
        $entity->count = $data['count'];
187
        $entity->lastModified = new DateTime($data['last_modified']);
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/NutsLayerRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class NutsLayerRepository
10
{
11
    const TABLE = 'nuts_layer';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return NutsLayerEntity[]
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 NutsLayerEntity
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 NutsLayerEntity[]
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 NutsLayerEntity
107
     */
108
    public function create(NutsLayerEntity $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 NutsLayerEntity
128
     */
129
    public function update(NutsLayerEntity $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 NutsLayerEntity
148
     */
149
    public function remove(NutsLayerEntity $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(NutsLayerEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'level' => $entity->level,
173
            'code' => $entity->code,
174
            'shape' => $entity->shape,
175
        ];
176
    }
177
178
    /**
179
     * @return NutsLayerEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new NutsLayerEntity();
184
        $entity->id = (int) $data['id'];
185
        $entity->level = (int) $data['level'];
186
        $entity->code = (string) $data['code'];
187
        $entity->shape = $data['shape'];
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/OkapiCacheRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiCacheRepository
10
{
11
    const TABLE = 'okapi_cache';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiCacheEntity[]
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 OkapiCacheEntity
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 OkapiCacheEntity[]
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 OkapiCacheEntity
107
     */
108
    public function create(OkapiCacheEntity $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->key = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return OkapiCacheEntity
128
     */
129
    public function update(OkapiCacheEntity $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
            ['key' => $entity->key]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return OkapiCacheEntity
148
     */
149
    public function remove(OkapiCacheEntity $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
            ['key' => $entity->key]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(OkapiCacheEntity $entity)
169
    {
170
        return [
171
            'key' => $entity->key,
172
            'score' => $entity->score,
173
            'expires' => $entity->expires,
174
            'value' => $entity->value,
175
        ];
176
    }
177
178
    /**
179
     * @return OkapiCacheEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new OkapiCacheEntity();
184
        $entity->key = (string) $data['key'];
185
        $entity->score = $data['score'];
186
        $entity->expires = new DateTime($data['expires']);
187
        $entity->value = (string) $data['value'];
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/OkapiSearchSetsRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class OkapiSearchSetsRepository
10
{
11
    const TABLE = 'okapi_search_sets';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return OkapiSearchSetsEntity[]
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 OkapiSearchSetsEntity
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 OkapiSearchSetsEntity[]
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 OkapiSearchSetsEntity
107
     */
108
    public function create(OkapiSearchSetsEntity $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 OkapiSearchSetsEntity
128
     */
129
    public function update(OkapiSearchSetsEntity $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 OkapiSearchSetsEntity
148
     */
149
    public function remove(OkapiSearchSetsEntity $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(OkapiSearchSetsEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'params_hash' => $entity->paramsHash,
173
            'date_created' => $entity->dateCreated,
174
            'expires' => $entity->expires,
175
        ];
176
    }
177
178
    /**
179
     * @return OkapiSearchSetsEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new OkapiSearchSetsEntity();
184
        $entity->id = (int) $data['id'];
185
        $entity->paramsHash = (string) $data['params_hash'];
186
        $entity->dateCreated = new DateTime($data['date_created']);
187
        $entity->expires = new DateTime($data['expires']);
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/SysLoginsRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysLoginsRepository
10
{
11
    const TABLE = 'sys_logins';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysLoginsEntity[]
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 SysLoginsEntity
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 SysLoginsEntity[]
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 SysLoginsEntity
107
     */
108
    public function create(SysLoginsEntity $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 SysLoginsEntity
128
     */
129
    public function update(SysLoginsEntity $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 SysLoginsEntity
148
     */
149
    public function remove(SysLoginsEntity $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(SysLoginsEntity $entity)
169
    {
170
        return [
171
            'id' => $entity->id,
172
            'date_created' => $entity->dateCreated,
173
            'remote_addr' => $entity->remoteAddr,
174
            'success' => $entity->success,
175
        ];
176
    }
177
178
    /**
179
     * @return SysLoginsEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new SysLoginsEntity();
184
        $entity->id = (int) $data['id'];
185
        $entity->dateCreated = new DateTime($data['date_created']);
186
        $entity->remoteAddr = (string) $data['remote_addr'];
187
        $entity->success = (int) $data['success'];
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/SysSessionsRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysSessionsRepository
10
{
11
    const TABLE = 'sys_sessions';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysSessionsEntity[]
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 SysSessionsEntity
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 SysSessionsEntity[]
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 SysSessionsEntity
107
     */
108
    public function create(SysSessionsEntity $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->uuid = (int) $this->connection->lastInsertId();
122
123
        return $entity;
124
    }
125
126
    /**
127
     * @return SysSessionsEntity
128
     */
129
    public function update(SysSessionsEntity $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
            ['uuid' => $entity->uuid]
141
        );
142
143
        return $entity;
144
    }
145
146
    /**
147
     * @return SysSessionsEntity
148
     */
149
    public function remove(SysSessionsEntity $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
            ['uuid' => $entity->uuid]
158
        );
159
160
        $entity->cacheId = null;
161
162
        return $entity;
163
    }
164
165
    /**
166
     * @return []
167
     */
168
    public function getDatabaseArrayFromEntity(SysSessionsEntity $entity)
169
    {
170
        return [
171
            'uuid' => $entity->uuid,
172
            'user_id' => $entity->userId,
173
            'permanent' => $entity->permanent,
174
            'last_login' => $entity->lastLogin,
175
        ];
176
    }
177
178
    /**
179
     * @return SysSessionsEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new SysSessionsEntity();
184
        $entity->uuid = (string) $data['uuid'];
185
        $entity->userId = (int) $data['user_id'];
186
        $entity->permanent = (int) $data['permanent'];
187
        $entity->lastLogin = new DateTime($data['last_login']);
188
189
        return $entity;
190
    }
191
}
192

local/devel/Repositories/SysTransTextRepository.php 1 location

@@ 9-198 (lines=190) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysTransTextRepository
10
{
11
    const TABLE = 'sys_trans_text';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysTransTextEntity[]
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 SysTransTextEntity
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 SysTransTextEntity[]
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 SysTransTextEntity
107
     */
108
    public function create(SysTransTextEntity $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 SysTransTextEntity
128
     */
129
    public function update(SysTransTextEntity $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 SysTransTextEntity
148
     */
149
    public function remove(SysTransTextEntity $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(SysTransTextEntity $entity)
169
    {
170
        return [
171
            'trans_id' => $entity->transId,
172
            'lang' => $entity->lang,
173
            'text' => $entity->text,
174
            'last_modified' => $entity->lastModified,
175
        ];
176
    }
177
178
    /**
179
     * @return SysTransTextEntity
180
     */
181
    public function getEntityFromDatabaseArray(array $data)
182
    {
183
        $entity = new SysTransTextEntity();
184
        $entity->transId = (int) $data['trans_id'];
185
        $entity->lang = (string) $data['lang'];
186
        $entity->text = (string) $data['text'];
187
        $entity->lastModified = new DateTime($data['last_modified']);
188
189
        return $entity;
190
    }
191
}
192

htdocs_symfony/src/Repository/CacheReportReasonsRepository.php 1 location

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