src/Controller/ApiController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Constant\StripeSubscription;
  4. use App\Entity\ConfigModel;
  5. use App\Entity\ConfigUi;
  6. use App\Entity\Configurator3D;
  7. use App\Entity\ConfiguratorUI;
  8. use App\Entity\ConfigViewer;
  9. use App\Services\Formatting;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * @Route("/api")
  17.  */
  18. class ApiController extends AbstractController
  19. {
  20.     private $doctrine;
  21.     public function __construct(ManagerRegistry $doctrine) {
  22.         $this->doctrine $doctrine;
  23.     }
  24.     /**
  25.      * @Route("/model-viewer/{modelConfigUuid}/{viewerConfigUuid}/{uiConfigUuid}", name="model_viewer_show")
  26.      */
  27.     public function apiModelViewerShow($modelConfigUuid$viewerConfigUuid$uiConfigUuid,
  28.                                        StripeSubscription $stripeSubscription,
  29.                                        Formatting $formatting)
  30.     {
  31.         $modelConfig $this->doctrine->getRepository(ConfigModel::class)->findOneBy(['uuid' => $modelConfigUuid]);
  32.         if (!$modelConfig){
  33.             return $this->render('api/model-viewer.html.twig', [
  34.                 'modelConfig' => [],
  35.                 'viewerConfig' => [],
  36.                 'uiConfig' => [],
  37.                 'domains' => [],
  38.                 'hideLogo' => false,
  39.                 'expired' => false,
  40.                 'error' => "Model not found",
  41.                 'title' => "Arty 3D Viewer - Model not found"
  42.             ]);
  43.         }
  44.         $viewerConfigOutput = [];
  45.         if (strtolower($viewerConfigUuid) != 'default'){
  46.             $viewerConfig $this->doctrine->getRepository(ConfigViewer::class)->findOneBy(['uuid' => $viewerConfigUuid]);
  47.             if ($viewerConfig) {
  48.                 $viewerConfigDecoded json_decode($viewerConfig->getConfig(), true);
  49.                 $viewerConfigOutput $viewerConfigDecoded['config'];
  50.             }
  51.         }
  52.         $uiConfigOutput = [];
  53.         if (strtolower($uiConfigUuid) != 'default'){
  54.             $uiConfig $this->doctrine->getRepository(ConfigUi::class)->findOneBy(['uuid' => $uiConfigUuid]);
  55.             if ($uiConfig) {
  56.                 $uiConfigDecoded json_decode($uiConfig->getConfig(), true);
  57.                 $uiConfigOutput $uiConfigDecoded['config'];
  58.             }
  59.         }
  60.         $domains $modelConfig->getProject()->getAccount()->getDomains();
  61.         if (!empty($domains)){
  62.             $domains $formatting->formatDomains($domains);
  63.         }
  64.         $expired false;
  65.         $subscription $modelConfig->getProject()->getAccount()->getSubscription();
  66.         if ($subscription->getService()->getCode() != 'FREE'){
  67.             $expiryDate $subscription->getExpiryDate();
  68.             $pendingExpirationDays $stripeSubscription->getSubscriptionExpirationPendingDays();
  69.             $dateNow = (new \DateTime("now"))->modify('-'.$pendingExpirationDays.' day');
  70.             $expired = ($dateNow >= $expiryDate);
  71.         }
  72.         $config json_decode($modelConfig->getConfig(), true);
  73.         $modelThumb $config['config']['modelScreenshot'];
  74.         $modelName $config['config']['name'];
  75.         return $this->render('api/model-viewer.html.twig', [
  76.             'title' => 'Arty 3D Viewer | ' ucwords($modelName),
  77.             'modelConfig' => json_encode($config['config']),
  78.             'modelThumb' => $modelThumb,
  79.             'viewerConfig' => json_encode($viewerConfigOutput),
  80.             'uiConfig' => json_encode($uiConfigOutput),
  81.             'domains' => json_encode($domains),
  82.             'hideLogo' => $modelConfig->getProject()->getAccount()->getSubscription()->getService()->isHideLogo(),
  83.             'expired' => $expired
  84.         ]);
  85.     }
  86.     /**
  87.      * @Route("/3d-configurator/{configUuid}/{presetUuid}", name="3d_configurator_show")
  88.      */
  89.     public function apiConfiguratorShow($configUuid$presetUuid)
  90.     {
  91.         $configurator $this->doctrine->getRepository(Configurator3D::class)->findOneBy(['uuid' => $configUuid]);
  92.         $preset $this->doctrine->getRepository(ConfiguratorUI::class)->findOneBy(['uuid' => $presetUuid]);
  93.         if (!$configurator) return new Response('Configurator not found');
  94.         $preview false;
  95.         if (!$preset){
  96.             $preview true;
  97.             $configObject = [];
  98.             $uiObject = [];
  99.         } else {
  100.             $configObject $preset->getConfigObject();
  101.             $uiObject $preset->getUiObject();
  102.         }
  103.         $modelConfig $configurator->getModelConfig();
  104.         $description $configurator->getDescription();
  105.         return $this->render('api/3d-configurator.html.twig', [
  106.             'preview' => $preview,
  107.             'modelConfig' => $modelConfig,
  108.             'configObject' => json_encode($configObject),
  109.             'uiObject' => json_encode($uiObject),
  110.             'description' => json_encode($description),
  111.             'configuratorName' => $configurator->getName(),
  112.             'configurationUuid' => $configurator->getUuid()
  113.         ]);
  114.     }
  115. }