Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Gestion des messages lu #37

Merged
merged 7 commits into from

2 participants

@Orkin
Collaborator

Ajout des fonctionnalités permettant de gérer la lecture ou non des messages

src/ZfrForum/Mapper/ThreadTrackingMapperInterface.php
((37 lines not shown))
+ * @return ThreadTracking
+ */
+ public function update(ThreadTracking $threadTracking);
+
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return void
+ */
+ public function remove(ThreadTracking $threadTracking);
+
+ /**
+ * @param Thread $thread
+ * @param UserInterface $user
+ * @return ThreadTracking
+ */
+ public function findByThreadAndUser(Thread $thread, UserInterface $user);
@bakura10 Owner

A virer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Mapper/ThreadTrackingMapperInterface.php
((44 lines not shown))
+ */
+ public function remove(ThreadTracking $threadTracking);
+
+ /**
+ * @param Thread $thread
+ * @param UserInterface $user
+ * @return ThreadTracking
+ */
+ public function findByThreadAndUser(Thread $thread, UserInterface $user);
+
+ /**
+ * @param Category $category
+ * @param UserInterface $user
+ * @return array
+ */
+ public function findByCategoryAndUser(Category $category, UserInterface $user);
@bakura10 Owner

A virer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Repository/ThreadTrackingRepository.php
((50 lines not shown))
+ * @param ThreadTracking $threadTracking
+ * @return void
+ */
+ public function remove(ThreadTracking $threadTracking)
+ {
+ // TODO: Implement remove() method.
+ }
+
+ /**
+ * @param Thread $thread
+ * @param UserInterface $user
+ * @return ThreadTracking
+ */
+ public function findByThreadAndUser(Thread $thread, UserInterface $user)
+ {
+ $queryBuilder = $this->getEntityManager()->createQueryBuilder();
@bakura10 Owner

A virer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Repository/ThreadTrackingRepository.php
((69 lines not shown))
+ ->andWhere('tt.category = :category')
+ ->andWhere('tt.user = :user')
+ ->setParameter('thread', $thread)
+ ->setParameter('user', $user);
+
+ $threadTracking = $queryBuilder->getQuery()->getOneOrNullResult();
+
+ return $threadTracking;
+ }
+
+ /**
+ * @param Category $category
+ * @param UserInterface $user
+ * @return array
+ */
+ public function findByCategoryAndUser(Category $category, UserInterface $user)
@bakura10 Owner

A virer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Service/ThreadService.php
@@ -66,6 +78,13 @@ public function addPost(Thread $thread, Post $post)
$thread->addPost($post);
$this->threadMapper->update($thread);
+
+ // we raised the event
+ $this->getEventManager()->trigger('addPost.post', this, array(
+ 'user' => $post->getAuthor(),
+ 'thread' => $thread,
+ 'date' => $post->getSentAt()
@bakura10 Owner

En fait je pense que c'est con d'envoyer le user et la date. Finalement, le mieux c'est d'envoyer le post et le thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Orkin
Collaborator

Normalement c'est tout bon !

src/ZfrForum/Entity/CategoryTracking.php
((50 lines not shown))
+ * @var DateTime
+ *
+ * @ORM\Column(type="datetime")
+ */
+ protected $markTime;
+
+ /**
+ * Constructor
+ *
+ * @param UserInterface $user
+ * @param Category $category
+ */
+ function __construct(UserInterface $user, Category $category)
+ {
+ $this->category = $category;
+ $this->user = $user;
@bakura10 Owner

Aligner le =.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Module.php
@@ -31,6 +32,27 @@ class Module implements
ServiceProviderInterface,
ViewHelperProviderInterface
{
+ /**
+ * {@inheritDoc}
+ */
+ public function onBootstrap(EventInterface $e)
+ {
+ /* @var $app \Zend\Mvc\ApplicationInterface */
+ $app = $e->getTarget();
@bakura10 Owner

Aligner le =.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Entity/ThreadTracking.php
((58 lines not shown))
+ * @var DateTime
+ *
+ * @ORM\Column(type="datetime")
+ */
+ protected $markTime;
+
+ /**
+ * Constructor
+ *
+ * @param UserInterface $user
+ * @param Thread $thread
+ */
+ function __construct(UserInterface $user, Thread $thread)
+ {
+ $this->user = $user;
+ $this->thread = $thread;
@bakura10 Owner

Aligner les =.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Mapper/CategoryTrackingMapperInterface.php
((15 lines not shown))
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Mapper;
+
+use Doctrine\Common\Persistence\ObjectRepository;
+use ZfrForum\Entity\CategoryTracking;
+
+interface CategoryTrackingMapperInterface extends ObjectRepository
+{
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return CategoryTracking
+ */
+ public function add(CategoryTracking $categoryTracking);
@bakura10 Owner

Je continue à trouver que c'est bizarre de l'appeler add. Je suis d'accord avec toi qu'on "ajoute" un tracking, mais initialmeent on le créé. Par cohéreence avec les autres mapper, je pense qu'il vaut mieux l'appeler "create" (histoire d'avoir le parallèle avec CRUD partout).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Mapper/ThreadTrackingMapperInterface.php
((15 lines not shown))
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Mapper;
+
+use Doctrine\Common\Persistence\ObjectRepository;
+use ZfrForum\Entity\ThreadTracking;
+
+interface ThreadTrackingMapperInterface extends ObjectRepository
+{
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return ThreadTracking
+ */
+ public function add(ThreadTracking $threadTracking);
@bakura10 Owner

Même remarque.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/ZfrForum/Service/ThreadService.php
((20 lines not shown))
*/
- public function __construct(ThreadMapperInterface $threadMapper, AuthenticationService $authenticationService)
+ public function __construct(ThreadMapperInterface $threadMapper, ThreadTrackingMapperInterface $threadTrackingMapper,
@bakura10 Owner

Lorsque les paramètres s'étendent sur plusieurs lignes, la convention est ainsi : https://gist.github.com/4124651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bakura10
Owner

J'ai ajouté quelques remarques supplémentaires de style, mais dans l'ensemble ça me paraît bien. Je mergerai pas tant que ce sera pas fait pour le tracking des catégories par contre :).

@bakura10 bakura10 merged commit 2eebdc8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 10, 2012
  1. @Orkin
  2. @Orkin

    Corrections

    Orkin authored
Commits on Nov 19, 2012
  1. @Orkin

    Ajout des mappers et repository

    Orkin authored
Commits on Nov 20, 2012
  1. @Orkin
  2. @Orkin

    Corrections

    Orkin authored
Commits on Nov 21, 2012
  1. @Orkin

    Corrections

    Orkin authored
  2. @Orkin

    Corrections oubliees

    Orkin authored
This page is out of date. Refresh to see the latest.
View
29 Module.php
@@ -18,6 +18,7 @@
namespace ZfrForum;
+use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ControllerPluginProviderInterface;
@@ -31,6 +32,27 @@ class Module implements
ServiceProviderInterface,
ViewHelperProviderInterface
{
+ /**
+ * {@inheritDoc}
+ */
+ public function onBootstrap(EventInterface $e)
+ {
+ /* @var $app \Zend\Mvc\ApplicationInterface */
+ $app = $e->getTarget();
+ $events = $app->getEventManager();
+
+ // Attach to helper set event and load the entity manager helper.
+ $events->attach('addPost.post', function(EventInterface $e) {
+ /* @var $threadService \ZfrForum\Service\ThreadService */
+ $threadService = $e->getTarget();
+
+ $params = $e->getParams();
+ $user = $params['user'];
+ $thread = $params['thread'];
+
+ $threadService->track($user, $thread);
+ });
+ }
/**
* @return array
@@ -146,9 +168,10 @@ public function getServiceConfig()
return new Service\SettingsService($settingsMapper);
},
'ZfrForum\Service\ThreadService' => function($serviceManager) {
- $threadMapper = $serviceManager->get('ZfrForum\Mapper\ThreadMapperInterface');
- $authentication = $serviceManager->get('Zend\Authentication\AuthenticationService');
- return new Service\ThreadService($threadMapper, $authentication);
+ $threadMapper = $serviceManager->get('ZfrForum\Mapper\ThreadMapperInterface');
+ $threadTrackingMapper = $serviceManager->get('ZfrForum\Mapper\ThreadTrackingMapperInterface');
+ $authentication = $serviceManager->get('Zend\Authentication\AuthenticationService');
+ return new Service\ThreadService($threadMapper, $threadTrackingMapper, $authentication);
},
'ZfrForum\Service\UserBanService' => function($serviceManager) {
$userBanMapper = $serviceManager->get('ZfrForum\Mapper\UserBanMapperInterface');
View
111 src/ZfrForum/Entity/CategoryTracking.php
@@ -0,0 +1,111 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Entity;
+
+use DateTime;
+use Doctrine\ORM\Mapping as ORM;
+use ZfrForum\Entity\UserInterface;
+use ZfrForum\Entity\Category;
+
+/**
+ * @ORM\Entity(repositoryClass="ZfrForum\Repository\CategoryTrackingRepository")
+ * @ORM\Entity
+ * @ORM\Table(name="CategoriesTracking")
+ */
+class CategoryTracking
+{
+ /**
+ * @var UserInterface
+ *
+ * @ORM\Id
+ * @ORM\ManyToOne(targetEntity="ZfrForum\Entity\UserInterface")
+ */
+ protected $user;
+
+ /**
+ * @var Category
+ *
+ * @ORM\Id
+ * @ORM\ManyToOne(targetEntity="ZfrForum\Entity\Category")
+ */
+ protected $category;
+
+ /**
+ * @var DateTime
+ *
+ * @ORM\Column(type="datetime")
+ */
+ protected $markTime;
+
+ /**
+ * Constructor
+ *
+ * @param UserInterface $user
+ * @param Category $category
+ */
+ function __construct(UserInterface $user, Category $category)
+ {
+ $this->category = $category;
+ $this->user = $user;
+ $this->markTime = new DateTime('now');
+ }
+
+
+ /**
+ * Set when all thread of the category was read
+ *
+ * @param DateTime $markTime
+ * @return CategoryTracking
+ */
+ public function setMarkTime(DateTime $markTime)
+ {
+ $this->markTime = clone $markTime;
+ return $this;
+ }
+
+ /**
+ * Return the markTime
+ *
+ * @return DateTime
+ */
+ public function getMarkTime()
+ {
+ return clone $this->markTime;
+ }
+
+ /**
+ * Return the category
+ *
+ * @return Category
+ */
+ public function getCategory()
+ {
+ return $this->category;
+ }
+
+ /**
+ * Return the user
+ *
+ * @return UserInterface
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+}
View
2  src/ZfrForum/Entity/Post.php
@@ -192,7 +192,7 @@ public function getContent()
/**
* Set when this post was sent for the first time
*
- * @param DateTime $sentAt
+ * @param DateTime $sentAt
* @return Post
*/
public function setSentAt(DateTime $sentAt)
View
140 src/ZfrForum/Entity/ThreadTracking.php
@@ -0,0 +1,140 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Entity;
+
+use DateTime;
+use Doctrine\ORM\Mapping as ORM;
+use ZfrForum\Entity\UserInterface;
+use ZfrForum\Entity\Thread;
+use ZfrForum\Entity\Category;
+
+/**
+ * @ORM\Entity(repositoryClass="ZfrForum\Repository\ThreadTrackingRepository")
+ * @ORM\Entity
+ * @ORM\Table(name="ThreadsTracking")
+ */
+class ThreadTracking
+{
+ /**
+ * @var UserInterface
+ *
+ * @ORM\Id
+ * @ORM\ManyToOne(targetEntity="ZfrForum\Entity\UserInterface")
+ */
+ protected $user;
+
+ /**
+ * @var Thread
+ *
+ * @ORM\Id
+ * @ORM\ManyToOne(targetEntity="ZfrForum\Entity\Thread")
+ */
+ protected $thread;
+
+ /**
+ * @var Category
+ *
+ * @ORM\ManyToOne(targetEntity="ZfrForum\Entity\Category")
+ */
+ protected $category;
+
+ /**
+ * @var DateTime
+ *
+ * @ORM\Column(type="datetime")
+ */
+ protected $markTime;
+
+ /**
+ * Constructor
+ *
+ * @param UserInterface $user
+ * @param Thread $thread
+ */
+ function __construct(UserInterface $user, Thread $thread)
+ {
+ $this->user = $user;
+ $this->thread = $thread;
+ $this->category = $thread->getCategory();
+ $this->markTime = $thread->getLastPost()->getSentAt();
+ }
+
+ /**
+ * Return the user
+ *
+ * @return UserInterface
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
+ * Return the thread
+ *
+ * @return Thread
+ */
+ public function getThread()
+ {
+ return $this->thread;
+ }
+
+ /**
+ * Set the category of the thread
+ *
+ * @param Category $category
+ * @return ThreadTracking
+ */
+ public function setCategory($category)
+ {
+ $this->category = $category;
+ return $this;
+ }
+
+ /**
+ * Return the category of the thread
+ *
+ * @return Category
+ */
+ public function getCategory()
+ {
+ return $this->category;
+ }
+
+ /**
+ * Set the created date of the lasted post of the thread
+ *
+ * @param DateTime $markTime
+ * @return ThreadTracking
+ */
+ public function setMarkTime(DateTime $markTime)
+ {
+ $this->markTime = clone $markTime;
+ return $this;
+ }
+
+ /**
+ * Return the date of the lasted post of the thread
+ * @return DateTime
+ */
+ public function getMarkTime()
+ {
+ return clone $this->markTime;
+ }
+}
View
43 src/ZfrForum/Mapper/CategoryTrackingMapperInterface.php
@@ -0,0 +1,43 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Mapper;
+
+use Doctrine\Common\Persistence\ObjectRepository;
+use ZfrForum\Entity\CategoryTracking;
+
+interface CategoryTrackingMapperInterface extends ObjectRepository
+{
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return CategoryTracking
+ */
+ public function create(CategoryTracking $categoryTracking);
+
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return CategoryTracking
+ */
+ public function update(CategoryTracking $categoryTracking);
+
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return void
+ */
+ public function remove(CategoryTracking $categoryTracking);
+}
View
43 src/ZfrForum/Mapper/ThreadTrackingMapperInterface.php
@@ -0,0 +1,43 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Mapper;
+
+use Doctrine\Common\Persistence\ObjectRepository;
+use ZfrForum\Entity\ThreadTracking;
+
+interface ThreadTrackingMapperInterface extends ObjectRepository
+{
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return ThreadTracking
+ */
+ public function create(ThreadTracking $threadTracking);
+
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return ThreadTracking
+ */
+ public function update(ThreadTracking $threadTracking);
+
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return void
+ */
+ public function remove(ThreadTracking $threadTracking);
+}
View
54 src/ZfrForum/Repository/CategoryTrackingRepository.php
@@ -0,0 +1,54 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Repository;
+
+use Doctrine\ORM\EntityRepository;
+use ZfrForum\Entity\CategoryTracking;
+use ZfrForum\Mapper\CategoryTrackingMapperInterface;
+
+class CategoryTrackingRepository extends EntityRepository implements CategoryTrackingMapperInterface
+{
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return CategoryTracking
+ */
+ public function create(CategoryTracking $categoryTracking)
+ {
+ // TODO: Implement add() method.
+ }
+
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return CategoryTracking
+ */
+ public function update(CategoryTracking $categoryTracking)
+ {
+ $this->getEntityManager()->flush($categoryTracking);
+ return $categoryTracking;
+ }
+
+ /**
+ * @param CategoryTracking $categoryTracking
+ * @return void
+ */
+ public function remove(CategoryTracking $categoryTracking)
+ {
+ // TODO: Implement remove() method.
+ }
+}
View
54 src/ZfrForum/Repository/ThreadTrackingRepository.php
@@ -0,0 +1,54 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license.
+ */
+
+namespace ZfrForum\Repository;
+
+use Doctrine\ORM\EntityRepository;
+use ZfrForum\Entity\ThreadTracking;
+use ZfrForum\Mapper\ThreadTrackingMapperInterface;
+
+class ThreadTrackingRepository extends EntityRepository implements ThreadTrackingMapperInterface
+{
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return ThreadTracking
+ */
+ public function create(ThreadTracking $threadTracking)
+ {
+
+ }
+
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return ThreadTracking
+ */
+ public function update(ThreadTracking $threadTracking)
+ {
+ $this->getEntityManager()->flush($threadTracking);
+ return $threadTracking;
+ }
+
+ /**
+ * @param ThreadTracking $threadTracking
+ * @return void
+ */
+ public function remove(ThreadTracking $threadTracking)
+ {
+ // TODO: Implement remove() method.
+ }
+}
View
54 src/ZfrForum/Service/ThreadService.php
@@ -19,14 +19,18 @@
namespace ZfrForum\Service;
use DateTime;
+use ZfcBase\EventManager\EventProvider;
use Zend\Authentication\AuthenticationService;
use Zend\Paginator\Paginator;
use ZfrForum\Entity\Category;
use ZfrForum\Entity\Post;
use ZfrForum\Entity\Thread;
+use ZfrForum\Entity\ThreadTracking;
use ZfrForum\Mapper\ThreadMapperInterface;
+use ZfrForum\Mapper\ThreadTrackingMapperInterface;
+use ZfrForum\Entity\UserInterface;
-class ThreadService
+class ThreadService extends EventProvider
{
/**
* @var ThreadMapperInterface
@@ -34,18 +38,28 @@ class ThreadService
protected $threadMapper;
/**
+ * @var ThreadTrackingMapperInterface
+ */
+ protected $threadTrackingMapper;
+
+ /**
* @var AuthenticationService
*/
protected $authenticationService;
/**
- * @param ThreadMapperInterface $threadMapper
- * @param AuthenticationService $authenticationService
+ * @param ThreadMapperInterface $threadMapper
+ * @param ThreadTrackingMapperInterface $threadTrackingMapper
+ * @param AuthenticationService $authenticationService
*/
- public function __construct(ThreadMapperInterface $threadMapper, AuthenticationService $authenticationService)
+ public function __construct(
+ ThreadMapperInterface $threadMapper,
+ ThreadTrackingMapperInterface $threadTrackingMapper,
+ AuthenticationService $authenticationService)
{
$this->threadMapper = $threadMapper;
+ $this->threadTrackingMapper = $threadTrackingMapper;
$this->authenticationService = $authenticationService;
}
@@ -66,6 +80,12 @@ public function addPost(Thread $thread, Post $post)
$thread->addPost($post);
$this->threadMapper->update($thread);
+
+ // we raised the event
+ $this->getEventManager()->trigger('addPost.post', this, array(
+ 'user' => $post->getAuthor(),
+ 'thread' => $thread
+ ));
}
/**
@@ -122,4 +142,30 @@ public function getById($id)
{
return $this->threadMapper->find($id);
}
+
+ /**
+ * Add or update the track for this thread
+ *
+ * @param UserInterface $user
+ * @param Thread $thread
+ */
+ public function track(UserInterface $user, Thread $thread) {
+ $threadTracking = $this->threadTrackingMapper->findOnBy(array(
+ 'thread' => $thread,
+ 'user' => $user
+ ));
+
+ // There is not a track for this thread
+ if ($threadTracking === null) {
+ $threadTracking = new ThreadTracking($user, $thread);
+ $this->threadTrackingMapper->create($threadTracking);
+ } elseif ($threadTracking->getMarkTime() < $thread->getLastPost()->getSentAt()) {
+ $threadTracking->setMarkTime($thread->getLastPost()->getSentAt());
+ $this->threadTrackingMapper->update($threadTracking);
+ }
+
+ // TODO : Penser à tenir compte du CategoryTracking : lorsque tous les threads d'une catégorie sont lus en
+ // TODO : tenant compte du markTime il faut supprimer les threadTracking et ajouter le CategoryTracking à la
+ // TODO : date du jour. Il faut donc s'assurer
+ }
}
Something went wrong with that request. Please try again.