2017 © Pedro Peláez
 

symfony-bundle sorter-bundle

Adds sorting functionality to your entities

image

ip/sorter-bundle

Adds sorting functionality to your entities

  • Tuesday, May 23, 2017
  • by interpunkt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 106 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*1)

$ composer require ip/sorter-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*2)

Step 2: Add it to an entity

Add the Doctrine entity listener to your entitiy and don't forget to include all the use statements. Then extend your Entity with BaseSort as shown as in the example below., (*3)

<?php
// AppBundle/Entity/Test.php

// ...

use Doctrine\ORM\Mapping as ORM;
use Ip\SorterBundle\Model\BaseSort;

/**
 * @ORM\Entity
 * @ORM\Table(name="test")
 * @ORM\EntityListeners({"Ip\SorterBundle\EventListener\SortListener"})
 */
class Test extends BaseSort
{
    // ...
}

After this changes the sort value is already being set automatically for new database entries and is also correctly modified when you delete or update entries., (*4)

Step 3: Move items up and down

To move your items up or down in the sort order use the entity functions moveUp($controller) and moveDown($controller). You can, for example, call these functions in your controller. Your controller class has to extend the Symfony controller:, (*5)

<?php
// AppBundle/Controller/testController.php

// ...

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

// ...

class testController extends Controller
{

    // ...

    public function moveUpAction($id)
    {
        // ...

        $testEntity->moveUp($this);

        // ...
    }

    public function moveDownAction($id)
    {
        // ...

        $testEntity->moveDown($this);

        // ...
    }

    // ...
}

(Optional) Step 4: Sorting within a supercategory

If your entity is a subcategory of another entity and should be sorted only within its own supercategory, you need to overwrite the function hasSuperCategory() in your entity., (*6)

In the example below we have a product sub category that needs to be sorted within the product category., (*7)

<?php
// AppBundle/Entity/ProductSubCategory.php

// ...

use Doctrine\ORM\Mapping as ORM;
use Ip\SorterBundle\Model\BaseSort;

/**
 * @ORM\Entity
 * @ORM\Table(name="product_sub_category")
 * @ORM\EntityListeners({"Ip\SorterBundle\EventListener\SortListener"})
 */
class ProductSubCategory extends BaseSort
{
    // ...

    /**
     * @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="productSubCategories")
     * @ORM\JoinColumn(name="product_category_id", referencedColumnName="id")
     */
    protected $productCategory;

    // ...

    /**
     * @return array
     */
    public function hasSuperCategory()
    {
        return array('productCategory' => $this->getProductCategory());
    }
}

An entity can have several supercategories. The array returned in hasSuperCategory just has to contain the values from them. The order of the supercategories has no influence on the sorting:, (*8)

return array(
    'productCategory' => $this->getProductCategory(),
    'anotherSuperCategory' => $this->getAnotherSuperCategory()
);

The Versions

23/05 2017

dev-master

9999999-dev https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Lehrner

symfony2 sort

23/05 2017

v0.6.1

0.6.1.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Lehrner

symfony2 sort

31/03 2017

0.6.0

0.6.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Lehrner

symfony2 sort

23/02 2017

0.5.0

0.5.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Lehrner

symfony2 sort

12/12 2016

0.4.2

0.4.2.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort

31/10 2016

0.4.1

0.4.1.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort

03/10 2016

0.4

0.4.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort

03/10 2016

0.3

0.3.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort

27/09 2016

0.2

0.2.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort

27/09 2016

0.1

0.1.0.0 https://github.com/daniellehrner/sorterbundle

Adds sorting functionality to your entities

  Sources   Download

MIT

The Requires

 

by Daniel Lehrner

symfony2 sort