| @@ -43,9 +43,9 @@ | ||
| 43 | 43 | */ |
| 44 | 44 | private $focus_keyphrase; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * The SEO title. | |
| 47 | + * The raw stored SEO title (empty string when never explicitly saved). | |
| 48 | 48 | * |
| 49 | 49 | * @var string |
| 50 | 50 | */ |
| 51 | 51 | private $seo_title; |
| @@ -50,9 +50,9 @@ | ||
| 50 | 50 | */ |
| 51 | 51 | private $seo_title; |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * The meta description. | |
| 54 | + * The raw stored meta description (empty string when never explicitly saved). | |
| 55 | 55 | * |
| 56 | 56 | * @var string |
| 57 | 57 | */ |
| 58 | 58 | private $meta_description; |
| @@ -57,9 +57,9 @@ | ||
| 57 | 57 | */ |
| 58 | 58 | private $meta_description; |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * The social title. | |
| 61 | + * The raw stored social title (empty string when never explicitly saved). | |
| 62 | 62 | * |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | 65 | private $social_title; |
| @@ -64,9 +64,9 @@ | ||
| 64 | 64 | */ |
| 65 | 65 | private $social_title; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * The social description. | |
| 68 | + * The raw stored social description (empty string when never explicitly saved). | |
| 69 | 69 | * |
| 70 | 70 | * @var string |
| 71 | 71 | */ |
| 72 | 72 | private $social_description; |
| @@ -78,20 +78,61 @@ | ||
| 78 | 78 | */ |
| 79 | 79 | private $editable; |
| 80 | 80 | |
| 81 | 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 | + /** | |
| 82 | 118 | * The constructor. |
| 83 | 119 | * |
| 84 | - * @param int $id The post ID. | |
| 85 | - * @param string $title The post title. | |
| 86 | - * @param string $status The post status. | |
| 87 | - * @param string $edit_link The URL to edit the post. | |
| 88 | - * @param string $focus_keyphrase The focus keyphrase. | |
| 89 | - * @param string $seo_title The SEO title. | |
| 90 | - * @param string $meta_description The meta description. | |
| 91 | - * @param string $social_title The social title. | |
| 92 | - * @param string $social_description The social description. | |
| 93 | - * @param bool $editable Whether the current user may edit this post. | |
| 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). | |
| 94 | 135 | */ |
| 95 | 136 | public function __construct( |
| 96 | 137 | int $id, |
| 97 | 138 | string $title, |
| @@ -101,38 +142,61 @@ | ||
| 101 | 142 | string $seo_title, |
| 102 | 143 | string $meta_description, |
| 103 | 144 | string $social_title, |
| 104 | 145 | string $social_description, |
| 105 | - bool $editable | |
| 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 = '' | |
| 106 | 152 | ) { |
| 107 | - $this->id = $id; | |
| 108 | - $this->title = $title; | |
| 109 | - $this->status = $status; | |
| 110 | - $this->edit_link = $edit_link; | |
| 111 | - $this->focus_keyphrase = $focus_keyphrase; | |
| 112 | - $this->seo_title = $seo_title; | |
| 113 | - $this->meta_description = $meta_description; | |
| 114 | - $this->social_title = $social_title; | |
| 115 | - $this->social_description = $social_description; | |
| 116 | - $this->editable = $editable; | |
| 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; | |
| 117 | 168 | } |
| 118 | 169 | |
| 119 | 170 | /** |
| 120 | 171 | * Parses the post to the expected key value representation. |
| 121 | 172 | * |
| 122 | - * @return array<string, int|string|bool> The post presented as the expected key value representation. | |
| 173 | + * @return array<string, int|string|bool|array<string, bool>> The post presented as the expected key value representation. | |
| 123 | 174 | */ |
| 124 | 175 | public function to_array(): array { |
| 125 | 176 | return [ |
| 126 | - 'id' => $this->id, | |
| 127 | - 'title' => $this->title, | |
| 128 | - 'status' => $this->status, | |
| 129 | - 'edit_link' => $this->edit_link, | |
| 130 | - 'focus_keyphrase' => $this->focus_keyphrase, | |
| 131 | - 'seo_title' => $this->seo_title, | |
| 132 | - 'meta_description' => $this->meta_description, | |
| 133 | - 'social_title' => $this->social_title, | |
| 134 | - 'social_description' => $this->social_description, | |
| 135 | - 'editable' => $this->editable, | |
| 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 | + ), | |
| 136 | 200 | ]; |
| 137 | 201 | } |
| 138 | 202 | } |