| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class AttributeCategoriesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'attribute_categories'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return AttributeCategoriesEntity[] |
|
| 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 AttributeCategoriesEntity |
|
| 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 AttributeCategoriesEntity[] |
|
| 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 AttributeCategoriesEntity $entity |
|
| 109 | * @return AttributeCategoriesEntity |
|
| 110 | */ |
|
| 111 | public function create(AttributeCategoriesEntity $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 AttributeCategoriesEntity $entity |
|
| 131 | * @return AttributeCategoriesEntity |
|
| 132 | */ |
|
| 133 | public function update(AttributeCategoriesEntity $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 AttributeCategoriesEntity $entity |
|
| 152 | * @return AttributeCategoriesEntity |
|
| 153 | */ |
|
| 154 | public function remove(AttributeCategoriesEntity $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 AttributeCategoriesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(AttributeCategoriesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'trans_id' => $entity->transId, |
|
| 180 | 'color' => $entity->color, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return AttributeCategoriesEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new AttributeCategoriesEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->name = $data['name']; |
|
| 193 | $entity->transId = $data['trans_id']; |
|
| 194 | $entity->color = $data['color']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class AttributeGroupsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'attribute_groups'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return AttributeGroupsEntity[] |
|
| 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 AttributeGroupsEntity |
|
| 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 AttributeGroupsEntity[] |
|
| 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 AttributeGroupsEntity $entity |
|
| 109 | * @return AttributeGroupsEntity |
|
| 110 | */ |
|
| 111 | public function create(AttributeGroupsEntity $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 AttributeGroupsEntity $entity |
|
| 131 | * @return AttributeGroupsEntity |
|
| 132 | */ |
|
| 133 | public function update(AttributeGroupsEntity $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 AttributeGroupsEntity $entity |
|
| 152 | * @return AttributeGroupsEntity |
|
| 153 | */ |
|
| 154 | public function remove(AttributeGroupsEntity $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 AttributeGroupsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(AttributeGroupsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'category_id' => $entity->categoryId, |
|
| 179 | 'name' => $entity->name, |
|
| 180 | 'trans_id' => $entity->transId, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return AttributeGroupsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new AttributeGroupsEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->categoryId = $data['category_id']; |
|
| 193 | $entity->name = $data['name']; |
|
| 194 | $entity->transId = $data['trans_id']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheReportReasonsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_report_reasons'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheReportReasonsEntity[] |
|
| 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 GeoCacheReportReasonsEntity |
|
| 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 GeoCacheReportReasonsEntity[] |
|
| 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 GeoCacheReportReasonsEntity $entity |
|
| 109 | * @return GeoCacheReportReasonsEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheReportReasonsEntity $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 GeoCacheReportReasonsEntity $entity |
|
| 131 | * @return GeoCacheReportReasonsEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheReportReasonsEntity $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 GeoCacheReportReasonsEntity $entity |
|
| 152 | * @return GeoCacheReportReasonsEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheReportReasonsEntity $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 GeoCacheReportReasonsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheReportReasonsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'trans_id' => $entity->transId, |
|
| 180 | 'order' => $entity->order, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return GeoCacheReportReasonsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new GeoCacheReportReasonsEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->name = $data['name']; |
|
| 193 | $entity->transId = $data['trans_id']; |
|
| 194 | $entity->order = $data['order']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheVisitsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_visits'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheVisitsEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return GeoCacheVisitsEntity |
|
| 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 GeoCacheVisitsEntity[] |
|
| 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 GeoCacheVisitsEntity $entity |
|
| 109 | * @return GeoCacheVisitsEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheVisitsEntity $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 GeoCacheVisitsEntity $entity |
|
| 131 | * @return GeoCacheVisitsEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheVisitsEntity $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 GeoCacheVisitsEntity $entity |
|
| 152 | * @return GeoCacheVisitsEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheVisitsEntity $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 GeoCacheVisitsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheVisitsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_id' => $entity->cacheId, |
|
| 178 | 'user_id_ip' => $entity->userIdIp, |
|
| 179 | 'count' => $entity->count, |
|
| 180 | 'last_modified' => $entity->lastModified, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return GeoCacheVisitsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new GeoCacheVisitsEntity(); |
|
| 191 | $entity->cacheId = $data['cache_id']; |
|
| 192 | $entity->userIdIp = $data['user_id_ip']; |
|
| 193 | $entity->count = $data['count']; |
|
| 194 | $entity->lastModified = $data['last_modified']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GeodbPolygonsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'geodb_polygons'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeodbPolygonsEntity[] |
|
| 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 GeodbPolygonsEntity |
|
| 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 GeodbPolygonsEntity[] |
|
| 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 GeodbPolygonsEntity $entity |
|
| 109 | * @return GeodbPolygonsEntity |
|
| 110 | */ |
|
| 111 | public function create(GeodbPolygonsEntity $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->polygonId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param GeodbPolygonsEntity $entity |
|
| 131 | * @return GeodbPolygonsEntity |
|
| 132 | */ |
|
| 133 | public function update(GeodbPolygonsEntity $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 | ['polygon_id' => $entity->polygonId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param GeodbPolygonsEntity $entity |
|
| 152 | * @return GeodbPolygonsEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeodbPolygonsEntity $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 | ['polygon_id' => $entity->polygonId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param GeodbPolygonsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeodbPolygonsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'polygon_id' => $entity->polygonId, |
|
| 178 | 'seq_no' => $entity->seqNo, |
|
| 179 | 'lon' => $entity->lon, |
|
| 180 | 'lat' => $entity->lat, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return GeodbPolygonsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new GeodbPolygonsEntity(); |
|
| 191 | $entity->polygonId = $data['polygon_id']; |
|
| 192 | $entity->seqNo = $data['seq_no']; |
|
| 193 | $entity->lon = $data['lon']; |
|
| 194 | $entity->lat = $data['lat']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GnsSearchRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'gns_search'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GnsSearchEntity[] |
|
| 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 GnsSearchEntity |
|
| 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 GnsSearchEntity[] |
|
| 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 GnsSearchEntity $entity |
|
| 109 | * @return GnsSearchEntity |
|
| 110 | */ |
|
| 111 | public function create(GnsSearchEntity $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->uniId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param GnsSearchEntity $entity |
|
| 131 | * @return GnsSearchEntity |
|
| 132 | */ |
|
| 133 | public function update(GnsSearchEntity $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 | ['uni_id' => $entity->uniId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param GnsSearchEntity $entity |
|
| 152 | * @return GnsSearchEntity |
|
| 153 | */ |
|
| 154 | public function remove(GnsSearchEntity $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 | ['uni_id' => $entity->uniId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param GnsSearchEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GnsSearchEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'uni_id' => $entity->uniId, |
|
| 178 | 'sort' => $entity->sort, |
|
| 179 | 'simple' => $entity->simple, |
|
| 180 | 'simplehash' => $entity->simplehash, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return GnsSearchEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new GnsSearchEntity(); |
|
| 191 | $entity->uniId = $data['uni_id']; |
|
| 192 | $entity->sort = $data['sort']; |
|
| 193 | $entity->simple = $data['simple']; |
|
| 194 | $entity->simplehash = $data['simplehash']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class NodesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'nodes'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return NodesEntity[] |
|
| 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 NodesEntity |
|
| 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 NodesEntity[] |
|
| 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 NodesEntity $entity |
|
| 109 | * @return NodesEntity |
|
| 110 | */ |
|
| 111 | public function create(NodesEntity $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 NodesEntity $entity |
|
| 131 | * @return NodesEntity |
|
| 132 | */ |
|
| 133 | public function update(NodesEntity $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 NodesEntity $entity |
|
| 152 | * @return NodesEntity |
|
| 153 | */ |
|
| 154 | public function remove(NodesEntity $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 NodesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(NodesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'url' => $entity->url, |
|
| 180 | 'waypoint_prefix' => $entity->waypointPrefix, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return NodesEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new NodesEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->name = $data['name']; |
|
| 193 | $entity->url = $data['url']; |
|
| 194 | $entity->waypointPrefix = $data['waypoint_prefix']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class NotifyWaitingRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'notify_waiting'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return NotifyWaitingEntity[] |
|
| 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 NotifyWaitingEntity |
|
| 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 NotifyWaitingEntity[] |
|
| 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 NotifyWaitingEntity $entity |
|
| 109 | * @return NotifyWaitingEntity |
|
| 110 | */ |
|
| 111 | public function create(NotifyWaitingEntity $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 NotifyWaitingEntity $entity |
|
| 131 | * @return NotifyWaitingEntity |
|
| 132 | */ |
|
| 133 | public function update(NotifyWaitingEntity $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 NotifyWaitingEntity $entity |
|
| 152 | * @return NotifyWaitingEntity |
|
| 153 | */ |
|
| 154 | public function remove(NotifyWaitingEntity $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 NotifyWaitingEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(NotifyWaitingEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'cache_id' => $entity->cacheId, |
|
| 179 | 'user_id' => $entity->userId, |
|
| 180 | 'type' => $entity->type, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return NotifyWaitingEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new NotifyWaitingEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->cacheId = $data['cache_id']; |
|
| 193 | $entity->userId = $data['user_id']; |
|
| 194 | $entity->type = $data['type']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class NpaTypesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'npa_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 NpaTypesEntity[] |
|
| 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 NpaTypesEntity |
|
| 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 NpaTypesEntity[] |
|
| 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 NpaTypesEntity $entity |
|
| 109 | * @return NpaTypesEntity |
|
| 110 | */ |
|
| 111 | public function create(NpaTypesEntity $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 NpaTypesEntity $entity |
|
| 131 | * @return NpaTypesEntity |
|
| 132 | */ |
|
| 133 | public function update(NpaTypesEntity $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 NpaTypesEntity $entity |
|
| 152 | * @return NpaTypesEntity |
|
| 153 | */ |
|
| 154 | public function remove(NpaTypesEntity $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 NpaTypesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(NpaTypesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'ordinal' => $entity->ordinal, |
|
| 180 | 'no_warning' => $entity->noWarning, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return NpaTypesEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new NpaTypesEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->name = $data['name']; |
|
| 193 | $entity->ordinal = $data['ordinal']; |
|
| 194 | $entity->noWarning = $data['no_warning']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class NutsLayerRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'nuts_layer'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return NutsLayerEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return NutsLayerEntity |
|
| 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 NutsLayerEntity[] |
|
| 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 NutsLayerEntity $entity |
|
| 109 | * @return NutsLayerEntity |
|
| 110 | */ |
|
| 111 | public function create(NutsLayerEntity $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 NutsLayerEntity $entity |
|
| 131 | * @return NutsLayerEntity |
|
| 132 | */ |
|
| 133 | public function update(NutsLayerEntity $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 NutsLayerEntity $entity |
|
| 152 | * @return NutsLayerEntity |
|
| 153 | */ |
|
| 154 | public function remove(NutsLayerEntity $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 NutsLayerEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(NutsLayerEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'level' => $entity->level, |
|
| 179 | 'code' => $entity->code, |
|
| 180 | 'shape' => $entity->shape, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return NutsLayerEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new NutsLayerEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->level = $data['level']; |
|
| 193 | $entity->code = $data['code']; |
|
| 194 | $entity->shape = $data['shape']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiCacheRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_cache'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiCacheEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return OkapiCacheEntity |
|
| 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 OkapiCacheEntity[] |
|
| 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 OkapiCacheEntity $entity |
|
| 109 | * @return OkapiCacheEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiCacheEntity $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->key = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param OkapiCacheEntity $entity |
|
| 131 | * @return OkapiCacheEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiCacheEntity $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 | ['key' => $entity->key] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param OkapiCacheEntity $entity |
|
| 152 | * @return OkapiCacheEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiCacheEntity $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 | ['key' => $entity->key] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param OkapiCacheEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiCacheEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'key' => $entity->key, |
|
| 178 | 'score' => $entity->score, |
|
| 179 | 'expires' => $entity->expires, |
|
| 180 | 'value' => $entity->value, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return OkapiCacheEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new OkapiCacheEntity(); |
|
| 191 | $entity->key = $data['key']; |
|
| 192 | $entity->score = $data['score']; |
|
| 193 | $entity->expires = $data['expires']; |
|
| 194 | $entity->value = $data['value']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiSearchSetsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_search_sets'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiSearchSetsEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return OkapiSearchSetsEntity |
|
| 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 OkapiSearchSetsEntity[] |
|
| 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 OkapiSearchSetsEntity $entity |
|
| 109 | * @return OkapiSearchSetsEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiSearchSetsEntity $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 OkapiSearchSetsEntity $entity |
|
| 131 | * @return OkapiSearchSetsEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiSearchSetsEntity $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 OkapiSearchSetsEntity $entity |
|
| 152 | * @return OkapiSearchSetsEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiSearchSetsEntity $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 OkapiSearchSetsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiSearchSetsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'params_hash' => $entity->paramsHash, |
|
| 179 | 'date_created' => $entity->dateCreated, |
|
| 180 | 'expires' => $entity->expires, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return OkapiSearchSetsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new OkapiSearchSetsEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->paramsHash = $data['params_hash']; |
|
| 193 | $entity->dateCreated = $data['date_created']; |
|
| 194 | $entity->expires = $data['expires']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiTileStatusRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_tile_status'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiTileStatusEntity[] |
|
| 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 OkapiTileStatusEntity |
|
| 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 OkapiTileStatusEntity[] |
|
| 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 OkapiTileStatusEntity $entity |
|
| 109 | * @return OkapiTileStatusEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiTileStatusEntity $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->z = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param OkapiTileStatusEntity $entity |
|
| 131 | * @return OkapiTileStatusEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiTileStatusEntity $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 | ['z' => $entity->z] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param OkapiTileStatusEntity $entity |
|
| 152 | * @return OkapiTileStatusEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiTileStatusEntity $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 | ['z' => $entity->z] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param OkapiTileStatusEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiTileStatusEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'z' => $entity->z, |
|
| 178 | 'x' => $entity->x, |
|
| 179 | 'y' => $entity->y, |
|
| 180 | 'status' => $entity->status, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return OkapiTileStatusEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new OkapiTileStatusEntity(); |
|
| 191 | $entity->z = $data['z']; |
|
| 192 | $entity->x = $data['x']; |
|
| 193 | $entity->y = $data['y']; |
|
| 194 | $entity->status = $data['status']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class ReplicationOverwriteRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'replication_overwrite'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return ReplicationOverwriteEntity[] |
|
| 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 ReplicationOverwriteEntity |
|
| 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 ReplicationOverwriteEntity[] |
|
| 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 ReplicationOverwriteEntity $entity |
|
| 109 | * @return ReplicationOverwriteEntity |
|
| 110 | */ |
|
| 111 | public function create(ReplicationOverwriteEntity $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 ReplicationOverwriteEntity $entity |
|
| 131 | * @return ReplicationOverwriteEntity |
|
| 132 | */ |
|
| 133 | public function update(ReplicationOverwriteEntity $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 ReplicationOverwriteEntity $entity |
|
| 152 | * @return ReplicationOverwriteEntity |
|
| 153 | */ |
|
| 154 | public function remove(ReplicationOverwriteEntity $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 ReplicationOverwriteEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(ReplicationOverwriteEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'type' => $entity->type, |
|
| 179 | 'value' => $entity->value, |
|
| 180 | 'uuid' => $entity->uuid, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return ReplicationOverwriteEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new ReplicationOverwriteEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->type = $data['type']; |
|
| 193 | $entity->value = $data['value']; |
|
| 194 | $entity->uuid = $data['uuid']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SearchIndexRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'search_index'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SearchIndexEntity[] |
|
| 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 SearchIndexEntity |
|
| 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 SearchIndexEntity[] |
|
| 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 SearchIndexEntity $entity |
|
| 109 | * @return SearchIndexEntity |
|
| 110 | */ |
|
| 111 | public function create(SearchIndexEntity $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->objectType = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param SearchIndexEntity $entity |
|
| 131 | * @return SearchIndexEntity |
|
| 132 | */ |
|
| 133 | public function update(SearchIndexEntity $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 | ['object_type' => $entity->objectType] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param SearchIndexEntity $entity |
|
| 152 | * @return SearchIndexEntity |
|
| 153 | */ |
|
| 154 | public function remove(SearchIndexEntity $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 | ['object_type' => $entity->objectType] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param SearchIndexEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SearchIndexEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'object_type' => $entity->objectType, |
|
| 178 | 'cache_id' => $entity->cacheId, |
|
| 179 | 'hash' => $entity->hash, |
|
| 180 | 'count' => $entity->count, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return SearchIndexEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new SearchIndexEntity(); |
|
| 191 | $entity->objectType = $data['object_type']; |
|
| 192 | $entity->cacheId = $data['cache_id']; |
|
| 193 | $entity->hash = $data['hash']; |
|
| 194 | $entity->count = $data['count']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysLoginsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_logins'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysLoginsEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return SysLoginsEntity |
|
| 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 SysLoginsEntity[] |
|
| 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 SysLoginsEntity $entity |
|
| 109 | * @return SysLoginsEntity |
|
| 110 | */ |
|
| 111 | public function create(SysLoginsEntity $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 SysLoginsEntity $entity |
|
| 131 | * @return SysLoginsEntity |
|
| 132 | */ |
|
| 133 | public function update(SysLoginsEntity $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 SysLoginsEntity $entity |
|
| 152 | * @return SysLoginsEntity |
|
| 153 | */ |
|
| 154 | public function remove(SysLoginsEntity $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 SysLoginsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SysLoginsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'date_created' => $entity->dateCreated, |
|
| 179 | 'remote_addr' => $entity->remoteAddr, |
|
| 180 | 'success' => $entity->success, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return SysLoginsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new SysLoginsEntity(); |
|
| 191 | $entity->id = $data['id']; |
|
| 192 | $entity->dateCreated = $data['date_created']; |
|
| 193 | $entity->remoteAddr = $data['remote_addr']; |
|
| 194 | $entity->success = $data['success']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysSessionsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_sessions'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysSessionsEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return SysSessionsEntity |
|
| 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 SysSessionsEntity[] |
|
| 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 SysSessionsEntity $entity |
|
| 109 | * @return SysSessionsEntity |
|
| 110 | */ |
|
| 111 | public function create(SysSessionsEntity $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->uuid = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param SysSessionsEntity $entity |
|
| 131 | * @return SysSessionsEntity |
|
| 132 | */ |
|
| 133 | public function update(SysSessionsEntity $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 | ['uuid' => $entity->uuid] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param SysSessionsEntity $entity |
|
| 152 | * @return SysSessionsEntity |
|
| 153 | */ |
|
| 154 | public function remove(SysSessionsEntity $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 | ['uuid' => $entity->uuid] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param SysSessionsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SysSessionsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'uuid' => $entity->uuid, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'permanent' => $entity->permanent, |
|
| 180 | 'last_login' => $entity->lastLogin, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return SysSessionsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new SysSessionsEntity(); |
|
| 191 | $entity->uuid = $data['uuid']; |
|
| 192 | $entity->userId = $data['user_id']; |
|
| 193 | $entity->permanent = $data['permanent']; |
|
| 194 | $entity->lastLogin = $data['last_login']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysTransTextRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_trans_text'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysTransTextEntity[] |
|
| 23 | */ |
|
| 24 | public function fetchAll() |
|
| 25 | { |
|
| 26 | $statement = $this->connection->createQueryBuilder() |
|
| 27 | ->select('*') |
|
| 28 | ->from(self::TABLE) |
|
| 29 | ->execute(); |
|
| 30 | ||
| 31 | $result = $statement->fetchAll(); |
|
| 32 | ||
| 33 | if ($statement->rowCount() === 0) { |
|
| 34 | throw new RecordsNotFoundException('No records found'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $records = []; |
|
| 38 | ||
| 39 | foreach ($result as $item) { |
|
| 40 | $records[] = $this->getEntityFromDatabaseArray($item); |
|
| 41 | } |
|
| 42 | ||
| 43 | return $records; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @param array $where |
|
| 48 | * @return SysTransTextEntity |
|
| 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 SysTransTextEntity[] |
|
| 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 SysTransTextEntity $entity |
|
| 109 | * @return SysTransTextEntity |
|
| 110 | */ |
|
| 111 | public function create(SysTransTextEntity $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->transId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param SysTransTextEntity $entity |
|
| 131 | * @return SysTransTextEntity |
|
| 132 | */ |
|
| 133 | public function update(SysTransTextEntity $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 | ['trans_id' => $entity->transId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param SysTransTextEntity $entity |
|
| 152 | * @return SysTransTextEntity |
|
| 153 | */ |
|
| 154 | public function remove(SysTransTextEntity $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 | ['trans_id' => $entity->transId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param SysTransTextEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SysTransTextEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'trans_id' => $entity->transId, |
|
| 178 | 'lang' => $entity->lang, |
|
| 179 | 'text' => $entity->text, |
|
| 180 | 'last_modified' => $entity->lastModified, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return SysTransTextEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new SysTransTextEntity(); |
|
| 191 | $entity->transId = $data['trans_id']; |
|
| 192 | $entity->lang = $data['lang']; |
|
| 193 | $entity->text = $data['text']; |
|
| 194 | $entity->lastModified = $data['last_modified']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||
| @@ 9-198 (lines=190) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class UserOptionsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'user_options'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return UserOptionsEntity[] |
|
| 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 UserOptionsEntity |
|
| 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 UserOptionsEntity[] |
|
| 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 UserOptionsEntity $entity |
|
| 109 | * @return UserOptionsEntity |
|
| 110 | */ |
|
| 111 | public function create(UserOptionsEntity $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 UserOptionsEntity $entity |
|
| 131 | * @return UserOptionsEntity |
|
| 132 | */ |
|
| 133 | public function update(UserOptionsEntity $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 UserOptionsEntity $entity |
|
| 152 | * @return UserOptionsEntity |
|
| 153 | */ |
|
| 154 | public function remove(UserOptionsEntity $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 UserOptionsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(UserOptionsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'user_id' => $entity->userId, |
|
| 178 | 'option_id' => $entity->optionId, |
|
| 179 | 'option_visible' => $entity->optionVisible, |
|
| 180 | 'option_value' => $entity->optionValue, |
|
| 181 | ]; |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * @param array $data |
|
| 186 | * @return UserOptionsEntity |
|
| 187 | */ |
|
| 188 | public function getEntityFromDatabaseArray(array $data) |
|
| 189 | { |
|
| 190 | $entity = new UserOptionsEntity(); |
|
| 191 | $entity->userId = $data['user_id']; |
|
| 192 | $entity->optionId = $data['option_id']; |
|
| 193 | $entity->optionVisible = $data['option_visible']; |
|
| 194 | $entity->optionValue = $data['option_value']; |
|
| 195 | ||
| 196 | return $entity; |
|
| 197 | } |
|
| 198 | } |
|
| 199 | ||