<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\WOS;
use App\Service\Sidbi;
use App\Repository\AuthorRepository;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\PublicationAuthor;
use App\Form\PublicationAuthorType;
use App\Form\PublicationAuthor2AuthorType;
use App\Repository\PublicationAuthorRepository;
use Doctrine\ORM\EntityManagerInterface;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function index(): Response
{
return $this->render('default/index.html.twig', [
]);
}
//tuve que dejar esto aqui porque el controlador de publication controller no queria funcionar
/**
* @Route("/toauthor/{id}", name="app_publication_author_2_author", methods={"GET", "POST"})
*/
public function toauthor(Request $request, PublicationAuthor $publicationAuthor, EntityManagerInterface $entityManager, PublicationAuthorRepository $publicationAuthorRepository): Response
{
$form = $this->createForm(PublicationAuthor2AuthorType::class, $publicationAuthor);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$externalAuthor = $publicationAuthor->getExternalAuthor();
$entityManager->remove($externalAuthor);
$entityManager->remove($publicationAuthor->setExternalAuthor(null));
$entityManager->persist($externalAuthor);
$entityManager->persist($publicationAuthor);
$entityManager->flush();
$publicationAuthorRepository->removeOrphaned();
$this->addFlash('success', 'Autor correctamente asociado');
return $this->redirectToRoute('publication_edit', ['id'=>$publicationAuthor->getPublication()->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('default/toauthor.html.twig', [
'publication_author' => $publicationAuthor,
'form' => $form,
]);
}
/**
* @Route("/test", name="test")
*/
public function test(Sidbi $sidbi, WOS $wos, AuthorRepository $authorRepository): Response
{
/*$wos->setApi('expanded');
$resp = $wos->getQuota();
var_dump($resp);
die();
*/
$author = $authorRepository->find(33);
echo "hola mundo";
die();
[$publications, $recordsFound, $queryId] = $wos->getAuthorPublications($author);
var_dump($publications, $recordsFound);
/*
[$publications, $recordsFound, $queryId] = $wos->getPublications('F-8281-2013',1,1);
var_dump($publications, $recordsFound);
*/
/*
$rIds = $sidbi->getResearchersId();
echo count($rIds);*/
return $this->render('default/index.html.twig', [
]);
}
}