Skip to content

Commit

Permalink
Merge pull request #69 from kitan1982/bugfix
Browse files Browse the repository at this point in the history
UI update
  • Loading branch information
ngodfraind committed Jun 22, 2015
2 parents bc9b7dd + ff4e002 commit 19c3ee6
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 26 deletions.
100 changes: 79 additions & 21 deletions Controller/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Claroline\ForumBundle\Form\SubjectType;
use Claroline\ForumBundle\Form\CategoryType;
use Claroline\ForumBundle\Form\EditTitleType;
use Claroline\ForumBundle\Event\Log\ReadSubjectEvent;
use Claroline\CoreBundle\Library\Resource\ResourceCollection;
use Claroline\CoreBundle\Entity\Workspace\Workspace;
use Claroline\CoreBundle\Entity\User;
Expand Down Expand Up @@ -92,7 +93,8 @@ public function openAction(Forum $forum)
'_resource' => $forum,
'isModerator' => $isModerator,
'categories' => $categories,
'hasSubscribed' => $hasSubscribed
'hasSubscribed' => $hasSubscribed,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -132,14 +134,38 @@ public function subjectsAction(Category $category, $page, $max)
$isModerator = $this->authorization->isGranted('moderate', $collection) &&
!$isAnon;

$logs = array();

if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();

if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$logs = $this->manager->getSubjectsReadingLogs($user, $forum->getResourceNode());
}
}
$lastAccessDates = array();

foreach ($logs as $log) {
$details = $log->getDetails();
$subjectId = $details['subject']['id'];

if (!isset($lastAccessDates[$subjectId])) {
$lastAccessDates[$subjectId] = $log->getDateLog();
}
}

return array(
'pager' => $pager,
'_resource' => $forum,
'canCreateSubject' => $canCreateSubject,
'isModerator' => $isModerator,
'category' => $category,
'max' => $max,
'lastMessages' => $lastMessages
'lastMessages' => $lastMessages,
'workspace' => $forum->getResourceNode()->getWorkspace(),
'lastAccessDates' => $lastAccessDates,
'isAnon' => $isAnon
);
}

Expand Down Expand Up @@ -167,7 +193,8 @@ public function subjectFormAction(Category $category)
return array(
'_resource' => $forum,
'form' => $formSubject->createView(),
'category' => $category
'category' => $category,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand All @@ -193,7 +220,8 @@ public function categoryFormAction(Forum $forum)

return array(
'_resource' => $forum,
'form' => $formCategory->createView()
'form' => $formCategory->createView(),
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -283,7 +311,8 @@ public function createSubjectAction(Category $category)

return array(
'form' => $form->createView(),
'_resource' => $forum
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -314,6 +343,17 @@ public function messagesAction(Subject $subject, $page, $max)
$canPost = $this->authorization->isGranted('post', $collection);
$form = $this->get('form.factory')->create(new MessageType());

if (!$isAnon) {
$securityToken = $this->tokenStorage->getToken();

if (!is_null($securityToken)) {
$user = $securityToken->getUser();
$event = new ReadSubjectEvent($subject);
$event->setDoer($user);
$this->dispatch($event);
}
}

return array(
'subject' => $subject,
'pager' => $pager,
Expand All @@ -322,7 +362,8 @@ public function messagesAction(Subject $subject, $page, $max)
'form' => $form->createView(),
'category' => $subject->getCategory(),
'max' => $max,
'canPost' => $canPost
'canPost' => $canPost,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -375,7 +416,8 @@ public function editMessageFormAction(Message $message)
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -415,7 +457,8 @@ public function editMessageAction(Message $message)
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand All @@ -442,7 +485,8 @@ public function editCategoryFormAction(Category $category)
return array(
'category' => $category,
'form' => $form->createView(),
'_resource' => $category->getForum()
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -471,7 +515,7 @@ public function editCategoryAction(Category $category)
$this->manager->editCategory($category, $oldName, $newName);

return new RedirectResponse(
$this->generateUrl('claro_forum_categories', array('forum' => $category->getForum()->getId()))
$this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
);
}
}
Expand Down Expand Up @@ -516,7 +560,13 @@ public function searchAction(Forum $forum, $page, $search)
{
$pager = $this->manager->searchPager($forum, $search, $page);

return array('pager' => $pager, '_resource' => $forum, 'search' => $search, 'page' => $page);
return array(
'pager' => $pager,
'_resource' => $forum,
'search' => $search,
'page' => $page,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

/**
Expand All @@ -534,7 +584,8 @@ public function searchAction(Forum $forum, $page, $search)
*/
public function editSubjectFormAction(Subject $subject)
{
$isModerator = $this->authorization->isGranted('moderate', new ResourceCollection(array($subject->getCategory()->getForum()->getResourceNode())));
$forum = $subject->getCategory()->getForum();
$isModerator = $this->authorization->isGranted('moderate', new ResourceCollection(array($forum->getResourceNode())));

if (!$isModerator && $this->tokenStorage->getToken()->getUser() !== $subject->getCreator()) {
throw new AccessDeniedException();
Expand All @@ -545,8 +596,9 @@ public function editSubjectFormAction(Subject $subject)
return array(
'form' => $form->createView(),
'subject' => $subject,
'forumId' => $subject->getCategory()->getForum()->getId(),
'_resource' => $subject->getCategory()->getForum()
'forumId' => $forum->getId(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand All @@ -565,8 +617,9 @@ public function editSubjectFormAction(Subject $subject)
*/
public function editSubjectAction(Subject $subject)
{
$forum = $subject->getCategory()->getForum();
$isModerator = $this->authorization->isGranted(
'moderate', new ResourceCollection(array($subject->getCategory()->getForum()->getResourceNode()))
'moderate', new ResourceCollection(array($forum->getResourceNode()))
);

if (!$isModerator && $this->tokenStorage->getToken()->getUser() !== $subject->getCreator()) {
Expand All @@ -589,8 +642,9 @@ public function editSubjectAction(Subject $subject)
return array(
'form' => $form->createView(),
'subjectId' => $subject->getId(),
'forumId' => $subject->getCategory()->getForum()->getId(),
'_resource' => $subject->getCategory()->getForum()
'forumId' => $forum->getId(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -784,7 +838,8 @@ public function moveSubjectFormAction(Subject $subject)
'_resource' => $forum,
'categories' => $categories,
'category' => $category,
'subject' => $subject
'subject' => $subject,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -813,7 +868,8 @@ public function moveMessageFormAction(Message $message, $page)
'category' => $category,
'subject' => $subject,
'pager' => $pager,
'message' => $message
'message' => $message,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down Expand Up @@ -976,7 +1032,8 @@ public function replyMessageAction(Message $message)
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);

}
Expand Down Expand Up @@ -1014,7 +1071,8 @@ public function quoteMessageAction(Message $message)
'subject' => $subject,
'form' => $form->createView(),
'message' => $message,
'_resource' => $forum
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}

Expand Down
49 changes: 49 additions & 0 deletions Event/Log/ReadSubjectEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\ForumBundle\Event\Log;

use Claroline\CoreBundle\Event\Log\AbstractLogResourceEvent;
use Claroline\ForumBundle\Entity\Subject;

class ReadSubjectEvent extends AbstractLogResourceEvent
{
const ACTION = 'resource-claroline_forum-read_subject';

/**
* @param Subject $subject
*/
public function __construct(Subject $subject)
{
$details = array(
'subject' => array(
'id' => $subject->getId(),
'title' => $subject->getTitle()
),
'category' => array(
'id' => $subject->getCategory()->getId()
),
'forum' => array(
'id' => $subject->getCategory()->getForum()->getId()
)
);

parent::__construct($subject->getCategory()->getForum()->getResourceNode(), $details);
}

/**
* @return array
*/
public static function getRestriction()
{
return array(self::DISPLAYED_WORKSPACE, self::DISPLAYED_ADMIN);
}
}
15 changes: 15 additions & 0 deletions Manager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,19 @@ public function createDefaultPostRights(ResourceNode $node)
}
}
}

public function getSubjectsReadingLogs(
User $user,
ResourceNode $node,
$orderedBy = 'id',
$order = 'DESC'
)
{
return $this->forumRepo->findSubjectsReadingLogs(
$user,
$node,
$orderedBy,
$order
);
}
}
26 changes: 26 additions & 0 deletions Repository/ForumRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Claroline\ForumBundle\Repository;

use Claroline\CoreBundle\Entity\Resource\ResourceNode;
use Claroline\CoreBundle\Entity\User;
use Claroline\ForumBundle\Entity\Forum;
use Claroline\ForumBundle\Entity\Subject;
use Claroline\ForumBundle\Entity\Category;
Expand Down Expand Up @@ -269,4 +271,28 @@ public function findNonSelfNotificationsByForum(

return $executeQuery ? $query->getResult() : $query;
}

public function findSubjectsReadingLogs(
User $user,
ResourceNode $node,
$orderedBy = 'id',
$order = 'DESC'
)
{
$dql = "
SELECT l
FROM Claroline\CoreBundle\Entity\Log\Log l
WHERE l.action = 'resource-claroline_forum-read_subject'
AND l.doer = :user
AND l.resourceNode = :node
ORDER BY l.{$orderedBy} {$order}
";

$query = $this->_em->createQuery($dql);
$query->setParameter('user', $user);
$query->setParameter('node', $node);

return $query->getResult();

}
}
4 changes: 3 additions & 1 deletion Resources/views/Forum/messages.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

{% block section_content %}
<div class="panel-heading">
<h3 class="panel-title">{{ _resource.getResourceNode().getName() }}</h3>
<h3 class="panel-title">
[{{ 'subject'|trans({}, 'forum') }}] {{ subject.getTitle() }}
</h3>
</div>
<div class="panel-body">
<div class="row">
Expand Down
Loading

0 comments on commit 19c3ee6

Please sign in to comment.