Skip to content

Commit

Permalink
Merge pull request #94 from alchemy-fr/PARADE-900-use-searchraw
Browse files Browse the repository at this point in the history
PARADE-900 use searchraw
  • Loading branch information
xrousset78800 authored Jun 27, 2024
2 parents 7c61d64 + db51ae6 commit a5b6d01
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 65 deletions.
38 changes: 4 additions & 34 deletions src/PhraseanetSDK/Entity/Permalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ public static function fromValue(\stdClass $value)
*/
protected $source;

/**
* @var \DateTimeInterface
*/
protected $createdOn;

/**
* @var \DateTimeInterface
*/
protected $updatedOn;

/**
* @param \stdClass $source
*/
Expand All @@ -57,7 +47,7 @@ public function getRawData()
*/
public function getId()
{
return $this->source->id;
return isset($this->source->id) ? $this->source->id : 0;
}

/**
Expand All @@ -67,7 +57,7 @@ public function getId()
*/
public function isActivated()
{
return $this->source->is_activated;
return !empty($this->getUrl()) ? true : false;
}

/**
Expand All @@ -77,27 +67,7 @@ public function isActivated()
*/
public function getLabel()
{
return $this->source->label;
}

/**
* Last updated date
*
* @return \DateTime
*/
public function getUpdatedOn()
{
return $this->updatedOn ?: $this->updatedOn = new \DateTime($this->source->updated_on);
}

/**
* Creation date
*
* @return \DateTime
*/
public function getCreatedOn()
{
return $this->createdOn ?: $this->createdOn = new \DateTime($this->source->created_on);
return isset($this->source->label) ? $this->source->label : '';
}

/**
Expand All @@ -117,6 +87,6 @@ public function getPageUrl()
*/
public function getUrl()
{
return $this->source->url;
return isset($this->source->url) ? $this->source->url : '' ;
}
}
37 changes: 28 additions & 9 deletions src/PhraseanetSDK/Entity/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getBaseId()
*/
public function getTitle()
{
return $this->source->title;
return isset($this->source->title->default) ? $this->source->title->default : $this->source->title;
}

/**
Expand All @@ -157,7 +157,7 @@ public function getTitle()
*/
public function getMimeType()
{
return $this->source->mime_type;
return isset($this->source->mime) ? $this->source->mime : $this->source->mime_type;
}

/**
Expand Down Expand Up @@ -218,11 +218,16 @@ public function getSha256()
*/
public function getThumbnail()
{
if (! isset($this->source->thumbnail)) {
if (isset($this->source->subdefs->thumbnail)) {
$thumbnail = $this->source->subdefs->thumbnail;
$thumbnail->name = 'thumbnail';
} elseif (isset($this->source->thumbnail)) {
$thumbnail = $this->source->thumbnail;
} else {
return null;
}

return $this->thumbnail ?: $this->thumbnail = Subdef::fromValue($this->source->thumbnail);
return $this->thumbnail ?: $this->thumbnail = Subdef::fromValue($thumbnail);
}

/**
Expand All @@ -232,7 +237,7 @@ public function getThumbnail()
*/
public function getPhraseaType()
{
return $this->source->phrasea_type;
return isset($this->source->type) ? $this->source->type : $this->source->phrasea_type;
}

/**
Expand All @@ -252,12 +257,16 @@ public function getUuid()
*/
public function getTechnicalInformation()
{
if (! isset($this->source->technical_informations)) {
if (isset($this->source->technical_informations)) {
$technicalInformations = $this->source->technical_informations;
} elseif (isset($this->source->metadata_tags)) {
$technicalInformations = $this->source->metadata_tags;
} else {
$this->technicalInformation = new ArrayCollection();
}

return $this->technicalInformation ?: new ArrayCollection(Technical::fromList(
$this->source->technical_informations
$technicalInformations
));
}

Expand All @@ -270,9 +279,14 @@ public function getSubdefs()
{
if (! isset($this->source->subdefs)) {
$this->subdefs = new ArrayCollection();
} else {
$subdefs = $this->source->subdefs;
if (is_object($this->source->subdefs)) {
$subdefs = get_object_vars($this->source->subdefs);
}
}

return $this->subdefs ?: new ArrayCollection(Subdef::fromList($this->source->subdefs));
return $this->subdefs ?: new ArrayCollection(Subdef::fromList($subdefs));
}

/**
Expand All @@ -294,9 +308,14 @@ public function getCaption()
{
if (! isset($this->source->caption)) {
$this->caption = new ArrayCollection();
} else {
$caption = $this->source->caption;
if (is_object($this->source->caption)) {
$caption = get_object_vars($this->source->caption);
}
}

return $this->caption ?: new ArrayCollection(RecordCaption::fromList($this->source->caption));
return $this->caption ?: new ArrayCollection(RecordCaption::fromList($caption));
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/PhraseanetSDK/Entity/RecordCaption.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ public static function fromList(array $values)
{
$captions = array();

foreach ($values as $value) {
$captions[$value->meta_structure_id] = self::fromValue($value);
foreach ($values as $name => $value) {
if (is_object($value)) {
$captions[$value->meta_structure_id] = self::fromValue($value);
} else {
$captions[] = self::fromValue((object) ['name' => $name, 'value' => implode(";", $value)]);
}
}

return $captions;
Expand Down Expand Up @@ -70,7 +74,7 @@ public function getSource()
*/
public function getMetaStructureId()
{
return $this->source->meta_structure_id;
return isset($this->source->meta_structure_id) ? $this->source->meta_structure_id : 0;
}

/**
Expand Down
18 changes: 14 additions & 4 deletions src/PhraseanetSDK/Entity/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getId()
*/
public function getStoryId()
{
return $this->source->story_id;
return isset($this->source->story_id) ? $this->source->story_id : $this->source->record_id;
}

/**
Expand All @@ -138,11 +138,16 @@ public function getDataboxId()
*/
public function getThumbnail()
{
if (! isset($this->source->thumbnail)) {
if (isset($this->source->subdefs->thumbnail)) {
$thumbnail = $this->source->subdefs->thumbnail;
$thumbnail->name = 'thumbnail';
} elseif (isset($this->source->thumbnail)) {
$thumbnail = $this->source->thumbnail;
} else {
return null;
}

return $this->thumbnail ?: $this->thumbnail = Subdef::fromValue($this->source->thumbnail);
return $this->thumbnail ?: $this->thumbnail = Subdef::fromValue($thumbnail);
}

/**
Expand Down Expand Up @@ -245,7 +250,12 @@ public function getStatus()
public function getCaption()
{
if (! isset($this->caption) && isset($this->source->caption)) {
$this->caption = RecordCaption::fromList((array) $this->source->caption);
$caption = $this->source->caption;
if (is_object($this->source->caption)) {
$caption = get_object_vars($this->source->caption);
}

$this->caption = RecordCaption::fromList($caption);
}

if (! isset($this->caption)) {
Expand Down
31 changes: 26 additions & 5 deletions src/PhraseanetSDK/Entity/Subdef.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ public static function fromList(array $values)
{
$subdefs = array();

foreach ($values as $value) {
foreach ($values as $key => $value) {
if ($value == null) {
continue;
}

$subdefs[$value->name] = self::fromValue($value);
if (!is_int($key)) {
$name = $key;
$value->name = $name;
} else {
$name = $value->name;
}

$subdefs[$name] = self::fromValue($value);
}

return $subdefs;
Expand Down Expand Up @@ -110,7 +117,7 @@ public function getWidth()
*/
public function getFileSize()
{
return $this->source->filesize;
return isset($this->source->size) ? $this->source->size : $this->source->filesize ;
}

/**
Expand All @@ -120,6 +127,10 @@ public function getFileSize()
*/
public function getPlayerType()
{
if (!isset($this->source->player_type)) {
return '';
}

return $this->source->player_type;
}

Expand All @@ -130,7 +141,7 @@ public function getPlayerType()
*/
public function getMimeType()
{
return $this->source->mime_type;
return isset($this->source->mime) ? $this->source->mime : $this->source->mime_type;
}

/**
Expand All @@ -140,6 +151,16 @@ public function getMimeType()
*/
public function getPermalink()
{
return $this->permalink ?: $this->permalink = Permalink::fromValue($this->source->permalink);
if ($this->permalink) {
return $this->permalink;
} else {
if (!is_object($this->source->permalink)) {
$permalink = (object) ['url' => $this->source->permalink];
} else {
$permalink = $this->source->permalink;
}

return Permalink::fromValue($permalink);
}
}
}
10 changes: 8 additions & 2 deletions src/PhraseanetSDK/Entity/Technical.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ public static function fromList(array $values)
{
$technical = array();

foreach ($values as $value) {
$technical[] = self::fromValue($value);
foreach ($values as $name => $value) {
if (is_object($value)) {
$techValue = $value;
} else {
$techValue = (object) ['name' => $name, 'value' => $value];
}

$technical[] = self::fromValue($techValue);
}

return $technical;
Expand Down
19 changes: 17 additions & 2 deletions src/PhraseanetSDK/Repository/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function find($offsetStart, $perPage)
*/
public function search(array $parameters = array(), $pAPINumber = 1)
{
$response = $this->query('POST', 'v'.$pAPINumber.'/search/', array(), array_merge(
$response = $this->query('POST', 'v'.$pAPINumber.'/searchraw/', array(), array_merge(
array('search_type' => 0),
$parameters
));
Expand All @@ -89,6 +89,21 @@ public function search(array $parameters = array(), $pAPINumber = 1)
throw new RuntimeException('Response content is empty');
}

return Query::fromValue($this->em, $response->getResult());
$results = $res = $response->getResult();
if ($pAPINumber == 3) {
$results = new \stdClass();
foreach ($res->results as $key => $r) {
$results->results->records[$key] = $r->_source;
}

$results->results->stories = [];
$results->count = $res->count;
$results->total = $res->total;
$results->limit = isset($res->limit) ? $res->limit : 10; // TODO: just $res->limit after a phraseanet PR in searchraw
$results->offset = isset($res->offset) ? $res->offset : 0; // TODO: just $res->offset after a phraseanet PR
}


return Query::fromValue($this->em, $results);
}
}
14 changes: 12 additions & 2 deletions src/PhraseanetSDK/Repository/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function find($offsetStart, $perPage)
*/
public function search(array $parameters = array(), $pAPINumber = 1)
{
$response = $this->query('POST', 'v'.$pAPINumber.'/search/', array(), array_merge(
$response = $this->query('POST', 'v'.$pAPINumber.'/searchraw/', array(), array_merge(
$parameters,
array('search_type' => SearchResult::TYPE_STORY)
));
Expand All @@ -83,6 +83,16 @@ public function search(array $parameters = array(), $pAPINumber = 1)
throw new RuntimeException('Response content is empty');
}

return Query::fromValue($this->em, $response->getResult());
$results = $res = $response->getResult();
if ($pAPINumber == 3) {
$results = new \stdClass();
foreach ($res->results as $key => $r) {
$results->results->stories[$key] = $r->_source;
}

$results->results->records = [];
}

return Query::fromValue($this->em, $results);
}
}
4 changes: 0 additions & 4 deletions tests/PhraseanetSDK/Tests/Repository/RepositoryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ protected function checkPermalink($permalink)
$this->assertInternalType('string', $permalink->getUrl());
$this->assertNotNull($permalink->getPageUrl());
$this->assertInternalType('string', $permalink->getPageUrl());
$this->assertNotNull($date = $permalink->getUpdatedOn());
$this->assertIsDate($date);
$this->assertNotNull($date = $permalink->getCreatedOn());
$this->assertIsDate($date);
}

protected function checkSubdef($subdef)
Expand Down

0 comments on commit a5b6d01

Please sign in to comment.