fixes in menu, routing, models
This commit is contained in:
parent
3a88c6c433
commit
b20be3e3cb
14 changed files with 180 additions and 52 deletions
|
|
@ -62,6 +62,10 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
|
||||
$view->app = $this->getApplication()->getOption('app');
|
||||
|
||||
|
||||
Zend_Locale::setDefault('sv_SE');
|
||||
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
@ -99,20 +103,58 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
|
||||
$router = $this->getResource('front')->getRouter();
|
||||
|
||||
$route = new Zend_Controller_Router_Route(
|
||||
':lang/:module/:controller/:action/*',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'default',
|
||||
'controller' => 'index',
|
||||
'action' => 'index'
|
||||
),
|
||||
array(
|
||||
'lang' => '[a-z]{2}'
|
||||
)
|
||||
);
|
||||
|
||||
$router->addRoute('default', $route);
|
||||
|
||||
|
||||
$router->addRoute('default', new Zend_Controller_Router_Route(':lang/:controller/:action',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'default',
|
||||
'controller' => 'index',
|
||||
'action' => 'index'
|
||||
)
|
||||
));
|
||||
|
||||
$router->addRoute('index', new Zend_Controller_Router_Route(
|
||||
':lang/:action',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'default',
|
||||
'controller' => 'index',
|
||||
'action' => 'index'
|
||||
)
|
||||
));
|
||||
|
||||
$router->addRoute('blog', new Zend_Controller_Router_Route(
|
||||
':lang/blog/:action',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'blog',
|
||||
'controller' => 'index',
|
||||
'action' => 'latest'
|
||||
)
|
||||
));
|
||||
|
||||
$router->addRoute('portfolio', new Zend_Controller_Router_Route(
|
||||
':lang/portfolio/:action',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'default',
|
||||
'controller' => 'portfolio',
|
||||
'action' => 'index'
|
||||
)
|
||||
));
|
||||
|
||||
$router->addRoute('admin', new Zend_Controller_Router_Route(
|
||||
':lang/admin/:action',
|
||||
array(
|
||||
'lang' => 'sv',
|
||||
'module' => 'blog',
|
||||
'controller' => 'index',
|
||||
'action' => 'latest'
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,35 +3,34 @@
|
|||
<navigation>
|
||||
<start>
|
||||
<label>u:home</label>
|
||||
<controller>index</controller>
|
||||
<action>index</action>
|
||||
<route>index</route>
|
||||
<module>default</module>
|
||||
<controller>index</controller>
|
||||
</start>
|
||||
|
||||
<blog>
|
||||
<label>u:blog</label>
|
||||
<route>default</route>
|
||||
<route>blog</route>
|
||||
<module>blog</module>
|
||||
<controller>index</controller>
|
||||
<action>index</action>
|
||||
<action>latest</action>
|
||||
<pages>
|
||||
<latest>
|
||||
<label>u:latest</label>
|
||||
<route>default</route>
|
||||
<route>blog</route>
|
||||
<module>blog</module>
|
||||
<controller>index</controller>
|
||||
<action>latest</action>
|
||||
</latest>
|
||||
<archive>
|
||||
<label>u:archive</label>
|
||||
<route>default</route>
|
||||
<route>blog</route>
|
||||
<module>blog</module>
|
||||
<controller>index</controller>
|
||||
<action>archive</action>
|
||||
</archive>
|
||||
<others>
|
||||
<label>u:readable</label>
|
||||
<route>default</route>
|
||||
<route>blog</route>
|
||||
<module>blog</module>
|
||||
<controller>index</controller>
|
||||
<action>readable</action>
|
||||
|
|
@ -49,7 +48,7 @@
|
|||
|
||||
<about>
|
||||
<label>uw:about</label>
|
||||
<route>default</route>
|
||||
<route>index</route>
|
||||
<module>default</module>
|
||||
<controller>index</controller>
|
||||
<action>about</action>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ class BlogPost
|
|||
protected $_isPublished = false;
|
||||
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
if (is_string($title) && null == $title[30]) {
|
||||
|
|
@ -22,6 +27,11 @@ class BlogPost
|
|||
}
|
||||
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->_content;
|
||||
}
|
||||
|
||||
public function setContent($content)
|
||||
{
|
||||
if (is_string($content)) {
|
||||
|
|
@ -34,6 +44,11 @@ class BlogPost
|
|||
}
|
||||
|
||||
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->_author;
|
||||
}
|
||||
|
||||
public function setAuthor($author)
|
||||
{
|
||||
if ($author instanceof User) {
|
||||
|
|
@ -46,15 +61,22 @@ class BlogPost
|
|||
}
|
||||
|
||||
|
||||
public function getPubDate()
|
||||
{
|
||||
return $this->_pubDate;
|
||||
}
|
||||
|
||||
public function setPubDate($date)
|
||||
{
|
||||
if (is_string($date) && preg_match('/^(?:(?:19[0-9]{2})|(?:20[0-9]{2}))\-' .
|
||||
'(?:(?:0[1-9])|(?:1[012]))\-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/', $date)) {
|
||||
|
||||
if (Fiktiv_Date::isDate($date)) {
|
||||
|
||||
$this->_pubDate = $date;
|
||||
$this->_pubDate = new Fiktiv_Date($date);
|
||||
|
||||
} else if ($date instanceof Zend_Date) {
|
||||
|
||||
$this->_pubDate = $date->toString('yyyy-MM-dd');
|
||||
$this->_pubDate = $date;
|
||||
|
||||
} else {
|
||||
|
||||
return false;
|
||||
|
|
@ -73,14 +95,4 @@ class BlogPost
|
|||
$this->_isPublished = (boolean)$flag;
|
||||
}
|
||||
|
||||
public function __call($name,$args) {
|
||||
|
||||
// getX methods
|
||||
if ('get' == substr($name,0,3)) {
|
||||
$dataPart = '_'.lcfirst(substr($name,3));
|
||||
if (isset($this->$dataPart))
|
||||
return $this->$dataPart;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,14 @@
|
|||
class Mapper_BlogPost extends Fiktiv_Data_Mapper_DbTable_Abstract
|
||||
{
|
||||
|
||||
protected $_mapperUser = null;
|
||||
|
||||
public function __construct($dbtable = null) {
|
||||
parent::__construct($dbtable);
|
||||
|
||||
$this->_mapperUser = new Mapper_User(new Table_User());
|
||||
}
|
||||
|
||||
protected function _createBlogPost($obj)
|
||||
{
|
||||
$blogPost = new BlogPost();
|
||||
|
|
@ -11,11 +19,8 @@ class Mapper_BlogPost extends Fiktiv_Data_Mapper_DbTable_Abstract
|
|||
|
||||
$blogPost->setTitle($obj->title);
|
||||
$blogPost->setContent($obj->content);
|
||||
$blogPost->setPubDate($obj->pubDate);
|
||||
|
||||
$mapperUser = new Mapper_User(new Table_User());
|
||||
$user = $mapperUser->findById($obj->userId);
|
||||
$blogPost->setAuthor($user);
|
||||
$blogPost->setPubDate(new Fiktiv_Date($obj->pubDate));
|
||||
$blogPost->setAuthor($this->_mapperUser->findById($obj->userId));
|
||||
|
||||
} else {
|
||||
$blogPost = null;
|
||||
|
|
@ -33,10 +38,11 @@ class Mapper_BlogPost extends Fiktiv_Data_Mapper_DbTable_Abstract
|
|||
|
||||
public function findAll($limit = null)
|
||||
{
|
||||
$rows = $this->_dbTable->fetchAll();
|
||||
|
||||
$rows = $this->_dbTable->fetchAll(null, 'pubDate DESC');
|
||||
|
||||
$posts = array();
|
||||
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$posts[] = $this->_createBlogPost($row);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@ class Blog_IndexController extends Fiktiv_Controller_Action
|
|||
{
|
||||
public function indexAction()
|
||||
{
|
||||
// TODO: Set latest as default
|
||||
|
||||
$this->view->posts = $this->dbService->BlogPost->findAll();
|
||||
|
||||
$this->_forward('latest');
|
||||
}
|
||||
|
||||
public function latestAction()
|
||||
{
|
||||
$this->view->posts = $this->dataService->BlogPost->findAll();
|
||||
}
|
||||
|
||||
public function archiveAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<h1><?=$this->translate('u:archive') ?></h1>
|
||||
14
application/modules/blog/views/scripts/index/latest.phtml
Normal file
14
application/modules/blog/views/scripts/index/latest.phtml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<h1><?=$this->translate('u:blog') ?></h1>
|
||||
|
||||
<p><?=$this->translate('BLOG_TXT') ?></p>
|
||||
|
||||
|
||||
<?php foreach ($this->posts as $post): ?>
|
||||
|
||||
<div>
|
||||
<h3><?=$post->getTitle() ?></h3>
|
||||
<div><?=$post->getContent() ?></div>
|
||||
<div><?=$post->getPubDate()->toString('yyyy-MM-dd').' at '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?></div>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -9,7 +9,7 @@ class IndexController extends Fiktiv_Controller_Action
|
|||
//echo $m->name;
|
||||
|
||||
// Quick access
|
||||
$me = $this->dbService->User->findRandom();
|
||||
$me = $this->dataService->User->findRandom();
|
||||
echo $me;
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ class IndexController extends Fiktiv_Controller_Action
|
|||
//$dbLayer = Fiktiv_Db_Service::getInstance();
|
||||
//$me = $dbLayer->users->findByEmail('fredric@fiktivkod.org');
|
||||
|
||||
$dbLayer = $this->_helper->dbService();
|
||||
$dbLayer = $this->_helper->dataService();
|
||||
$me = $dbLayer->User->findByEmail('fredric@fiktivkod.org');
|
||||
echo $me;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
class PortfolioController extends Fiktiv_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
17
library/Fiktiv/Controller/Action/Helper/DataService.php
Normal file
17
library/Fiktiv/Controller/Action/Helper/DataService.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Access Fiktiv_Db_Service instance from controller
|
||||
* Not easier than calling the class itself but what the heck.
|
||||
*/
|
||||
class Fiktiv_Controller_Action_Helper_DataService extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
public function dataService()
|
||||
{
|
||||
return Fiktiv_Data_Service::getInstance();
|
||||
}
|
||||
|
||||
public function direct()
|
||||
{
|
||||
return $this->dataService();
|
||||
}
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ class Fiktiv_Data_Service
|
|||
public function __get($name) {
|
||||
|
||||
// Class prefix
|
||||
$table = 'Table_'.$name;
|
||||
$name = 'Mapper_'.$name;
|
||||
$table = 'Table_'.$name;
|
||||
$name = 'Mapper_'.$name;
|
||||
|
||||
/*
|
||||
* Two ways to go, if we already have the datapoint object we
|
||||
|
|
|
|||
26
library/Fiktiv/Date.php
Normal file
26
library/Fiktiv/Date.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class Fiktiv_Date extends Zend_Date
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
public function toString($format = null, $type = null, $locale = null)
|
||||
{
|
||||
if (null === $format)
|
||||
$format = 'yyyy-MM-dd HH:mm:ss';
|
||||
|
||||
return parent::toString($format, $type, $locale);
|
||||
}
|
||||
|
||||
public static function isDate($date, $format = null, $locale = null)
|
||||
{
|
||||
|
||||
if (null === $format)
|
||||
$format = 'yyyy-MM-dd HH:mm:ss';
|
||||
|
||||
return parent::isDate($date, $format, $locale);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ class Fiktiv_View_Helper_RenderMenu extends Zend_View_Helper_Abstract
|
|||
$container = $navigation->getContainer();
|
||||
$active = $navigation->menu()->findActive($navigation->getContainer());
|
||||
|
||||
if ($active && $active['page']->hasPages()) {
|
||||
if ($active && $active['page']->getParent()->hasPages()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Reference in a new issue