Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SonicJalopy/3308d163b4888186c29a to your computer and use it in GitHub Desktop.
Save SonicJalopy/3308d163b4888186c29a to your computer and use it in GitHub Desktop.
<?php
namespace Application\Search;
use Application\Model\Repository\BillRepositoryInterface;
use Application\Model\Repository\BillProfileRepositoryInterface;
class BillSearchResultBillProfileKeywordsDecorator implements BillSearchResultDecoratorInterface
{
/**
* @var array
*/
protected $profileIds = [];
/**
* Add keywords to a single search result
*
* @param BillSearchResult $result
* @param array $profileIds
* @return BillSearchResult
*/
public function decorate(BillSearchResult $result)
{
$billId = $result->getId();
$profileIds = $this->getProfileIds();
$keywords = $this->getBillProfilesKeywords($billId, $profileIds);
$result->setOptionalFieldCollection(
new BillProfileKeywordsOptionFieldDecorator(
$result->getOptionalFieldCollection(),
OptionalField::billProfileKeywords($keywords)
)
);
return $result;
}
/**
* Add keywords to each search result in a collection
*
* @param BillSearchResultCollection $collection
* @param array $profileIds
* @return BillSearchResultCollection
*/
public function decorateAll(BillSearchResultCollection $collection)
{
$results = $collection->getResults();
$profileIds = $this->getProfileIds();
foreach ($results as $i => $result) {
$billId = $result->getId();
$keywords = $this->getBillProfilesKeywords($billId, $profileIds);
$result->setOptionalFieldCollection(
new BillProfileKeywordsOptionFieldDecorator(
$result->getOptionalFieldCollection(),
OptionalField::billProfileKeywords('Keyword '.$billId)
)
);
}
return $collection;
}
/**
* @return array
*/
public function getProfileIds()
{
return $this->profileIds;
}
/**
* @param array $profileIds
*/
public function setProfileIds($profileIds)
{
$this->profileIds = $profileIds;
}
/**
* @param int $billId
* @param array $profileIds
*/
public function getBillProfilesKeywords($billId, $profileIds)
{
$keywords = 'Placeholder'; // Actually get this from the below yet-to-be-written code
/*
* Here I need to reference BillProfile->keywords for each profile for a given bill and return a keywords array in the form:
* array('profileName1' => 'keywords, 'profileName2' => 'keywords');
*
* There is a chance we could be right back at square one after this given the potential bloat of using Doctrine
* at all for large datasets and I may need to attempt raw SQL or look back at a paginated option where only 100 results
* are fetched at a time from ES and therefore only 100 at a time are decorated
*/
return $keywords;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment