Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROGRAMMES-7180 - add various external contributor profile IDs #299

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
71 changes: 70 additions & 1 deletion src/Data/ProgrammesDb/Entity/Contributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Contributor
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="string", length=511, nullable=true)
*/
private $sortName;

Expand Down Expand Up @@ -109,6 +109,35 @@ class Contributor
*/
private $contributions;

/**
* @var Thing|null
*
* @ORM\ManyToOne(targetEntity="Thing")
* @ORM\JoinColumn(name="thing_id", referencedColumnName="id")
*/
private $thing;

/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $wikidataItemId;

/**
* @var string|null
*
* @ORM\Column(type="text", nullable=true)
*/
private $imdbUri;

/**
* @var string|null
*
* @ORM\Column(type="text", nullable=true)
*/
private $wikipediaUri;

public function __construct(string $pid, string $type)
{
$this->pid = $pid;
Expand Down Expand Up @@ -230,4 +259,44 @@ public function setGender(?string $gender)
{
$this->gender = $gender;
}

public function getThing(): ?Thing
{
return $this->thing;
}

public function setThing(?Thing $thing)
{
$this->thing = $thing;
}

public function getWikidataItemId(): ?string
{
return $this->wikidataItemId;
}

public function setWikidataItemId(?string $wikidataItemId)
{
$this->wikidataItemId = $wikidataItemId;
}

public function getImdbUri(): ?string
{
return $this->imdbUri;
}

public function setImdbUri(?string $imdbUri)
{
$this->imdbUri = $imdbUri;
}

public function getWikipediaUri(): ?string
{
return $this->wikipediaUri;
}

public function setWikipediaUri(?string $wikipediaUri)
{
$this->wikipediaUri = $wikipediaUri;
}
}
72 changes: 72 additions & 0 deletions src/Data/ProgrammesDb/Entity/Thing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace BBC\ProgrammesPagesService\Data\ProgrammesDb\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
* @ORM\Entity(repositoryClass="BBC\ProgrammesPagesService\Data\ProgrammesDb\EntityRepository\ThingRepository")
*/
class Thing
{
use TimestampableEntity;

/**
* @var string
*
* @ORM\Id()
* @ORM\Column(type="string", length=36, nullable=false)
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="text", nullable=false)
*/
private $preferredLabel;

/**
* @var string|null
*
* @ORM\Column(type="text", nullable=true)
*/
private $disambiguationHint;

public function __construct(string $id, string $preferredLabel)
{
$this->id = $id;
$this->preferredLabel = $preferredLabel;
}

public function getId(): string
{
return $this->id;
}

public function setId(string $id)
{
$this->id = $id;
}

public function getPreferredLabel(): string
{
return $this->preferredLabel;
}

public function setPreferredLabel(string $preferredLabel)
{
$this->preferredLabel = $preferredLabel;
}

public function getDisambiguationHint(): ?string
{
return $this->disambiguationHint;
}

public function setDisambiguationHint(?string $disambiguationHint)
{
$this->disambiguationHint = $disambiguationHint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public function findByContributionTo(
$columnName = $columnNameLookup[$type] ?? 'contributionToCoreEntity';

$qb = $this->createQueryBuilder('contribution')
->addSelect(['contributor', 'creditRole'])
->addSelect(['contributor', 'creditRole', 'thing'])
->join('contribution.contributor', 'contributor')
->join('contribution.creditRole', 'creditRole')
->leftJoin('contributor.thing', 'thing')
->andWhere('contribution.' . $columnName . ' IN (:dbIds)')
->orderBy('contribution.position')
->setFirstResult($offset)
Expand Down
27 changes: 27 additions & 0 deletions src/Data/ProgrammesDb/EntityRepository/CoreEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,33 @@ public function coreEntityAncestryGetter(array $ids): array
return $cached;
}

public function findByThing(
string $thingDbId,
?int $limit,
int $offset
): array {
return $this->resolveParents(
$this->getEntityManager()->createQueryBuilder()
->addSelect(['coreEntity', 'image', 'masterBrand', 'mbImage', 'network', 'nwImage'])
->from('ProgrammesPagesService:ProgrammeItem', 'coreEntity')
->leftJoin('coreEntity.image', 'image')
->leftJoin('coreEntity.masterBrand', 'masterBrand')
->leftJoin('masterBrand.image', 'mbImage')
->leftJoin('masterBrand.network', 'network')
->leftJoin('network.image', 'nwImage')
->innerJoin('ProgrammesPagesService:Contribution', 'contribution', Query\Expr\Join::WITH, 'contribution.contributionToCoreEntity = coreEntity')
->innerJoin('contribution.contributor', 'contributor')
->innerJoin('contributor.thing', 'thing')
->where('thing.id = :thingId')
->orderBy('coreEntity.onDemandSortDate', 'DESC')
->setFirstResult($offset)
->setMaxResults($limit)
->setParameter('thingId', $thingDbId)
->getQuery()
->getResult(AbstractQuery::HYDRATE_ARRAY)
);
}

private function findFullCommon(string $entityType): QueryBuilder
{
$this->assertEntityType($entityType, self::ALL_VALID_ENTITY_TYPES);
Expand Down
18 changes: 18 additions & 0 deletions src/Data/ProgrammesDb/EntityRepository/ThingRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace BBC\ProgrammesPagesService\Data\ProgrammesDb\EntityRepository;

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

class ThingRepository extends EntityRepository
{
public function findById(string $id): ?array
{
return $this->createQueryBuilder('thing')
->andWhere('thing.id = :id')
->setParameter('id', $id)
->getQuery()
->getOneOrNullResult(Query::HYDRATE_ARRAY);
}
}
12 changes: 11 additions & 1 deletion src/Domain/Entity/Contributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Contributor
/** @var string|null */
private $musicBrainzId;

/** @var Thing|null */
private $thing;

public function __construct(
int $dbId,
Pid $pid,
Expand All @@ -38,7 +41,8 @@ public function __construct(
?string $sortName = null,
?string $givenName = null,
?string $familyName = null,
?string $musicBrainzId = null
?string $musicBrainzId = null,
?Thing $thing = null
) {
$this->dbId = $dbId;
$this->pid = $pid;
Expand All @@ -48,6 +52,7 @@ public function __construct(
$this->givenName = $givenName;
$this->familyName = $familyName;
$this->musicBrainzId = $musicBrainzId;
$this->thing = $thing;
}

/**
Expand Down Expand Up @@ -95,4 +100,9 @@ public function getMusicBrainzId(): ?string
{
return $this->musicBrainzId;
}

public function getThing(): ?Thing
{
return $this->thing;
}
}
37 changes: 37 additions & 0 deletions src/Domain/Entity/Thing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace BBC\ProgrammesPagesService\Domain\Entity;

class Thing
{
/** @var string */
private $id;

/** @var string */
private $preferredLabel;

/** @var string|null */
private $disambiguationHint;

public function __construct(string $id, string $preferredLabel, ?string $disambiguationHint)
{
$this->id = $id;
$this->preferredLabel = $preferredLabel;
$this->disambiguationHint = $disambiguationHint;
}

public function getId(): string
{
return $this->id;
}

public function getPreferredLabel(): string
{
return $this->preferredLabel;
}

public function getDisambiguationHint(): ?string
{
return $this->disambiguationHint;
}
}
15 changes: 14 additions & 1 deletion src/Mapper/ProgrammesDbToDomain/ContributorMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Contributor;
use BBC\ProgrammesPagesService\Domain\Entity\Thing;
use BBC\ProgrammesPagesService\Domain\ValueObject\Pid;

class ContributorMapper extends AbstractMapper
Expand All @@ -19,6 +20,17 @@ public function getDomainModel(array $dbContributor): Contributor
$cacheKey = $this->getCacheKey($dbContributor);

if (!isset($this->cache[$cacheKey])) {
if (isset($dbContributor['thing'])) {
$dbThing = $dbContributor['thing'];
$thing = new Thing(
$dbThing['id'],
$dbThing['preferredLabel'],
$dbThing['disambiguationHint']
);
} else {
$thing = null;
}

$this->cache[$cacheKey] = new Contributor(
$dbContributor['id'],
new Pid($dbContributor['pid']),
Expand All @@ -27,7 +39,8 @@ public function getDomainModel(array $dbContributor): Contributor
$dbContributor['sortName'],
$dbContributor['givenName'],
$dbContributor['familyName'],
$dbContributor['musicBrainzId']
$dbContributor['musicBrainzId'],
$thing
);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Mapper/ProgrammesDbToDomain/MapperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ public function getServiceMapper(): ServiceMapper
return $this->instances[ServiceMapper::class];
}

public function getThingMapper(): ThingMapper
{
if (!isset($this->instances[ThingMapper::class])) {
$this->instances[ThingMapper::class] = new ThingMapper($this);
}

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

public function getVersionMapper(): VersionMapper
{
if (!isset($this->instances[VersionMapper::class])) {
Expand Down
30 changes: 30 additions & 0 deletions src/Mapper/ProgrammesDbToDomain/ThingMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Thing;

class ThingMapper extends AbstractMapper
{
private $cache = [];

public function getCacheKey(array $dbThing): string
{
return $this->buildCacheKey($dbThing, 'id');
}

public function getDomainModel(array $dbThing): Thing
{
$cacheKey = $this->getCacheKey($dbThing);

if (!isset($this->cache[$cacheKey])) {
$this->cache[$cacheKey] = new Thing(
$dbThing['id'],
$dbThing['preferredLabel'],
$dbThing['disambiguationHint']
);
}

return $this->cache[$cacheKey];
}
}
Loading