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