| @@ 175-213 (lines=39) @@ | ||
| 172 | * This is based on code found in the culturefeed theme. |
|
| 173 | * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284 |
|
| 174 | */ |
|
| 175 | private function importPicture($detail, $jsonLD) |
|
| 176 | { |
|
| 177 | $mainPicture = null; |
|
| 178 | ||
| 179 | // first check if there is a media file that is main and has the PHOTO media type |
|
| 180 | $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO); |
|
| 181 | foreach ($photos as $photo) { |
|
| 182 | if ($photo->isMain()) { |
|
| 183 | $mainPicture = $photo; |
|
| 184 | } |
|
| 185 | } |
|
| 186 | ||
| 187 | // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO |
|
| 188 | if (empty($mainPicture)) { |
|
| 189 | $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB); |
|
| 190 | foreach ($images as $image) { |
|
| 191 | if ($image->isMain()) { |
|
| 192 | $mainPicture = $image; |
|
| 193 | } |
|
| 194 | } |
|
| 195 | } |
|
| 196 | ||
| 197 | // if there is no explicit main image we just use the oldest picture of any type |
|
| 198 | if (empty($mainPicture)) { |
|
| 199 | $pictures = $detail->getMedia()->byMediaTypes( |
|
| 200 | [ |
|
| 201 | CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO, |
|
| 202 | CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB |
|
| 203 | ] |
|
| 204 | ); |
|
| 205 | ||
| 206 | $pictures->rewind(); |
|
| 207 | $mainPicture = count($pictures) > 0 ? $pictures->current() : null; |
|
| 208 | } |
|
| 209 | ||
| 210 | if ($mainPicture) { |
|
| 211 | $jsonLD->image = $mainPicture->getHLink(); |
|
| 212 | } |
|
| 213 | } |
|
| 214 | } |
|
| 215 | ||
| @@ 218-256 (lines=39) @@ | ||
| 215 | * This is based on code found in the culturefeed theme. |
|
| 216 | * @see https://github.com/cultuurnet/culturefeed/blob/master/culturefeed_agenda/theme/theme.inc#L266-L284 |
|
| 217 | */ |
|
| 218 | private function importPicture($detail, $jsonLD) |
|
| 219 | { |
|
| 220 | $mainPicture = null; |
|
| 221 | ||
| 222 | // first check if there is a media file that is main and has the PHOTO media type |
|
| 223 | $photos = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO); |
|
| 224 | foreach ($photos as $photo) { |
|
| 225 | if ($photo->isMain()) { |
|
| 226 | $mainPicture = $photo; |
|
| 227 | } |
|
| 228 | } |
|
| 229 | ||
| 230 | // the IMAGEWEB media type is deprecated but can still be used as a main image if there is no PHOTO |
|
| 231 | if (empty($mainPicture)) { |
|
| 232 | $images = $detail->getMedia()->byMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB); |
|
| 233 | foreach ($images as $image) { |
|
| 234 | if ($image->isMain()) { |
|
| 235 | $mainPicture = $image; |
|
| 236 | } |
|
| 237 | } |
|
| 238 | } |
|
| 239 | ||
| 240 | // if there is no explicit main image we just use the oldest picture of any type |
|
| 241 | if (empty($mainPicture)) { |
|
| 242 | $pictures = $detail->getMedia()->byMediaTypes( |
|
| 243 | [ |
|
| 244 | CultureFeed_Cdb_Data_File::MEDIA_TYPE_PHOTO, |
|
| 245 | CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB |
|
| 246 | ] |
|
| 247 | ); |
|
| 248 | ||
| 249 | $pictures->rewind(); |
|
| 250 | $mainPicture = count($pictures) > 0 ? $pictures->current() : null; |
|
| 251 | } |
|
| 252 | ||
| 253 | if ($mainPicture) { |
|
| 254 | $jsonLD->image = $mainPicture->getHLink(); |
|
| 255 | } |
|
| 256 | } |
|
| 257 | ||
| 258 | /** |
|
| 259 | * @param \CultureFeed_Cdb_Item_Event $event |
|