private function linkOrUnlinkResources($playlist, $request, $action = 'link')
{
$matched = false;
$resources = $request->attributes->get('links', array());
foreach ($resources as $key => $objectArray) {
if (!is_array($objectArray)) {
return true;
}
$object = $objectArray['object'];
if ($object instanceof \Exception) {
throw $object;
}
if ($object instanceof Article) {
if ($action == 'link') {
$position = false;
if (count($notConvertedLinks = $this->getNotConvertedLinks($request)) > 0) {
foreach ($notConvertedLinks as $link) {
if (isset($link['resourceType']) && $link['resourceType'] == 'article-position') {
$position = $link['resource'];
}
}
}
$playlistService = $this->get('playlists');
$playlistService->addArticle($playlist, $object, $position);
} elseif ($action == 'unlink') {
$playlistService = $this->get('playlists');
$playlistService->removePlaylistArticle($playlist, $object);
}
$matched = true;
continue;
}
}
if ($matched === false) {
throw new InvalidParametersException('Any supported link object not found');
}
}