2017-25 © Pedro Pelåez
 

symfony-bundle unique-views-bundle

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

image

positibe/unique-views-bundle

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  • Tuesday, April 11, 2017
  • by pcabreus
  • Repository
  • 2 Watchers
  • 3 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 16 % Grown

The README.md

Positibe UniqueViews Bundle

This bundle allow you add a counter system to your visitable entities., (*1)

Installation

To install the bundle just add the dependent bundles:, (*2)

php composer.phar require positibe/media-bundle

Next, be sure to enable the bundles in your application kernel:, (*3)

<?php
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Positibe\Bundle\UniqueViewsBundle\PositibeUniqueViewsBundle(),

        // ...
    );
}

Documentation in 2 step

  1. Implement the VisitableInterface, (*4)

    // src/AppBundle/Entity/Post.php, (*5)

    namespace AppBundle\Entity;, (*6)

    use Doctrine\ORM\Mapping as ORM; use Positibe\Bundle\UniqueViewsBundle\Model\VisitableInterface;, (*7)

    class Post implement VisitableInterface {, (*8)

    /**
     * @ORM\Column(name="count_views", type="integer")
     */
    protected $countViews = 0;
    
    /**
     * @ORM\Column(name="slug", type="string", length=255)
     */
    protected $slug;
    
    public function getSlug()
    {
        return $this->slug;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getVisitableId()
    {
        return $this->getSlug();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getVisitableType()
    {
        return 'post';
    }
    
    /**
     * {@inheritdoc}
     */
    public function onNewViewed()
    {
        return $this->countViews++;
    }
    
    /**
     * {@inheritdoc}
     */
    public function countViews()
    {
        return $this->countViews;
    }

    }, (*9)

Tips: You could use the AbstractVisitable or VisitableTrait instead to minimize your code., (*10)

// src/AppBundle/Entity/Post.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Positibe\Bundle\UniqueViewsBundle\Model\VisitableInterface;

class Post implement VisitableInterface {

    use VisitableTrait;

    /**
     * @ORM\Column(name="slug", type="string", length=255)
     */
    protected $slug;

    public function getSlug()
    {
        return $this->slug;
    }

    /**
     * {@inheritdoc}
     */
    public function getVisitableId()
    {
        return $this->getSlug();
    }
}
  1. On a countable template you could count views using positibe_unique_views function., (*11)

    {# app/Resources/views/post/show.html.twig #}, (*12)

    {{ post.title }}

    {{ positibe_unique_views(post) }} unique views, (*13)

2.1. On a countable controller you could count views using positibe_unique_views.views_counter service:, (*14)

//src/AppBundle/Controller/PostController

$this->get('positibe_unique_views.views_counter')->count($post);

The Versions

11/04 2017

dev-master

9999999-dev http://positibelabs.com/bundles/unique_views

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  Sources   Download

MIT

The Requires

 

news post views views counter positibelabs positibe unique views

11/04 2017

1.1.0

1.1.0.0 http://positibelabs.com/bundles/unique_views

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  Sources   Download

MIT

The Requires

 

news post views views counter positibelabs positibe unique views

05/01 2017

1.0.0

1.0.0.0 https://github.com/Positibe/UniqueViewsBundle

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  Sources   Download

MIT

The Requires

 

news post views views counter positibelabs positibe unique views

19/06 2016

0.1.3.0

0.1.3.0 http://positibelabs.blogspot.com/bundles/news

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  Sources   Download

Private

The Requires

 

news post views views counter positibelabs positibe unique views

14/05 2016

0.1.2.0

0.1.2.0 http://positibelabs.blogspot.com/bundles/news

Symfony PositibeUniqueViewsBundle for count the number of views of a object model

  Sources   Download

Private

The Requires

 

news post views views counter positibelabs positibe unique views