diff --git a/application/Bootstrap.php b/application/Bootstrap.php index cc38c2b..70c0d0c 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -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; } diff --git a/application/configs/navigation.xml b/application/configs/navigation.xml index 0a031be..3291a22 100644 --- a/application/configs/navigation.xml +++ b/application/configs/navigation.xml @@ -3,35 +3,34 @@ - index - index + index default + index - - default + blog blog index - index + latest - default + blog blog index latest - default + blog blog index archive - default + blog blog index readable @@ -49,7 +48,7 @@ - default + index default index about diff --git a/application/models/BlogPost.php b/application/models/BlogPost.php index 33f513e..ff12b5c 100644 --- a/application/models/BlogPost.php +++ b/application/models/BlogPost.php @@ -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; - } - - } } \ No newline at end of file diff --git a/application/models/Mapper/BlogPost.php b/application/models/Mapper/BlogPost.php index dbcaf36..c56a4d3 100644 --- a/application/models/Mapper/BlogPost.php +++ b/application/models/Mapper/BlogPost.php @@ -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); } diff --git a/application/modules/blog/controllers/IndexController.php b/application/modules/blog/controllers/IndexController.php index aa77765..7df107a 100644 --- a/application/modules/blog/controllers/IndexController.php +++ b/application/modules/blog/controllers/IndexController.php @@ -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() { } diff --git a/application/modules/blog/views/scripts/index/archive.phtml b/application/modules/blog/views/scripts/index/archive.phtml new file mode 100644 index 0000000..5ef7103 --- /dev/null +++ b/application/modules/blog/views/scripts/index/archive.phtml @@ -0,0 +1 @@ +

translate('u:archive') ?>

\ 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 new file mode 100644 index 0000000..d1477d8 --- /dev/null +++ b/application/modules/blog/views/scripts/index/latest.phtml @@ -0,0 +1,14 @@ +

translate('u:blog') ?>

+ +

translate('BLOG_TXT') ?>

+ + +posts as $post): ?> + +
+

getTitle() ?>

+
getContent() ?>
+
getPubDate()->toString('yyyy-MM-dd').' at '.$post->getPubDate()->toString('HH:mm').' '.$post->getAuthor()->getFirstName() ?>
+
+ + \ No newline at end of file diff --git a/application/modules/default/controllers/IndexController.php b/application/modules/default/controllers/IndexController.php index edef0a9..f290cc2 100644 --- a/application/modules/default/controllers/IndexController.php +++ b/application/modules/default/controllers/IndexController.php @@ -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; diff --git a/application/modules/default/controllers/PortfolioController.php b/application/modules/default/controllers/PortfolioController.php new file mode 100644 index 0000000..d6b6336 --- /dev/null +++ b/application/modules/default/controllers/PortfolioController.php @@ -0,0 +1,9 @@ +dataService(); + } +} \ No newline at end of file diff --git a/library/Fiktiv/Data/Service.php b/library/Fiktiv/Data/Service.php index fcd9129..a8d9547 100644 --- a/library/Fiktiv/Data/Service.php +++ b/library/Fiktiv/Data/Service.php @@ -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 diff --git a/library/Fiktiv/Date.php b/library/Fiktiv/Date.php new file mode 100644 index 0000000..48642bf --- /dev/null +++ b/library/Fiktiv/Date.php @@ -0,0 +1,26 @@ +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); + } +} \ No newline at end of file diff --git a/library/Fiktiv/View/Helper/RenderMenu.php b/library/Fiktiv/View/Helper/RenderMenu.php index 10845bb..c77aacf 100644 --- a/library/Fiktiv/View/Helper/RenderMenu.php +++ b/library/Fiktiv/View/Helper/RenderMenu.php @@ -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;