| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Bulk_Editor\Domain\Posts; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class describes a single content item shown in the bulk editor table. |
| 8 |
*/ |
| 9 |
class Post { |
| 10 |
|
| 11 |
/** |
| 12 |
* The post ID. |
| 13 |
* |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
private $id; |
| 17 |
|
| 18 |
/** |
| 19 |
* The post title. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $title; |
| 24 |
|
| 25 |
/** |
| 26 |
* The post status. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
private $status; |
| 31 |
|
| 32 |
/** |
| 33 |
* The URL to edit the post. |
| 34 |
* |
| 35 |
* @var string |
| 36 |
*/ |
| 37 |
private $edit_link; |
| 38 |
|
| 39 |
/** |
| 40 |
* The focus keyphrase. |
| 41 |
* |
| 42 |
* @var string |
| 43 |
*/ |
| 44 |
private $focus_keyphrase; |
| 45 |
|
| 46 |
/** |
| 47 |
* The raw stored SEO title (empty string when never explicitly saved). |
| 48 |
* |
| 49 |
* @var string |
| 50 |
*/ |
| 51 |
private $seo_title; |
| 52 |
|
| 53 |
/** |
| 54 |
* The raw stored meta description (empty string when never explicitly saved). |
| 55 |
* |
| 56 |
* @var string |
| 57 |
*/ |
| 58 |
private $meta_description; |
| 59 |
|
| 60 |
/** |
| 61 |
* The raw stored social title (empty string when never explicitly saved). |
| 62 |
* |
| 63 |
* @var string |
| 64 |
*/ |
| 65 |
private $social_title; |
| 66 |
|
| 67 |
/** |
| 68 |
* The raw stored social description (empty string when never explicitly saved). |
| 69 |
* |
| 70 |
* @var string |
| 71 |
*/ |
| 72 |
private $social_description; |
| 73 |
|
| 74 |
/** |
| 75 |
* Whether the current user may edit this post. |
| 76 |
* |
| 77 |
* @var bool |
| 78 |
*/ |
| 79 |
private $editable; |
| 80 |
|
| 81 |
/** |
| 82 |
* Whether each field needs improvement, keyed by field param (e.g. `seo_title`). Empty for a post whose |
| 83 |
* fields are not editable. |
| 84 |
* |
| 85 |
* @var array<string, bool> |
| 86 |
*/ |
| 87 |
private $needs_improvement; |
| 88 |
|
| 89 |
/** |
| 90 |
* The post type's SEO title template, shown when the stored value is empty. Empty string when the stored value is set. |
| 91 |
* |
| 92 |
* @var string |
| 93 |
*/ |
| 94 |
private $seo_title_fallback; |
| 95 |
|
| 96 |
/** |
| 97 |
* The post type's meta description template, shown when the stored value is empty. Empty string when the stored value is set. |
| 98 |
* |
| 99 |
* @var string |
| 100 |
*/ |
| 101 |
private $meta_description_fallback; |
| 102 |
|
| 103 |
/** |
| 104 |
* The post type's social title template, shown when the stored value is empty. Empty string when the stored value is set. |
| 105 |
* |
| 106 |
* @var string |
| 107 |
*/ |
| 108 |
private $social_title_fallback; |
| 109 |
|
| 110 |
/** |
| 111 |
* The post type's social description template, shown when the stored value is empty. Empty string when the stored value is set. |
| 112 |
* |
| 113 |
* @var string |
| 114 |
*/ |
| 115 |
private $social_description_fallback; |
| 116 |
|
| 117 |
/** |
| 118 |
* The constructor. |
| 119 |
* |
| 120 |
* @param int $id The post ID. |
| 121 |
* @param string $title The post title. |
| 122 |
* @param string $status The post status. |
| 123 |
* @param string $edit_link The URL to edit the post. |
| 124 |
* @param string $focus_keyphrase The focus keyphrase. |
| 125 |
* @param string $seo_title The raw stored SEO title. |
| 126 |
* @param string $meta_description The raw stored meta description. |
| 127 |
* @param string $social_title The raw stored social title. |
| 128 |
* @param string $social_description The raw stored social description. |
| 129 |
* @param bool $editable Whether the current user may edit this post. |
| 130 |
* @param array<string, bool> $needs_improvement Whether each field needs improvement, keyed by field param. |
| 131 |
* @param string $seo_title_fallback The post type's SEO title template (empty when stored value is set). |
| 132 |
* @param string $meta_description_fallback The post type's meta description template (empty when stored value is set). |
| 133 |
* @param string $social_title_fallback The post type's social title template (empty when stored value is set). |
| 134 |
* @param string $social_description_fallback The post type's social description template (empty when stored value is set). |
| 135 |
*/ |
| 136 |
public function __construct( |
| 137 |
int $id, |
| 138 |
string $title, |
| 139 |
string $status, |
| 140 |
string $edit_link, |
| 141 |
string $focus_keyphrase, |
| 142 |
string $seo_title, |
| 143 |
string $meta_description, |
| 144 |
string $social_title, |
| 145 |
string $social_description, |
| 146 |
bool $editable, |
| 147 |
array $needs_improvement = [], |
| 148 |
string $seo_title_fallback = '', |
| 149 |
string $meta_description_fallback = '', |
| 150 |
string $social_title_fallback = '', |
| 151 |
string $social_description_fallback = '' |
| 152 |
) { |
| 153 |
$this->id = $id; |
| 154 |
$this->title = $title; |
| 155 |
$this->status = $status; |
| 156 |
$this->edit_link = $edit_link; |
| 157 |
$this->focus_keyphrase = $focus_keyphrase; |
| 158 |
$this->seo_title = $seo_title; |
| 159 |
$this->meta_description = $meta_description; |
| 160 |
$this->social_title = $social_title; |
| 161 |
$this->social_description = $social_description; |
| 162 |
$this->editable = $editable; |
| 163 |
$this->needs_improvement = $needs_improvement; |
| 164 |
$this->seo_title_fallback = $seo_title_fallback; |
| 165 |
$this->meta_description_fallback = $meta_description_fallback; |
| 166 |
$this->social_title_fallback = $social_title_fallback; |
| 167 |
$this->social_description_fallback = $social_description_fallback; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Parses the post to the expected key value representation. |
| 172 |
* |
| 173 |
* @return array<string, int|string|bool|array<string, bool>> The post presented as the expected key value representation. |
| 174 |
*/ |
| 175 |
public function to_array(): array { |
| 176 |
return [ |
| 177 |
'id' => $this->id, |
| 178 |
'title' => $this->title, |
| 179 |
'status' => $this->status, |
| 180 |
'edit_link' => $this->edit_link, |
| 181 |
'focus_keyphrase' => $this->focus_keyphrase, |
| 182 |
'seo_title' => $this->seo_title, |
| 183 |
'meta_description' => $this->meta_description, |
| 184 |
'social_title' => $this->social_title, |
| 185 |
'social_description' => $this->social_description, |
| 186 |
'seo_title_fallback' => $this->seo_title_fallback, |
| 187 |
'meta_description_fallback' => $this->meta_description_fallback, |
| 188 |
'social_title_fallback' => $this->social_title_fallback, |
| 189 |
'social_description_fallback' => $this->social_description_fallback, |
| 190 |
'editable' => $this->editable, |
| 191 |
'needs_improvement' => \array_merge( |
| 192 |
[ |
| 193 |
'seo_title' => false, |
| 194 |
'meta_description' => false, |
| 195 |
'social_title' => false, |
| 196 |
'social_description' => false, |
| 197 |
], |
| 198 |
$this->needs_improvement, |
| 199 |
), |
| 200 |
]; |
| 201 |
} |
| 202 |
} |
| 203 |
|