| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class EmailUserRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'email_user'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return EmailUserEntity[] |
|
| 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 EmailUserEntity |
|
| 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 EmailUserEntity[] |
|
| 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 EmailUserEntity $entity |
|
| 109 | * @return EmailUserEntity |
|
| 110 | */ |
|
| 111 | public function create(EmailUserEntity $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 EmailUserEntity $entity |
|
| 131 | * @return EmailUserEntity |
|
| 132 | */ |
|
| 133 | public function update(EmailUserEntity $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 EmailUserEntity $entity |
|
| 152 | * @return EmailUserEntity |
|
| 153 | */ |
|
| 154 | public function remove(EmailUserEntity $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 EmailUserEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(EmailUserEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'date_created' => $entity->dateCreated, |
|
| 179 | 'ipaddress' => $entity->ipaddress, |
|
| 180 | 'from_user_id' => $entity->fromUserId, |
|
| 181 | 'from_email' => $entity->fromEmail, |
|
| 182 | 'to_user_id' => $entity->toUserId, |
|
| 183 | 'to_email' => $entity->toEmail, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return EmailUserEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new EmailUserEntity(); |
|
| 194 | $entity->id = $data['id']; |
|
| 195 | $entity->dateCreated = $data['date_created']; |
|
| 196 | $entity->ipaddress = $data['ipaddress']; |
|
| 197 | $entity->fromUserId = $data['from_user_id']; |
|
| 198 | $entity->fromEmail = $data['from_email']; |
|
| 199 | $entity->toUserId = $data['to_user_id']; |
|
| 200 | $entity->toEmail = $data['to_email']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||
| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class OkapiConsumersRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'okapi_consumers'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return OkapiConsumersEntity[] |
|
| 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 OkapiConsumersEntity |
|
| 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 OkapiConsumersEntity[] |
|
| 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 OkapiConsumersEntity $entity |
|
| 109 | * @return OkapiConsumersEntity |
|
| 110 | */ |
|
| 111 | public function create(OkapiConsumersEntity $entity) |
|
| 112 | { |
|
| 113 | if (!$entity->isNew()) { |
|
| 114 | throw new RecordAlreadyExistsException('The entity does already exist.'); |
|
| 115 | } |
|
| 116 | ||
| 117 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 118 | ||
| 119 | $this->connection->insert( |
|
| 120 | self::TABLE, |
|
| 121 | $databaseArray |
|
| 122 | ); |
|
| 123 | ||
| 124 | $entity->key = (int) $this->connection->lastInsertId(); |
|
| 125 | ||
| 126 | return $entity; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param OkapiConsumersEntity $entity |
|
| 131 | * @return OkapiConsumersEntity |
|
| 132 | */ |
|
| 133 | public function update(OkapiConsumersEntity $entity) |
|
| 134 | { |
|
| 135 | if ($entity->isNew()) { |
|
| 136 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $databaseArray = $this->getDatabaseArrayFromEntity($entity); |
|
| 140 | ||
| 141 | $this->connection->update( |
|
| 142 | self::TABLE, |
|
| 143 | $databaseArray, |
|
| 144 | ['key' => $entity->key] |
|
| 145 | ); |
|
| 146 | ||
| 147 | return $entity; |
|
| 148 | } |
|
| 149 | ||
| 150 | /** |
|
| 151 | * @param OkapiConsumersEntity $entity |
|
| 152 | * @return OkapiConsumersEntity |
|
| 153 | */ |
|
| 154 | public function remove(OkapiConsumersEntity $entity) |
|
| 155 | { |
|
| 156 | if ($entity->isNew()) { |
|
| 157 | throw new RecordNotPersistedException('The entity does not exist.'); |
|
| 158 | } |
|
| 159 | ||
| 160 | $this->connection->delete( |
|
| 161 | self::TABLE, |
|
| 162 | ['key' => $entity->key] |
|
| 163 | ); |
|
| 164 | ||
| 165 | $entity->cacheId = null; |
|
| 166 | ||
| 167 | return $entity; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param OkapiConsumersEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(OkapiConsumersEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'key' => $entity->key, |
|
| 178 | 'name' => $entity->name, |
|
| 179 | 'secret' => $entity->secret, |
|
| 180 | 'url' => $entity->url, |
|
| 181 | 'email' => $entity->email, |
|
| 182 | 'date_created' => $entity->dateCreated, |
|
| 183 | 'bflags' => $entity->bflags, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return OkapiConsumersEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new OkapiConsumersEntity(); |
|
| 194 | $entity->key = $data['key']; |
|
| 195 | $entity->name = $data['name']; |
|
| 196 | $entity->secret = $data['secret']; |
|
| 197 | $entity->url = $data['url']; |
|
| 198 | $entity->email = $data['email']; |
|
| 199 | $entity->dateCreated = $data['date_created']; |
|
| 200 | $entity->bflags = $data['bflags']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||
| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class PageRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'page'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return PageEntity[] |
|
| 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 PageEntity |
|
| 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 PageEntity[] |
|
| 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 PageEntity $entity |
|
| 109 | * @return PageEntity |
|
| 110 | */ |
|
| 111 | public function create(PageEntity $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 PageEntity $entity |
|
| 131 | * @return PageEntity |
|
| 132 | */ |
|
| 133 | public function update(PageEntity $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 PageEntity $entity |
|
| 152 | * @return PageEntity |
|
| 153 | */ |
|
| 154 | public function remove(PageEntity $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 PageEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(PageEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'slug' => $entity->slug, |
|
| 179 | 'meta_keywords' => $entity->metaKeywords, |
|
| 180 | 'meta_description' => $entity->metaDescription, |
|
| 181 | 'meta_social' => $entity->metaSocial, |
|
| 182 | 'updated_at' => $entity->updatedAt, |
|
| 183 | 'active' => $entity->active, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return PageEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new PageEntity(); |
|
| 194 | $entity->id = $data['id']; |
|
| 195 | $entity->slug = $data['slug']; |
|
| 196 | $entity->metaKeywords = $data['meta_keywords']; |
|
| 197 | $entity->metaDescription = $data['meta_description']; |
|
| 198 | $entity->metaSocial = $data['meta_social']; |
|
| 199 | $entity->updatedAt = $data['updated_at']; |
|
| 200 | $entity->active = $data['active']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||
| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class StatCacheLogsRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'stat_cache_logs'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return StatCacheLogsEntity[] |
|
| 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 StatCacheLogsEntity |
|
| 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 StatCacheLogsEntity[] |
|
| 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 StatCacheLogsEntity $entity |
|
| 109 | * @return StatCacheLogsEntity |
|
| 110 | */ |
|
| 111 | public function create(StatCacheLogsEntity $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 StatCacheLogsEntity $entity |
|
| 131 | * @return StatCacheLogsEntity |
|
| 132 | */ |
|
| 133 | public function update(StatCacheLogsEntity $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 StatCacheLogsEntity $entity |
|
| 152 | * @return StatCacheLogsEntity |
|
| 153 | */ |
|
| 154 | public function remove(StatCacheLogsEntity $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 StatCacheLogsEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(StatCacheLogsEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'cache_id' => $entity->cacheId, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'found' => $entity->found, |
|
| 180 | 'notfound' => $entity->notfound, |
|
| 181 | 'note' => $entity->note, |
|
| 182 | 'will_attend' => $entity->willAttend, |
|
| 183 | 'maintenance' => $entity->maintenance, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return StatCacheLogsEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new StatCacheLogsEntity(); |
|
| 194 | $entity->cacheId = $data['cache_id']; |
|
| 195 | $entity->userId = $data['user_id']; |
|
| 196 | $entity->found = $data['found']; |
|
| 197 | $entity->notfound = $data['notfound']; |
|
| 198 | $entity->note = $data['note']; |
|
| 199 | $entity->willAttend = $data['will_attend']; |
|
| 200 | $entity->maintenance = $data['maintenance']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||
| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class StatUserRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'stat_user'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return StatUserEntity[] |
|
| 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 StatUserEntity |
|
| 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 StatUserEntity[] |
|
| 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 StatUserEntity $entity |
|
| 109 | * @return StatUserEntity |
|
| 110 | */ |
|
| 111 | public function create(StatUserEntity $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 StatUserEntity $entity |
|
| 131 | * @return StatUserEntity |
|
| 132 | */ |
|
| 133 | public function update(StatUserEntity $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 StatUserEntity $entity |
|
| 152 | * @return StatUserEntity |
|
| 153 | */ |
|
| 154 | public function remove(StatUserEntity $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 StatUserEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(StatUserEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'user_id' => $entity->userId, |
|
| 178 | 'found' => $entity->found, |
|
| 179 | 'notfound' => $entity->notfound, |
|
| 180 | 'note' => $entity->note, |
|
| 181 | 'hidden' => $entity->hidden, |
|
| 182 | 'will_attend' => $entity->willAttend, |
|
| 183 | 'maintenance' => $entity->maintenance, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return StatUserEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new StatUserEntity(); |
|
| 194 | $entity->userId = $data['user_id']; |
|
| 195 | $entity->found = $data['found']; |
|
| 196 | $entity->notfound = $data['notfound']; |
|
| 197 | $entity->note = $data['note']; |
|
| 198 | $entity->hidden = $data['hidden']; |
|
| 199 | $entity->willAttend = $data['will_attend']; |
|
| 200 | $entity->maintenance = $data['maintenance']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||
| @@ 9-204 (lines=196) @@ | ||
| 6 | use Oc\Repository\Exception\RecordNotPersistedException; |
|
| 7 | use Oc\Repository\Exception\RecordsNotFoundException; |
|
| 8 | ||
| 9 | class WatchesWaitingRepository |
|
| 10 | { |
|
| 11 | const TABLE = 'watches_waiting'; |
|
| 12 | ||
| 13 | /** @var Connection */ |
|
| 14 | private $connection; |
|
| 15 | ||
| 16 | public function __construct(Connection $connection) |
|
| 17 | { |
|
| 18 | $this->connection = $connection; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @return WatchesWaitingEntity[] |
|
| 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 WatchesWaitingEntity |
|
| 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 WatchesWaitingEntity[] |
|
| 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 WatchesWaitingEntity $entity |
|
| 109 | * @return WatchesWaitingEntity |
|
| 110 | */ |
|
| 111 | public function create(WatchesWaitingEntity $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 WatchesWaitingEntity $entity |
|
| 131 | * @return WatchesWaitingEntity |
|
| 132 | */ |
|
| 133 | public function update(WatchesWaitingEntity $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 WatchesWaitingEntity $entity |
|
| 152 | * @return WatchesWaitingEntity |
|
| 153 | */ |
|
| 154 | public function remove(WatchesWaitingEntity $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 WatchesWaitingEntity $entity |
|
| 172 | * @return [] |
|
| 173 | */ |
|
| 174 | public function getDatabaseArrayFromEntity(WatchesWaitingEntity $entity) |
|
| 175 | { |
|
| 176 | return [ |
|
| 177 | 'id' => $entity->id, |
|
| 178 | 'user_id' => $entity->userId, |
|
| 179 | 'object_id' => $entity->objectId, |
|
| 180 | 'object_type' => $entity->objectType, |
|
| 181 | 'date_created' => $entity->dateCreated, |
|
| 182 | 'watchtext' => $entity->watchtext, |
|
| 183 | 'watchtype' => $entity->watchtype, |
|
| 184 | ]; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * @param array $data |
|
| 189 | * @return WatchesWaitingEntity |
|
| 190 | */ |
|
| 191 | public function getEntityFromDatabaseArray(array $data) |
|
| 192 | { |
|
| 193 | $entity = new WatchesWaitingEntity(); |
|
| 194 | $entity->id = $data['id']; |
|
| 195 | $entity->userId = $data['user_id']; |
|
| 196 | $entity->objectId = $data['object_id']; |
|
| 197 | $entity->objectType = $data['object_type']; |
|
| 198 | $entity->dateCreated = $data['date_created']; |
|
| 199 | $entity->watchtext = $data['watchtext']; |
|
| 200 | $entity->watchtype = $data['watchtype']; |
|
| 201 | ||
| 202 | return $entity; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||