| @@ 12-198 (lines=187) @@ | ||
| 9 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 10 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 11 | ||
| 12 | class SecurityRoleHierarchyRepository |
|
| 13 | { |
|
| 14 | const TABLE = 'security_role_hierarchy'; |
|
| 15 | ||
| 16 | /** @var Connection */ |
|
| 17 | private $connection; |
|
| 18 | ||
| 19 | ||
| 20 | public function __construct(Connection $connection) |
|
| 21 | { |
|
| 22 | $this->connection = $connection; |
|
| 23 | } |
|
| 24 | ||
| 25 | ||
| 26 | /** |
|
| 27 | * @return SecurityRoleHierarchyEntity[] |
|
| 28 | */ |
|
| 29 | public function fetchAll() |
|
| 30 | { |
|
| 31 | $statement = $this->connection->createQueryBuilder() |
|
| 32 | ->select('*') |
|
| 33 | ->from(self::TABLE) |
|
| 34 | ->execute(); |
|
| 35 | ||
| 36 | $result = $statement->fetchAll(); |
|
| 37 | ||
| 38 | if ($statement->rowCount() === 0) { |
|
| 39 | throw new RecordsNotFoundException('No records found'); |
|
| 40 | } |
|
| 41 | ||
| 42 | $records = []; |
|
| 43 | ||
| 44 | foreach ($result as $item) { |
|
| 45 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 46 | } |
|
| 47 | ||
| 48 | return $records; |
|
| 49 | } |
|
| 50 | ||
| 51 | ||
| 52 | /** |
|
| 53 | * @return SecurityRoleHierarchyEntity |
|
| 54 | */ |
|
| 55 | public function fetchOneBy(array $where = []) |
|
| 56 | { |
|
| 57 | $queryBuilder = $this->connection->createQueryBuilder() |
|
| 58 | ->select('*') |
|
| 59 | ->from(self::TABLE) |
|
| 60 | ->setMaxResults(1); |
|
| 61 | ||
| 62 | if (count($where) > 0) { |
|
| 63 | foreach ($where as $column => $value) { |
|
| 64 | $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value)); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| 68 | $statement = $queryBuilder->execute(); |
|
| 69 | ||
| 70 | $result = $statement->fetch(); |
|
| 71 | ||
| 72 | if ($statement->rowCount() === 0) { |
|
| 73 | throw new RecordNotFoundException('Record with given where clause not found'); |
|
| 74 | } |
|
| 75 | ||
| 76 | return $this->getEntityFromDatabaseArray($result); |
|
| 77 | } |
|
| 78 | ||
| 79 | ||
| 80 | /** |
|
| 81 | * @return SecurityRoleHierarchyEntity[] |
|
| 82 | */ |
|
| 83 | public function fetchBy(array $where = []) |
|
| 84 | { |
|
| 85 | $queryBuilder = $this->connection->createQueryBuilder() |
|
| 86 | ->select('*') |
|
| 87 | ->from(self::TABLE); |
|
| 88 | ||
| 89 | if (count($where) > 0) { |
|
| 90 | foreach ($where as $column => $value) { |
|
| 91 | $queryBuilder->andWhere($column . ' = ' . $queryBuilder->createNamedParameter($value)); |
|
| 92 | } |
|
| 93 | } |
|
| 94 | ||
| 95 | $statement = $queryBuilder->execute(); |
|
| 96 | ||
| 97 | $result = $statement->fetchAll(); |
|
| 98 | ||
| 99 | if ($statement->rowCount() === 0) { |
|
| 100 | throw new RecordsNotFoundException('No records with given where clause found'); |
|
| 101 | } |
|
| 102 | ||
| 103 | $entities = []; |
|
| 104 | ||
| 105 | foreach ($result as $item) { |
|
| 106 | $entities[] = $this->getEntityFromDatabaseArray($item); |
|
| 107 | } |
|
| 108 | ||
| 109 | return $entities; |
|
| 110 | } |
|
| 111 | ||
| 112 | ||
| 113 | /** |
|
| 114 | * @return SecurityRoleHierarchyEntity |
|
| 115 | */ |
|
| 116 | public function create(SecurityRoleHierarchyEntity $entity) |
|
| 117 | { |
|
| 118 | if (!$entity->isNew()) { |
|
| 119 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 120 | } |
|
| 121 | ||
| 122 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 123 | ||
| 124 | $this->connection->insert( |
|
| 125 | self::TABLE, |
|
| 126 | $databaseArray |
|
| 127 | ); |
|
| 128 | ||
| 129 | $entity->roleId = (int)$this->connection->lastInsertId(); |
|
| 130 | ||
| 131 | return $entity; |
|
| 132 | } |
|
| 133 | ||
| 134 | ||
| 135 | /** |
|
| 136 | * @return SecurityRoleHierarchyEntity |
|
| 137 | */ |
|
| 138 | public function update(SecurityRoleHierarchyEntity $entity) |
|
| 139 | { |
|
| 140 | if ($entity->isNew()) { |
|
| 141 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 142 | } |
|
| 143 | ||
| 144 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 145 | ||
| 146 | $this->connection->update( |
|
| 147 | self::TABLE, |
|
| 148 | $databaseArray, |
|
| 149 | ['role_id' => $entity->roleId] |
|
| 150 | ); |
|
| 151 | ||
| 152 | return $entity; |
|
| 153 | } |
|
| 154 | ||
| 155 | ||
| 156 | /** |
|
| 157 | * @return SecurityRoleHierarchyEntity |
|
| 158 | */ |
|
| 159 | public function remove(SecurityRoleHierarchyEntity $entity) |
|
| 160 | { |
|
| 161 | if ($entity->isNew()) { |
|
| 162 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 163 | } |
|
| 164 | ||
| 165 | $this->connection->delete( |
|
| 166 | self::TABLE, |
|
| 167 | ['role_id' => $entity->roleId] |
|
| 168 | ); |
|
| 169 | ||
| 170 | $entity->cacheId = null; |
|
| 171 | ||
| 172 | return $entity; |
|
| 173 | } |
|
| 174 | ||
| 175 | ||
| 176 | /** |
|
| 177 | * @return [] |
|
| 178 | */ |
|
| 179 | public function getDatabaseArrayFromEntity(SecurityRoleHierarchyEntity $entity) |
|
| 180 | { |
|
| 181 | return [ |
|
| 182 | 'role_id' => $entity->roleId, |
|
| 183 | 'sub_role_id' => $entity->subRoleId, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | ||
| 188 | /** |
|
| 189 | * @return SecurityRoleHierarchyEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new SecurityRoleHierarchyEntity(); |
|
| 194 | $entity->roleId = (int)$data['role_id']; |
|
| 195 | $entity->subRoleId = (int)$data['sub_role_id']; |
|
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheIgnoreRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_ignore'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheIgnoreEntity[] |
|
| 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 GeoCacheIgnoreEntity |
|
| 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 GeoCacheIgnoreEntity[] |
|
| 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 GeoCacheIgnoreEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheIgnoreEntity $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 GeoCacheIgnoreEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheIgnoreEntity $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 GeoCacheIgnoreEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheIgnoreEntity $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(GeoCacheIgnoreEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_id' => $entity->cacheId, |
|
| 172 | 'user_id' => $entity->userId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheIgnoreEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheIgnoreEntity(); |
|
| 182 | $entity->cacheId = (int) $data['cache_id']; |
|
| 183 | $entity->userId = (int) $data['user_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheListItemsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_list_items'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheListItemsEntity[] |
|
| 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 GeoCacheListItemsEntity |
|
| 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 GeoCacheListItemsEntity[] |
|
| 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 GeoCacheListItemsEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheListItemsEntity $entity) |
|
| 109 | { |
|
| 110 | if (!$entity->isNew()) { |
|
| 111 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 112 | } |
|
| 113 | ||
| 114 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 115 | ||
| 116 | $this->connection->insert( |
|
| 117 | self::TABLE, |
|
| 118 | $databaseArray |
|
| 119 | ); |
|
| 120 | ||
| 121 | $entity->cacheListId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return GeoCacheListItemsEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheListItemsEntity $entity) |
|
| 130 | { |
|
| 131 | if ($entity->isNew()) { |
|
| 132 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 133 | } |
|
| 134 | ||
| 135 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 136 | ||
| 137 | $this->connection->update( |
|
| 138 | self::TABLE, |
|
| 139 | $databaseArray, |
|
| 140 | ['cache_list_id' => $entity->cacheListId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return GeoCacheListItemsEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheListItemsEntity $entity) |
|
| 150 | { |
|
| 151 | if ($entity->isNew()) { |
|
| 152 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 153 | } |
|
| 154 | ||
| 155 | $this->connection->delete( |
|
| 156 | self::TABLE, |
|
| 157 | ['cache_list_id' => $entity->cacheListId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(GeoCacheListItemsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_list_id' => $entity->cacheListId, |
|
| 172 | 'cache_id' => $entity->cacheId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheListItemsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheListItemsEntity(); |
|
| 182 | $entity->cacheListId = (int) $data['cache_list_id']; |
|
| 183 | $entity->cacheId = (int) $data['cache_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheListWatchesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_list_watches'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheListWatchesEntity[] |
|
| 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 GeoCacheListWatchesEntity |
|
| 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 GeoCacheListWatchesEntity[] |
|
| 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 GeoCacheListWatchesEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheListWatchesEntity $entity) |
|
| 109 | { |
|
| 110 | if (!$entity->isNew()) { |
|
| 111 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 112 | } |
|
| 113 | ||
| 114 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 115 | ||
| 116 | $this->connection->insert( |
|
| 117 | self::TABLE, |
|
| 118 | $databaseArray |
|
| 119 | ); |
|
| 120 | ||
| 121 | $entity->cacheListId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return GeoCacheListWatchesEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheListWatchesEntity $entity) |
|
| 130 | { |
|
| 131 | if ($entity->isNew()) { |
|
| 132 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 133 | } |
|
| 134 | ||
| 135 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 136 | ||
| 137 | $this->connection->update( |
|
| 138 | self::TABLE, |
|
| 139 | $databaseArray, |
|
| 140 | ['cache_list_id' => $entity->cacheListId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return GeoCacheListWatchesEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheListWatchesEntity $entity) |
|
| 150 | { |
|
| 151 | if ($entity->isNew()) { |
|
| 152 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 153 | } |
|
| 154 | ||
| 155 | $this->connection->delete( |
|
| 156 | self::TABLE, |
|
| 157 | ['cache_list_id' => $entity->cacheListId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(GeoCacheListWatchesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_list_id' => $entity->cacheListId, |
|
| 172 | 'user_id' => $entity->userId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheListWatchesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheListWatchesEntity(); |
|
| 182 | $entity->cacheListId = (int) $data['cache_list_id']; |
|
| 183 | $entity->userId = (int) $data['user_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheLogtypeRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_logtype'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheLogtypeEntity[] |
|
| 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 GeoCacheLogtypeEntity |
|
| 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 GeoCacheLogtypeEntity[] |
|
| 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 GeoCacheLogtypeEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheLogtypeEntity $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->cacheTypeId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return GeoCacheLogtypeEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheLogtypeEntity $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_type_id' => $entity->cacheTypeId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return GeoCacheLogtypeEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheLogtypeEntity $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_type_id' => $entity->cacheTypeId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(GeoCacheLogtypeEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_type_id' => $entity->cacheTypeId, |
|
| 172 | 'log_type_id' => $entity->logTypeId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheLogtypeEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheLogtypeEntity(); |
|
| 182 | $entity->cacheTypeId = (int) $data['cache_type_id']; |
|
| 183 | $entity->logTypeId = (int) $data['log_type_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheMapsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_maps'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheMapsEntity[] |
|
| 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 GeoCacheMapsEntity |
|
| 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 GeoCacheMapsEntity[] |
|
| 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 GeoCacheMapsEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheMapsEntity $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 GeoCacheMapsEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheMapsEntity $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 GeoCacheMapsEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheMapsEntity $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(GeoCacheMapsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_id' => $entity->cacheId, |
|
| 172 | 'last_refresh' => $entity->lastRefresh, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheMapsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheMapsEntity(); |
|
| 182 | $entity->cacheId = (int) $data['cache_id']; |
|
| 183 | $entity->lastRefresh = new DateTime($data['last_refresh']); |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CachesAttributesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'caches_attributes'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCachesAttributesEntity[] |
|
| 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 GeoCachesAttributesEntity |
|
| 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 GeoCachesAttributesEntity[] |
|
| 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 GeoCachesAttributesEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCachesAttributesEntity $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 GeoCachesAttributesEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCachesAttributesEntity $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 GeoCachesAttributesEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCachesAttributesEntity $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(GeoCachesAttributesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_id' => $entity->cacheId, |
|
| 172 | 'attrib_id' => $entity->attribId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCachesAttributesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCachesAttributesEntity(); |
|
| 182 | $entity->cacheId = (int) $data['cache_id']; |
|
| 183 | $entity->attribId = (int) $data['attrib_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheWatchesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_watches'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheWatchesEntity[] |
|
| 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 GeoCacheWatchesEntity |
|
| 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 GeoCacheWatchesEntity[] |
|
| 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 GeoCacheWatchesEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheWatchesEntity $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 GeoCacheWatchesEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheWatchesEntity $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 GeoCacheWatchesEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheWatchesEntity $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(GeoCacheWatchesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_id' => $entity->cacheId, |
|
| 172 | 'user_id' => $entity->userId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheWatchesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheWatchesEntity(); |
|
| 182 | $entity->cacheId = (int) $data['cache_id']; |
|
| 183 | $entity->userId = (int) $data['user_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheWaypointPoolRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_waypoint_pool'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheWaypointPoolEntity[] |
|
| 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 GeoCacheWaypointPoolEntity |
|
| 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 GeoCacheWaypointPoolEntity[] |
|
| 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 GeoCacheWaypointPoolEntity |
|
| 107 | */ |
|
| 108 | public function create(GeoCacheWaypointPoolEntity $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->wpOc = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return GeoCacheWaypointPoolEntity |
|
| 128 | */ |
|
| 129 | public function update(GeoCacheWaypointPoolEntity $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 | ['wp_oc' => $entity->wpOc] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return GeoCacheWaypointPoolEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeoCacheWaypointPoolEntity $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 | ['wp_oc' => $entity->wpOc] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(GeoCacheWaypointPoolEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'wp_oc' => $entity->wpOc, |
|
| 172 | 'uuid' => $entity->uuid, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeoCacheWaypointPoolEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeoCacheWaypointPoolEntity(); |
|
| 182 | $entity->wpOc = (string) $data['wp_oc']; |
|
| 183 | $entity->uuid = (string) $data['uuid']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CountriesListDefaultRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'countries_list_default'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return CountriesListDefaultEntity[] |
|
| 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 CountriesListDefaultEntity |
|
| 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 CountriesListDefaultEntity[] |
|
| 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 CountriesListDefaultEntity |
|
| 107 | */ |
|
| 108 | public function create(CountriesListDefaultEntity $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->lang = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return CountriesListDefaultEntity |
|
| 128 | */ |
|
| 129 | public function update(CountriesListDefaultEntity $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 | ['lang' => $entity->lang] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return CountriesListDefaultEntity |
|
| 148 | */ |
|
| 149 | public function remove(CountriesListDefaultEntity $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 | ['lang' => $entity->lang] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(CountriesListDefaultEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'lang' => $entity->lang, |
|
| 172 | 'show' => $entity->show, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return CountriesListDefaultEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new CountriesListDefaultEntity(); |
|
| 182 | $entity->lang = (string) $data['lang']; |
|
| 183 | $entity->show = (string) $data['show']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GeodbLocationsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'geodb_locations'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeodbLocationsEntity[] |
|
| 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 GeodbLocationsEntity |
|
| 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 GeodbLocationsEntity[] |
|
| 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 GeodbLocationsEntity |
|
| 107 | */ |
|
| 108 | public function create(GeodbLocationsEntity $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->locId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return GeodbLocationsEntity |
|
| 128 | */ |
|
| 129 | public function update(GeodbLocationsEntity $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 | ['loc_id' => $entity->locId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return GeodbLocationsEntity |
|
| 148 | */ |
|
| 149 | public function remove(GeodbLocationsEntity $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 | ['loc_id' => $entity->locId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(GeodbLocationsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'loc_id' => $entity->locId, |
|
| 172 | 'loc_type' => $entity->locType, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GeodbLocationsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GeodbLocationsEntity(); |
|
| 182 | $entity->locId = (int) $data['loc_id']; |
|
| 183 | $entity->locType = (int) $data['loc_type']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GkItemTypeRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gk_item_type'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GkItemTypeEntity[] |
|
| 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 GkItemTypeEntity |
|
| 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 GkItemTypeEntity[] |
|
| 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 GkItemTypeEntity |
|
| 107 | */ |
|
| 108 | public function create(GkItemTypeEntity $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 GkItemTypeEntity |
|
| 128 | */ |
|
| 129 | public function update(GkItemTypeEntity $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 GkItemTypeEntity |
|
| 148 | */ |
|
| 149 | public function remove(GkItemTypeEntity $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(GkItemTypeEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GkItemTypeEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GkItemTypeEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GkItemWaypointRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gk_item_waypoint'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GkItemWaypointEntity[] |
|
| 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 GkItemWaypointEntity |
|
| 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 GkItemWaypointEntity[] |
|
| 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 GkItemWaypointEntity |
|
| 107 | */ |
|
| 108 | public function create(GkItemWaypointEntity $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 GkItemWaypointEntity |
|
| 128 | */ |
|
| 129 | public function update(GkItemWaypointEntity $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 GkItemWaypointEntity |
|
| 148 | */ |
|
| 149 | public function remove(GkItemWaypointEntity $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(GkItemWaypointEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'wp' => $entity->wp, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GkItemWaypointEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GkItemWaypointEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->wp = (string) $data['wp']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GkMoveTypeRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gk_move_type'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GkMoveTypeEntity[] |
|
| 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 GkMoveTypeEntity |
|
| 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 GkMoveTypeEntity[] |
|
| 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 GkMoveTypeEntity |
|
| 107 | */ |
|
| 108 | public function create(GkMoveTypeEntity $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 GkMoveTypeEntity |
|
| 128 | */ |
|
| 129 | public function update(GkMoveTypeEntity $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 GkMoveTypeEntity |
|
| 148 | */ |
|
| 149 | public function remove(GkMoveTypeEntity $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(GkMoveTypeEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GkMoveTypeEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GkMoveTypeEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GkMoveWaypointRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gk_move_waypoint'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GkMoveWaypointEntity[] |
|
| 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 GkMoveWaypointEntity |
|
| 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 GkMoveWaypointEntity[] |
|
| 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 GkMoveWaypointEntity |
|
| 107 | */ |
|
| 108 | public function create(GkMoveWaypointEntity $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 GkMoveWaypointEntity |
|
| 128 | */ |
|
| 129 | public function update(GkMoveWaypointEntity $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 GkMoveWaypointEntity |
|
| 148 | */ |
|
| 149 | public function remove(GkMoveWaypointEntity $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(GkMoveWaypointEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'wp' => $entity->wp, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GkMoveWaypointEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GkMoveWaypointEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->wp = (string) $data['wp']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GkUserRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gk_user'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GkUserEntity[] |
|
| 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 GkUserEntity |
|
| 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 GkUserEntity[] |
|
| 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 GkUserEntity |
|
| 107 | */ |
|
| 108 | public function create(GkUserEntity $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 GkUserEntity |
|
| 128 | */ |
|
| 129 | public function update(GkUserEntity $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 GkUserEntity |
|
| 148 | */ |
|
| 149 | public function remove(GkUserEntity $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(GkUserEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return GkUserEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new GkUserEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class LanguagesListDefaultRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'languages_list_default'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return LanguagesListDefaultEntity[] |
|
| 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 LanguagesListDefaultEntity |
|
| 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 LanguagesListDefaultEntity[] |
|
| 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 LanguagesListDefaultEntity |
|
| 107 | */ |
|
| 108 | public function create(LanguagesListDefaultEntity $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->lang = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return LanguagesListDefaultEntity |
|
| 128 | */ |
|
| 129 | public function update(LanguagesListDefaultEntity $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 | ['lang' => $entity->lang] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return LanguagesListDefaultEntity |
|
| 148 | */ |
|
| 149 | public function remove(LanguagesListDefaultEntity $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 | ['lang' => $entity->lang] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(LanguagesListDefaultEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'lang' => $entity->lang, |
|
| 172 | 'show' => $entity->show, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return LanguagesListDefaultEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new LanguagesListDefaultEntity(); |
|
| 182 | $entity->lang = (string) $data['lang']; |
|
| 183 | $entity->show = (string) $data['show']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class Map2DataRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'map2_data'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return Map2DataEntity[] |
|
| 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 Map2DataEntity |
|
| 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 Map2DataEntity[] |
|
| 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 Map2DataEntity |
|
| 107 | */ |
|
| 108 | public function create(Map2DataEntity $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->resultId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return Map2DataEntity |
|
| 128 | */ |
|
| 129 | public function update(Map2DataEntity $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 | ['result_id' => $entity->resultId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return Map2DataEntity |
|
| 148 | */ |
|
| 149 | public function remove(Map2DataEntity $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 | ['result_id' => $entity->resultId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(Map2DataEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'result_id' => $entity->resultId, |
|
| 172 | 'cache_id' => $entity->cacheId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return Map2DataEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new Map2DataEntity(); |
|
| 182 | $entity->resultId = (int) $data['result_id']; |
|
| 183 | $entity->cacheId = (int) $data['cache_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class MapresultDataRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'mapresult_data'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return MapresultDataEntity[] |
|
| 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 MapresultDataEntity |
|
| 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 MapresultDataEntity[] |
|
| 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 MapresultDataEntity |
|
| 107 | */ |
|
| 108 | public function create(MapresultDataEntity $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->queryId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return MapresultDataEntity |
|
| 128 | */ |
|
| 129 | public function update(MapresultDataEntity $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 | ['query_id' => $entity->queryId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return MapresultDataEntity |
|
| 148 | */ |
|
| 149 | public function remove(MapresultDataEntity $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 | ['query_id' => $entity->queryId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(MapresultDataEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'query_id' => $entity->queryId, |
|
| 172 | 'cache_id' => $entity->cacheId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return MapresultDataEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new MapresultDataEntity(); |
|
| 182 | $entity->queryId = (int) $data['query_id']; |
|
| 183 | $entity->cacheId = (int) $data['cache_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class MapresultRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'mapresult'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return MapresultEntity[] |
|
| 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 MapresultEntity |
|
| 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 MapresultEntity[] |
|
| 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 MapresultEntity |
|
| 107 | */ |
|
| 108 | public function create(MapresultEntity $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->queryId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return MapresultEntity |
|
| 128 | */ |
|
| 129 | public function update(MapresultEntity $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 | ['query_id' => $entity->queryId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return MapresultEntity |
|
| 148 | */ |
|
| 149 | public function remove(MapresultEntity $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 | ['query_id' => $entity->queryId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(MapresultEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'query_id' => $entity->queryId, |
|
| 172 | 'date_created' => $entity->dateCreated, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return MapresultEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new MapresultEntity(); |
|
| 182 | $entity->queryId = (int) $data['query_id']; |
|
| 183 | $entity->dateCreated = new DateTime($data['date_created']); |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class NutsCodesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'nuts_codes'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return NutsCodesEntity[] |
|
| 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 NutsCodesEntity |
|
| 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 NutsCodesEntity[] |
|
| 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 NutsCodesEntity |
|
| 107 | */ |
|
| 108 | public function create(NutsCodesEntity $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->code = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return NutsCodesEntity |
|
| 128 | */ |
|
| 129 | public function update(NutsCodesEntity $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 | ['code' => $entity->code] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return NutsCodesEntity |
|
| 148 | */ |
|
| 149 | public function remove(NutsCodesEntity $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 | ['code' => $entity->code] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(NutsCodesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'code' => $entity->code, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return NutsCodesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new NutsCodesEntity(); |
|
| 182 | $entity->code = (string) $data['code']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class ObjectTypesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'object_types'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return ObjectTypesEntity[] |
|
| 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 ObjectTypesEntity |
|
| 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 ObjectTypesEntity[] |
|
| 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 ObjectTypesEntity |
|
| 107 | */ |
|
| 108 | public function create(ObjectTypesEntity $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 ObjectTypesEntity |
|
| 128 | */ |
|
| 129 | public function update(ObjectTypesEntity $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 ObjectTypesEntity |
|
| 148 | */ |
|
| 149 | public function remove(ObjectTypesEntity $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(ObjectTypesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return ObjectTypesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new ObjectTypesEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiClogRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_clog'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiClogEntity[] |
|
| 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 OkapiClogEntity |
|
| 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 OkapiClogEntity[] |
|
| 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 OkapiClogEntity |
|
| 107 | */ |
|
| 108 | public function create(OkapiClogEntity $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 OkapiClogEntity |
|
| 128 | */ |
|
| 129 | public function update(OkapiClogEntity $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 OkapiClogEntity |
|
| 148 | */ |
|
| 149 | public function remove(OkapiClogEntity $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(OkapiClogEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'data' => $entity->data, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return OkapiClogEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new OkapiClogEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->data = (string) $data['data']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiSearchResultsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_search_results'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiSearchResultsEntity[] |
|
| 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 OkapiSearchResultsEntity |
|
| 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 OkapiSearchResultsEntity[] |
|
| 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 OkapiSearchResultsEntity |
|
| 107 | */ |
|
| 108 | public function create(OkapiSearchResultsEntity $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->setId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return OkapiSearchResultsEntity |
|
| 128 | */ |
|
| 129 | public function update(OkapiSearchResultsEntity $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 | ['set_id' => $entity->setId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return OkapiSearchResultsEntity |
|
| 148 | */ |
|
| 149 | public function remove(OkapiSearchResultsEntity $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 | ['set_id' => $entity->setId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(OkapiSearchResultsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'set_id' => $entity->setId, |
|
| 172 | 'cache_id' => $entity->cacheId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return OkapiSearchResultsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new OkapiSearchResultsEntity(); |
|
| 182 | $entity->setId = (int) $data['set_id']; |
|
| 183 | $entity->cacheId = (int) $data['cache_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiVarsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_vars'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiVarsEntity[] |
|
| 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 OkapiVarsEntity |
|
| 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 OkapiVarsEntity[] |
|
| 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 OkapiVarsEntity |
|
| 107 | */ |
|
| 108 | public function create(OkapiVarsEntity $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->var = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return OkapiVarsEntity |
|
| 128 | */ |
|
| 129 | public function update(OkapiVarsEntity $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 | ['var' => $entity->var] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return OkapiVarsEntity |
|
| 148 | */ |
|
| 149 | public function remove(OkapiVarsEntity $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 | ['var' => $entity->var] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(OkapiVarsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'var' => $entity->var, |
|
| 172 | 'value' => $entity->value, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return OkapiVarsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new OkapiVarsEntity(); |
|
| 182 | $entity->var = (string) $data['var']; |
|
| 183 | $entity->value = (string) $data['value']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class RatingTopsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'rating_tops'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return RatingTopsEntity[] |
|
| 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 RatingTopsEntity |
|
| 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 RatingTopsEntity[] |
|
| 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 RatingTopsEntity |
|
| 107 | */ |
|
| 108 | public function create(RatingTopsEntity $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 RatingTopsEntity |
|
| 128 | */ |
|
| 129 | public function update(RatingTopsEntity $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 RatingTopsEntity |
|
| 148 | */ |
|
| 149 | public function remove(RatingTopsEntity $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(RatingTopsEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'cache_id' => $entity->cacheId, |
|
| 172 | 'rating' => $entity->rating, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return RatingTopsEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new RatingTopsEntity(); |
|
| 182 | $entity->cacheId = (int) $data['cache_id']; |
|
| 183 | $entity->rating = (int) $data['rating']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysconfigRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sysconfig'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysconfigEntity[] |
|
| 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 SysconfigEntity |
|
| 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 SysconfigEntity[] |
|
| 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 SysconfigEntity |
|
| 107 | */ |
|
| 108 | public function create(SysconfigEntity $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->name = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return SysconfigEntity |
|
| 128 | */ |
|
| 129 | public function update(SysconfigEntity $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 | ['name' => $entity->name] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return SysconfigEntity |
|
| 148 | */ |
|
| 149 | public function remove(SysconfigEntity $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 | ['name' => $entity->name] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(SysconfigEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'name' => $entity->name, |
|
| 172 | 'value' => $entity->value, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return SysconfigEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new SysconfigEntity(); |
|
| 182 | $entity->name = (string) $data['name']; |
|
| 183 | $entity->value = (string) $data['value']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysCronRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_cron'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysCronEntity[] |
|
| 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 SysCronEntity |
|
| 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 SysCronEntity[] |
|
| 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 SysCronEntity |
|
| 107 | */ |
|
| 108 | public function create(SysCronEntity $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->name = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return SysCronEntity |
|
| 128 | */ |
|
| 129 | public function update(SysCronEntity $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 | ['name' => $entity->name] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return SysCronEntity |
|
| 148 | */ |
|
| 149 | public function remove(SysCronEntity $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 | ['name' => $entity->name] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(SysCronEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'name' => $entity->name, |
|
| 172 | 'last_run' => $entity->lastRun, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return SysCronEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new SysCronEntity(); |
|
| 182 | $entity->name = (string) $data['name']; |
|
| 183 | $entity->lastRun = new DateTime($data['last_run']); |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysReplExcludeRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_repl_exclude'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysReplExcludeEntity[] |
|
| 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 SysReplExcludeEntity |
|
| 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 SysReplExcludeEntity[] |
|
| 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 SysReplExcludeEntity |
|
| 107 | */ |
|
| 108 | public function create(SysReplExcludeEntity $entity) |
|
| 109 | { |
|
| 110 | if (!$entity->isNew()) { |
|
| 111 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 112 | } |
|
| 113 | ||
| 114 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 115 | ||
| 116 | $this->connection->insert( |
|
| 117 | self::TABLE, |
|
| 118 | $databaseArray |
|
| 119 | ); |
|
| 120 | ||
| 121 | $entity->userId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return SysReplExcludeEntity |
|
| 128 | */ |
|
| 129 | public function update(SysReplExcludeEntity $entity) |
|
| 130 | { |
|
| 131 | if ($entity->isNew()) { |
|
| 132 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 133 | } |
|
| 134 | ||
| 135 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 136 | ||
| 137 | $this->connection->update( |
|
| 138 | self::TABLE, |
|
| 139 | $databaseArray, |
|
| 140 | ['user_id' => $entity->userId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return SysReplExcludeEntity |
|
| 148 | */ |
|
| 149 | public function remove(SysReplExcludeEntity $entity) |
|
| 150 | { |
|
| 151 | if ($entity->isNew()) { |
|
| 152 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 153 | } |
|
| 154 | ||
| 155 | $this->connection->delete( |
|
| 156 | self::TABLE, |
|
| 157 | ['user_id' => $entity->userId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(SysReplExcludeEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'user_id' => $entity->userId, |
|
| 172 | 'datExclude' => $entity->datExclude, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return SysReplExcludeEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new SysReplExcludeEntity(); |
|
| 182 | $entity->userId = (int) $data['user_id']; |
|
| 183 | $entity->datExclude = new DateTime($data['datExclude']); |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysReplTimestampRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_repl_timestamp'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysReplTimestampEntity[] |
|
| 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 SysReplTimestampEntity |
|
| 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 SysReplTimestampEntity[] |
|
| 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 SysReplTimestampEntity |
|
| 107 | */ |
|
| 108 | public function create(SysReplTimestampEntity $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 SysReplTimestampEntity |
|
| 128 | */ |
|
| 129 | public function update(SysReplTimestampEntity $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 SysReplTimestampEntity |
|
| 148 | */ |
|
| 149 | public function remove(SysReplTimestampEntity $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(SysReplTimestampEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'data' => $entity->data, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return SysReplTimestampEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new SysReplTimestampEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->data = new DateTime($data['data']); |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysTemptablesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_temptables'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysTemptablesEntity[] |
|
| 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 SysTemptablesEntity |
|
| 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 SysTemptablesEntity[] |
|
| 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 SysTemptablesEntity |
|
| 107 | */ |
|
| 108 | public function create(SysTemptablesEntity $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->threadid = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return SysTemptablesEntity |
|
| 128 | */ |
|
| 129 | public function update(SysTemptablesEntity $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 | ['threadid' => $entity->threadid] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return SysTemptablesEntity |
|
| 148 | */ |
|
| 149 | public function remove(SysTemptablesEntity $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 | ['threadid' => $entity->threadid] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(SysTemptablesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'threadid' => $entity->threadid, |
|
| 172 | 'name' => $entity->name, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return SysTemptablesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new SysTemptablesEntity(); |
|
| 182 | $entity->threadid = (int) $data['threadid']; |
|
| 183 | $entity->name = (string) $data['name']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class WatchesLogqueueRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'watches_logqueue'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return WatchesLogqueueEntity[] |
|
| 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 WatchesLogqueueEntity |
|
| 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 WatchesLogqueueEntity[] |
|
| 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 WatchesLogqueueEntity |
|
| 107 | */ |
|
| 108 | public function create(WatchesLogqueueEntity $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->logId = (int) $this->connection->lastInsertId(); |
|
| 122 | ||
| 123 | return $entity; |
|
| 124 | } |
|
| 125 | ||
| 126 | /** |
|
| 127 | * @return WatchesLogqueueEntity |
|
| 128 | */ |
|
| 129 | public function update(WatchesLogqueueEntity $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 | ['log_id' => $entity->logId] |
|
| 141 | ); |
|
| 142 | ||
| 143 | return $entity; |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @return WatchesLogqueueEntity |
|
| 148 | */ |
|
| 149 | public function remove(WatchesLogqueueEntity $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 | ['log_id' => $entity->logId] |
|
| 158 | ); |
|
| 159 | ||
| 160 | $entity->cacheId = null; |
|
| 161 | ||
| 162 | return $entity; |
|
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * @return [] |
|
| 167 | */ |
|
| 168 | public function getDatabaseArrayFromEntity(WatchesLogqueueEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'log_id' => $entity->logId, |
|
| 172 | 'user_id' => $entity->userId, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return WatchesLogqueueEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new WatchesLogqueueEntity(); |
|
| 182 | $entity->logId = (int) $data['log_id']; |
|
| 183 | $entity->userId = (int) $data['user_id']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||
| @@ 9-187 (lines=179) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class WatchesWaitingtypesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'watches_waitingtypes'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return WatchesWaitingtypesEntity[] |
|
| 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 WatchesWaitingtypesEntity |
|
| 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 WatchesWaitingtypesEntity[] |
|
| 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 WatchesWaitingtypesEntity |
|
| 107 | */ |
|
| 108 | public function create(WatchesWaitingtypesEntity $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 WatchesWaitingtypesEntity |
|
| 128 | */ |
|
| 129 | public function update(WatchesWaitingtypesEntity $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 WatchesWaitingtypesEntity |
|
| 148 | */ |
|
| 149 | public function remove(WatchesWaitingtypesEntity $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(WatchesWaitingtypesEntity $entity) |
|
| 169 | { |
|
| 170 | return [ |
|
| 171 | 'id' => $entity->id, |
|
| 172 | 'watchtype' => $entity->watchtype, |
|
| 173 | ]; |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * @return WatchesWaitingtypesEntity |
|
| 178 | */ |
|
| 179 | public function getEntityFromDatabaseArray(array $data) |
|
| 180 | { |
|
| 181 | $entity = new WatchesWaitingtypesEntity(); |
|
| 182 | $entity->id = (int) $data['id']; |
|
| 183 | $entity->watchtype = (string) $data['watchtype']; |
|
| 184 | ||
| 185 | return $entity; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | ||