Skip to content

Commit edc54e2

Browse files
authored
Merge pull request #147 from tigranmaestro/master
Add missing properties & smart current screen ID
2 parents e07e9c4 + 25784d0 commit edc54e2

File tree

6 files changed

+114
-3
lines changed

6 files changed

+114
-3
lines changed

src/ApiClient.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Renderforest\Project\Collection\ProjectCollection;
99
use Renderforest\Project\Project;
1010
use Renderforest\ProjectData\ProjectData;
11+
use Renderforest\ProjectData\Screen\Entity\Screen;
1112
use Renderforest\Sound\Collection\SoundCollection;
1213
use Renderforest\Support\SupportTicket;
1314
use Renderforest\Support\SupportTicketResponse;
@@ -124,13 +125,30 @@ public function __construct(string $apiKey, string $clientId)
124125
$this->httpClient = new Client();
125126
}
126127

128+
/**
129+
* @param int $projectId
130+
* @param ProjectData $projectData
131+
* @return int
132+
* @throws GuzzleException
133+
*/
127134
public function updateProjectData(
128135
int $projectId,
129136
ProjectData $projectData
130137
) {
131138
$endpoint = self::PROJECT_DATA_API_PATH;
132139
$uri = self::API_ENDPOINT . self::PROJECT_DATA_API_PATH . '/' . $projectId;
133140

141+
$screenIds = [];
142+
/** @var Screen[] $screens */
143+
$screens = $projectData->getScreens();
144+
foreach ($screens as $screen) {
145+
$screenIds[] = $screen->getId();
146+
}
147+
148+
if (false === in_array($projectData->getCurrentScreenId(), $screenIds)) {
149+
$projectData->setCurrentScreenId($screenIds[0]);
150+
}
151+
134152
$options = [
135153
'method' => 'PATCH',
136154
'headers' => [
@@ -1264,7 +1282,7 @@ public function getProjectData(int $projectId): ProjectData
12641282

12651283
/**
12661284
* @param ProjectData $projectData
1267-
* @return str
1285+
* @return string
12681286
* @throws GuzzleException
12691287
*/
12701288
public function getScreenSnapshot(ProjectData $projectData): string {

src/ProjectData/ProjectData.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ProjectData extends ApiEntityBase
2121
const KEY_TEMPLATE_ID = 'templateId';
2222
const KEY_CURRENT_SCREEN_ID = 'currentScreenId';
2323
const KEY_DURATION = 'duration';
24+
const KEY_EDITING_MODE = 'editingMode';
2425
const KEY_FPS = 'fps';
2526
const KEY_EQUALIZER = 'equalizer';
2627
const KEY_EXTENDABLE_SCREENS = 'extendableScreens';
@@ -40,6 +41,7 @@ class ProjectData extends ApiEntityBase
4041

4142
const WRITABLE_KEYS = [
4243
self::KEY_CURRENT_SCREEN_ID,
44+
self::KEY_EDITING_MODE,
4345
self::KEY_MUTE_MUSIC,
4446
self::KEY_SOUNDS,
4547
self::KEY_PROJECT_COLORS,
@@ -49,6 +51,13 @@ class ProjectData extends ApiEntityBase
4951
self::KEY_FONTS,
5052
];
5153

54+
const EDITING_MODE_SIMPLE = 'simple';
55+
const EDITING_MODE_ADVANCED = 'advanced';
56+
const EDITING_MODES = [
57+
self::EDITING_MODE_SIMPLE,
58+
self::EDITING_MODE_ADVANCED,
59+
];
60+
5261
/** @var int */
5362
protected $templateId;
5463

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

70+
/** @var string */
71+
protected $editingMode;
72+
6173
/** @var int */
6274
protected $fps;
6375

@@ -170,6 +182,25 @@ private function setDuration(int $duration): ProjectData
170182
return $this;
171183
}
172184

185+
/**
186+
* @return string
187+
*/
188+
public function getEditingMode(): string
189+
{
190+
return $this->editingMode;
191+
}
192+
193+
/**
194+
* @param string $editingMode
195+
* @return ProjectData
196+
*/
197+
public function setEditingMode(string $editingMode): ProjectData
198+
{
199+
$this->editingMode = $editingMode;
200+
201+
return $this;
202+
}
203+
173204
/**
174205
* @return int
175206
*/
@@ -554,6 +585,10 @@ public function exchangeArray(array $projectDataArrayData)
554585
$this->setCurrentScreenId($projectDataArrayData[self::KEY_CURRENT_SCREEN_ID]);
555586
}
556587

588+
if (array_key_exists(self::KEY_EDITING_MODE, $projectDataArrayData)) {
589+
$this->setEditingMode($projectDataArrayData[self::KEY_EDITING_MODE]);
590+
}
591+
557592
$duration = $projectDataArrayData[self::KEY_DURATION];
558593
$this->setDuration($duration);
559594

@@ -683,6 +718,7 @@ public function getArrayCopyFull(): array
683718
self::KEY_TEMPLATE_ID => $this->getTemplateId(),
684719
self::KEY_CURRENT_SCREEN_ID => $this->getCurrentScreenId(),
685720
self::KEY_DURATION => $this->getDuration(),
721+
self::KEY_EDITING_MODE => $this->getEditingMode(),
686722
self::KEY_FPS => $this->getFps(),
687723
self::KEY_EQUALIZER => $this->isEqualizer(),
688724
self::KEY_EXTENDABLE_SCREENS => $this->isExtendableScreens(),

src/ProjectData/Screen/Area/Entity/AbstractArea.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ abstract class AbstractArea extends EntityBase
2525
const KEY_CORDS = 'cords';
2626
const KEY_HEIGHT = 'height';
2727
const KEY_WIDTH = 'width';
28+
const KEY_ORIGINAL_HEIGHT = 'originalHeight';
29+
const KEY_ORIGINAL_WIDTH = 'originalWidth';
2830
const KEY_ORDER = 'order';
2931
const KEY_WORD_COUNT = 'wordCount';
3032
const KEY_TITLE = 'title';

src/ProjectData/Screen/Area/Entity/ImageArea.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
class ImageArea extends AbstractArea
1212
{
1313
const KEY_COLOR_FILTERS = 'colorFilters';
14-
const KEY_ORIGINAL_HEIGHT = 'originalHeight';
15-
const KEY_ORIGINAL_WIDTH = 'originalWidth';
1614
const KEY_MIME_TYPE = 'mimeType';
1715
const KEY_FILE_NAME = 'fileName';
1816
const KEY_WEBP_PATH = 'webpPath';

src/ProjectData/Screen/Area/Entity/TextArea.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class TextArea extends AbstractArea
1616
self::KEY_CORDS,
1717
self::KEY_HEIGHT,
1818
self::KEY_WIDTH,
19+
self::KEY_ORIGINAL_HEIGHT,
20+
self::KEY_ORIGINAL_WIDTH,
1921
self::KEY_ORDER,
2022
self::KEY_WORD_COUNT,
2123
self::KEY_TITLE,
@@ -25,6 +27,12 @@ class TextArea extends AbstractArea
2527
/** @var string */
2628
protected $type = self::AREA_TYPE_TEXT;
2729

30+
/** @var int */
31+
protected $originalHeight;
32+
33+
/** @var int */
34+
protected $originalWidth;
35+
2836
/** @var bool|null */
2937
protected $removed;
3038

@@ -102,6 +110,44 @@ private function setFont($font): TextArea
102110
return $this;
103111
}
104112

113+
/**
114+
* @return int
115+
*/
116+
public function getOriginalHeight(): int
117+
{
118+
return $this->originalHeight;
119+
}
120+
121+
/**
122+
* @param int $originalHeight
123+
* @return TextArea
124+
*/
125+
public function setOriginalHeight(int $originalHeight): TextArea
126+
{
127+
$this->originalHeight = $originalHeight;
128+
129+
return $this;
130+
}
131+
132+
/**
133+
* @return int
134+
*/
135+
public function getOriginalWidth(): int
136+
{
137+
return $this->originalWidth;
138+
}
139+
140+
/**
141+
* @param int $originalWidth
142+
* @return TextArea
143+
*/
144+
public function setOriginalWidth(int $originalWidth): TextArea
145+
{
146+
$this->originalWidth = $originalWidth;
147+
148+
return $this;
149+
}
150+
105151
/**
106152
* @param array $textAreaArrayData
107153
* @throws \Exception
@@ -114,6 +160,12 @@ public function exchangeArray(array $textAreaArrayData)
114160
}
115161
}
116162

163+
$originalHeight = $textAreaArrayData[self::KEY_ORIGINAL_HEIGHT];
164+
$this->setOriginalHeight($originalHeight);
165+
166+
$originalWidth = $textAreaArrayData[self::KEY_ORIGINAL_WIDTH];
167+
$this->setOriginalWidth($originalWidth);
168+
117169
if (array_key_exists(self::KEY_REMOVED, $textAreaArrayData)) {
118170
$this->setRemoved($textAreaArrayData[self::KEY_REMOVED]);
119171
}
@@ -136,6 +188,8 @@ public function getArrayCopy(): array
136188
{
137189
$arrayCopy = [
138190
self::KEY_TYPE => self::AREA_TYPE_TEXT,
191+
self::KEY_ORIGINAL_HEIGHT => $this->getOriginalHeight(),
192+
self::KEY_ORIGINAL_WIDTH => $this->getOriginalWidth(),
139193
];
140194

141195
if (false === is_null($this->getRemoved())) {

src/ProjectData/Screen/Entity/Screen.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,9 @@ public function exchangeArray(array $screenArrayData)
698698
$screenDuration = $screenArrayData[self::KEY_DURATION];
699699
$this->duration = $screenDuration;
700700

701+
$screenSelectedDuration = $screenArrayData[self::KEY_SELECTED_DURATION];
702+
$this->selectedDuration = $screenSelectedDuration;
703+
701704
$screenExtraVideoSecond = $screenArrayData[self::KEY_EXTRA_VIDEO_SECOND];
702705
$this->setExtraVideoSecond($screenExtraVideoSecond);
703706

0 commit comments

Comments
 (0)