98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\ChangeReport;
|
|
use App\Entity\User;
|
|
use App\Service\Jdate;
|
|
use App\Service\Provider;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Exception;
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class AdminController extends AbstractController
|
|
{
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
#[Route('/api/admin/sync/database', name: 'app_admin_sync_database')]
|
|
public function app_admin_sync_database(KernelInterface $kernel): JsonResponse
|
|
{
|
|
$application = new Application($kernel);
|
|
$application->setAutoExit(false);
|
|
|
|
$input = new ArrayInput([
|
|
'command' => 'doctrine:schema:update',
|
|
// (optional) define the value of command arguments
|
|
'--force' => true,
|
|
'--complete' => true
|
|
]);
|
|
|
|
// You can use NullOutput() if you don't need the output
|
|
$output = new BufferedOutput();
|
|
$application->run($input, $output);
|
|
|
|
// return the output, don't use if you used NullOutput()
|
|
$content = $output->fetch();
|
|
return $this->json([
|
|
'message' => $content,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
#[Route('/api/admin/has/role/{role}', name: 'app_admin_has_role')]
|
|
public function app_admin_has_role($role): JsonResponse
|
|
{
|
|
if(!is_bool(array_search($role,$this->getUser()->getRoles())))
|
|
{
|
|
return $this->json([
|
|
'result' => true,
|
|
]);
|
|
}
|
|
return $this->json([
|
|
'result' => false,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
#[Route('/api/admin/users/list', name: 'app_admin_users_list')]
|
|
public function app_admin_users_list(Provider $provider,EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$users = $entityManager->getRepository(User::class)->findAll();
|
|
return $this->json($provider->ArrayEntity2ArrayJustIncludes($users,[
|
|
|
|
]));
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/lists', name: 'app_admin_reportchange_list')]
|
|
public function app_admin_reportchange_list(Jdate $jdate,Provider $provider,EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$rows = $entityManager->getRepository(ChangeReport::class)->findAll();
|
|
foreach ($rows as $row){
|
|
$row->setDateSubmit($jdate->jdate('Y/n/d',$row->getDateSubmit()));
|
|
}
|
|
return $this->json($provider->ArrayEntity2ArrayJustIncludes($rows,['getDateSubmit','getVersion','getId']));
|
|
}
|
|
|
|
#[Route('/api/admin/reportchange/delete/{id}', name: 'app_admin_reportchange_delete')]
|
|
public function app_admin_reportchange_delete(string $id,EntityManagerInterface $entityManager): JsonResponse
|
|
{
|
|
$item = $entityManager->getRepository(ChangeReport::class)->find($id);
|
|
if($item){
|
|
$entityManager->remove($item);
|
|
$entityManager->flush();
|
|
}
|
|
return $this->json(['result'=>1]);
|
|
}
|
|
}
|