em = $container->get('doctrine')->getManager(); } /** * {@inheritdoc} */ public function configure(): void { $this->setName('prometeo:make:user-manual'); $this->addArgument( 'folder', InputArgument::OPTIONAL, 'Path to folder with images default "screenshoots"' ) ; } /** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output): void { $folder='screenshoots'; $folderadmin='src/Admin'; $prefix='App.Entity'; if ($input->getArgument('folder')) { $folder=$input->getArgument('folder'); } $this->createWord($folder,$folderadmin); } public function createWord($folder,$folderadmin){ $phpWord = new PhpWord(); $this->createDefaultFonts($phpWord); $phpWord->getSettings()->setUpdateFields(true); $phpWord->getSettings()->setEvenAndOddHeaders(true); // New portrait section $section = $phpWord->addSection(array('pageNumberingStart' => 1)); $this->createFooter($section); $this->createHeader($section); $this->createPortada($section,$phpWord); // Simple text $section->addTOC([$this->fonts['second']], ['indent'], [1], [3]); foreach (glob($folderadmin."/*.php") as $index=>$nombre_fichero) { $tokenize=explode('/',$nombre_fichero); $clase= preg_replace('/\\.[^.\\s]{3,4}$/', '', end($tokenize)); $reader = new Reader(); $ref = new ReflectionClass('App\Admin\\'.$clase); $entidad=substr($clase, 0, -5); $section->addTitle('Sección '.$entidad, 2); if($reader->getClassAnnotation($ref, 'Prometeo\CommandsBundle\Annotations\Admin')){ $section->addText($reader->getClassAnnotation($ref, 'Prometeo\CommandsBundle\Annotations\Admin')->getText(), $this->fonts['paragraph']); }else{ $section->addText(filter_var( $ref->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']); } foreach (glob($folder."/*.png") as $index=>$nombre_fichero) { if(strpos($nombre_fichero, strtolower($entidad))!==false){ if(strpos($nombre_fichero, strtolower('list'))!==false){ $section->addTitle('Listado '.$entidad, 1); if($reader->getMethodAnnotation($ref->getMethod('configureListFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')){ $section->addText($reader->getMethodAnnotation($ref->getMethod('configureListFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']); }else{ $section->addText(filter_var($ref->getMethod('configureListFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']); } } if(strpos($nombre_fichero, strtolower('create'))!==false){ $section->addTitle('Edición '.$entidad, 1); if($reader->getMethodAnnotation($ref->getMethod('configureFormFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')){ $section->addText($reader->getMethodAnnotation($ref->getMethod('configureFormFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']); $tableStyle = array( 'borderColor' => '8064a2', 'borderSize' => 6, 'cellMargin' => 50 ); $firstRowStyle = array('bgColor' => '8064a2', 'color'=>'fff'); $phpWord->addTableStyle('PTable', $tableStyle, $firstRowStyle); $table = $section->addTable('PTable'); $properties=$reader->getMethodAnnotations($ref->getMethod('configureFormFields')); $table->addRow(); $table->addCell()->addText('Campo'); $table->addCell()->addText('Descripcion'); foreach($properties as $property){ if ($property instanceof \Prometeo\CommandsBundle\Annotations\AdminProperty) { $table->addRow(); $table->addCell()->addText($property->getName()); $table->addCell()->addText($property->getText()); } } }else{ $section->addText(filter_var($ref->getMethod('configureFormFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']); } } if(strpos($nombre_fichero, strtolower('show'))!==false){ $section->addTitle('Visualización '.$entidad, 1); if($reader->getMethodAnnotation($ref->getMethod('configureShowFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')) { $section->addText($reader->getMethodAnnotation($ref->getMethod('configureShowFields'), 'Prometeo\CommandsBundle\Annotations\AdminMethod')->getText(), $this->fonts['paragraph']); }else{ $section->addText(filter_var($ref->getMethod('configureShowFields')->getDocComment(), FILTER_SANITIZE_STRING), $this->fonts['paragraph']); } } $section->addImage($nombre_fichero, array('width'=>500, 'alignment' => Jc::CENTER)); $section->addPageBreak(); } } } $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('docs/UserManual.docx'); } }