public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $page = new Page();
     $id = $context->get('id');
     $title = $context->get('title');
     $content = $context->get('content');
     $page->setId($id);
     if (isset($title) && isset($content)) {
         $page->setTitle($title);
         $page->setContent($content);
         $mapper->update($page);
     } else {
         $mapper->find($page);
     }
     $title = $page->getTitle();
     if (empty($title)) {
         throw new ResourceNotFoundException('The page could not be found.');
     }
     $variables = (array) $page;
     $variables['action'] = url('page', $id, 'edit');
     $template = new Template('Nigel:WebsitePackage:html', array('title' => "Editing page <em>{$page->getTitle()}</em>", 'page' => new Template('Nigel:WebsitePackage:page:edit', $variables)));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript(array('Nigel:WebsitePackage:default', 'Nigel:WebsitePackage:jquery', 'Nigel:WebsitePackage:ckeditor:ckeditor', 'Nigel:WebsitePackage:editor'));
     return new Response($template->render());
 }
 public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $page = new Page();
     $response = new Response();
     $title = $context->get('title');
     $content = $context->get('content');
     if (isset($title) && isset($content)) {
         $page->setTitle($title);
         $page->setContent($content);
         $mapper->create($page);
         return $response->redirect(url('page', $page->getId()));
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Create new page', 'page' => new Template('Nigel:WebsitePackage:page:edit', array('title' => '', 'content' => '', 'action' => url('page', 'create')))));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript(array('Nigel:WebsitePackage:default', 'Nigel:WebsitePackage:jquery', 'Nigel:WebsitePackage:ckeditor:ckeditor', 'Nigel:WebsitePackage:editor'));
     return $response->content($template->render());
 }
 public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $id = $context->get('id');
     if ($id == 'all') {
         $pages = $mapper->findAll();
         $title = 'All Content';
         $content = new Template('Nigel:WebsitePackage:page:index', array('pages' => $pages));
     } else {
         $page = new Page();
         $page->setId($id);
         $mapper->find($page);
         $title = $page->getTitle();
         $content = new Template('Nigel:WebsitePackage:page:view', (array) $page);
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => $title, 'page' => $content));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return new Response($template->render());
 }