| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheAdoptionRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_adoption'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheAdoptionEntity[] |
|
| 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 GeoCacheAdoptionEntity |
|
| 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 GeoCacheAdoptionEntity[] |
|
| 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 GeoCacheAdoptionEntity $entity |
|
| 109 | * @return GeoCacheAdoptionEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheAdoptionEntity $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 GeoCacheAdoptionEntity $entity |
|
| 131 | * @return GeoCacheAdoptionEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheAdoptionEntity $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 GeoCacheAdoptionEntity $entity |
|
| 152 | * @return GeoCacheAdoptionEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheAdoptionEntity $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 GeoCacheAdoptionEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheAdoptionEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_id' => $entity->cacheId, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'date_created' => $entity->dateCreated, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeoCacheAdoptionEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeoCacheAdoptionEntity(); |
|
| 190 | $entity->cacheId = $data['cache_id']; |
|
| 191 | $entity->userId = $data['user_id']; |
|
| 192 | $entity->dateCreated = $data['date_created']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheListBookmarksRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_list_bookmarks'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheListBookmarksEntity[] |
|
| 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 GeoCacheListBookmarksEntity |
|
| 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 GeoCacheListBookmarksEntity[] |
|
| 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 GeoCacheListBookmarksEntity $entity |
|
| 109 | * @return GeoCacheListBookmarksEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheListBookmarksEntity $entity) |
|
| 112 | { |
|
| 113 | if (!$entity->isNew()) { |
|
| 114 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 115 | } |
|
| 116 | ||
| 117 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 118 | ||
| 119 | $this->connection->insert( |
|
| 120 | self::TABLE, |
|
| 121 | $databaseArray |
|
| 122 | ); |
|
| 123 | ||
| 124 | $entity->cacheListId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param GeoCacheListBookmarksEntity $entity |
|
| 131 | * @return GeoCacheListBookmarksEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheListBookmarksEntity $entity) |
|
| 134 | { |
|
| 135 | if ($entity->isNew()) { |
|
| 136 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 140 | ||
| 141 | $this->connection->update( |
|
| 142 | self::TABLE, |
|
| 143 | $databaseArray, |
|
| 144 | ['cache_list_id' => $entity->cacheListId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param GeoCacheListBookmarksEntity $entity |
|
| 152 | * @return GeoCacheListBookmarksEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheListBookmarksEntity $entity) |
|
| 155 | { |
|
| 156 | if ($entity->isNew()) { |
|
| 157 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 158 | } |
|
| 159 | ||
| 160 | $this->connection->delete( |
|
| 161 | self::TABLE, |
|
| 162 | ['cache_list_id' => $entity->cacheListId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param GeoCacheListBookmarksEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheListBookmarksEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_list_id' => $entity->cacheListId, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'password' => $entity->password, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeoCacheListBookmarksEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeoCacheListBookmarksEntity(); |
|
| 190 | $entity->cacheListId = $data['cache_list_id']; |
|
| 191 | $entity->userId = $data['user_id']; |
|
| 192 | $entity->password = $data['password']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheNpaAreasRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_npa_areas'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheNpaAreasEntity[] |
|
| 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 GeoCacheNpaAreasEntity |
|
| 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 GeoCacheNpaAreasEntity[] |
|
| 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 GeoCacheNpaAreasEntity $entity |
|
| 109 | * @return GeoCacheNpaAreasEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheNpaAreasEntity $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 GeoCacheNpaAreasEntity $entity |
|
| 131 | * @return GeoCacheNpaAreasEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheNpaAreasEntity $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 GeoCacheNpaAreasEntity $entity |
|
| 152 | * @return GeoCacheNpaAreasEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheNpaAreasEntity $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 GeoCacheNpaAreasEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheNpaAreasEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_id' => $entity->cacheId, |
|
| 178 | 'npa_id' => $entity->npaId, |
|
| 179 | 'calculated' => $entity->calculated, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeoCacheNpaAreasEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeoCacheNpaAreasEntity(); |
|
| 190 | $entity->cacheId = $data['cache_id']; |
|
| 191 | $entity->npaId = $data['npa_id']; |
|
| 192 | $entity->calculated = $data['calculated']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheRatingRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_rating'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeoCacheRatingEntity[] |
|
| 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 GeoCacheRatingEntity |
|
| 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 GeoCacheRatingEntity[] |
|
| 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 GeoCacheRatingEntity $entity |
|
| 109 | * @return GeoCacheRatingEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheRatingEntity $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 GeoCacheRatingEntity $entity |
|
| 131 | * @return GeoCacheRatingEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheRatingEntity $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 GeoCacheRatingEntity $entity |
|
| 152 | * @return GeoCacheRatingEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheRatingEntity $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 GeoCacheRatingEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheRatingEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_id' => $entity->cacheId, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'rating_date' => $entity->ratingDate, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeoCacheRatingEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeoCacheRatingEntity(); |
|
| 190 | $entity->cacheId = $data['cache_id']; |
|
| 191 | $entity->userId = $data['user_id']; |
|
| 192 | $entity->ratingDate = $data['rating_date']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class CacheReportStatusRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'cache_report_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 GeoCacheReportStatusEntity[] |
|
| 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 GeoCacheReportStatusEntity |
|
| 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 GeoCacheReportStatusEntity[] |
|
| 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 GeoCacheReportStatusEntity $entity |
|
| 109 | * @return GeoCacheReportStatusEntity |
|
| 110 | */ |
|
| 111 | public function create(GeoCacheReportStatusEntity $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 GeoCacheReportStatusEntity $entity |
|
| 131 | * @return GeoCacheReportStatusEntity |
|
| 132 | */ |
|
| 133 | public function update(GeoCacheReportStatusEntity $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 GeoCacheReportStatusEntity $entity |
|
| 152 | * @return GeoCacheReportStatusEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeoCacheReportStatusEntity $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 GeoCacheReportStatusEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeoCacheReportStatusEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'trans_id' => $entity->transId, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeoCacheReportStatusEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeoCacheReportStatusEntity(); |
|
| 190 | $entity->id = $data['id']; |
|
| 191 | $entity->name = $data['name']; |
|
| 192 | $entity->transId = $data['trans_id']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class GeodbTypeNamesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'geodb_type_names'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return GeodbTypeNamesEntity[] |
|
| 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 GeodbTypeNamesEntity |
|
| 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 GeodbTypeNamesEntity[] |
|
| 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 GeodbTypeNamesEntity $entity |
|
| 109 | * @return GeodbTypeNamesEntity |
|
| 110 | */ |
|
| 111 | public function create(GeodbTypeNamesEntity $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->typeId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param GeodbTypeNamesEntity $entity |
|
| 131 | * @return GeodbTypeNamesEntity |
|
| 132 | */ |
|
| 133 | public function update(GeodbTypeNamesEntity $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 | ['type_id' => $entity->typeId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param GeodbTypeNamesEntity $entity |
|
| 152 | * @return GeodbTypeNamesEntity |
|
| 153 | */ |
|
| 154 | public function remove(GeodbTypeNamesEntity $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 | ['type_id' => $entity->typeId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param GeodbTypeNamesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(GeodbTypeNamesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'type_id' => $entity->typeId, |
|
| 178 | 'type_locale' => $entity->typeLocale, |
|
| 179 | 'name' => $entity->name, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return GeodbTypeNamesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new GeodbTypeNamesEntity(); |
|
| 190 | $entity->typeId = $data['type_id']; |
|
| 191 | $entity->typeLocale = $data['type_locale']; |
|
| 192 | $entity->name = $data['name']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class HelppagesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'helppages'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return HelppagesEntity[] |
|
| 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 HelppagesEntity |
|
| 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 HelppagesEntity[] |
|
| 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 HelppagesEntity $entity |
|
| 109 | * @return HelppagesEntity |
|
| 110 | */ |
|
| 111 | public function create(HelppagesEntity $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->ocpage = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param HelppagesEntity $entity |
|
| 131 | * @return HelppagesEntity |
|
| 132 | */ |
|
| 133 | public function update(HelppagesEntity $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 | ['ocpage' => $entity->ocpage] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param HelppagesEntity $entity |
|
| 152 | * @return HelppagesEntity |
|
| 153 | */ |
|
| 154 | public function remove(HelppagesEntity $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 | ['ocpage' => $entity->ocpage] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param HelppagesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(HelppagesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'ocpage' => $entity->ocpage, |
|
| 178 | 'language' => $entity->language, |
|
| 179 | 'helppage' => $entity->helppage, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return HelppagesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new HelppagesEntity(); |
|
| 190 | $entity->ocpage = $data['ocpage']; |
|
| 191 | $entity->language = $data['language']; |
|
| 192 | $entity->helppage = $data['helppage']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class LogentriesTypesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'logentries_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 LogentriesTypesEntity[] |
|
| 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 LogentriesTypesEntity |
|
| 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 LogentriesTypesEntity[] |
|
| 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 LogentriesTypesEntity $entity |
|
| 109 | * @return LogentriesTypesEntity |
|
| 110 | */ |
|
| 111 | public function create(LogentriesTypesEntity $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 LogentriesTypesEntity $entity |
|
| 131 | * @return LogentriesTypesEntity |
|
| 132 | */ |
|
| 133 | public function update(LogentriesTypesEntity $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 LogentriesTypesEntity $entity |
|
| 152 | * @return LogentriesTypesEntity |
|
| 153 | */ |
|
| 154 | public function remove(LogentriesTypesEntity $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 LogentriesTypesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(LogentriesTypesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'module' => $entity->module, |
|
| 179 | 'eventname' => $entity->eventname, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return LogentriesTypesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new LogentriesTypesEntity(); |
|
| 190 | $entity->id = $data['id']; |
|
| 191 | $entity->module = $data['module']; |
|
| 192 | $entity->eventname = $data['eventname']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiAuthorizationsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_authorizations'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiAuthorizationsEntity[] |
|
| 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 OkapiAuthorizationsEntity |
|
| 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 OkapiAuthorizationsEntity[] |
|
| 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 OkapiAuthorizationsEntity $entity |
|
| 109 | * @return OkapiAuthorizationsEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiAuthorizationsEntity $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->consumerKey = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param OkapiAuthorizationsEntity $entity |
|
| 131 | * @return OkapiAuthorizationsEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiAuthorizationsEntity $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 | ['consumer_key' => $entity->consumerKey] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param OkapiAuthorizationsEntity $entity |
|
| 152 | * @return OkapiAuthorizationsEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiAuthorizationsEntity $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 | ['consumer_key' => $entity->consumerKey] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param OkapiAuthorizationsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiAuthorizationsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'consumer_key' => $entity->consumerKey, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'last_access_token' => $entity->lastAccessToken, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return OkapiAuthorizationsEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new OkapiAuthorizationsEntity(); |
|
| 190 | $entity->consumerKey = $data['consumer_key']; |
|
| 191 | $entity->userId = $data['user_id']; |
|
| 192 | $entity->lastAccessToken = $data['last_access_token']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiNoncesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_nonces'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiNoncesEntity[] |
|
| 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 OkapiNoncesEntity |
|
| 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 OkapiNoncesEntity[] |
|
| 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 OkapiNoncesEntity $entity |
|
| 109 | * @return OkapiNoncesEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiNoncesEntity $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->consumerKey = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param OkapiNoncesEntity $entity |
|
| 131 | * @return OkapiNoncesEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiNoncesEntity $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 | ['consumer_key' => $entity->consumerKey] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param OkapiNoncesEntity $entity |
|
| 152 | * @return OkapiNoncesEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiNoncesEntity $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 | ['consumer_key' => $entity->consumerKey] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param OkapiNoncesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiNoncesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'consumer_key' => $entity->consumerKey, |
|
| 178 | 'nonce_hash' => $entity->nonceHash, |
|
| 179 | 'timestamp' => $entity->timestamp, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return OkapiNoncesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new OkapiNoncesEntity(); |
|
| 190 | $entity->consumerKey = $data['consumer_key']; |
|
| 191 | $entity->nonceHash = $data['nonce_hash']; |
|
| 192 | $entity->timestamp = $data['timestamp']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiSubmittedObjectsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_submitted_objects'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiSubmittedObjectsEntity[] |
|
| 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 OkapiSubmittedObjectsEntity |
|
| 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 OkapiSubmittedObjectsEntity[] |
|
| 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 OkapiSubmittedObjectsEntity $entity |
|
| 109 | * @return OkapiSubmittedObjectsEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiSubmittedObjectsEntity $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 OkapiSubmittedObjectsEntity $entity |
|
| 131 | * @return OkapiSubmittedObjectsEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiSubmittedObjectsEntity $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 OkapiSubmittedObjectsEntity $entity |
|
| 152 | * @return OkapiSubmittedObjectsEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiSubmittedObjectsEntity $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 OkapiSubmittedObjectsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiSubmittedObjectsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'object_type' => $entity->objectType, |
|
| 178 | 'object_id' => $entity->objectId, |
|
| 179 | 'consumer_key' => $entity->consumerKey, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return OkapiSubmittedObjectsEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new OkapiSubmittedObjectsEntity(); |
|
| 190 | $entity->objectType = $data['object_type']; |
|
| 191 | $entity->objectId = $data['object_id']; |
|
| 192 | $entity->consumerKey = $data['consumer_key']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class ReplicationNotimportedRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'replication_notimported'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return ReplicationNotimportedEntity[] |
|
| 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 ReplicationNotimportedEntity |
|
| 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 ReplicationNotimportedEntity[] |
|
| 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 ReplicationNotimportedEntity $entity |
|
| 109 | * @return ReplicationNotimportedEntity |
|
| 110 | */ |
|
| 111 | public function create(ReplicationNotimportedEntity $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 ReplicationNotimportedEntity $entity |
|
| 131 | * @return ReplicationNotimportedEntity |
|
| 132 | */ |
|
| 133 | public function update(ReplicationNotimportedEntity $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 ReplicationNotimportedEntity $entity |
|
| 152 | * @return ReplicationNotimportedEntity |
|
| 153 | */ |
|
| 154 | public function remove(ReplicationNotimportedEntity $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 ReplicationNotimportedEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(ReplicationNotimportedEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'object_uuid' => $entity->objectUuid, |
|
| 179 | 'object_type' => $entity->objectType, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return ReplicationNotimportedEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new ReplicationNotimportedEntity(); |
|
| 190 | $entity->id = $data['id']; |
|
| 191 | $entity->objectUuid = $data['object_uuid']; |
|
| 192 | $entity->objectType = $data['object_type']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SearchDoublesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'search_doubles'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SearchDoublesEntity[] |
|
| 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 SearchDoublesEntity |
|
| 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 SearchDoublesEntity[] |
|
| 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 SearchDoublesEntity $entity |
|
| 109 | * @return SearchDoublesEntity |
|
| 110 | */ |
|
| 111 | public function create(SearchDoublesEntity $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->hash = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param SearchDoublesEntity $entity |
|
| 131 | * @return SearchDoublesEntity |
|
| 132 | */ |
|
| 133 | public function update(SearchDoublesEntity $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 | ['hash' => $entity->hash] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param SearchDoublesEntity $entity |
|
| 152 | * @return SearchDoublesEntity |
|
| 153 | */ |
|
| 154 | public function remove(SearchDoublesEntity $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 | ['hash' => $entity->hash] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param SearchDoublesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SearchDoublesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'hash' => $entity->hash, |
|
| 178 | 'word' => $entity->word, |
|
| 179 | 'simple' => $entity->simple, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return SearchDoublesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new SearchDoublesEntity(); |
|
| 190 | $entity->hash = $data['hash']; |
|
| 191 | $entity->word = $data['word']; |
|
| 192 | $entity->simple = $data['simple']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SearchIndexTimesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'search_index_times'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SearchIndexTimesEntity[] |
|
| 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 SearchIndexTimesEntity |
|
| 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 SearchIndexTimesEntity[] |
|
| 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 SearchIndexTimesEntity $entity |
|
| 109 | * @return SearchIndexTimesEntity |
|
| 110 | */ |
|
| 111 | public function create(SearchIndexTimesEntity $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 SearchIndexTimesEntity $entity |
|
| 131 | * @return SearchIndexTimesEntity |
|
| 132 | */ |
|
| 133 | public function update(SearchIndexTimesEntity $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 SearchIndexTimesEntity $entity |
|
| 152 | * @return SearchIndexTimesEntity |
|
| 153 | */ |
|
| 154 | public function remove(SearchIndexTimesEntity $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 SearchIndexTimesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SearchIndexTimesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'object_type' => $entity->objectType, |
|
| 178 | 'object_id' => $entity->objectId, |
|
| 179 | 'last_refresh' => $entity->lastRefresh, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return SearchIndexTimesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new SearchIndexTimesEntity(); |
|
| 190 | $entity->objectType = $data['object_type']; |
|
| 191 | $entity->objectId = $data['object_id']; |
|
| 192 | $entity->lastRefresh = $data['last_refresh']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class StatCacheListsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'stat_cache_lists'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return StatCacheListsEntity[] |
|
| 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 StatCacheListsEntity |
|
| 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 StatCacheListsEntity[] |
|
| 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 StatCacheListsEntity $entity |
|
| 109 | * @return StatCacheListsEntity |
|
| 110 | */ |
|
| 111 | public function create(StatCacheListsEntity $entity) |
|
| 112 | { |
|
| 113 | if (!$entity->isNew()) { |
|
| 114 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 115 | } |
|
| 116 | ||
| 117 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 118 | ||
| 119 | $this->connection->insert( |
|
| 120 | self::TABLE, |
|
| 121 | $databaseArray |
|
| 122 | ); |
|
| 123 | ||
| 124 | $entity->cacheListId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param StatCacheListsEntity $entity |
|
| 131 | * @return StatCacheListsEntity |
|
| 132 | */ |
|
| 133 | public function update(StatCacheListsEntity $entity) |
|
| 134 | { |
|
| 135 | if ($entity->isNew()) { |
|
| 136 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 140 | ||
| 141 | $this->connection->update( |
|
| 142 | self::TABLE, |
|
| 143 | $databaseArray, |
|
| 144 | ['cache_list_id' => $entity->cacheListId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param StatCacheListsEntity $entity |
|
| 152 | * @return StatCacheListsEntity |
|
| 153 | */ |
|
| 154 | public function remove(StatCacheListsEntity $entity) |
|
| 155 | { |
|
| 156 | if ($entity->isNew()) { |
|
| 157 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 158 | } |
|
| 159 | ||
| 160 | $this->connection->delete( |
|
| 161 | self::TABLE, |
|
| 162 | ['cache_list_id' => $entity->cacheListId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param StatCacheListsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(StatCacheListsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_list_id' => $entity->cacheListId, |
|
| 178 | 'entries' => $entity->entries, |
|
| 179 | 'watchers' => $entity->watchers, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return StatCacheListsEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new StatCacheListsEntity(); |
|
| 190 | $entity->cacheListId = $data['cache_list_id']; |
|
| 191 | $entity->entries = $data['entries']; |
|
| 192 | $entity->watchers = $data['watchers']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysTransRefRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_trans_ref'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysTransRefEntity[] |
|
| 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 SysTransRefEntity |
|
| 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 SysTransRefEntity[] |
|
| 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 SysTransRefEntity $entity |
|
| 109 | * @return SysTransRefEntity |
|
| 110 | */ |
|
| 111 | public function create(SysTransRefEntity $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 SysTransRefEntity $entity |
|
| 131 | * @return SysTransRefEntity |
|
| 132 | */ |
|
| 133 | public function update(SysTransRefEntity $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 SysTransRefEntity $entity |
|
| 152 | * @return SysTransRefEntity |
|
| 153 | */ |
|
| 154 | public function remove(SysTransRefEntity $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 SysTransRefEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SysTransRefEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'trans_id' => $entity->transId, |
|
| 178 | 'resource_name' => $entity->resourceName, |
|
| 179 | 'line' => $entity->line, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return SysTransRefEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new SysTransRefEntity(); |
|
| 190 | $entity->transId = $data['trans_id']; |
|
| 191 | $entity->resourceName = $data['resource_name']; |
|
| 192 | $entity->line = $data['line']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class SysTransRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'sys_trans'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return SysTransEntity[] |
|
| 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 SysTransEntity |
|
| 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 SysTransEntity[] |
|
| 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 SysTransEntity $entity |
|
| 109 | * @return SysTransEntity |
|
| 110 | */ |
|
| 111 | public function create(SysTransEntity $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 SysTransEntity $entity |
|
| 131 | * @return SysTransEntity |
|
| 132 | */ |
|
| 133 | public function update(SysTransEntity $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 SysTransEntity $entity |
|
| 152 | * @return SysTransEntity |
|
| 153 | */ |
|
| 154 | public function remove(SysTransEntity $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 SysTransEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(SysTransEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'text' => $entity->text, |
|
| 179 | 'last_modified' => $entity->lastModified, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return SysTransEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new SysTransEntity(); |
|
| 190 | $entity->id = $data['id']; |
|
| 191 | $entity->text = $data['text']; |
|
| 192 | $entity->lastModified = $data['last_modified']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class UserDelegatesRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'user_delegates'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return UserDelegatesEntity[] |
|
| 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 UserDelegatesEntity |
|
| 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 UserDelegatesEntity[] |
|
| 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 UserDelegatesEntity $entity |
|
| 109 | * @return UserDelegatesEntity |
|
| 110 | */ |
|
| 111 | public function create(UserDelegatesEntity $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 UserDelegatesEntity $entity |
|
| 131 | * @return UserDelegatesEntity |
|
| 132 | */ |
|
| 133 | public function update(UserDelegatesEntity $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 UserDelegatesEntity $entity |
|
| 152 | * @return UserDelegatesEntity |
|
| 153 | */ |
|
| 154 | public function remove(UserDelegatesEntity $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 UserDelegatesEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(UserDelegatesEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'user_id' => $entity->userId, |
|
| 178 | 'node' => $entity->node, |
|
| 179 | 'date_created' => $entity->dateCreated, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return UserDelegatesEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new UserDelegatesEntity(); |
|
| 190 | $entity->userId = $data['user_id']; |
|
| 191 | $entity->node = $data['node']; |
|
| 192 | $entity->dateCreated = $data['date_created']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class UserStatpicRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'user_statpic'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return UserStatpicEntity[] |
|
| 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 UserStatpicEntity |
|
| 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 UserStatpicEntity[] |
|
| 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 UserStatpicEntity $entity |
|
| 109 | * @return UserStatpicEntity |
|
| 110 | */ |
|
| 111 | public function create(UserStatpicEntity $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 UserStatpicEntity $entity |
|
| 131 | * @return UserStatpicEntity |
|
| 132 | */ |
|
| 133 | public function update(UserStatpicEntity $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 UserStatpicEntity $entity |
|
| 152 | * @return UserStatpicEntity |
|
| 153 | */ |
|
| 154 | public function remove(UserStatpicEntity $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 UserStatpicEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(UserStatpicEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'user_id' => $entity->userId, |
|
| 178 | 'lang' => $entity->lang, |
|
| 179 | 'date_created' => $entity->dateCreated, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return UserStatpicEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new UserStatpicEntity(); |
|
| 190 | $entity->userId = $data['user_id']; |
|
| 191 | $entity->lang = $data['lang']; |
|
| 192 | $entity->dateCreated = $data['date_created']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||
| @@ 9-196 (lines=188) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class XmlsessionDataRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'xmlsession_data'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return XmlsessionDataEntity[] |
|
| 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 XmlsessionDataEntity |
|
| 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 XmlsessionDataEntity[] |
|
| 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 XmlsessionDataEntity $entity |
|
| 109 | * @return XmlsessionDataEntity |
|
| 110 | */ |
|
| 111 | public function create(XmlsessionDataEntity $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->sessionId = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param XmlsessionDataEntity $entity |
|
| 131 | * @return XmlsessionDataEntity |
|
| 132 | */ |
|
| 133 | public function update(XmlsessionDataEntity $entity) |
|
| 134 | { |
|
| 135 | if ($entity->isNew()) { |
|
| 136 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 140 | ||
| 141 | $this->connection->update( |
|
| 142 | self::TABLE, |
|
| 143 | $databaseArray, |
|
| 144 | ['session_id' => $entity->sessionId] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param XmlsessionDataEntity $entity |
|
| 152 | * @return XmlsessionDataEntity |
|
| 153 | */ |
|
| 154 | public function remove(XmlsessionDataEntity $entity) |
|
| 155 | { |
|
| 156 | if ($entity->isNew()) { |
|
| 157 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 158 | } |
|
| 159 | ||
| 160 | $this->connection->delete( |
|
| 161 | self::TABLE, |
|
| 162 | ['session_id' => $entity->sessionId] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param XmlsessionDataEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(XmlsessionDataEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'session_id' => $entity->sessionId, |
|
| 178 | 'object_type' => $entity->objectType, |
|
| 179 | 'object_id' => $entity->objectId, |
|
| 180 | ]; |
|
| 181 | } |
|
| 182 | ||
| 183 | /** |
|
| 184 | * @param array $data |
|
| 185 | * @return XmlsessionDataEntity |
|
| 186 | */ |
|
| 187 | public function getEntityFromDatabaseArray(array $data) |
|
| 188 | { |
|
| 189 | $entity = new XmlsessionDataEntity(); |
|
| 190 | $entity->sessionId = $data['session_id']; |
|
| 191 | $entity->objectType = $data['object_type']; |
|
| 192 | $entity->objectId = $data['object_id']; |
|
| 193 | ||
| 194 | return $entity; |
|
| 195 | } |
|
| 196 | } |
|
| 197 | ||