Skip to content

Commit

Permalink
Merge pull request #358 from Victoire/feature/user-heartbeat
Browse files Browse the repository at this point in the history
Feature/user heartbeat
  • Loading branch information
Leny BERNARD committed Mar 14, 2016
2 parents e022eb3 + efca47d commit 8ee1660
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 17 deletions.
20 changes: 17 additions & 3 deletions Bundle/AnalyticsBundle/Controller/BrowseEventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Victoire\Bundle\AnalyticsBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent;
use Victoire\Bundle\UserBundle\Entity\User;

/**
* @Route("/browseEvent")
Expand All @@ -16,15 +17,14 @@ class BrowseEventController extends Controller
{
/**
* @Route("/track/{viewReferenceId}/{referer}", name="victoire_analytics_track")
* @Template()
*/
public function trackAction(Request $request, $viewReferenceId, $referer = null)
{
$browseEvent = new BrowseEvent();
$browseEvent->setViewReferenceId($viewReferenceId);
$browseEvent->setIp($request->getClientIp());
$browseEvent->setReferer($referer);
if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$browseEvent->setAuthor($this->getUser());
}
$entityManager = $this->get('doctrine.orm.entity_manager');
Expand All @@ -33,4 +33,18 @@ public function trackAction(Request $request, $viewReferenceId, $referer = null)

return new Response();
}

/**
* @Route("/heartbeat/{id}", name="victoire_analytics_heartbeat")
*/
public function heartbeatAction($id)
{
$entityManager = $this->get('doctrine.orm.entity_manager');
/** @var User $user */
$user = $entityManager->getRepository($this->getParameter('victoire_core.user_class'))->find($id);
$user->setHeartbeat(new \DateTime());
$entityManager->flush();

return new JsonResponse(['Glad you\'re alive :beating-heart:']);
}
}
2 changes: 1 addition & 1 deletion Bundle/CoreBundle/Builder/ViewCssBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* ref: victoire_core.view_css_builder.
*
* @property templating
*/
*/
class ViewCssBuilder
{
protected $templating;
Expand Down
10 changes: 6 additions & 4 deletions Bundle/CoreBundle/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<!DOCTYPE html>
<html ng-app="ngApp" lang="{{ app.request.locale|split('_')[0] }}">
<head>
{% block meta %}
{% include 'VictoireSeoBundle::_meta.html.twig' %}
{% endblock meta %}
{% block head %}
{% block meta %}
{% include 'VictoireSeoBundle::_meta.html.twig' %}
{% endblock meta %}
{% block head_script %}{% endblock %}
{% block head_style %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
{% block head_icons %}<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />{% endblock %}
{% endblock head %}
</head>
<body {% block container_attributes %}{% endblock container_attributes %} class="{% block container_class %}{% endblock container_class %}" ng-controller="PageController as pageCtrl" ng-init="init({% if view is defined %}'{{ view.cssHash }}'{% endif %})">
{{ cms_page_css() }}
Expand Down
5 changes: 5 additions & 0 deletions Bundle/CoreBundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@
<script type="text/javascript">
var viewReferenceId = '{{ vic_current_page_reference() }}';
</script>
{% if not app.debug %}
{{ render_hinclude(controller('VictoireAnalyticsBundle:BrowseEvent:track', {'viewReferenceId': vic_current_page_reference(), 'referer': app.request.headers.get('referer')})) }}
{% endif %}
{% if app.user %}
{{ render_hinclude(controller('VictoireAnalyticsBundle:BrowseEvent:heartbeat', {'id': app.user.id })) }}
{% endif %}
{% endif %}
{% if is_granted('ROLE_VICTOIRE') %}
{% javascripts injector='victoire-edit, victoire-leftnavbar' %}
Expand Down
4 changes: 2 additions & 2 deletions Bundle/FormBundle/Twig/FlashExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $mapping)
public function getFunctions()
{
return [
new \Twig_SimpleFunction('mopa_bootstrap_flash_mapping', [$this, 'getMapping'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('vic_mopa_bootstrap_flash_mapping', [$this, 'getMapping'], ['is_safe' => ['html']]),
];
}

Expand All @@ -58,6 +58,6 @@ public function getMapping()
*/
public function getName()
{
return 'mopa_bootstrap_flash';
return 'vic_mopa_bootstrap_flash';
}
}
23 changes: 23 additions & 0 deletions Bundle/UserBundle/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class User extends BaseUser implements VictoireUserInterface
*/
protected $locale;

/**
* @var \DateTime
*
* @ORM\Column(name="heartbeat", type="datetime", nullable=true)
*/
protected $heartbeat;

protected $pages;

/**
Expand Down Expand Up @@ -123,4 +130,20 @@ public function setLocale($locale)

return $this;
}

/**
* @return \DateTime
*/
public function getHeartbeat()
{
return $this->heartbeat;
}

/**
* @param \DateTime $heartbeat
*/
public function setHeartbeat($heartbeat)
{
$this->heartbeat = $heartbeat;
}
}
1 change: 0 additions & 1 deletion Bundle/UserBundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
</div>
</div>


{% javascripts
'@VictoireCoreBundle/Resources/public/js/constellations/TweenLite.min.js'
'@VictoireCoreBundle/Resources/public/js/constellations/EasePack.min.js'
Expand Down
3 changes: 0 additions & 3 deletions Bundle/WidgetBundle/Cache/WidgetCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Predis\Client;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\SecurityContext;
use Victoire\Bundle\WidgetBundle\Entity\Widget;
use Victoire\Bundle\WidgetBundle\Entity\WidgetSlotInterface;
use Victoire\Bundle\WidgetBundle\Helper\WidgetHelper;
Expand Down Expand Up @@ -108,6 +107,4 @@ private function generateHash($widget)
(string) $this->authorizationChecker->isGranted('ROLE_VICTOIRE')
);
}


}
1 change: 0 additions & 1 deletion Bundle/WidgetBundle/Command/CreateWidgetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
$entity = 'Widget'.$name;
$input->setOption('entity', $bundle.':'.$entity);


$cache = $input->getOption('cache');
$question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want use cache for this widget ?', 'yes', '?'));
if (null !== $cache) {
Expand Down
1 change: 1 addition & 0 deletions Bundle/WidgetBundle/Helper/WidgetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function isEnabled(Widget $widget)

return false;
}

/**
* Check in the driver chain if the given widget is enabled.
*
Expand Down
1 change: 0 additions & 1 deletion Bundle/WidgetBundle/Renderer/WidgetRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,4 @@ public function getExtraCssClass(Widget $widget)

return $cssClass;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends ':layout:fullWidth.html.twig' %}

0 comments on commit 8ee1660

Please sign in to comment.