Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Renderforest\Project\Collection\ProjectCollection;
use Renderforest\Project\Project;
use Renderforest\ProjectData\ProjectData;
use Renderforest\ProjectData\Screen\Entity\Screen;
use Renderforest\Sound\Collection\SoundCollection;
use Renderforest\Support\SupportTicket;
use Renderforest\Support\SupportTicketResponse;
Expand Down Expand Up @@ -124,13 +125,30 @@ public function __construct(string $apiKey, string $clientId)
$this->httpClient = new Client();
}

/**
* @param int $projectId
* @param ProjectData $projectData
* @return int
* @throws GuzzleException
*/
public function updateProjectData(
int $projectId,
ProjectData $projectData
) {
$endpoint = self::PROJECT_DATA_API_PATH;
$uri = self::API_ENDPOINT . self::PROJECT_DATA_API_PATH . '/' . $projectId;

$screenIds = [];
/** @var Screen[] $screens */
$screens = $projectData->getScreens();
foreach ($screens as $screen) {
$screenIds[] = $screen->getId();
}

if (false === in_array($projectData->getCurrentScreenId(), $screenIds)) {
$projectData->setCurrentScreenId($screenIds[0]);
}

$options = [
'method' => 'PATCH',
'headers' => [
Expand Down Expand Up @@ -1264,7 +1282,7 @@ public function getProjectData(int $projectId): ProjectData

/**
* @param ProjectData $projectData
* @return str
* @return string
* @throws GuzzleException
*/
public function getScreenSnapshot(ProjectData $projectData): string {
Expand Down
36 changes: 36 additions & 0 deletions src/ProjectData/ProjectData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ProjectData extends ApiEntityBase
const KEY_TEMPLATE_ID = 'templateId';
const KEY_CURRENT_SCREEN_ID = 'currentScreenId';
const KEY_DURATION = 'duration';
const KEY_EDITING_MODE = 'editingMode';
const KEY_FPS = 'fps';
const KEY_EQUALIZER = 'equalizer';
const KEY_EXTENDABLE_SCREENS = 'extendableScreens';
Expand All @@ -40,6 +41,7 @@ class ProjectData extends ApiEntityBase

const WRITABLE_KEYS = [
self::KEY_CURRENT_SCREEN_ID,
self::KEY_EDITING_MODE,
self::KEY_MUTE_MUSIC,
self::KEY_SOUNDS,
self::KEY_PROJECT_COLORS,
Expand All @@ -49,6 +51,13 @@ class ProjectData extends ApiEntityBase
self::KEY_FONTS,
];

const EDITING_MODE_SIMPLE = 'simple';
const EDITING_MODE_ADVANCED = 'advanced';
const EDITING_MODES = [
self::EDITING_MODE_SIMPLE,
self::EDITING_MODE_ADVANCED,
];

/** @var int */
protected $templateId;

Expand All @@ -58,6 +67,9 @@ class ProjectData extends ApiEntityBase
/** @var int */
protected $duration;

/** @var string */
protected $editingMode;

/** @var int */
protected $fps;

Expand Down Expand Up @@ -170,6 +182,25 @@ private function setDuration(int $duration): ProjectData
return $this;
}

/**
* @return string
*/
public function getEditingMode(): string
{
return $this->editingMode;
}

/**
* @param string $editingMode
* @return ProjectData
*/
public function setEditingMode(string $editingMode): ProjectData
{
$this->editingMode = $editingMode;

return $this;
}

/**
* @return int
*/
Expand Down Expand Up @@ -554,6 +585,10 @@ public function exchangeArray(array $projectDataArrayData)
$this->setCurrentScreenId($projectDataArrayData[self::KEY_CURRENT_SCREEN_ID]);
}

if (array_key_exists(self::KEY_EDITING_MODE, $projectDataArrayData)) {
$this->setEditingMode($projectDataArrayData[self::KEY_EDITING_MODE]);
}

$duration = $projectDataArrayData[self::KEY_DURATION];
$this->setDuration($duration);

Expand Down Expand Up @@ -683,6 +718,7 @@ public function getArrayCopyFull(): array
self::KEY_TEMPLATE_ID => $this->getTemplateId(),
self::KEY_CURRENT_SCREEN_ID => $this->getCurrentScreenId(),
self::KEY_DURATION => $this->getDuration(),
self::KEY_EDITING_MODE => $this->getEditingMode(),
self::KEY_FPS => $this->getFps(),
self::KEY_EQUALIZER => $this->isEqualizer(),
self::KEY_EXTENDABLE_SCREENS => $this->isExtendableScreens(),
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectData/Screen/Area/Entity/AbstractArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ abstract class AbstractArea extends EntityBase
const KEY_CORDS = 'cords';
const KEY_HEIGHT = 'height';
const KEY_WIDTH = 'width';
const KEY_ORIGINAL_HEIGHT = 'originalHeight';
const KEY_ORIGINAL_WIDTH = 'originalWidth';
const KEY_ORDER = 'order';
const KEY_WORD_COUNT = 'wordCount';
const KEY_TITLE = 'title';
Expand Down
2 changes: 0 additions & 2 deletions src/ProjectData/Screen/Area/Entity/ImageArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
class ImageArea extends AbstractArea
{
const KEY_COLOR_FILTERS = 'colorFilters';
const KEY_ORIGINAL_HEIGHT = 'originalHeight';
const KEY_ORIGINAL_WIDTH = 'originalWidth';
const KEY_MIME_TYPE = 'mimeType';
const KEY_FILE_NAME = 'fileName';
const KEY_WEBP_PATH = 'webpPath';
Expand Down
54 changes: 54 additions & 0 deletions src/ProjectData/Screen/Area/Entity/TextArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class TextArea extends AbstractArea
self::KEY_CORDS,
self::KEY_HEIGHT,
self::KEY_WIDTH,
self::KEY_ORIGINAL_HEIGHT,
self::KEY_ORIGINAL_WIDTH,
self::KEY_ORDER,
self::KEY_WORD_COUNT,
self::KEY_TITLE,
Expand All @@ -25,6 +27,12 @@ class TextArea extends AbstractArea
/** @var string */
protected $type = self::AREA_TYPE_TEXT;

/** @var int */
protected $originalHeight;

/** @var int */
protected $originalWidth;

/** @var bool|null */
protected $removed;

Expand Down Expand Up @@ -102,6 +110,44 @@ private function setFont($font): TextArea
return $this;
}

/**
* @return int
*/
public function getOriginalHeight(): int
{
return $this->originalHeight;
}

/**
* @param int $originalHeight
* @return TextArea
*/
public function setOriginalHeight(int $originalHeight): TextArea
{
$this->originalHeight = $originalHeight;

return $this;
}

/**
* @return int
*/
public function getOriginalWidth(): int
{
return $this->originalWidth;
}

/**
* @param int $originalWidth
* @return TextArea
*/
public function setOriginalWidth(int $originalWidth): TextArea
{
$this->originalWidth = $originalWidth;

return $this;
}

/**
* @param array $textAreaArrayData
* @throws \Exception
Expand All @@ -114,6 +160,12 @@ public function exchangeArray(array $textAreaArrayData)
}
}

$originalHeight = $textAreaArrayData[self::KEY_ORIGINAL_HEIGHT];
$this->setOriginalHeight($originalHeight);

$originalWidth = $textAreaArrayData[self::KEY_ORIGINAL_WIDTH];
$this->setOriginalWidth($originalWidth);

if (array_key_exists(self::KEY_REMOVED, $textAreaArrayData)) {
$this->setRemoved($textAreaArrayData[self::KEY_REMOVED]);
}
Expand All @@ -136,6 +188,8 @@ public function getArrayCopy(): array
{
$arrayCopy = [
self::KEY_TYPE => self::AREA_TYPE_TEXT,
self::KEY_ORIGINAL_HEIGHT => $this->getOriginalHeight(),
self::KEY_ORIGINAL_WIDTH => $this->getOriginalWidth(),
];

if (false === is_null($this->getRemoved())) {
Expand Down
3 changes: 3 additions & 0 deletions src/ProjectData/Screen/Entity/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ public function exchangeArray(array $screenArrayData)
$screenDuration = $screenArrayData[self::KEY_DURATION];
$this->duration = $screenDuration;

$screenSelectedDuration = $screenArrayData[self::KEY_SELECTED_DURATION];
$this->selectedDuration = $screenSelectedDuration;

$screenExtraVideoSecond = $screenArrayData[self::KEY_EXTRA_VIDEO_SECOND];
$this->setExtraVideoSecond($screenExtraVideoSecond);

Expand Down