public function unassignAction()
{
$translator = \Zend_Registry::get('container')->getService('translator');
$p_forwardedFrom = $this->_request->getParam('p_forwardedFrom');
if ($themeId = $this->_getParam('id', null)) {
try {
$theme = $this->getThemeService()->getById($themeId);
$playlistsService = \Zend_Registry::get('container')->getService('playlists');
$themePlaylists = $playlistsService->loadThemePlaylists(__DIR__ . '/../../../../themes/' . $theme->getPath() . 'theme.xml');
$playlistsService->removeThemeFromPlaylists($theme, $themePlaylists);
if ($p_forwardedFrom == 'deleteAction') {
$themeIsAssigned = false;
$themeName = $theme->getName();
$em = \Zend_Registry::get('container')->getService('em');
$publications = $em->getRepository('Newscoop\\Entity\\Publication')->getPublications()->getResult();
foreach ($publications as $publication) {
foreach ($this->getThemeService()->getThemes($publication) as $th) {
if (trim($th->getName()) === trim($themeName)) {
$themeIsAssigned = true;
break 2;
}
}
}
if ($themeIsAssigned) {
throw new Exception('Theme is assigned and can not be deleted', 500);
}
}
$this->getThemeService()->removeTheme($themeId);
$this->_helper->service('image.rendition')->reloadRenditions();
$this->view->status = true;
$this->view->response = $translator->trans("Unassign successful", array(), 'themes');
} catch (RemoveThemeException $e) {
$this->view->status = false;
$this->view->response = $translator->trans("The theme can not be unassigned because it is in use by issues (\$1) in this publication", array('$1' => $e->getMessage()), 'themes');
} catch (Exception $e) {
$this->view->status = false;
if ($e->getCode() == 500) {
$this->view->response = $translator->trans("Theme is assigned and can not be deleted", array(), 'themes');
} else {
$this->view->response = $translator->trans("Failed unassigning theme", array(), 'themes');
}
}
}
}