2017 © Pedro Peláez
 

symfony-bundle counter-bundle

Counter Bundle of Symfony

image

pianosolo/counter-bundle

Counter Bundle of Symfony

  • Thursday, February 2, 2017
  • by PianoSolo
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PianoSolo Counter Bundle

Symfony bundle helps to easily add a counter to entities. Using CounterTrait in entities will create a Counter entity relation automatically. Then you can easily add clicks to the counter. You can also add fake counts to your entites by keeping the real count., (*1)

Latest Stable Version Latest Unstable Version License, (*2)

Installation

1-) Tell composer to download by running the command:, (*3)

composer require pianosolo/counter-bundle

2-) Add the bundle to AppKernel, (*4)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new PianoSolo\CounterBundle\PianoSoloCounterBundle(),
    );
}

Usage

1-) Add CounterTrait to your entity., (*5)

<?php

namespace MyBundle\Entity;

use PianoSolo\Traits\CounterTrait;

class MyEntity
{
    use CounterTrait;

    //...
}

2-) EventListener will create a new Counter for your entity while persisting your entity., (*6)

    $myEntity = new MyEntity();
    $entityManager->persist($myEntity);
    $entityManager->flush();

3-) Call Counter and add clicks., (*7)

<?php

namespace MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function showEntityAction()
    {
        //...

        $myEntity = $myEntityRepository->findOneBy(array('id' => $id));
        $myEntity->getCounter()->addClick(5); // Default value of parameter is 1

        $entityManager->persist($myEntity);
        $entityManager->flush();
    }
}

4-) Get Count, (*8)

    $count = $myEntity->getCounter()->getCount();
    {{ myEntity.counter.count }}

Adding Fake Count

You can add fake counts to your entities and keep the real counts. Whenever you want you can delete this fake counts., (*9)

    // Example initial count values of entity
    $count = $myEntity->getCounter()->getCount(); // return 10
    $realCount = $myEntity->getCounter()->getRealCount(); // return 10

    // Adding fake count
    $myEntity->getCounter()->setCorrectionCount(100);
    $entityManager->persist($myEntity);
    $entityManager->flush();

    // Keeping real count
    $count = $myEntity->getCounter()->getCount(); // return 110
    $realCount = $myEntity->getCounter()->getRealCount(); // return 10

    // Delete fake count
    $myEntity->getCounter()->setCorrectionCount(0):
    $entityManager->persist($myEntity);
    $entityManager->flush();

The Versions

02/02 2017

dev-master

9999999-dev

Counter Bundle of Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ahmet Akbana

symfony counter

09/07 2016

v1.1

1.1.0.0

Counter Bundle of Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ahmet Akbana

symfony counter

19/06 2016

v1.0

1.0.0.0

Counter Bundle of Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ahmet Akbana

symfony counter