Skip to content
This repository has been archived by the owner on May 23, 2018. It is now read-only.

Not showing up/down buttons #3

Open
amadohin opened this issue Feb 10, 2018 · 0 comments
Open

Not showing up/down buttons #3

amadohin opened this issue Feb 10, 2018 · 0 comments

Comments

@amadohin
Copy link

amadohin commented Feb 10, 2018

I have configured all, but I can't get work this bundle.

I can't see the buttons up/down

Here my ORM

AppBundle\Entity\SupvPageCategories:
type: entity
repositoryClass: Gedmo\Tree\Entity\Repository\NestedTreeRepository
table: supv_page_categories
gedmo:
tree:
type: nested
id:
pcId:
type: integer
nullable: false
options:
unsigned: false
id: true
column: pc_id
generator:
strategy: IDENTITY
fields:
pcCatname:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catname
pcCattype:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catType
lft:
type: integer
gedmo:
- treeLeft
rgt:
type: integer
gedmo:
- treeRight
lvl:
type: integer
gedmo:
- treeLevel
pcIsactive:
type: boolean
nullable: false
column: pc_isActive
pcUpdatedat:
type: datetime
nullable: true
column: pc_updatedAt
pcCreatedat:
type: datetime
nullable: false
column: pc_createdAt
manyToOne:
root:
targetEntity: AppBundle\Entity\SupvPageCategories
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeRoot
parent:
targetEntity: AppBundle\Entity\SupvPageCategories
inversedBy: children
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeParent
oneToMany:
children:
targetEntity: AppBundle\Entity\SupvPageCategories
mappedBy: parent
orderBy:
lft: ASC
lifecycleCallbacks: { }

Here my Entity

`<?php

namespace AppBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
/**

  • SupvPageCategories
    /
    class SupvPageCategories
    {
    /
    *

    • @var int
      */
      private $pcId;

    /**

    • @var string
      */
      private $pcCatname;

    /**

    • @var string
      */
      private $pcCattype;

    /**

    • @var bool
      */
      private $pcIsactive;

    /**

    • @var \DateTime|null
      */
      private $pcUpdatedat;

    /**

    • @var \DateTime
      */
      private $pcCreatedat;

    public function __construct()
    {
    $this->pcIsactive = true;
    $this->pcCreatedat = new \DateTime();
    $this->children = new ArrayCollection();
    }

    /**

    • Get pcId.
    • @return int
      */
      public function getPcId()
      {
      return $this->pcId;
      }

    /**

    • Set pcCatname.

    • @param string $pcCatname

    • @return SupvPageCategories
      */
      public function setPcCatname($pcCatname)
      {
      $this->pcCatname = $pcCatname;

      return $this;
      }

    /**

    • Get pcCatname.
    • @return string
      */
      public function getPcCatname()
      {
      return $this->pcCatname;
      }

    /**

    • Set pcCattype.

    • @param string $pcCattype

    • @return SupvPageCategories
      */
      public function setPcCattype($pcCattype)
      {
      $this->pcCattype = $pcCattype;

      return $this;
      }

    /**

    • Get pcCattype.
    • @return string
      */
      public function getPcCattype()
      {
      return $this->pcCattype;
      }

    /**

    • Set pcIsactive.

    • @param bool $pcIsactive

    • @return SupvPageCategories
      */
      public function setPcIsactive($pcIsactive)
      {
      $this->pcIsactive = $pcIsactive;

      return $this;
      }

    /**

    • Get pcIsactive.
    • @return bool
      */
      public function getPcIsactive()
      {
      return $this->pcIsactive;
      }

    /**

    • Set pcUpdatedat.

    • @param \DateTime|null $pcUpdatedat

    • @return SupvPageCategories
      */
      public function setPcUpdatedat($pcUpdatedat = null)
      {
      $this->pcUpdatedat = $pcUpdatedat;

      return $this;
      }

    /**

    • Get pcUpdatedat.
    • @return \DateTime|null
      */
      public function getPcUpdatedat()
      {
      return $this->pcUpdatedat;
      }

    /**

    • Set pcCreatedat.

    • @param \DateTime $pcCreatedat

    • @return SupvPageCategories
      */
      public function setPcCreatedat($pcCreatedat)
      {
      $this->pcCreatedat = $pcCreatedat;

      return $this;
      }

    /**

    • Get pcCreatedat.
    • @return \DateTime
      */
      public function getPcCreatedat()
      {
      return $this->pcCreatedat;
      }

    public function __toString()
    {
    if( is_null( $this->getPcCatname() ) ) {
    return 'NULL';
    }else{
    return $this->getPcCatname();
    }
    }

    /**

    • @var \AppBundle\Entity\SupvPageCategories
      */
      private $pcParentcat;

    /**

    • Set pcParentcat.

    • @param \AppBundle\Entity\SupvPageCategories|null $pcParentcat

    • @return SupvPageCategories
      */
      public function setPcParentcat(\AppBundle\Entity\SupvPageCategories $pcParentcat = null)
      {
      $this->pcParentcat = $pcParentcat;

      return $this;
      }

    /**

    • Get pcParentcat.
    • @return \AppBundle\Entity\SupvPageCategories|null
      /
      public function getPcParentcat()
      {
      return $this->pcParentcat;
      }
      /
      *
    • @var int
      */
      private $lft;

    /**

    • @var int
      */
      private $rgt;

    /**

    • @var int
      */
      private $lvl;

    /**

    • @var \Doctrine\Common\Collections\Collection
      */
      private $children;

    /**

    • @var \AppBundle\Entity\SupvPageCategories
      */
      private $root;

    /**

    • @var \AppBundle\Entity\SupvPageCategories
      */
      private $parent;

    /**

    • Set lft.

    • @param int $lft

    • @return SupvPageCategories
      */
      public function setLft($lft)
      {
      $this->lft = $lft;

      return $this;
      }

    /**

    • Get lft.
    • @return int
      */
      public function getLft()
      {
      return $this->lft;
      }

    /**

    • Set rgt.

    • @param int $rgt

    • @return SupvPageCategories
      */
      public function setRgt($rgt)
      {
      $this->rgt = $rgt;

      return $this;
      }

    /**

    • Get rgt.
    • @return int
      */
      public function getRgt()
      {
      return $this->rgt;
      }

    /**

    • Set lvl.

    • @param int $lvl

    • @return SupvPageCategories
      */
      public function setLvl($lvl)
      {
      $this->lvl = $lvl;

      return $this;
      }

    /**

    • Get lvl.
    • @return int
      */
      public function getLvl()
      {
      return $this->lvl;
      }

    /**

    • Add child.

    • @param \AppBundle\Entity\SupvPageCategories $child

    • @return SupvPageCategories
      */
      public function addChild(\AppBundle\Entity\SupvPageCategories $child)
      {
      $this->children[] = $child;

      return $this;
      }

    /**

    • Remove child.
    • @param \AppBundle\Entity\SupvPageCategories $child
    • @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
      */
      public function removeChild(\AppBundle\Entity\SupvPageCategories $child)
      {
      return $this->children->removeElement($child);
      }

    /**

    • Get children.
    • @return \Doctrine\Common\Collections\Collection
      */
      public function getChildren()
      {
      return $this->children;
      }

    /**

    • Set root.

    • @param \AppBundle\Entity\SupvPageCategories|null $root

    • @return SupvPageCategories
      */
      public function setRoot(\AppBundle\Entity\SupvPageCategories $root = null)
      {
      $this->root = $root;

      return $this;
      }

    /**

    • Get root.
    • @return \AppBundle\Entity\SupvPageCategories|null
      */
      public function getRoot()
      {
      return $this->root;
      }

    /**

    • Set parent.

    • @param \AppBundle\Entity\SupvPageCategories|null $parent

    • @return SupvPageCategories
      */
      public function setParent(\AppBundle\Entity\SupvPageCategories $parent = null)
      {
      $this->parent = $parent;

      return $this;
      }

    /**

    • Get parent.
    • @return \AppBundle\Entity\SupvPageCategories|null
      */
      public function getParent()
      {
      return $this->parent;
      }
      }
      `

And here my categoryAdmin

`<?php

// src/AppBundle/Admin/SupvPageCategoriesAdmin.php
namespace AppBundle\Admin;

use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

class SupvPageCategoriesAdmin extends AbstractAdmin
{

protected $datagridValues = array(
    '_sort_by' => 'pcCatname',
);

protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('up', $this->getRouterIdParameter().'/up');
    $collection->add('down', $this->getRouterIdParameter().'/down');
}

protected function configureFormFields(FormMapper $formMapper)
{
    // create custom query to hide the current element by `id`

    $subjectId = $this->getRoot()->getSubject()->getPcId();
    $query = null;

    if ($subjectId)
    {
        $query = $this->modelManager
            ->getEntityManager('AppBundle\Entity\SupvPageCategories')
            ->createQueryBuilder('c')
            ->select('c')
            ->from('AppBundle:SupvPageCategories', 'c')
            ->where('c.pcId != '. $subjectId);
    }
    
    // ...
    $formMapper->add('parent', 'sonata_type_model', array(
        'query' => $query,
        'required' => false, // remove this row after the root element is created
        'btn_add' => false,
        'property' => 'pcCatname'
    ))
               ->add('pcCatname', 'text');
 
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('pcCatname');
}

protected function configureListFields(ListMapper $listMapper)
{

  $listMapper->addIdentifier('pcCatname', 'text')
             ->addIdentifier('_action', null, array(
              'actions' => array(
                'up' => array(
                        'template' => 'MevSortableTreeBundle:Default:list__action_up.html.twig'
                        ),
                        'down' => array(
                            'template' => 'MevSortableTreeBundle:Default:list__action_down.html.twig'
                        )
              )
  ));

}


public function createQuery($context = 'list')
{

    $proxyQuery = parent::createQuery('list');
    // Default Alias is "o"
    // You can use `id` to hide root element
    // $proxyQuery->where('o.id != 1');

    $proxyQuery->addOrderBy('o.root', 'ASC');
    $proxyQuery->addOrderBy('o.lft', 'ASC');

    return $proxyQuery;
}

}`

What I'm doing wrong?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant