public function testFetchMissingSubdefinitionReturnsDefaultThumbnail() { $definitionMap = new DefinitionMap(['low' => 'missing_subdef']); $thumbHelper = new ThumbHelper($definitionMap); $thumbnail = new Subdef(); $mySubdef = new Subdef(); $record = new Record(); $record->setThumbnail($thumbnail); $record->setSubdefs(new ArrayCollection(['my_subdef' => $mySubdef])); $this->assertSame($thumbnail, $thumbHelper->fetch($record, 'low')); }
public function getFeedEntryItems() { $firstRecord = new Record(); $firstRecord->setMimeType('application/pdf'); $secondRecord = new Record(); $secondRecord->setMimeType('text/plain'); $first = new FeedEntryItem(); $second = new FeedEntryItem(); $first->setRecord($firstRecord); $second->setRecord($secondRecord); return new ArrayCollection([$first, $second]); }
/** * Fetch correct thumbnail according to type (medium or large) * * @param Record|Story $record Record for which to fetch the thumbnail * @param string $type Size of the thumbnail * @return null|\PhraseanetSDK\Entity\Subdef * @throws \InvalidArgumentException */ public function fetch($record, $type) { if (!$record instanceof Record && !$record instanceof Story) { throw new \InvalidArgumentException(); } if (!$this->thumbnailMap->hasSubDefinition($type) || $record instanceof Story) { return $record->getThumbnail(); } $subdefinition = $this->thumbnailMap->getSubDefinition($type); if ($record->getSubdefs()->containsKey($subdefinition)) { return $record->getSubdefs()->get($subdefinition); } return $record->getThumbnail(); }
public function subdefs(Record $record, array $names, $prefix = null) { $defsByName = array(); $subdefs = array(); foreach ($record->getSubdefs() as $subdef) { $defsByName[$subdef->getName()] = $subdef; } foreach ($names as $name) { $fullName = $prefix ? $prefix . '_' . $name : $name; if (!isset($this->subdefsMap[$fullName])) { throw new \RuntimeException('Subdef "' . $fullName . '" is not configured.'); } $defName = $this->subdefsMap[$fullName]; if (isset($defsByName[$defName])) { $subdefs[$name] = $defsByName[$defName]; } } return $subdefs; }
public function testGetUnmappedRecordMultiFieldReturnsEmptyArray() { $map = new FieldMap(['ham' => ['en' => 'bacon'], 'eggs' => ['en' => 'yolk']]); $helper = new MetadataHelper($map, 'en', 'en'); $record = new Record(); $record->setMetadata($this->buildMetadata(['steak' => ['cow', 'ox']])); $this->assertEquals([], $helper->getRecordMultiField($record, 'steak', 'en')); }
public function getRecordHash(Record $record, $instanceName = null) { return base64_encode(sprintf('%s_%s_%s', $instanceName, $record->getDataboxId(), $record->getRecordId())); }
public function getRecordMultiField(Record $record, $field, $locale = null) { if (!$this->fieldsMap->hasAlias($field, $locale)) { return []; } $key = $this->fieldsMap->getFieldName($field, $locale); $values = array(); foreach ($record->getMetadata() as $metadata) { // Try to find the corresponding RecordCaption if ($key === $metadata->getName()) { $values[] = $metadata->getValue(); } } return $values; }