Permalink
Browse files

Merge pull request #41 from bakura10/views

Allow to show all categories
  • Loading branch information...
2 parents 0d5b36c + 9a17bbc commit 059d23722214674b765b58c7c9b9d993ba853055 @bakura10 bakura10 committed Nov 24, 2012
Showing with 507 additions and 91 deletions.
  1. +2 −2 Module.php
  2. +1 −1 config/module.config.php
  3. +14 −9 config/module.config.routes.php
  4. +30 −0 public/js/angular.js
  5. +6 −0 public/js/bootstrap.min.js
  6. +3 −0 public/js/html5.js
  7. +2 −0 public/js/jquery.min.js
  8. +10 −0 public/partials/messages.html
  9. +6 −0 public/partials/thread-detail.html
  10. +13 −3 src/ZfrForum/Controller/CategoryController.php
  11. +48 −4 src/ZfrForum/Controller/{MessageController.php → PostController.php}
  12. +8 −3 src/ZfrForum/Controller/ThreadController.php
  13. +16 −1 src/ZfrForum/Entity/Category.php
  14. +155 −2 src/ZfrForum/Entity/Post.php
  15. +24 −2 src/ZfrForum/Entity/Thread.php
  16. +1 −0 src/ZfrForum/Mapper/PostMapperInterface.php
  17. +0 −6 src/ZfrForum/Mapper/ReportMapperInterface.php
  18. +13 −1 src/ZfrForum/Repository/CategoryRepository.php
  19. +0 −1 src/ZfrForum/Repository/CategoryTrackingRepository.php
  20. +67 −0 src/ZfrForum/Repository/EntityRepository.php
  21. +0 −1 src/ZfrForum/Repository/PostRepository.php
  22. +0 −1 src/ZfrForum/Repository/RankRepository.php
  23. +0 −21 src/ZfrForum/Repository/ReportRepository.php
  24. +0 −1 src/ZfrForum/Repository/SettingsRepository.php
  25. +0 −1 src/ZfrForum/Repository/ThreadRepository.php
  26. +0 −1 src/ZfrForum/Repository/ThreadTrackingRepository.php
  27. +0 −1 src/ZfrForum/Repository/UserBanRepository.php
  28. +11 −0 src/ZfrForum/Service/CategoryService.php
  29. +27 −0 src/ZfrForum/Service/PostService.php
  30. +27 −27 src/ZfrForum/Service/ThreadService.php
  31. +3 −1 view/zfr-forum/category/get-list.phtml
  32. +0 −1 view/zfr-forum/message/item.phtml
  33. +3 −0 view/zfr-forum/post/get-list.phtml
  34. +17 −0 view/zfr-forum/post/get.phtml
  35. 0 view/zfr-forum/thread/get-list.phtml
  36. 0 view/zfr-forum/thread/get.phtml
View
@@ -156,7 +156,7 @@ public function getServiceConfig()
'ZfrForum\Service\PostService' => function($serviceManager) {
$postMapper = $serviceManager->get('ZfrForum\Mapper\PostMapperInterface');
$reportMapper = $serviceManager->get('ZfrForum\Mapper\ReportMapperInterface');
- $authentication = $serviceManager->get('Zend\Authentication\AuthenticationService');
+ $authentication = $serviceManager->get('zfcuser_auth_service');
return new Service\PostService($postMapper, $reportMapper, $authentication);
},
'ZfrForum\Service\RankService' => function($serviceManager) {
@@ -170,7 +170,7 @@ public function getServiceConfig()
'ZfrForum\Service\ThreadService' => function($serviceManager) {
$threadMapper = $serviceManager->get('ZfrForum\Mapper\ThreadMapperInterface');
$threadTrackingMapper = $serviceManager->get('ZfrForum\Mapper\ThreadTrackingMapperInterface');
- $authentication = $serviceManager->get('Zend\Authentication\AuthenticationService');
+ $authentication = $serviceManager->get('zfcuser_auth_service');
return new Service\ThreadService($threadMapper, $threadTrackingMapper, $authentication);
},
'ZfrForum\Service\UserBanService' => function($serviceManager) {
View
@@ -90,7 +90,7 @@
'controllers' => array(
'invokables' => array(
'ZfrForum\Controller\Category' => 'ZfrForum\Controller\CategoryController',
- 'ZfrForum\Controller\Message' => 'ZfrForum\Controller\MessageController',
+ 'ZfrForum\Controller\Post' => 'ZfrForum\Controller\PostController',
'ZfrForum\Controller\Thread' => 'ZfrForum\Controller\ThreadController'
)
),
@@ -5,7 +5,7 @@
'zfrforum' => array(
'type' => 'Literal',
'options' => array(
- 'route' => '/forum/',
+ 'route' => '/forum',
'defaults' => array(
'controller' => 'ZfrForum\Controller\Category'
)
@@ -15,40 +15,45 @@
'categories' => array(
'type' => 'Segment',
'options' => array(
- 'route' => '/categories[/:id/:slug]',
+ 'route' => '/categories[/:id[/:slug]]',
'constraints' => array(
'id' => '[0-9]+',
'slug' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
- 'controller' => 'ZfrForum\Controller\Category'
+ 'controller' => 'ZfrForum\Controller\Category',
+ 'slug' => ''
)
)
),
'threads' => array(
'type' => 'Segment',
'options' => array(
- 'route' => '/threads[/:id/:slug]',
+ 'route' => '/threads[/:id[/:slug]]',
'constraints' => array(
'id' => '[0-9]+',
'slug' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
- 'controller' => 'ZfrForum\Controller\Thread'
+ 'controller' => 'ZfrForum\Controller\Thread',
+ 'slug' => ''
)
)
),
- 'messages' => array(
+ 'posts' => array(
'type' => 'Segment',
'options' => array(
- 'route' => '/messages[/:id]',
+ 'route' => '/threads/:threadId[/:slug]/posts[/:id]',
'constraints' => array(
- 'id' => '[0-9]+'
+ 'id' => '[0-9]+',
+ 'threadId' => '[0-9]+',
+ 'slug' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
- 'controller' => 'ZfrForum\Controller\Message'
+ 'controller' => 'ZfrForum\Controller\Post',
+ 'slug' => ''
)
)
)
View
@@ -0,0 +1,30 @@
+angular.module('threadServices', ['ngResource']).
+ factory('Thread', function($resource) {
+ return $resource('/forum/threads/:id', {}, {
+ query: {method: 'GET', params: {id: 'thread'}, isArray: true}
+ });
+ });
+
+angular.module('postServices', ['ngResource']).
+ factory('Post', function($resource) {
+ return $resource('/forum/threads/:threadId/posts', {}, {
+ query: {method: 'GET', isArray: true}
+ });
+ });
+
+function ThreadDetailController($scope, $routeParams, Thread) {
+ $scope.thread = Thread.get({id: $routeParams.id});
+}
+
+function PostsController($scope, $routeParams, Post) {
+ $scope.posts = Post.get({threadId: $routeParams.id});
+}
+
+angular.module('app', ['threadServices', 'postServices']).
+ config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
+ $locationProvider.html5Mode(true);
+
+ $routeProvider.
+ when('/forum/threads/:id', {templateUrl: '/partials/thread-detail.html', controller: ThreadDetailController}).
+ when('/forum/threads/:threadId/messages', {templateUrl: '/partials/messages.html', controller: PostsController})
+}]);

Large diffs are not rendered by default.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,10 @@
+<p>Salut</p>
+
+<div data-ng-controller="PostsController">
+ <ul>
+ <li data-ng-repeat="post in posts.posts">
+ {{ post.id }}
+ {{ post.content }}
+ </li>
+ </ul>
+</div>
@@ -0,0 +1,6 @@
+<h1>Ok</h1>
+<p>{{ thread.thread.title }}</p>
+
+<div data-ng-include data-src="'/partials/messages.html'"></div>
+
+<a href="/forum/threads/{{ thread.thread.id + 1 }}">Load next</a>
@@ -30,13 +30,23 @@ class CategoryController extends AbstractRestfulController
/**
- * Return list of resources
+ * Return the list of all categories (with a max depth). This is likely to be called as the index page
+ * of the forum
*
* @return mixed
*/
public function getList()
{
- // TODO: Implement getList() method.
+ $categoryService = $this->getCategoryService();
+
+ // TODO: make the depth configurable
+ $maxDepth = 3;
+ $categories = $categoryService->getAll($maxDepth);
+
+ // TODO: we need to convert to JSON/XML as we're REST
+ return array(
+ 'categories' => $categories
+ );
}
/**
@@ -87,7 +97,7 @@ public function delete($id)
/**
* @return CategoryService
*/
- public function getCategoryService()
+ protected function getCategoryService()
{
if ($this->categoryService === null) {
$this->categoryService = $this->serviceLocator->get('ZfrForum\Service\CategoryService');
@@ -19,17 +19,45 @@
namespace ZfrForum\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
+use Zend\View\Model\JsonModel;
+use ZfrForum\Service\PostService;
-class MessageController extends AbstractRestfulController
+class PostController extends AbstractRestfulController
{
/**
- * Return list of resources
+ * @var PostService
+ */
+ protected $postService;
+
+
+ /**
+ * Get the list of messages for a given thread
*
* @return mixed
*/
public function getList()
{
- // TODO: Implement getList() method.
+ /*$threadId = $this->params('threadId');
+ $page = $this->params()->fromQuery('page', 1);
+
+ $posts = $this->getPostService()->getByThread($threadId);
+
+ return array(
+ 'posts' => $posts->setCurrentPageNumber($page)
+ );*/
+
+ if ($this->request->isXmlHttpRequest()) {
+ $threadId = $this->params('threadId');
+ $page = $this->params()->fromQuery('page', 1);
+
+ $posts = $this->getPostService()->getByThread($threadId);
+
+ $posts = $posts->getCurrentItems();
+
+ return new JsonModel(array(
+ 'posts' => (array)$posts
+ ));
+ }
}
/**
@@ -40,7 +68,11 @@ public function getList()
*/
public function get($id)
{
- // TODO: Implement get() method.
+ $post = $this->getPostService()->getById($id);
+
+ return array(
+ 'post' => $post
+ );
}
/**
@@ -76,4 +108,16 @@ public function delete($id)
{
// TODO: Implement delete() method.
}
+
+ /**
+ * @return PostService
+ */
+ protected function getPostService()
+ {
+ if ($this->postService === null) {
+ $this->postService = $this->serviceLocator->get('ZfrForum\Service\PostService');
+ }
+
+ return $this->postService;
+ }
}
@@ -19,6 +19,7 @@
namespace ZfrForum\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
+use Zend\View\Model\JsonModel;
use ZfrForum\Entity\Thread;
use ZfrForum\Service\ThreadService;
@@ -37,7 +38,7 @@ class ThreadController extends AbstractRestfulController
*/
public function getList()
{
- //return $this->threadService
+ // TODO: Implement getList() method
}
/**
@@ -48,7 +49,11 @@ public function getList()
*/
public function get($id)
{
- return $this->threadService->getById($id);
+ if ($this->request->isXmlHttpRequest()) {
+ $thread = $this->getThreadService()->getById($id);
+
+ return (new JsonModel(array('thread' => $thread)));
+ }
}
/**
@@ -88,7 +93,7 @@ public function delete($id)
/**
* @return ThreadService
*/
- public function getThreadService()
+ protected function getThreadService()
{
if ($this->threadService === null) {
$this->threadService = $this->serviceLocator->get('ZfrForum\Service\ThreadService');
@@ -19,6 +19,7 @@
namespace ZfrForum\Entity;
use Doctrine\ORM\Mapping as ORM;
+use JsonSerializable;
/**
* Internally, categories are stored into a hierarchical tree in order to easily fetch threads
@@ -27,7 +28,7 @@
* @ORM\Entity(repositoryClass="ZfrForum\Repository\CategoryRepository")
* @ORM\Table(name="Categories")
*/
-class Category
+class Category implements JsonSerializable
{
/**
* @var int
@@ -165,4 +166,18 @@ public function getDepth()
{
return $this->depth;
}
+
+ /**
+ * (PHP 5 >= 5.4.0)
+ * Serializes the object to a value that can be serialized natively by json_encode().
+ */
+ function jsonSerialize()
+ {
+ return array(
+ 'id' => $this->id,
+ 'name' => $this->name,
+ 'description' => $this->description,
+ 'depth' => $this->depth
+ );
+ }
}
Oops, something went wrong.

0 comments on commit 059d237

Please sign in to comment.