コード例 #1
0
 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'));
 }
コード例 #2
0
 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]);
 }
コード例 #3
0
 /**
  * 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();
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 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'));
 }
コード例 #6
0
 public function getRecordHash(Record $record, $instanceName = null)
 {
     return base64_encode(sprintf('%s_%s_%s', $instanceName, $record->getDataboxId(), $record->getRecordId()));
 }
コード例 #7
0
 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;
 }