Code Duplication    Length = 200-200 lines in 6 locations

local/devel/Repositories/GeodbCoordinatesRepository.php 1 location

@@ 9-208 (lines=200) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class GeodbCoordinatesRepository
10
{
11
    const TABLE = 'geodb_coordinates';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GeodbCoordinatesEntity[]
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
     * @param array $where
48
     * @return GeodbCoordinatesEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return GeodbCoordinatesEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param GeodbCoordinatesEntity $entity
109
     * @return GeodbCoordinatesEntity
110
     */
111
    public function create(GeodbCoordinatesEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->locId = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param GeodbCoordinatesEntity $entity
131
     * @return GeodbCoordinatesEntity
132
     */
133
    public function update(GeodbCoordinatesEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['loc_id' => $entity->locId]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param GeodbCoordinatesEntity $entity
152
     * @return GeodbCoordinatesEntity
153
     */
154
    public function remove(GeodbCoordinatesEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['loc_id' => $entity->locId]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param GeodbCoordinatesEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(GeodbCoordinatesEntity $entity)
175
    {
176
        return [
177
        'loc_id' => $entity->locId,
178
        'lon' => $entity->lon,
179
        'lat' => $entity->lat,
180
        'coord_type' => $entity->coordType,
181
        'coord_subtype' => $entity->coordSubtype,
182
        'valid_since' => $entity->validSince,
183
        'date_type_since' => $entity->dateTypeSince,
184
        'valid_until' => $entity->validUntil,
185
        'date_type_until' => $entity->dateTypeUntil,
186
        ];
187
    }
188
189
    /**
190
     * @param array $data
191
     * @return GeodbCoordinatesEntity
192
     */
193
    public function getEntityFromDatabaseArray(array $data)
194
    {
195
        $entity = new GeodbCoordinatesEntity();
196
        $entity->locId = $data['loc_id'];
197
        $entity->lon = $data['lon'];
198
        $entity->lat = $data['lat'];
199
        $entity->coordType = $data['coord_type'];
200
        $entity->coordSubtype = $data['coord_subtype'];
201
        $entity->validSince = $data['valid_since'];
202
        $entity->dateTypeSince = $data['date_type_since'];
203
        $entity->validUntil = $data['valid_until'];
204
        $entity->dateTypeUntil = $data['date_type_until'];
205
206
        return $entity;
207
    }
208
}
209

local/devel/Repositories/GkMoveRepository.php 1 location

@@ 9-208 (lines=200) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class GkMoveRepository
10
{
11
    const TABLE = 'gk_move';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return GkMoveEntity[]
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
     * @param array $where
48
     * @return GkMoveEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return GkMoveEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param GkMoveEntity $entity
109
     * @return GkMoveEntity
110
     */
111
    public function create(GkMoveEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->id = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param GkMoveEntity $entity
131
     * @return GkMoveEntity
132
     */
133
    public function update(GkMoveEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['id' => $entity->id]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param GkMoveEntity $entity
152
     * @return GkMoveEntity
153
     */
154
    public function remove(GkMoveEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['id' => $entity->id]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param GkMoveEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(GkMoveEntity $entity)
175
    {
176
        return [
177
        'id' => $entity->id,
178
        'itemid' => $entity->itemid,
179
        'latitude' => $entity->latitude,
180
        'longitude' => $entity->longitude,
181
        'datemoved' => $entity->datemoved,
182
        'datelogged' => $entity->datelogged,
183
        'userid' => $entity->userid,
184
        'comment' => $entity->comment,
185
        'logtypeid' => $entity->logtypeid,
186
        ];
187
    }
188
189
    /**
190
     * @param array $data
191
     * @return GkMoveEntity
192
     */
193
    public function getEntityFromDatabaseArray(array $data)
194
    {
195
        $entity = new GkMoveEntity();
196
        $entity->id = $data['id'];
197
        $entity->itemid = $data['itemid'];
198
        $entity->latitude = $data['latitude'];
199
        $entity->longitude = $data['longitude'];
200
        $entity->datemoved = $data['datemoved'];
201
        $entity->datelogged = $data['datelogged'];
202
        $entity->userid = $data['userid'];
203
        $entity->comment = $data['comment'];
204
        $entity->logtypeid = $data['logtypeid'];
205
206
        return $entity;
207
    }
208
}
209

local/devel/Repositories/LanguagesRepository.php 1 location

@@ 9-208 (lines=200) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class LanguagesRepository
10
{
11
    const TABLE = 'languages';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return LanguagesEntity[]
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
     * @param array $where
48
     * @return LanguagesEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return LanguagesEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param LanguagesEntity $entity
109
     * @return LanguagesEntity
110
     */
111
    public function create(LanguagesEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->short = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param LanguagesEntity $entity
131
     * @return LanguagesEntity
132
     */
133
    public function update(LanguagesEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['short' => $entity->short]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param LanguagesEntity $entity
152
     * @return LanguagesEntity
153
     */
154
    public function remove(LanguagesEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['short' => $entity->short]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param LanguagesEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(LanguagesEntity $entity)
175
    {
176
        return [
177
        'short' => $entity->short,
178
        'name' => $entity->name,
179
        'trans_id' => $entity->transId,
180
        'native_name' => $entity->nativeName,
181
        'de' => $entity->de,
182
        'en' => $entity->en,
183
        'list_default_de' => $entity->listDefaultDe,
184
        'list_default_en' => $entity->listDefaultEn,
185
        'is_translated' => $entity->isTranslated,
186
        ];
187
    }
188
189
    /**
190
     * @param array $data
191
     * @return LanguagesEntity
192
     */
193
    public function getEntityFromDatabaseArray(array $data)
194
    {
195
        $entity = new LanguagesEntity();
196
        $entity->short = $data['short'];
197
        $entity->name = $data['name'];
198
        $entity->transId = $data['trans_id'];
199
        $entity->nativeName = $data['native_name'];
200
        $entity->de = $data['de'];
201
        $entity->en = $data['en'];
202
        $entity->listDefaultDe = $data['list_default_de'];
203
        $entity->listDefaultEn = $data['list_default_en'];
204
        $entity->isTranslated = $data['is_translated'];
205
206
        return $entity;
207
    }
208
}
209

local/devel/Repositories/LogentriesRepository.php 1 location

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

local/devel/Repositories/ProfileOptionsRepository.php 1 location

@@ 9-208 (lines=200) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class ProfileOptionsRepository
10
{
11
    const TABLE = 'profile_options';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return ProfileOptionsEntity[]
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
     * @param array $where
48
     * @return ProfileOptionsEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return ProfileOptionsEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param ProfileOptionsEntity $entity
109
     * @return ProfileOptionsEntity
110
     */
111
    public function create(ProfileOptionsEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->id = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param ProfileOptionsEntity $entity
131
     * @return ProfileOptionsEntity
132
     */
133
    public function update(ProfileOptionsEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['id' => $entity->id]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param ProfileOptionsEntity $entity
152
     * @return ProfileOptionsEntity
153
     */
154
    public function remove(ProfileOptionsEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['id' => $entity->id]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param ProfileOptionsEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(ProfileOptionsEntity $entity)
175
    {
176
        return [
177
        'id' => $entity->id,
178
        'name' => $entity->name,
179
        'trans_id' => $entity->transId,
180
        'internal_use' => $entity->internalUse,
181
        'default_value' => $entity->defaultValue,
182
        'check_regex' => $entity->checkRegex,
183
        'option_order' => $entity->optionOrder,
184
        'option_input' => $entity->optionInput,
185
        'optionset' => $entity->optionset,
186
        ];
187
    }
188
189
    /**
190
     * @param array $data
191
     * @return ProfileOptionsEntity
192
     */
193
    public function getEntityFromDatabaseArray(array $data)
194
    {
195
        $entity = new ProfileOptionsEntity();
196
        $entity->id = $data['id'];
197
        $entity->name = $data['name'];
198
        $entity->transId = $data['trans_id'];
199
        $entity->internalUse = $data['internal_use'];
200
        $entity->defaultValue = $data['default_value'];
201
        $entity->checkRegex = $data['check_regex'];
202
        $entity->optionOrder = $data['option_order'];
203
        $entity->optionInput = $data['option_input'];
204
        $entity->optionset = $data['optionset'];
205
206
        return $entity;
207
    }
208
}
209

local/devel/Repositories/SysReplSlavesRepository.php 1 location

@@ 9-208 (lines=200) @@
6
use Oc\Repository\Exception\RecordNotPersistedException;
7
use Oc\Repository\Exception\RecordsNotFoundException;
8
9
class SysReplSlavesRepository
10
{
11
    const TABLE = 'sys_repl_slaves';
12
13
    /** @var Connection */
14
    private $connection;
15
16
    public function __construct(Connection $connection)
17
    {
18
        $this->connection = $connection;
19
    }
20
21
    /**
22
     * @return SysReplSlavesEntity[]
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
     * @param array $where
48
     * @return SysReplSlavesEntity
49
     */
50
    public function fetchOneBy(array $where = [])
51
    {
52
        $queryBuilder = $this->connection->createQueryBuilder()
53
                     ->select('*')
54
                     ->from(self::TABLE)
55
                     ->setMaxResults(1);
56
57
        if (count($where) > 0) {
58
            foreach ($where as $column => $value) {
59
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
60
            }
61
        }
62
63
        $statement = $queryBuilder->execute();
64
65
        $result = $statement->fetch();
66
67
        if ($statement->rowCount() === 0) {
68
            throw new RecordNotFoundException('Record with given where clause not found');
69
        }
70
71
        return $this->getEntityFromDatabaseArray($result);
72
    }
73
74
    /**
75
     * @param array $where
76
     * @return SysReplSlavesEntity[]
77
     */
78
    public function fetchBy(array $where = [])
79
    {
80
        $queryBuilder = $this->connection->createQueryBuilder()
81
                     ->select('*')
82
                     ->from(self::TABLE);
83
84
        if (count($where) > 0) {
85
            foreach ($where as $column => $value) {
86
                $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value));
87
            }
88
        }
89
90
        $statement = $queryBuilder->execute();
91
92
        $result = $statement->fetchAll();
93
94
        if ($statement->rowCount() === 0) {
95
            throw new RecordsNotFoundException('No records with given where clause found');
96
        }
97
98
        $entities = [];
99
100
        foreach ($result as $item) {
101
            $entities[] = $this->getEntityFromDatabaseArray($item);
102
        }
103
104
        return $entities;
105
    }
106
107
    /**
108
     * @param SysReplSlavesEntity $entity
109
     * @return SysReplSlavesEntity
110
     */
111
    public function create(SysReplSlavesEntity $entity)
112
    {
113
        if (!$entity->isNew()) {
114
            throw new RecordAlreadyExistsException('The entity does already exist.');
115
        }
116
117
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
118
119
        $this->connection->insert(
120
                    self::TABLE,
121
                    $databaseArray
122
                );
123
124
        $entity->id = (int) $this->connection->lastInsertId();
125
126
        return $entity;
127
    }
128
129
    /**
130
     * @param SysReplSlavesEntity $entity
131
     * @return SysReplSlavesEntity
132
     */
133
    public function update(SysReplSlavesEntity $entity)
134
    {
135
        if ($entity->isNew()) {
136
            throw new RecordNotPersistedException('The entity does not exist.');
137
        }
138
139
        $databaseArray = $this->getDatabaseArrayFromEntity($entity);
140
141
        $this->connection->update(
142
                    self::TABLE,
143
                    $databaseArray,
144
                    ['id' => $entity->id]
145
                );
146
147
        return $entity;
148
    }
149
150
    /**
151
     * @param SysReplSlavesEntity $entity
152
     * @return SysReplSlavesEntity
153
     */
154
    public function remove(SysReplSlavesEntity $entity)
155
    {
156
        if ($entity->isNew()) {
157
            throw new RecordNotPersistedException('The entity does not exist.');
158
        }
159
160
        $this->connection->delete(
161
                    self::TABLE,
162
                    ['id' => $entity->id]
163
                );
164
165
        $entity->cacheId = null;
166
167
        return $entity;
168
    }
169
170
    /**
171
     * @param SysReplSlavesEntity $entity
172
     * @return []
173
     */
174
    public function getDatabaseArrayFromEntity(SysReplSlavesEntity $entity)
175
    {
176
        return [
177
        'id' => $entity->id,
178
        'server' => $entity->server,
179
        'active' => $entity->active,
180
        'weight' => $entity->weight,
181
        'online' => $entity->online,
182
        'last_check' => $entity->lastCheck,
183
        'time_diff' => $entity->timeDiff,
184
        'current_log_name' => $entity->currentLogName,
185
        'current_log_pos' => $entity->currentLogPos,
186
        ];
187
    }
188
189
    /**
190
     * @param array $data
191
     * @return SysReplSlavesEntity
192
     */
193
    public function getEntityFromDatabaseArray(array $data)
194
    {
195
        $entity = new SysReplSlavesEntity();
196
        $entity->id = $data['id'];
197
        $entity->server = $data['server'];
198
        $entity->active = $data['active'];
199
        $entity->weight = $data['weight'];
200
        $entity->online = $data['online'];
201
        $entity->lastCheck = $data['last_check'];
202
        $entity->timeDiff = $data['time_diff'];
203
        $entity->currentLogName = $data['current_log_name'];
204
        $entity->currentLogPos = $data['current_log_pos'];
205
206
        return $entity;
207
    }
208
}
209