diff --git a/Application/Controller/Admin/Posts.php b/Application/Controller/Admin/Posts.php
index 41b5d67..5506d4c 100644
--- a/Application/Controller/Admin/Posts.php
+++ b/Application/Controller/Admin/Posts.php
@@ -7,6 +7,9 @@
-> import('Model.Post')
-> import('Model.Comment');
+from('Hoa')
+-> import('Stringbuffer.Read');
+
}
namespace Application\Controller\Admin {
@@ -48,6 +51,37 @@ public function IndexAction ( ) {
return;
}
+ public function ShowAction ( $id ) {
+
+ $post = $this->LoadPost($this, $id, \Application\Model\Post::STATE_ALL);
+
+ $this->data->title = $post->title;
+ $this->data->post = $post;
+
+ $buffer = new \Hoa\Stringbuffer\Read();
+ $buffer->initializeWith(
+ '' . "\n\n" .
+ '' . "\n".
+ ' ' . "\n" .
+ $post->content .
+ ' ' . "\n" .
+ ''
+ );
+ $this->view->addFragment(
+ $buffer->getStreamName(),
+ 'content'
+ );
+
+ // TODO use post id from post in view
+ $this->data->post_id = $post->id;
+ $this->data->comments = $post->comments;
+
+ $this->view->addOverlay('hoa://Application/View/Admin/Posts/Show.xyl');
+ $this->view->render();
+
+ return;
+ }
+
public function NewAction ( ) {
$this->adminGuard();
diff --git a/Application/Model/Post.php b/Application/Model/Post.php
index 7a35d86..39a9c39 100644
--- a/Application/Model/Post.php
+++ b/Application/Model/Post.php
@@ -42,20 +42,23 @@ protected function construct ( ) {
return;
}
- static public function findByIdAndState ( $id, $state = STATE_PUBLISHED ) {
+ static public function findByIdAndState ( $id, $state = Post::STATE_PUBLISHED ) {
$post = new Post();
- $data = $post->getMappingLayer()
- ->prepare(
+ $query = $post->getMappingLayer()
+ ->prepare(
'SELECT id, posted, title, content, state ' .
'FROM post ' .
- 'WHERE id = :id ' .
- 'AND (state1 = :state OR :state2 = -1)'
- )
- ->bindParam(':id', $id, PDO::PARAM_INT)
- ->bindParam(':state1', $state, PDO::PARAM_INT)
- ->bindParam(':state2', $state, PDO::PARAM_INT)
- ->fetchAll();
+ 'WHERE (id = :id) ' .
+ 'AND (state = :state1 OR :state2 = -1)'
+ );
+
+ $query->bindParameter(':id', $id, \PDO::PARAM_INT);
+ $query->bindParameter(':state1', $state, \PDO::PARAM_INT);
+ $query->bindParameter(':state2', $state, \PDO::PARAM_INT);
+
+ $data = $query->execute()
+ ->fetchAll();
if(!empty($data)) {
$post->map($data[0]);
@@ -152,19 +155,21 @@ public function getList ( $current_page, $post_per_page, $state = Post::STATE_PU
$first_entry = ($current_page - 1) * $post_per_page;
- $list = $this->getMappingLayer()
- ->prepare(
- 'SELECT id, title, posted, state ' .
- 'FROM post ' .
- 'WHERE (state = :state1 OR :state2 = -1)' .
- 'ORDER BY posted DESC ' .
- 'LIMIT :first_entry, :post_per_page'
- )
- ->bindParam(':state1', $state, PDO::PARAM_INT)
- ->bindParam(':state2', $state, PDO::PARAM_INT)
- ->bindParam(':first_entry', $first_entry, PDO::PARAM_INT)
- ->bindParam(':post_per_page', $post_per_page, PDO::PARAM_INT)
- ->fetchAll();
+ $query = $this->getMappingLayer()
+ ->prepare(
+ 'SELECT id, title, posted, state ' .
+ 'FROM post ' .
+ 'WHERE (state = :state1 OR :state2 = -1)' .
+ 'ORDER BY posted DESC ' .
+ 'LIMIT :first_entry, :post_per_page'
+ );
+ $query->bindParameter(':state1', $state, \PDO::PARAM_INT);
+ $query->bindParameter(':state2', $state, \PDO::PARAM_INT);
+ $query->bindParameter(':first_entry', $first_entry, \PDO::PARAM_INT);
+ $query->bindParameter(':post_per_page', $post_per_page, \PDO::PARAM_INT);
+
+ $list = $query->execute()
+ ->fetchAll();
foreach($list as &$post) {
@@ -190,16 +195,17 @@ public static function getNormalizedTitle( $title ) {
public function count ( $state = Post::STATE_PUBLISHED ) {
- return $this->getMappingLayer()
- ->prepare(
+ $query = $this->getMappingLayer()
+ ->prepare(
'SELECT COUNT(*) ' .
- 'FROM post ' .
- 'WHERE (state = :state1 OR :state2 = -1)'
- )
- ->bindParam(':state1', $state, PDO::PARAM_INT)
- ->bindParam(':state2', $state, PDO::PARAM_INT)
- ->execute()
- ->fetchColumn();
+ 'FROM post ' .
+ 'WHERE (state = :state1 OR :state2 = -1)'
+ );
+ $query->bindParameter(':state1', $state, \PDO::PARAM_INT);
+ $query->bindParameter(':state2', $state, \PDO::PARAM_INT);
+
+ return $query->execute()
+ ->fetchColumn();
}
}
diff --git a/Application/Public/index.php b/Application/Public/index.php
index f440b2b..89099a3 100644
--- a/Application/Public/index.php
+++ b/Application/Public/index.php
@@ -34,6 +34,7 @@
->post('login', '/admin/log/in', 'admin\log', 'in')
->get('logout', '/admin/log/out', 'admin\log', 'out')
->get('admin_posts', '/admin/posts', 'admin\posts', 'index')
+ ->get('admin_post', '/admin/posts/(?\d+)\-(?.+)\.html', 'admin\posts', 'show')
->get('new_post', '/admin/posts/new', 'admin\posts', 'new')
->post('create_post','/admin/posts/create', 'admin\posts', 'create')
->get('edit_post', '/admin/posts/(?\d+)/edit', 'admin\posts', 'edit')
diff --git a/Application/View/Admin/Posts/Index.xyl b/Application/View/Admin/Posts/Index.xyl
index 1ed35d1..543b5f9 100644
--- a/Application/View/Admin/Posts/Index.xyl
+++ b/Application/View/Admin/Posts/Index.xyl
@@ -13,7 +13,7 @@
—
-
+
diff --git a/Application/View/Admin/Posts/Show.xyl b/Application/View/Admin/Posts/Show.xyl
new file mode 100644
index 0000000..3af25cd
--- /dev/null
+++ b/Application/View/Admin/Posts/Show.xyl
@@ -0,0 +1,19 @@
+
+
+
+
+
+
☜ Back to list
+
+
+
+
+
+
+
+
\ No newline at end of file