You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.1 KiB
113 lines
4.1 KiB
<?php
|
|
namespace Zitec\RuleEngineBundle\Command;
|
|
|
|
use Doctrine\Common\Annotations\AnnotationReader as Reader;
|
|
use Symfony\Component\Console\Command\Command as ContainerAwareCommand;;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
// use Doctrine\Common\Annotations\Reader;
|
|
use App\Entity\Licitador;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
use DateTime;
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
use FOS\UserBundle\Model\UserInterface;
|
|
use FOS\UserBundle\Model\UserManagerInterface;
|
|
use App\Kernel;
|
|
|
|
|
|
class FillTranslationCommand extends ContainerAwareCommand
|
|
{
|
|
private $em;
|
|
private $output;
|
|
private $sectores=[];
|
|
private $userManager;
|
|
private $tokenStorage;
|
|
protected $projectDir;
|
|
protected $propertyAccessor;
|
|
public function __construct(EntityManagerInterface $em,
|
|
UserManagerInterface $userManager,
|
|
TokenStorageInterface $tokenStorage,
|
|
Kernel $kernel)
|
|
{
|
|
parent::__construct();
|
|
$this->em = $em;
|
|
$this->userManager = $userManager;
|
|
$this->tokenStorage = $tokenStorage;
|
|
$this->projectDir = $kernel->getProjectDir();
|
|
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
|
|
}
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function configure(): void
|
|
{
|
|
$this->setName('zitec:fill:translations');
|
|
$this->addArgument(
|
|
'language',
|
|
InputArgument::REQUIRED,
|
|
'language to translate'
|
|
);
|
|
|
|
$this->setDescription(
|
|
'Translation tables filler'
|
|
);
|
|
}
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$language=$input->getArgument('language');
|
|
$folderentity='src/Entity';
|
|
$translationClass=null;
|
|
foreach (glob($folderentity."/*.php") as $index=>$nombre_fichero) {
|
|
$tokenize=explode('/',$nombre_fichero);
|
|
$clase= preg_replace('/\\.[^.\\s]{3,4}$/', '', end($tokenize));
|
|
$clase='App\Entity\\'.$clase;
|
|
$reader = new Reader();
|
|
$ref = new \ReflectionClass($clase);
|
|
//Check if class is translatable
|
|
if($reader->getClassAnnotation($ref, 'Gedmo\TranslationEntity')){
|
|
$translationClass=$reader->getClassAnnotation($ref, 'Gedmo\TranslationEntity')->getClass();
|
|
echo "Identificada Clase ".$translationClass;
|
|
}else{
|
|
continue;
|
|
}
|
|
//Get properties
|
|
$properties= array_map(function (\ReflectionProperty $prop) {
|
|
return $prop->getName();
|
|
}, $ref->getProperties());
|
|
$translatable=[];
|
|
foreach($properties as $property) {
|
|
if($type=$reader->getPropertyAnnotation(
|
|
$ref->getProperty($property),
|
|
'Gedmo\Mapping\Annotation\Translatable'
|
|
)) {
|
|
$translatable[] = $property;
|
|
}
|
|
}
|
|
echo "Propiedades Traducibles de Clase ".$translationClass."\n".print_r($translatable,true);
|
|
|
|
foreach($translatable as $prop){
|
|
$this->insertTranslation($prop, $language,$clase,$translationClass);
|
|
}
|
|
}
|
|
exit(0);
|
|
}
|
|
private function insertTranslation($prop, $language,$class, $translationClass){
|
|
$records = $this->em->getRepository($class)->findAll();
|
|
echo "Translation class $class with class Translatos $translationClass to language $language";
|
|
foreach($records as $record){
|
|
//$record->addTranslation(new Entity\CategoryTranslation($language, $prop, $propertyAccessor->getValue($record,$prop)));
|
|
echo "'$language', '$prop', '".$propertyAccessor->getValue($record,$prop)."'\n";
|
|
//$this->em->persist($record);
|
|
}
|
|
//$this->em->flush();
|
|
}
|
|
|
|
}
|