Code Duplication    Length = 200-200 lines in 3 locations

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 = (string) $data['short'];
197
        $entity->name = (string) $data['name'];
198
        $entity->transId = (int) $data['trans_id'];
199
        $entity->nativeName = (string) $data['native_name'];
200
        $entity->de = (string) $data['de'];
201
        $entity->en = (string) $data['en'];
202
        $entity->listDefaultDe = (int) $data['list_default_de'];
203
        $entity->listDefaultEn = (int) $data['list_default_en'];
204
        $entity->isTranslated = (int) $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 = (int) $data['id'];
197
        $entity->dateCreated = new DateTime($data['date_created']);
198
        $entity->module = (string) $data['module'];
199
        $entity->eventid = (int) $data['eventid'];
200
        $entity->userid = (int) $data['userid'];
201
        $entity->objectid1 = (int) $data['objectid1'];
202
        $entity->objectid2 = (int) $data['objectid2'];
203
        $entity->logtext = (string) $data['logtext'];
204
        $entity->details = (string) $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 = (int) $data['id'];
197
        $entity->name = (string) $data['name'];
198
        $entity->transId = (int) $data['trans_id'];
199
        $entity->internalUse = (int) $data['internal_use'];
200
        $entity->defaultValue = (string) $data['default_value'];
201
        $entity->checkRegex = (string) $data['check_regex'];
202
        $entity->optionOrder = (int) $data['option_order'];
203
        $entity->optionInput = (string) $data['option_input'];
204
        $entity->optionset = (int) $data['optionset'];
205
206
        return $entity;
207
    }
208
}
209