Skip to content

Commit 020b166

Browse files
authored
Merge pull request #144 from tigranmaestro/master
Fix & Update `template` Examples (Part 2)
2 parents 64ccfcf + 624cbce commit 020b166

File tree

9 files changed

+366
-61
lines changed

9 files changed

+366
-61
lines changed

examples/templates/get-template-categories.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require '../../vendor/autoload.php';
44

5-
$templateCategories = \Renderforest\ApiClient::getTemplateCategories('ru');
5+
$templateCategories = \Renderforest\ApiClient::getTemplateCategories('en');
66

77
echo 'Count - ' . count($templateCategories) . PHP_EOL;
88
echo PHP_EOL;
@@ -14,7 +14,6 @@
1414

1515
foreach ($templateCategory->getSubCategoriesCollection() as $templateSubCategory) {
1616
echo '-- ' . 'ID - ' . $templateSubCategory->getId() . PHP_EOL;
17-
echo '-- ' . 'Parent ID - ' . $templateSubCategory->getParentId() . PHP_EOL;
1817
echo '-- ' . 'Title - ' . $templateSubCategory->getTitle() . PHP_EOL;
1918
}
2019

examples/templates/get-template.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require '../../vendor/autoload.php';
44

5-
$template = \Renderforest\ApiClient::getTemplate(701, 'ru');
5+
$template = \Renderforest\ApiClient::getTemplate(1445, 'en');
66

77
echo 'ID - ' . $template->getId() . PHP_EOL;
88
echo 'Description - ' . $template->getDescription() . PHP_EOL;
@@ -19,10 +19,24 @@
1919

2020
foreach ($template->getCategories() as $category) {
2121
echo '-- ID - ' . $category->getId() . PHP_EOL;
22-
echo '-- Project ID - ' . $category->getProjectId() . PHP_EOL;
22+
echo '-- Parent ID - ' . $category->getParentId() . PHP_EOL;
2323
echo '-- Title - ' . $category->getTitle() . PHP_EOL;
2424

2525
echo PHP_EOL;
2626
}
2727

2828
echo PHP_EOL;
29+
30+
echo 'Durations:' . PHP_EOL;
31+
32+
foreach ($template->getDurations() as $duration) {
33+
echo '-- Template ID - ' . $duration->getTemplateId() . PHP_EOL;
34+
echo '-- Duration - ' . $duration->getDuration() . PHP_EOL;
35+
echo '-- Name - ' . $duration->getName() . PHP_EOL;
36+
echo '-- Link Name - ' . $duration->getLinkName() . PHP_EOL;
37+
echo '-- Video URL - ' . $duration->getVideoUrl() . PHP_EOL;
38+
39+
echo PHP_EOL;
40+
}
41+
42+
echo PHP_EOL;

examples/templates/get-templates-categories.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/ApiClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Renderforest\Sound\Collection\SoundCollection;
1212
use Renderforest\Support\SupportTicket;
1313
use Renderforest\Support\SupportTicketResponse;
14+
use Renderforest\Template\Category\Category;
1415
use Renderforest\Template\Category\Collection\CategoryCollection;
1516
use Renderforest\Template\Collection\TemplateCollection;
1617
use Renderforest\Template\ColorPreset\Collection\ColorPresetCollection;
@@ -481,10 +482,10 @@ public function renderProject(
481482
* @todo validate language code, supported codes - ar, de, en, es, fr, pt, ru, tr
482483
*
483484
* @param string|null $languageIsoCode
484-
* @return CategoryCollection
485+
* @return CategoryCollection|Category[]
485486
* @throws GuzzleException
486487
*/
487-
public static function getTemplatesCategories(string $languageIsoCode = null): CategoryCollection
488+
public static function getTemplateCategories(string $languageIsoCode = null): CategoryCollection
488489
{
489490
$endpoint = self::TEMPLATE_CATEGORIES_API_PATH;
490491
$uri = self::API_ENDPOINT . self::TEMPLATE_CATEGORIES_API_PATH;

src/Template/Category/Collection/CategoryCollection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Renderforest\Template\Category\Collection;
44

5+
use Exception;
56
use Renderforest\Base\CollectionBase;
67
use Renderforest\Template\Category\Category;
78

@@ -87,9 +88,9 @@ public function getArrayCopy(): array
8788
/**
8889
* @param int $categoryId
8990
* @return Category
90-
* @throws \Exception
91+
* @throws Exception
9192
*/
92-
public function getCategoryById(int $categoryId)
93+
public function getCategoryById(int $categoryId): Category
9394
{
9495
if (false === array_key_exists($categoryId, $this->categoriesAssocArray)) {
9596
throw new \Exception(

src/Template/CategoryExtended/CategoryExtended.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
class CategoryExtended extends EntityBase
1212
{
1313
const KEY_ID = 'id';
14-
const KEY_PROJECT_ID = 'projectId';
14+
const KEY_PARENT_ID = 'parentId';
1515
const KEY_TITLE = 'title';
1616

1717
const REQUIRED_KEYS = [
1818
self::KEY_ID,
19-
self::KEY_PROJECT_ID,
19+
self::KEY_PARENT_ID,
2020
self::KEY_TITLE,
2121
];
2222

2323
/** @var int */
2424
protected $id;
2525

2626
/** @var int */
27-
protected $projectId;
27+
protected $parentId;
2828

2929
/** @var string */
3030
protected $title;
@@ -48,17 +48,17 @@ private function setId(int $id)
4848
/**
4949
* @return int
5050
*/
51-
public function getProjectId(): int
51+
public function getParentId(): int
5252
{
53-
return $this->projectId;
53+
return $this->parentId;
5454
}
5555

5656
/**
57-
* @param int $projectId
57+
* @param int $parentId
5858
*/
59-
private function setProjectId(int $projectId)
59+
private function setParentId(int $parentId)
6060
{
61-
$this->projectId = $projectId;
61+
$this->parentId = $parentId;
6262
}
6363

6464
/**
@@ -89,11 +89,11 @@ public function exchangeArray(array $categoryArrayData)
8989
}
9090

9191
$categoryId = $categoryArrayData[self::KEY_ID];
92-
$categoryProjectId = $categoryArrayData[self::KEY_PROJECT_ID];
92+
$categoryParentId = $categoryArrayData[self::KEY_PARENT_ID];
9393
$categoryTitle = $categoryArrayData[self::KEY_TITLE];
9494

9595
$this->setId($categoryId);
96-
$this->setProjectId($categoryProjectId);
96+
$this->setParentId($categoryParentId);
9797
$this->setTitle($categoryTitle);
9898
}
9999

@@ -102,12 +102,10 @@ public function exchangeArray(array $categoryArrayData)
102102
*/
103103
public function getArrayCopy(): array
104104
{
105-
$arrayCopy = [
105+
return [
106106
self::KEY_ID => $this->getId(),
107-
self::KEY_PROJECT_ID => $this->getProjectId(),
107+
self::KEY_PARENT_ID => $this->getParentId(),
108108
self::KEY_TITLE => $this->getTitle(),
109109
];
110-
111-
return $arrayCopy;
112110
}
113111
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Renderforest\Template\Duration\Collection;
4+
5+
use Renderforest\Base\CollectionBase;
6+
use Renderforest\Template\Duration\Duration;
7+
8+
/**
9+
* Class DurationCollection
10+
* @package Renderforest\Template\Duration\Collection
11+
*/
12+
class DurationCollection extends CollectionBase
13+
{
14+
/**
15+
* @var Duration[]
16+
*/
17+
private $durations;
18+
19+
/**
20+
* @var Duration[]
21+
*/
22+
private $durationsAssocArray;
23+
24+
/**
25+
* DurationCollection constructor.
26+
*/
27+
public function __construct()
28+
{
29+
$this->durations = [];
30+
$this->durationsAssocArray = [];
31+
32+
parent::__construct();
33+
}
34+
35+
/**
36+
* @param Duration $duration
37+
* @return DurationCollection
38+
*/
39+
private function add(Duration $duration): DurationCollection
40+
{
41+
$this->iteratorItems[] = $duration;
42+
$this->durations[] = $duration;
43+
44+
return $this;
45+
}
46+
47+
/**
48+
* @param string $durationCollectionJson
49+
*/
50+
public function exchangeJson(string $durationCollectionJson)
51+
{
52+
$durationCollectionArrayData = json_decode($durationCollectionJson, true);
53+
54+
$durationCollectionArrayData = $durationCollectionArrayData['data'];
55+
56+
$this->exchangeArray($durationCollectionArrayData);
57+
}
58+
59+
/**
60+
* @param array $durationCollectionArrayData
61+
*/
62+
public function exchangeArray(array $durationCollectionArrayData)
63+
{
64+
foreach ($durationCollectionArrayData as $durationArrayData) {
65+
$duration = new Duration();
66+
$duration->exchangeArray($durationArrayData);
67+
68+
$this->add($duration);
69+
}
70+
}
71+
72+
/**
73+
* @return array
74+
*/
75+
public function getArrayCopy(): array
76+
{
77+
$arrayCopy = [];
78+
79+
foreach ($this->durations as $duration) {
80+
$arrayCopy[] = $duration->getArrayCopy();
81+
}
82+
83+
return $arrayCopy;
84+
}
85+
}

0 commit comments

Comments
 (0)