ed30a11fb28f976a07705f6f8c934526bedc46db

Author: alkemann

Date: 2009-09-25 14:11:16 +0200

working prototype for creating articles and article pages, then publishing them

diff --git a/controllers/article_pages_controller.php b/controllers/article_pages_controller.php index f9361bd..6641777 100644 --- a/controllers/article_pages_controller.php +++ b/controllers/article_pages_controller.php @@ -14,7 +14,9 @@ class ArticlePagesController extends AppController { $this->Session->setFlash(__('Invalid ArticlePage.', true)); $this->redirect(array('action'=>'index')); } + $this->ArticlePage->showDraft = true; $this->set('articlePage', $this->ArticlePage->read(null, $id)); + $this->set('revisions', $this->ArticlePage->revisions()); } function add() { diff --git a/controllers/articles_controller.php b/controllers/articles_controller.php index 1ebb19b..b8d9332 100644 --- a/controllers/articles_controller.php +++ b/controllers/articles_controller.php @@ -6,9 +6,12 @@ class ArticlesController extends AppController { function index() { $this->paginate['conditions'] = array( - // 'Article.published' => true, - 'Article.deleted' => false + // 'Article.published' => true, + // 'Article.deleted' => false ); + if (isset($this->params['named']['published'])) + $this->paginate['conditions']['Article.published'] = $this->params['named']['published']; + if (isset($this->passedArgs['category_id'])) $this->paginate['conditions']['Article.category_id'] = $this->passedArgs['category_id']; $this->Article->recursive = 0; @@ -52,10 +55,9 @@ class ArticlesController extends AppController { $this->Article->save(null,false); $this->Article->Intro->set('article_id',$this->Article->id); $this->Article->Intro->set('pagenum',0); + $this->Article->Intro->saveDraft = false; $this->Article->Intro->save(null,false); - $this->Article->Intro->showDraft = true; $this->Article->Intro->createRevision(); - $this->Article->Intro->showDraft = false; $this->Session->write('Article',$this->Article->id); $this->redirect(array('controller'=>'article_pages','action'=>'add','page'=>1)); @@ -103,5 +105,27 @@ class ArticlesController extends AppController { } } + function publish($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Article', true)); + $this->redirect(array('action'=>'index')); + } + if ($this->Article->publish($id)) { + $this->Session->setFlash(__('Article published', true)); + $this->redirect(array('action'=>'index')); + } + } + + function unpublish($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Article', true)); + $this->redirect(array('action'=>'index')); + } + if ($this->Article->unpublish($id)) { + $this->Session->setFlash(__('Article unpublished', true)); + $this->redirect(array('action'=>'index')); + } + } + } ?> \ No newline at end of file diff --git a/views/article_pages/view.ctp b/views/article_pages/view.ctp index 17c8590..5d8211b 100644 --- a/views/article_pages/view.ctp +++ b/views/article_pages/view.ctp @@ -32,5 +32,5 @@ $menu->add('context',array(__('Edit ArticlePage', true), array('action'=>'edit', $articlePage['ArticlePage']['id']))); $menu->add('context',array(__('Delete ArticlePage', true), array('action'=>'delete', $articlePage['ArticlePage']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $articlePage['ArticlePage']['id']))); $menu->add('context',array(__('List ArticlePages', true), array('action'=>'index'))); - $menu->add('context',array(__('New ArticlePage', true), array('action'=>'add'))); + $menu->add('context',array(__('List Articles', true), array('controller' => 'articles', 'action'=>'index'))); ?> diff --git a/views/articles/index.ctp b/views/articles/index.ctp index c3fc66f..30c21b6 100644 --- a/views/articles/index.ctp +++ b/views/articles/index.ctp @@ -2,10 +2,19 @@ <h2><?php __('Articles');?></h2> <p> <?php +$paginator->options(array('url'=>$this->passedArgs)); echo $paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) )); ?></p> +<p><h4>Show:</h4> +<?php + +$menu->add('filter', array('Published', am($this->params['named'], array('published' => 1)))); +$menu->add('filter', array('Unpublished', am($this->params['named'], array('published' => 0)))); +echo $menu->generate('filter'); +echo $html->tag('br'); +?></p> <table cellpadding="0" cellspacing="0"> <tr> <th><?php echo $paginator->sort('title');?></th> diff --git a/views/articles/view.ctp b/views/articles/view.ctp index 8681903..f3c314b 100644 --- a/views/articles/view.ctp +++ b/views/articles/view.ctp @@ -68,6 +68,12 @@ </div> <?php $menu->add('context',array(__('Edit Article', true), array('action'=>'edit', $article['Article']['id']))); + + if ($article['Article']['published']) + $menu->add('context',array(__('Unpublish Article', true), array('action'=>'unpublish', $article['Article']['id']))); + else + $menu->add('context',array(__('Publish Article', true), array('action'=>'publish', $article['Article']['id']))); + $menu->add('context',array(__('Delete Article', true), array('action'=>'delete', $article['Article']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $article['Article']['id']))); $menu->add('context',array(__('List Articles', true), array('controller'=> 'articles', 'action'=>'index'))); $menu->add('context',array(__('List Categories', true), array('controller'=> 'categories', 'action'=>'index')));