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.
153 lines
7.4 KiB
153 lines
7.4 KiB
<?php
|
|
|
|
namespace Prometeo\CommandsBundle\Commands;
|
|
|
|
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\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use PhpOffice\PhpWord\PhpWord;
|
|
use PhpOffice\PhpWord\Style\Font;
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
|
use PhpOffice\PhpWord\SimpleType\Jc;
|
|
use PhpOffice\PhpWord\Element\Footer;
|
|
use PhpOffice\PhpWord\Element\Header;
|
|
use ReflectionClass;
|
|
use Prometeo\CommandsBundle\ManualTraits\HeaderTrait;
|
|
use Prometeo\CommandsBundle\ManualTraits\FooterTrait;
|
|
use Prometeo\CommandsBundle\ManualTraits\StylesTrait;
|
|
use Prometeo\CommandsBundle\ManualTraits\PortadaTrait;
|
|
|
|
|
|
class MakeUserManual extends ContainerAwareCommand
|
|
{
|
|
use HeaderTrait,FooterTrait,StylesTrait,PortadaTrait;
|
|
private $fonts;
|
|
private $em;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->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');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|