1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-18 13:10:08 -07:00

Fix color dependencies

This commit is contained in:
David Hübner 2017-04-24 11:07:44 +02:00
parent 328d14426e
commit 7e31eee729
5 changed files with 40 additions and 21 deletions

View File

@ -1,5 +1,9 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}{{ 'page.color' | trans }}{% endblock %}
{% block header %}{{ 'page.color' | trans }}{% endblock %}
{% block content %} {% block content %}
<table class="ui celled small padded table"> <table class="ui celled small padded table">

View File

@ -1,4 +1,10 @@
services: services:
repository.color:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine", getRepository]
arguments:
- AppBundle\Entity\Color
repository.ldraw.keyword: repository.ldraw.keyword:
class: Doctrine\ORM\EntityRepository class: Doctrine\ORM\EntityRepository
factory: ["@doctrine", getRepository] factory: ["@doctrine", getRepository]
@ -54,12 +60,6 @@ services:
arguments: arguments:
- AppBundle\Entity\Rebrickable\Category - AppBundle\Entity\Rebrickable\Category
repository.rebrickable.color:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine", getRepository]
arguments:
- AppBundle\Entity\Rebrickable\Color
repository.rebrickable.inventory: repository.rebrickable.inventory:
class: Doctrine\ORM\EntityRepository class: Doctrine\ORM\EntityRepository
factory: ["@doctrine", getRepository] factory: ["@doctrine", getRepository]

View File

@ -42,7 +42,7 @@ class LoadModelImagesCommand extends ContainerAwareCommand
} }
if($input->getOption('models')) { if($input->getOption('models')) {
$imageLoaderService->loadMissingModelImages($color); $imageLoaderService->loadMissingModelImages();
} }
} }
} }

View File

@ -1,15 +1,14 @@
<?php <?php
namespace AppBundle\Controller\Rebrickable; namespace AppBundle\Controller;
use AppBundle\Entity\Color;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/** /**
* Part controller. * Part controller.
* *
* @Route("rebrickable/colors") * @Route("colors")
*/ */
class ColorController extends Controller class ColorController extends Controller
{ {
@ -18,11 +17,9 @@ class ColorController extends Controller
*/ */
public function indexAction() public function indexAction()
{ {
$em = $this->getDoctrine()->getManager(); $colors = $this->get('repository.color')->findAll();
$colors = $em->getRepository(Color::class)->findAll(); return $this->render('color/index.html.twig', [
return $this->render('rebrickable/color/index.html.twig', [
'colors' => $colors, 'colors' => $colors,
]); ]);
} }

View File

@ -2,7 +2,6 @@
namespace AppBundle\Service\Loader; namespace AppBundle\Service\Loader;
use AppBundle\Entity\LDraw\Model; use AppBundle\Entity\LDraw\Model;
use AppBundle\Service\StlRendererService; use AppBundle\Service\StlRendererService;
use League\Flysystem\Filesystem; use League\Flysystem\Filesystem;
@ -25,6 +24,10 @@ class ImageLoader extends BaseLoader
$this->stlRendererService = $stlRendererService; $this->stlRendererService = $stlRendererService;
} }
/**
* @param $color
* @param null $path
*/
public function loadColorFromRebrickable($color, $path = null) public function loadColorFromRebrickable($color, $path = null)
{ {
if(!$path) { if(!$path) {
@ -46,23 +49,38 @@ class ImageLoader extends BaseLoader
} }
} }
public function loadMissingModelImages($color) {
/**
* Load images of models
*
*/
public function loadMissingModelImages() {
$models = $this->em->getRepository(Model::class)->findAll(); $models = $this->em->getRepository(Model::class)->findAll();
$this->initProgressBar(count($models)); $this->initProgressBar(count($models));
foreach ($models as $model) { foreach ($models as $model) {
$this->progressBar->setMessage($model->getNumber()); $this->progressBar->setMessage($model->getNumber());
if(!$this->mediaFilesystem->has('images'.DIRECTORY_SEPARATOR.$color.DIRECTORY_SEPARATOR.$model->getNumber().'.png')) { if(!$this->mediaFilesystem->has('images'.DIRECTORY_SEPARATOR.'-1'.DIRECTORY_SEPARATOR.$model->getNumber().'.png')) {
try { try {
$this->stlRendererService->render( $this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
$this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath(),
$this->mediaFilesystem->getAdapter()->getPathPrefix().'images'.DIRECTORY_SEPARATOR.$color.DIRECTORY_SEPARATOR
);
} catch (\Exception $e) { } catch (\Exception $e) {
dump($e->getMessage()); dump($e->getMessage());
} }
} }
$this->progressBar->advance(); $this->progressBar->advance();
} }
$this->progressBar->finish();
}
/**
* Render model and save image into co
*
* @param $file
*/
public function loadModelImage($file) {
$this->stlRendererService->render(
$file,
$this->mediaFilesystem->getAdapter()->getPathPrefix().'images'.DIRECTORY_SEPARATOR.'-1'.DIRECTORY_SEPARATOR
);
} }
} }