Licitator 1.0
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.

152 lines
7.4 KiB

5 years ago
  1. <?php
  2. namespace Prometeo\CommandsBundle\Commands;
  3. use Doctrine\Common\Annotations\AnnotationReader as Reader;
  4. use Symfony\Component\Console\Command\Command as ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use PhpOffice\PhpWord\PhpWord;
  12. use PhpOffice\PhpWord\Style\Font;
  13. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  14. use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
  15. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  16. use PhpOffice\PhpWord\SimpleType\Jc;
  17. use PhpOffice\PhpWord\Element\Footer;
  18. use PhpOffice\PhpWord\Element\Header;
  19. use ReflectionClass;
  20. use Prometeo\CommandsBundle\ManualTraits\HeaderTrait;
  21. use Prometeo\CommandsBundle\ManualTraits\FooterTrait;
  22. use Prometeo\CommandsBundle\ManualTraits\StylesTrait;
  23. use Prometeo\CommandsBundle\ManualTraits\PortadaTrait;
  24. class MakeUserManual extends ContainerAwareCommand
  25. {
  26. use HeaderTrait,FooterTrait,StylesTrait,PortadaTrait;
  27. private $fonts;
  28. private $em;
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. // $this->em = $container->get('doctrine')->getManager();
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function configure(): void
  38. {
  39. $this->setName('prometeo:make:user-manual');
  40. $this->addArgument(
  41. 'folder',
  42. InputArgument::OPTIONAL,
  43. 'Path to folder with images default "screenshoots"'
  44. )
  45. ;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function execute(InputInterface $input, OutputInterface $output): void
  51. {
  52. $folder='screenshoots';
  53. $folderadmin='src/Admin';
  54. $prefix='App.Entity';
  55. if ($input->getArgument('folder')) {
  56. $folder=$input->getArgument('folder');
  57. }
  58. $this->createWord($folder,$folderadmin);
  59. }
  60. public function createWord($folder,$folderadmin){
  61. $phpWord = new PhpWord();
  62. $this->createDefaultFonts($phpWord);
  63. $phpWord->getSettings()->setUpdateFields(true);
  64. $phpWord->getSettings()->setEvenAndOddHeaders(true);
  65. // New portrait section
  66. $section = $phpWord->addSection(array('pageNumberingStart' => 1));
  67. $this->createFooter($section);
  68. $this->createHeader($section);
  69. $this->createPortada($section,$phpWord);
  70. // Simple text
  71. $section->addTOC([$this->fonts['second']], ['indent'], [1], [3]);
  72. foreach (glob($folderadmin."/*.php") as $index=>$nombre_fichero) {
  73. $tokenize=explode('/',$nombre_fichero);
  74. $clase= preg_replace('/\\.[^.\\s]{3,4}$/', '', end($tokenize));
  75. $reader = new Reader();
  76. $ref = new ReflectionClass('App\Admin\\'.$clase);
  77. $entidad=substr($clase, 0, -5);
  78. $section->addTitle('Sección '.$entidad, 2);
  79. if($reader->getClassAnnotation($ref, 'Prometeo\CommandsBundle\Annotations\Admin')){
  80. $section->addText($reader->getClassAnnotation($ref, 'Prometeo\CommandsBundle\Annotations\Admin')->getText(), $this->fonts['paragraph']);
  81. }else{
  82. $section->addText(filter_var( $ref->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']);
  83. }
  84. foreach (glob($folder."/*.png") as $index=>$nombre_fichero) {
  85. if(strpos($nombre_fichero, strtolower($entidad))!==false){
  86. if(strpos($nombre_fichero, strtolower('list'))!==false){
  87. $section->addTitle('Listado '.$entidad, 1);
  88. if($reader->getMethodAnnotation($ref->getMethod('configureListFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')){
  89. $section->addText($reader->getMethodAnnotation($ref->getMethod('configureListFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']);
  90. }else{
  91. $section->addText(filter_var($ref->getMethod('configureListFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']);
  92. }
  93. }
  94. if(strpos($nombre_fichero, strtolower('create'))!==false){
  95. $section->addTitle('Edición '.$entidad, 1);
  96. if($reader->getMethodAnnotation($ref->getMethod('configureFormFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')){
  97. $section->addText($reader->getMethodAnnotation($ref->getMethod('configureFormFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']);
  98. $tableStyle = array(
  99. 'borderColor' => '8064a2',
  100. 'borderSize' => 6,
  101. 'cellMargin' => 50
  102. );
  103. $firstRowStyle = array('bgColor' => '8064a2', 'color'=>'fff');
  104. $phpWord->addTableStyle('PTable', $tableStyle, $firstRowStyle);
  105. $table = $section->addTable('PTable');
  106. $properties=$reader->getMethodAnnotations($ref->getMethod('configureFormFields'));
  107. $table->addRow();
  108. $table->addCell()->addText('Campo');
  109. $table->addCell()->addText('Descripcion');
  110. foreach($properties as $property){
  111. if ($property instanceof \Prometeo\CommandsBundle\Annotations\AdminProperty) {
  112. $table->addRow();
  113. $table->addCell()->addText($property->getName());
  114. $table->addCell()->addText($property->getText());
  115. }
  116. }
  117. }else{
  118. $section->addText(filter_var($ref->getMethod('configureFormFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']);
  119. }
  120. }
  121. if(strpos($nombre_fichero, strtolower('show'))!==false){
  122. $section->addTitle('Visualización '.$entidad, 1);
  123. if($reader->getMethodAnnotation($ref->getMethod('configureShowFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')) {
  124. $section->addText($reader->getMethodAnnotation($ref->getMethod('configureShowFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']);
  125. }else{
  126. $section->addText(filter_var($ref->getMethod('configureShowFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']);
  127. }
  128. }
  129. $section->addImage($nombre_fichero, array('width'=>500, 'alignment' => Jc::CENTER));
  130. $section->addPageBreak();
  131. }
  132. }
  133. }
  134. $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
  135. $objWriter->save('docs/UserManual.docx');
  136. }
  137. }