PHP code example of xepozz / entity-sorter-bundle

1. Go to this page and download the library: Download xepozz/entity-sorter-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xepozz / entity-sorter-bundle example snippets



// AppBundle/Entity/OrderListItem.php

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="order_list_item")
 * @ORM\EntityListeners({"Xepozz\EntitySorterBundle\EventListener\SortListener"})
 */
class OrderListItem
{
    public function getId(){ /**/ }
    public function setId(){ /**/ }
    public function getSort(){ /**/ }
    public function setSort(){ /**/ }
    public function getSuperCategories(){ /**/ }
}


// AppBundle/Controller/testController.php

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Xepozz\EntitySorterBundle\Utils\EntitySorter;

class TestController extends Controller
{
    private $entitySorter;

    public function __construct(EntitySorter $entitySorter) 
    {
        $this->entitySorter = $entitySorter;
    }
    
    public function moveUpAction(OrderListItem $entity)
    {
        $this->entitySorter->moveUp($entity);

        return $this->redirect('...');
    }
    
    public function moveDownAction(OrderListItem $entity)
    {
        $this->entitySorter->moveDown($entity);

        return $this->redirect('...');
    }
}


// AppBundle/Entity/ProductSubCategory.php

use Doctrine\ORM\Mapping as ORM;use Xepozz\EntitySorterBundle\Model\BaseSort;

/**
 * @ORM\Entity
 * @ORM\Table(name="product_sub_category")
 * @ORM\EntityListeners({"Xepozz\EntitySorterBundle\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 getSuperCategories()
    {
        return ['productCategory' => $this->getProductCategory()];
    }
}

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