Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/ContentBundle/Admin/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/ContentBundle/Admin/FormCompletedAdmin.php

<?php

namespace App\ContentBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\CollectionType;
use Symfony\Component\Security\Core\Authentication\Token\Storage\UsageTrackingTokenStorage;
use App\ContentBundle\Entity\Form;

/**
 * Form Completed Admin
 *
 * @author Otto Saayman <otto@igotafrica.com>
 * @package ContentBundle
 * @subpackage Admin
 * @version 0.0.1
 */
class FormCompletedAdmin extends AbstractAdmin {

    /**
     * Security Context
     * @var \Symfony\Component\Security\Core\SecurityContextInterface
     */
    protected $securityContext;

    /**
     * Entity manager
     * @var \Doctrine\ORM\EntityManager
     */
    protected $em;

    /**
     * Container
     * @var $container
     */
    protected $container;
    protected $formObject;
    protected function generateBaseRouteName(bool $isChildAdmin = false): string
    {
        return 'form_completed';
    }

    protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
    {
        return 'form_completed';
    }

    public function setSecurityContext(UsageTrackingTokenStorage $securityContext) {
        $this->securityContext = $securityContext;
    }

    /**
     * @param \Doctrine\ORM\EntityManager $em
     */
    public function setEntityManager($em) {
        $this->em = $em;
    }

    /**
     * @return null
     */
    public function setContainer($container) {
        $this->container = $container;
    }

    public function getFormObject() {

        if (is_object($this->formObject)) {
            return $this->formObject;
        }

        $formRepository = $this->em->getRepository(Form::class);

        if (strlen($this->getRequest()->get('form_id')) > 0) {
            $this->formObject = $formRepository->find($this->getRequest()->get('form_id'));
        }

        if (!is_object($this->formObject)) {
            $this->formObject = new Form();
        }

        return $this->formObject;
    }

    public function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface {

        $this->getFormObject();

        $query = $this->getModelManager()->createQuery($this->getClass(), 'fc');
        $query->join('fc.form', 'f');
        $query->where('f.id=:formId')->setParameter("formId", $this->formObject->getId());

        $query->orderBy('fc.created_at', 'DESC');

        return $query;
    }

    protected function configureFormFields(FormMapper $formMapper): void {

        $formMapper
                ->add('created_at', null, array('label' => 'Date Created'))
        ;
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void {

        $datagridMapper
                ->add('created_at', null, array('label' => 'Date Created'))
        ;
    }

    protected function configureListFields(ListMapper $listMapper): void {

        $listMapper
                ->addIdentifier('created_at', null, array('label' => 'Date Created'))
                ->add('form_item_completed', null, array('label' => 'Data'))
                ->add('_action', 'actions', array(
                    'actions' => array(
                        'show' => array(),
                        'delete' => array(),
                    )
                ))
        ;
    }

    protected function configureShowFields(ShowMapper $showMapper): void {

        $showMapper
                ->add('form_item_completed', null, array('label' => 'Values'))
                ->add('created_at', null, array('label' => 'Date Created'))
        ;
    }

    public function configurePersistentParameters(): array {
        if (!$this->getRequest()) {
            return array();
        }

        return array(
            'form_id' => $this->getFormObject()->getId(),
        );
    }
}