Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
 public function execute(Context $context)
 {
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Welcome', 'page' => '<p>No homepage has been set.</p>'));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return new Response($template->render());
 }
Ejemplo n.º 3
0
 public function execute(Context $context)
 {
     $session = new Session();
     $response = new Response();
     $session->start();
     if ($session->valid()) {
         return $response->redirect(url());
     }
     $username = $context->get('username');
     $password = $context->get('password');
     if (isset($username) && isset($password)) {
         $mapper = new UserMapper();
         $user = new User();
         $user->setUsername($username);
         $mapper->find($user);
         if (hash('sha256', $password) == $user->getPassword()) {
             $session->validate($context);
             return $response->redirect(url());
         }
         throw new AccessDeniedException('Incorrect username or password');
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Login', 'page' => new Template('Nigel:WebsitePackage:login:login', array('action' => url('login')))));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return $response->content($template->render());
 }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
 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());
 }