Skip to content

Commit

Permalink
5996 - Brandingtool-specific functionality (#303)
Browse files Browse the repository at this point in the history
functionality to support brandingtool-faucet
  • Loading branch information
gmarinov authored Feb 11, 2020
1 parent 6f10390 commit 8c4e13d
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 6 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,43 @@ This repository is available under the terms of the Apache 2.0 license.
View the [LICENSE file](LICENSE) for more information.

Copyright (c) 2017 BBC


New Yaml
--------

To use PPS, as a minimum pull in bbc/programmes-caching-library, then in services.yml:

```yaml
framework:
cache:
pools:
cache.programmes:
adapter: 'cache.adapter.psr6'
provider: cache.null_provider
services:
cache.null_provider:
class: Symfony\Component\Cache\Adapter\NullAdapter
BBC\ProgrammesCachingLibrary\Cache:
arguments:
- '@cache.null_provider'
- 'nullcache'
BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\MapperFactory: ~
BBC\ProgrammesPagesService\Service\ServiceFactory:
public: true
autowire: true
arguments:
- '@doctrine.orm.programmesdb_entity_manager'
- '@BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\MapperFactory'
- '@BBC\ProgrammesCachingLibrary\Cache'
BBC\ProgrammesPagesService\Service\CoreEntitiesService:
public: true
factory: ['@BBC\ProgrammesPagesService\Service\ServiceFactory', 'getCoreEntitiesService']
# follow the above pattern for other services
```
3 changes: 2 additions & 1 deletion src/Data/ProgrammesDb/Entity/MasterBrand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
* @ORM\Entity()
*
* @ORM\Entity(repositoryClass="BBC\ProgrammesPagesService\Data\ProgrammesDb\EntityRepository\MasterBrandRepository")
*/
class MasterBrand
{
Expand Down
21 changes: 21 additions & 0 deletions src/Data/ProgrammesDb/EntityRepository/MasterBrandRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace BBC\ProgrammesPagesService\Data\ProgrammesDb\EntityRepository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;

class MasterBrandRepository extends EntityRepository
{
public function findByMid(string $mid): ?array
{
$qb = $this->createQueryBuilder('master_brand')
->addSelect(['master_brand', 'network', 'service'])
->leftJoin('master_brand.network', 'network')
->leftJoin('network.defaultService', 'service')
->andWhere('master_brand.mid = :mid')
->setParameter('mid', $mid);

return $qb->getQuery()->getOneOrNullResult(Query::HYDRATE_ARRAY);
}
}
23 changes: 22 additions & 1 deletion src/Domain/Entity/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BBC\ProgrammesPagesService\Domain\ValueObject\Pid;
use BBC\ProgrammesPagesService\Domain\ValueObject\Synopses;
use \DateTimeImmutable;

class Season extends Group
{
Expand All @@ -12,6 +13,12 @@ class Season extends Group
/* @var int */
private $aggregatedBroadcastsCount;

/* @var DateTimeImmutable */
private $endDate;

/* @var DateTimeImmutable */
private $startDate;

public function __construct(
array $dbAncestryIds,
Pid $pid,
Expand All @@ -24,7 +31,9 @@ public function __construct(
int $contributionsCount,
Options $options,
int $aggregatedBroadcastsCount,
?MasterBrand $masterBrand = null
?MasterBrand $masterBrand = null,
?DateTimeImmutable $startDate = null,
?DateTimeImmutable $endDate = null
) {
parent::__construct(
$dbAncestryIds,
Expand All @@ -41,10 +50,22 @@ public function __construct(
);

$this->aggregatedBroadcastsCount = $aggregatedBroadcastsCount;
$this->startDate = $startDate;
$this->endDate = $endDate;
}

public function getAggregatedBroadcastsCount(): int
{
return $this->aggregatedBroadcastsCount;
}

public function getStartDate(): ?DateTimeImmutable
{
return $this->startDate;
}

public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
}
4 changes: 3 additions & 1 deletion src/Mapper/ProgrammesDbToDomain/CoreEntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ private function getSeasonModel($dbGroup): Season
$dbGroup['contributionsCount'],
$this->getOptionsModel($dbGroup),
$dbGroup['aggregatedBroadcastsCount'],
$this->getMasterBrandModel($dbGroup)
$this->getMasterBrandModel($dbGroup),
$this->castDateTime($dbGroup['startDate']),
$this->castDateTime($dbGroup['endDate'])
);
}

Expand Down
31 changes: 31 additions & 0 deletions src/Service/MasterBrandsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace BBC\ProgrammesPagesService\Service;

use BBC\ProgrammesCachingLibrary\CacheInterface;
use BBC\ProgrammesPagesService\Data\ProgrammesDb\EntityRepository\MasterBrandRepository;
use BBC\ProgrammesPagesService\Domain\Entity\MasterBrand;
use BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\MasterBrandMapper;

class MasterBrandsService extends AbstractService
{
/* @var MasterBrandMapper */
protected $mapper;
/* @var MasterBrandRepository */
protected $repository;

public function __construct(
MasterBrandRepository $repository,
MasterBrandMapper $mapper,
CacheInterface $cache
) {
parent::__construct($repository, $mapper, $cache);
}

public function findByMid($mid): ?MasterBrand
{
$result = $this->repository->findByMid($mid);

return $this->mapSingleEntity($result);
}
}
13 changes: 13 additions & 0 deletions src/Service/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public function getNetworksService(): NetworksService
return $this->instances[NetworksService::class];
}

public function getMasterBrandsService(): MasterBrandsService
{
if (!isset($this->instances[MasterBrandsService::class])) {
$this->instances[MasterBrandsService::class] = new MasterBrandsService(
$this->entityManager->getRepository('ProgrammesPagesService:MasterBrand'),
$this->mapperFactory->getMasterBrandMapper(),
$this->cache
);
}

return $this->instances[MasterBrandsService::class];
}

public function getPodcastsService(): PodcastsService
{
if (!isset($this->instances[PodcastsService::class])) {
Expand Down
10 changes: 7 additions & 3 deletions tests/Mapper/ProgrammesDbToDomain/CoreEntityMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ public function testGetDomainModelGallery()

public function testGetDomainModelSeason()
{
$startDate = new DateTimeImmutable('2015-01-03');
$endDate = new DateTimeImmutable('2015-01-03');
$dbEntityArray = [
'id' => 1,
'type' => 'season',
Expand All @@ -481,8 +483,8 @@ public function testGetDomainModelSeason()
'relatedLinksCount' => 2,
'contributionsCount' => 10,
'aggregatedBroadcastsCount' => 100,
'startDate' => new DateTime('2015-01-03'),
'endDate' => new DateTime('2015-01-03'),
'startDate' => $startDate,
'endDate' => $endDate,
'parent' => null,
'masterBrand' => null,
'options' => [],
Expand All @@ -500,7 +502,9 @@ public function testGetDomainModelSeason()
10,
$this->mockOptions,
100,
null
null,
$startDate,
$endDate
);

$mapper = $this->getMapper();
Expand Down

0 comments on commit 8c4e13d

Please sign in to comment.