Routing fix and some work on the blog
This commit is contained in:
parent
239a496304
commit
8cab418a8a
13 changed files with 140 additions and 14 deletions
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
ERROR_FORM_EMAIL_INVALID = epost adressen är inte gilltig
|
||||
|
||||
|
||||
TIME_AT = vid
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
23
application/models/Mapper/Tag.php
Normal file
23
application/models/Mapper/Tag.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
class Mapper_Tag extends Fiktiv_Model_Mapper_DbTableAbstract
|
||||
{
|
||||
public function findByBlogPost($id)
|
||||
{
|
||||
|
||||
$postHasTagsTable = new Table_PosthasTag();
|
||||
|
||||
$rows = $postHasTagsTable->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;
|
||||
}
|
||||
}
|
||||
20
application/models/Table/PosthasTag.php
Normal file
20
application/models/Table/PosthasTag.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
class Table_PosthasTag extends Fiktiv_Db_Table_Abstract
|
||||
{
|
||||
protected $_schema = 'fiktivkod';
|
||||
protected $_name = 'Post_has_Tag';
|
||||
protected $_referenceMap = array(
|
||||
'Post' => array(
|
||||
'columns' => 'postId',
|
||||
'refTableClass' => 'Post',
|
||||
'refColumns' => 'id'
|
||||
),
|
||||
'Tag' => array(
|
||||
'columns' => 'tagId',
|
||||
'refTableClass' => 'Tag',
|
||||
'refColumns' => 'id'
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
8
application/models/Table/Tag.php
Normal file
8
application/models/Table/Tag.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
class Table_Tag extends Fiktiv_Db_Table_Abstract
|
||||
{
|
||||
protected $_schema = 'fiktivkod';
|
||||
protected $_name = 'Tag';
|
||||
protected $_primary = 'id';
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
<a href="<?=$this->url(array('action' => 'latest', 'id' => ''), 'blog-default') ?>">« <?=$this->translate('u:back') ?></a>
|
||||
|
||||
<?php foreach($this->posts as $post) : ?>
|
||||
<div class="blogpost">
|
||||
<h3><a href="<?=$this->url(array('action' => 'read','id' => $post->getPermalink()),'blog-default') ?>"><?=$post->getTitle() ?></a></h3>
|
||||
<p class="publish"><?=$post->getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?></p>
|
||||
<div class="content">
|
||||
<?=$post->getContent() ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ($post->getTags()) {
|
||||
|
||||
echo '<div class="tags">';
|
||||
|
||||
$tagList = '';
|
||||
foreach ($post->getTags() as $k => $t) {
|
||||
$tagList .= '<a href="'.$this->url(array('controller' => 'archive','action' => 'filter', 'tag' => $t), 'blog').'">'.$t.'</a>, ';
|
||||
}
|
||||
|
||||
echo substr($tagList,0,-2);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -2,15 +2,29 @@
|
|||
|
||||
<p><?=$this->translate('BLOG_LATEST_INTRO') ?></p>
|
||||
|
||||
|
||||
<?php foreach($this->posts as $post) : ?>
|
||||
<div class="blogpost">
|
||||
<h3><a href="<?=$this->url(array('action' => 'read','id' => $post->getPermalink()),'blog-default') ?>"><?=$post->getTitle() ?></a></h3>
|
||||
<p class="publish"><?=$post->getPubDate()->toString('yyyy-MM-dd').' at '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?></p>
|
||||
<p class="publish"><?=$post->getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?></p>
|
||||
<div class="content">
|
||||
<?=$post->getContent() ?>
|
||||
</div>
|
||||
<!-- <div class="tags"><?=join(', ',$post->getTags()) ?></div> -->
|
||||
<div class="tags">Something, Something</div>
|
||||
|
||||
<?php
|
||||
if ($post->getTags()) {
|
||||
|
||||
echo '<div class="tags">';
|
||||
|
||||
$tagList = '';
|
||||
foreach ($post->getTags() as $k => $t) {
|
||||
$tagList .= '<a href="'.$this->url(array('controller' => 'archive','action' => 'filter', 'tag' => $t), 'blog').'">'.$t.'</a>, ';
|
||||
}
|
||||
|
||||
echo substr($tagList,0,-2);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<div class="blogpost">
|
||||
<h1><?=$this->post->getTitle() ?></h1>
|
||||
<p class="publish"><?=$this->post->getPubDate()->toString('yyyy-MM-dd').' at '.$this->post->getPubDate()->toString('HH:mm').' '.$this->post->getAuthor()->getFirstName() ?></p>
|
||||
<p class="publish"><?=$this->post->getPubDate()->toString('yyyy-MM-dd').' '.$this->translate('TIME_AT').' '.$this->post->getPubDate()->toString('HH:mm').' '.$this->post->getAuthor()->getFirstName() ?></p>
|
||||
<div class="content"><?=$this->post->getContent() ?></div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -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'))) {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract
|
|||
$options['action'] = 'logout';
|
||||
$display = ' (' . $this->view->translate('u:logout') . ')';
|
||||
|
||||
$prefix = '<a href="'.$this->view->url(array('controller' => 'profile'), 'default').'">';
|
||||
$prefix = '<a href="'.$this->view->url(array('controller' => 'profile'), 'default', true).'">';
|
||||
|
||||
if (strlen($identity->firstName)) {
|
||||
$prefix .= $identity->firstName;
|
||||
|
|
@ -37,7 +37,7 @@ class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract
|
|||
}
|
||||
|
||||
return $prefix
|
||||
. '<a href="' . $this->view->url($options, 'auth') . '">'
|
||||
. '<a href="' . $this->view->url($options, 'auth', true) . '">'
|
||||
. $display
|
||||
. '</a> ';
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue