Commit e6583b9b authored by Keven's avatar Keven
Browse files

Added metadata modification on Resource

parent 75b15be5
......@@ -31,13 +31,6 @@ class CreateResource extends ResourceCommand
$this->setVar('stream', $stream);
}
$this->setPayload(array(
'file' => $this->getUrlSlug($resource->file()->href),
'title' => $resource->getTitle(),
'subtitle' => $resource->getSubtitle(),
'description' => $resource->description,
'published_at' => $resource->getPublishedAt(),
'visibility' => $resource->getVisibility(),
));
$this->buildPayload($resource);
}
}
......@@ -3,6 +3,7 @@
namespace Libcast\Client\Command;
use Libcast\Client\Entity\UsageCollection;
use Libcast\Client\Model\ResourceInterface;
abstract class ResourceCommand extends Command
{
......@@ -65,4 +66,30 @@ abstract class ResourceCommand extends Command
return $usageParameters;
}
}
\ No newline at end of file
/**
* Build and set the payload for the command
*
* @param ResourceInterface $resource
*/
protected function buildPayload(ResourceInterface $resource)
{
$payload = array_merge(
$this->formatUsages($resource->getUsages()),
array(
'title' => $resource->title,
'subtitle' => $resource->subtitle,
'description' => $resource->description,
'published_at' => $resource->publishedAt,
'visibility' => $resource->visibility,
'metadata' => $resource->metadata,
));
// File is only given at Resource creation and cannot be modified after
if (!$resource->href) {
$payload['file'] = $this->getUrlSlug($resource->file()->href);
}
$this->setPayload($payload);
}
}
......@@ -25,14 +25,6 @@ class UpdateResource extends ResourceCommand
public function __construct(ResourceInterface $resource)
{
$this->fullPath = $resource->getHref();
$usageParameters = $this->formatUsages($resource->getUsages());
$this->setPayload(array_merge($usageParameters, array(
'title' => $resource->getTitle(),
'subtitle' => $resource->getSubtitle(),
'published_at' => $resource->getPublishedAt(),
'visibility' => $resource->getVisibility(),
)));
$this->buildPayload($resource);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment