Skip to content

Instantly share code, notes, and snippets.

@RodolVelasco
Created December 12, 2018 03:48
Show Gist options
  • Save RodolVelasco/f35fa211f5324773e18554d7441217be to your computer and use it in GitHub Desktop.
Save RodolVelasco/f35fa211f5324773e18554d7441217be to your computer and use it in GitHub Desktop.
Symfony 2.8 must code
Symfony 2.8 must code
@RodolVelasco
Copy link
Author

RodolVelasco commented Dec 31, 2018

Composer

composer require symfony/intl
composer require symfony/polyfill-iconv
composer install --ignore-platform-reqs
php bin/console doctrine:schema:update --force

@RodolVelasco
Copy link
Author

RodolVelasco commented Jan 2, 2019

Cloning in PHP

Cloning objects with deep level 3 or more

public function __clone() {
    if ($this->id) {
        $this->package = clone $this->package;
        $imagenes = $this->getImagenes();
        $this->imagenes = new ArrayCollection();
        if(count($imagenes) > 0){
            foreach ($imagenes as $imagen) {
                $cloneImagen = clone $imagen;
                $this->imagenes->add($cloneImagen);
                $cloneImagen->setProduct($this);
            }
        } 
    }
}

Ejemplo en sistema AEPP instalado en juegos_esa.

private function duplicateProcess($entity)
    {
        $dupEntity = clone $entity;
        // dump([
        //     $entity,
        //     $dupEntity]
        // );exit;die;
        $ar = [];
        array_push($ar, $dupEntity->getNombre() . ' => ' . $dupEntity->getId());
        
        foreach($dupEntity->getCriterios() as $cri) {
            array_push($ar, $cri->getEtiqueta() . ' ' . $cri->getNombre() . ' => ' . $cri->getId());

            foreach($cri->getPreguntas() as $preg) {
                array_push($ar, $preg->getNombre(). ' => ' . $preg->getId());
                
                foreach($preg->getGuias() as $guia) {
                    array_push($ar, $guia->getNombre() . ' => ' . $guia->getId());
                }
            }
        }
        
        dump($ar);exit;die;
        return true;
    }

Luego en Autoevaluación.php

public function __clone()
    {
        if ($this->id) {
            $this->setId(null);
            $this->setEstado(false);
            $criterios = $this->getCriterios();
            $this->criterios = new ArrayCollection();
            if(count($criterios) > 0){
                foreach ($criterios as $criterio) {
                    $cloneCriterio = clone $criterio;
                    $this->criterios->add($cloneCriterio);
                    $cloneCriterio->setAutoEvaluacion($this);
                }
            }
        }
    }

Luego en Criterio.php

public function __clone()
    {
        if ($this->id) {
            $this->setId(null);
            //$this->children = clone $this->children;
            // $this->preguntas = clone $this->preguntas;
            $preguntas = $this->getPreguntas();
            $this->preguntas = new ArrayCollection();
            if(count($preguntas) > 0){
                foreach ($preguntas as $pregunta) {
                    $clonePregunta = clone $pregunta;
                    $this->preguntas->add($clonePregunta);
                    $clonePregunta->setCriterio($this);
                }
            }
        }
    }

Luego en Pregunta.php

public function __clone()
    {
        if ($this->id) {
            $this->setId(null);
            //$this->guias = clone $this->guias;
            $guias = $this->getGuias();
            $this->guias = new ArrayCollection();
            if(count($guias) > 0){
                foreach ($guias as $guia) {
                    $cloneGuia = clone $guia;
                    $this->guias->add($cloneGuia);
                    $cloneGuia->setPregunta($this);
                }
            }
        }
    }

Luego en Guia.php

public function __clone()
    {
        if ($this->id) {
            $this->setId(null);
        }
    }

@RodolVelasco
Copy link
Author

Controller

Acceso denegado
throw $this->createAccessDeniedException("No tiene permisos para acceder a esta página!");

No se encuentra el producto
throw $this->createNotFoundException('The product does not exist');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment