Skip to content

Commit 8824844

Browse files
committed
Update page resource
1 parent 16aed0d commit 8824844

File tree

5 files changed

+111
-9
lines changed

5 files changed

+111
-9
lines changed

src/OminityApiClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OminityApiClient
1818
/**
1919
* Version of our client.
2020
*/
21-
public const CLIENT_VERSION = "1.1.34";
21+
public const CLIENT_VERSION = "1.1.35";
2222

2323
/**
2424
* Endpoint of the remote API.

src/Resources/Cms/Page.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Ominity\Api\Resources\BaseResource;
66
use Ominity\Api\Resources\ResourceFactory;
7+
use Ominity\Api\Types\PageStatus;
78

89
class Page extends BaseResource
910
{
@@ -35,6 +36,13 @@ class Page extends BaseResource
3536
*/
3637
public $slug;
3738

39+
/**
40+
* Status of the page.
41+
*
42+
* @var string
43+
*/
44+
public $status;
45+
3846
/**
3947
* Page meta data for SEO puposes.
4048
*
@@ -99,20 +107,33 @@ class Page extends BaseResource
99107
public $_links;
100108

101109
/**
102-
* Is this page published?
110+
* Is this page a draft?
103111
*
104112
* @return bool
105113
*/
106-
public function isPublished()
114+
public function isDraft()
107115
{
108-
if (is_null($this->publishedAt)) {
109-
return false;
110-
}
116+
return $this->status === PageStatus::DRAFT;
117+
}
111118

112-
$publishedTimestamp = strtotime($this->publishedAt);
113-
$currentTimestamp = time();
119+
/**
120+
* Is this page scheduled?
121+
*
122+
* @return bool
123+
*/
124+
public function isScheduled()
125+
{
126+
return $this->status === PageStatus::SCHEDULED;
127+
}
114128

115-
return $publishedTimestamp <= $currentTimestamp;
129+
/**
130+
* Is this page published?
131+
*
132+
* @return bool
133+
*/
134+
public function isPublished()
135+
{
136+
return $this->status === PageStatus::PUBLISHED;
116137
}
117138

118139
/**
@@ -121,6 +142,14 @@ public function isPublished()
121142
*/
122143
public function layout()
123144
{
145+
if (isset($this->_embedded, $this->_embedded->layout))
146+
{
147+
return ResourceFactory::createFromApiResult(
148+
$this->_embedded->layout,
149+
new Layout($this->client)
150+
);
151+
}
152+
124153
return $this->client->cms->layouts->get($this->layoutId);
125154
}
126155

src/Resources/Cms/PageComponent.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Ominity\Api\Resources\BaseResource;
66
use Ominity\Api\Resources\ResourceFactory;
7+
use Ominity\Api\Types\PageComponentStatus;
78

89
class PageComponent extends BaseResource
910
{
@@ -21,6 +22,20 @@ class PageComponent extends BaseResource
2122
*/
2223
public $id;
2324

25+
/**
26+
* Internal label of the page component.
27+
*
28+
* @var string
29+
*/
30+
public $label;
31+
32+
/**
33+
* Status of the page component.
34+
*
35+
* @var string
36+
*/
37+
public $status;
38+
2439
/**
2540
* The ID of the page for this page component.
2641
*
@@ -42,6 +57,14 @@ class PageComponent extends BaseResource
4257
*/
4358
public $fields;
4459

60+
/**
61+
* UTC datetime the page component was published in ISO-8601 format.
62+
*
63+
* @example "2013-12-25T10:30:54+00:00"
64+
* @var string|null
65+
*/
66+
public $publishedAt;
67+
4568
/**
4669
* UTC datetime the page component was last updated in ISO-8601 format.
4770
*
@@ -63,6 +86,36 @@ class PageComponent extends BaseResource
6386
*/
6487
public $_links;
6588

89+
/**
90+
* Is this page component a draft?
91+
*
92+
* @return bool
93+
*/
94+
public function isDraft()
95+
{
96+
return $this->status === PageComponentStatus::DRAFT;
97+
}
98+
99+
/**
100+
* Is this page component scheduled?
101+
*
102+
* @return bool
103+
*/
104+
public function isScheduled()
105+
{
106+
return $this->status === PageComponentStatus::SCHEDULED;
107+
}
108+
109+
/**
110+
* Is this page component published?
111+
*
112+
* @return bool
113+
*/
114+
public function isPublished()
115+
{
116+
return $this->status === PageComponentStatus::PUBLISHED;
117+
}
118+
66119
/**
67120
* @return Page
68121
* @throws ApiException

src/Types/PageComponentStatus.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Ominity\Api\Types;
4+
5+
class PageComponentStatus
6+
{
7+
public const DRAFT = 'draft';
8+
public const SCHEDULED = 'scheduled';
9+
public const PUBLISHED = 'published';
10+
}

src/Types/PageStatus.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Ominity\Api\Types;
4+
5+
class PageStatus
6+
{
7+
public const DRAFT = 'draft';
8+
public const SCHEDULED = 'scheduled';
9+
public const PUBLISHED = 'published';
10+
}

0 commit comments

Comments
 (0)