Beispiel #1
0
 /**
  * Perform actions on content.
  *
  * @param Application $app             The application/container
  * @param string      $action          The action
  * @param string      $contenttypeslug The content type slug
  * @param integer     $id              The content ID
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function contentAction(Application $app, $action, $contenttypeslug, $id)
 {
     if ($action === 'delete') {
         return $this->deleteContent($app, $contenttypeslug, $id);
     }
     $contenttype = $app['storage']->getContentType($contenttypeslug);
     $content = $app['storage']->getContent($contenttype['slug'] . '/' . $id);
     $title = $content->getTitle();
     // get the parameters from the URL of the previous page, so we can return to it.
     $redirectParameters = Lib::getQueryParameters($app['request']->server->get('HTTP_REFERER'));
     $redirectParameters['contenttypeslug'] = $contenttype['slug'];
     // map actions to new statuses
     $actionStatuses = array('held' => 'held', 'draft' => 'draft', 'publish' => 'published');
     // Map actions to requre permission
     $actionPermissions = array('publish' => 'publish', 'held' => 'depublish', 'draft' => 'depublish');
     if (!isset($actionStatuses[$action])) {
         $app['session']->getFlashBag()->add('error', Trans::__('No such action for content.'));
         return Lib::redirect('overview', $redirectParameters);
     }
     $newStatus = $actionStatuses[$action];
     if (!$app['users']->isAllowed("contenttype:{$contenttype['slug']}:{$actionPermissions[$action]}:{$id}") || !$app['users']->isContentStatusTransitionAllowed($content['status'], $newStatus, $contenttype['slug'], $id)) {
         $app['session']->getFlashBag()->add('error', Trans::__('You do not have the right privileges to %ACTION% that record.', array('%ACTION%' => $actionPermissions[$action])));
         return Lib::redirect('overview', $redirectParameters);
     }
     if ($app['storage']->updateSingleValue($contenttype['slug'], $id, 'status', $newStatus)) {
         $app['session']->getFlashBag()->add('info', Trans::__("Content '%title%' has been changed to '%newStatus%'", array('%title%' => $title, '%newStatus%' => $newStatus)));
     } else {
         $app['session']->getFlashBag()->add('info', Trans::__("Content '%title%' could not be modified.", array('%title%' => $title)));
     }
     return Lib::redirect('overview', $redirectParameters);
 }