From 8cab418a8a61525a36219cd52aa5d3f291d090f5 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sat, 30 Oct 2010 15:11:34 +0200 Subject: [PATCH] Routing fix and some work on the blog --- application/Bootstrap.php | 3 ++ application/languages/en.ini | 4 +-- application/languages/se.ini | 5 +++- application/models/BlogPost.php | 6 ++-- application/models/Mapper/BlogPost.php | 24 ++++++++++++++- application/models/Mapper/Tag.php | 23 +++++++++++++++ application/models/Table/PosthasTag.php | 20 +++++++++++++ application/models/Table/Tag.php | 8 +++++ .../blog/views/scripts/archive/filter.phtml | 29 +++++++++++++++++++ .../blog/views/scripts/index/latest.phtml | 22 +++++++++++--- .../blog/views/scripts/index/read.phtml | 2 +- library/Fiktiv/Controller/Plugin/Language.php | 4 +++ library/Fiktiv/View/Helper/AuthLink.php | 4 +-- 13 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 application/models/Mapper/Tag.php create mode 100644 application/models/Table/PosthasTag.php create mode 100644 application/models/Table/Tag.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index e76b554..f466745 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -117,6 +117,9 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $this->bootstrap('front'); $router = $this->getResource('front')->getRouter(); + + // Use request params + //$router->useRequestParametersAsGlobal(false); // Set global lang param $router->setGlobalParam('lang', 'sv'); diff --git a/application/languages/en.ini b/application/languages/en.ini index 927e113..0154f6d 100644 --- a/application/languages/en.ini +++ b/application/languages/en.ini @@ -27,6 +27,4 @@ ERROR_500_TXT = "We will look into it as soon as we can." ERROR_TXT_WHAT = "The following went wrong" - - - +TIME_AT = at diff --git a/application/languages/se.ini b/application/languages/se.ini index 1c282c3..07e378a 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -49,4 +49,7 @@ back = tillbaka ERROR_FORM_EMPTY = fältet får inte vara tomt -ERROR_FORM_EMAIL_INVALID = epost adressen är inte gilltig \ No newline at end of file +ERROR_FORM_EMAIL_INVALID = epost adressen är inte gilltig + + +TIME_AT = vid \ No newline at end of file diff --git a/application/models/BlogPost.php b/application/models/BlogPost.php index ade1a60..0da4740 100644 --- a/application/models/BlogPost.php +++ b/application/models/BlogPost.php @@ -95,9 +95,11 @@ class BlogPost extends Fiktiv_Model_Abstract public function setTags(array $tags) { // make sure the all elements are strings - foreach ($tags as $tag) { - if (!is_string($tag)) + foreach ($tags as $key => $tag) { + + if (!is_string($tag)) { return false; + } } $this->_data['tags'] = $tags; diff --git a/application/models/Mapper/BlogPost.php b/application/models/Mapper/BlogPost.php index 1b01c84..87c6ac1 100644 --- a/application/models/Mapper/BlogPost.php +++ b/application/models/Mapper/BlogPost.php @@ -32,11 +32,15 @@ class Mapper_BlogPost extends Fiktiv_Model_Mapper_DbTableAbstract if (is_array($obj)) { - + + // Get Author if (isset($obj['userId'])) { $obj['author'] = Fiktiv_Data_Service::getInstance()->User->findById($obj['userId']); unset($obj['userId']); } + + // Get tags + $obj['tags'] = $this->getTags($obj['id']); $blogPost = new BlogPost($obj); @@ -47,6 +51,10 @@ class Mapper_BlogPost extends Fiktiv_Model_Mapper_DbTableAbstract return $blogPost; } + public function getTags($blogPostId) + { + return Fiktiv_Data_Service::getInstance()->Tag->findByBlogPost($blogPostId); + } public function findById($id) { @@ -73,6 +81,18 @@ class Mapper_BlogPost extends Fiktiv_Model_Mapper_DbTableAbstract } } + public function findByTag($tag) + { + $rows = $this->_dbTable->getAdapter() + ->select()->from('Post') + ->join('Post_has_Tag', 'Post_has_Tag.postId = Post.id') + ->join('Tag', 'Tag.id = Post_has_Tag.tagId') + ->where('Tag.name = ?', $tag) + ->query()->fetchAll(); + + return $this->_createBlogPosts($rows); + } + public function findByMonth($month = null) { return $this->_dbTable->select() @@ -109,6 +129,8 @@ class Mapper_BlogPost extends Fiktiv_Model_Mapper_DbTableAbstract $tags = $data['tags']; unset($data['tags']); + + return $this->_dbTable->update( $data, $this->quoteInto('id = ?',$post->getId()) diff --git a/application/models/Mapper/Tag.php b/application/models/Mapper/Tag.php new file mode 100644 index 0000000..d4ecc80 --- /dev/null +++ b/application/models/Mapper/Tag.php @@ -0,0 +1,23 @@ +getAdapter()->select() + ->from('Post_has_Tag',array()) + ->join('Tag', 'Tag.id = Post_has_Tag.tagId', array('id', 'name')) + ->where('Post_has_Tag.postId = ?', $id) + ->query()->fetchAll(); + + $tags = array(); + foreach ($rows as $row) { + $tags[$row['id']] = $row['name']; + } + + return $tags; + } +} \ No newline at end of file diff --git a/application/models/Table/PosthasTag.php b/application/models/Table/PosthasTag.php new file mode 100644 index 0000000..9e9e543 --- /dev/null +++ b/application/models/Table/PosthasTag.php @@ -0,0 +1,20 @@ + array( + 'columns' => 'postId', + 'refTableClass' => 'Post', + 'refColumns' => 'id' + ), + 'Tag' => array( + 'columns' => 'tagId', + 'refTableClass' => 'Tag', + 'refColumns' => 'id' + ) + ); + +} \ No newline at end of file diff --git a/application/models/Table/Tag.php b/application/models/Table/Tag.php new file mode 100644 index 0000000..00fd7e5 --- /dev/null +++ b/application/models/Table/Tag.php @@ -0,0 +1,8 @@ +url(array('action' => 'latest', 'id' => ''), 'blog-default') ?>">« translate('u:back') ?> + +posts as $post) : ?> +
+

getTitle() ?>

+

getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?>

+
+ getContent() ?> +
+ + getTags()) { + + echo '
'; + + $tagList = ''; + foreach ($post->getTags() as $k => $t) { + $tagList .= ''.$t.', '; + } + + echo substr($tagList,0,-2); + + echo '
'; + } + ?> + +
+ \ No newline at end of file diff --git a/application/modules/blog/views/scripts/index/latest.phtml b/application/modules/blog/views/scripts/index/latest.phtml index 3a033d0..a7eac5f 100644 --- a/application/modules/blog/views/scripts/index/latest.phtml +++ b/application/modules/blog/views/scripts/index/latest.phtml @@ -2,15 +2,29 @@

translate('BLOG_LATEST_INTRO') ?>

- posts as $post) : ?>

getTitle() ?>

-

getPubDate()->toString('yyyy-MM-dd').' at '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?>

+

getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?>

getContent() ?>
- -
Something, Something
+ + getTags()) { + + echo '
'; + + $tagList = ''; + foreach ($post->getTags() as $k => $t) { + $tagList .= ''.$t.', '; + } + + echo substr($tagList,0,-2); + + echo '
'; + } + ?> +
\ No newline at end of file diff --git a/application/modules/blog/views/scripts/index/read.phtml b/application/modules/blog/views/scripts/index/read.phtml index 0602cec..5b5460c 100644 --- a/application/modules/blog/views/scripts/index/read.phtml +++ b/application/modules/blog/views/scripts/index/read.phtml @@ -6,7 +6,7 @@

post->getTitle() ?>

-

post->getPubDate()->toString('yyyy-MM-dd').' at '.$this->post->getPubDate()->toString('HH:mm').' '.$this->post->getAuthor()->getFirstName() ?>

+

post->getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$this->post->getPubDate()->toString('HH:mm').' '.$this->post->getAuthor()->getFirstName() ?>

post->getContent() ?>
diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php index 8b7e0ed..e97451f 100644 --- a/library/Fiktiv/Controller/Plugin/Language.php +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -11,6 +11,10 @@ class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract $lang = $request->getParam('lang'); + // Set language. + $router = $bootstrap->getResource('frontcontroller')->getRouter(); + $router->setGlobalParam('lang', $lang); + // If lang is not supplied we use default. if (is_null($lang) || !in_array($lang, array('sv', 'en'))) { diff --git a/library/Fiktiv/View/Helper/AuthLink.php b/library/Fiktiv/View/Helper/AuthLink.php index 270294b..9d6fb07 100644 --- a/library/Fiktiv/View/Helper/AuthLink.php +++ b/library/Fiktiv/View/Helper/AuthLink.php @@ -18,7 +18,7 @@ class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract $options['action'] = 'logout'; $display = ' (' . $this->view->translate('u:logout') . ')'; - $prefix = ''; + $prefix = ''; if (strlen($identity->firstName)) { $prefix .= $identity->firstName; @@ -37,7 +37,7 @@ class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract } return $prefix - . '' + . '' . $display . ' '; }