mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 20:30:09 -07:00
Fix coding style
This commit is contained in:
parent
e8c225c021
commit
30c4eb8c82
@ -13,7 +13,6 @@ use AppBundle\Api\Exception\ApiException;
|
||||
use AppBundle\Api\Exception\AuthenticationFailedException;
|
||||
use AppBundle\Api\Exception\CallFailedException;
|
||||
use AppBundle\Api\Exception\EmptyResponseException;
|
||||
use Symfony\Component\Asset\Exception\LogicException;
|
||||
use Symfony\Component\Debug\Exception\ContextErrorException;
|
||||
|
||||
class Brickset extends \SoapClient
|
||||
@ -79,6 +78,7 @@ class Brickset extends \SoapClient
|
||||
|
||||
try {
|
||||
$this->checkApiKey();
|
||||
|
||||
return $this->__soapCall($method, [$parameters])->{$method.'Result'};
|
||||
} catch (\SoapFault $e) {
|
||||
throw new CallFailedException(ApiException::BRICKSET);
|
||||
@ -266,7 +266,7 @@ class Brickset extends \SoapClient
|
||||
{
|
||||
$parameters['apiKey'] = $this->apiKey;
|
||||
|
||||
if($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') {
|
||||
if ($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') {
|
||||
throw new AuthenticationFailedException(ApiException::BRICKSET);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use AppBundle\Api\Exception\EmptyResponseException;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use Symfony\Component\Asset\Exception\LogicException;
|
||||
|
||||
class Rebrickable_v3
|
||||
{
|
||||
@ -59,11 +58,11 @@ class Rebrickable_v3
|
||||
} catch (ClientException $e) {
|
||||
if ($e->getCode() == 404) {
|
||||
throw new EmptyResponseException(ApiException::REBRICKABLE);
|
||||
} else if ($e->getCode() == 401) {
|
||||
} elseif ($e->getCode() == 401) {
|
||||
throw new AuthenticationFailedException(ApiException::REBRICKABLE);
|
||||
}
|
||||
|
||||
throw new ApiException(ApiException::REBRICKABLE,$e,$e->getCode());
|
||||
throw new ApiException(ApiException::REBRICKABLE, $e, $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,15 +48,18 @@ class BricksetManager
|
||||
return isset($sets[0]) ? $sets[0] : null;
|
||||
}
|
||||
|
||||
public function getSetInstructions($id) {
|
||||
public function getSetInstructions($id)
|
||||
{
|
||||
return $this->bricksetClient->getInstructions($id);
|
||||
}
|
||||
|
||||
public function getSetReviews($id) {
|
||||
public function getSetReviews($id)
|
||||
{
|
||||
return $this->bricksetClient->getReviews($id);
|
||||
}
|
||||
|
||||
public function getAdditionalImages($id) {
|
||||
public function getAdditionalImages($id)
|
||||
{
|
||||
return $this->bricksetClient->getAdditionalImages($id);
|
||||
}
|
||||
}
|
||||
|
@ -119,18 +119,19 @@ class RebrickableManager
|
||||
return $this->serializer->deserialize($data, PartCategory::class, self::FORMAT);
|
||||
}
|
||||
|
||||
public function getPartsByLDrawNumber($number) {
|
||||
public function getPartsByLDrawNumber($number)
|
||||
{
|
||||
$options = [
|
||||
'query' => [
|
||||
'ldraw_id' => $number
|
||||
'ldraw_id' => $number,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->rebrickableClient->call('GET','lego/parts', $options);
|
||||
$response = $this->rebrickableClient->call('GET', 'lego/parts', $options);
|
||||
|
||||
$data = json_decode($response, true)['results'];
|
||||
|
||||
return $this->serializer->denormalize($data,Part::class.'[]',self::FORMAT);
|
||||
return $this->serializer->denormalize($data, Part::class.'[]', self::FORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,13 +2,11 @@
|
||||
|
||||
namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
|
@ -28,8 +28,7 @@ class ModelController extends Controller
|
||||
{
|
||||
$form = $this->get('form.factory')->create(ModelFilterType::class);
|
||||
|
||||
$filterBuilder = $this->get('repository.ldraw.model')
|
||||
->createQueryBuilder('model');
|
||||
$filterBuilder = $this->get('repository.ldraw.model')->getFilteredQueryBuilder();
|
||||
|
||||
if ($request->query->has($form->getName())) {
|
||||
// manually bind values from the request
|
||||
@ -62,7 +61,7 @@ class ModelController extends Controller
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
if($model = $this->get('manager.ldraw.model')->findByNumber($number)) {
|
||||
if ($model = $this->get('repository.ldraw.model')->findOneByNumber($number)) {
|
||||
try {
|
||||
$rbParts = $model != null ? $em->getRepository(Part::class)->findAllByModel($model) : null;
|
||||
$sets = $model != null ? $em->getRepository(Set::class)->findAllByModel($model) : null;
|
||||
@ -73,12 +72,11 @@ class ModelController extends Controller
|
||||
'model' => $model,
|
||||
'rbParts' => $rbParts,
|
||||
'sets' => $sets,
|
||||
'related' => $related
|
||||
'related' => $related,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->render('error/error.html.twig');
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace AppBundle\Controller\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Color;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
/**
|
||||
* Part controller.
|
||||
@ -14,10 +14,10 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
class ColorController extends Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @Route("/", name="color_index")
|
||||
*/
|
||||
public function indexAction() {
|
||||
public function indexAction()
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$colors = $em->getRepository(Color::class)->findAll();
|
||||
@ -26,4 +26,4 @@ class ColorController extends Controller
|
||||
'colors' => $colors,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,13 @@
|
||||
|
||||
namespace AppBundle\Controller\Rebrickable;
|
||||
|
||||
use AppBundle\Api\Exception\EmptyResponseException;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Color;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Set;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Entity\Rebrickable\Theme;
|
||||
use AppBundle\Form\FilterSetType;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
@ -24,7 +19,8 @@ class SetController extends Controller
|
||||
/**
|
||||
* @Route("/{number}/parts", name="rebrickable_set_parts")
|
||||
*/
|
||||
public function partsAction(Set $set) {
|
||||
public function partsAction(Set $set)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$em->getRepository(Color::class)->findAll();
|
||||
@ -41,13 +37,15 @@ class SetController extends Controller
|
||||
$json = json_encode($template->getContent());
|
||||
$response = new Response($json, 200);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{number}/sets", name="rebrickable_set_sets")
|
||||
*/
|
||||
public function setsAction(Set $set) {
|
||||
public function setsAction(Set $set)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$inventorySets = $em->getRepository(Inventory_Set::class)->findAllBySetNumber($set->getNumber());
|
||||
@ -59,6 +57,7 @@ class SetController extends Controller
|
||||
$json = json_encode($template->getContent());
|
||||
$response = new Response($json, 200);
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,9 @@ namespace AppBundle\Controller;
|
||||
|
||||
use AppBundle\Api\Exception\ApiException;
|
||||
use AppBundle\Api\Exception\EmptyResponseException;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Color;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Set;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Entity\Rebrickable\Theme;
|
||||
use AppBundle\Form\Filter\Set\SetFilterType;
|
||||
use AppBundle\Form\FilterSetType;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -50,7 +44,7 @@ class SetController extends Controller
|
||||
|
||||
return $this->render('set/index.html.twig', [
|
||||
'sets' => $sets,
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -62,9 +56,9 @@ class SetController extends Controller
|
||||
$rebrickableSet = null;
|
||||
$bricksetSet = null;
|
||||
try {
|
||||
if(($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) {
|
||||
if (($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) {
|
||||
$this->addFlash('warning', 'Set not found in Rebrickable database');
|
||||
};
|
||||
}
|
||||
|
||||
$bricksetSet = $this->get('api.manager.brickset')->getSetByNumber($number);
|
||||
dump($bricksetSet);
|
||||
@ -76,7 +70,7 @@ class SetController extends Controller
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
}
|
||||
|
||||
if(!$rebrickableSet && !$bricksetSet) {
|
||||
if (!$rebrickableSet && !$bricksetSet) {
|
||||
return $this->render('error/error.html.twig');
|
||||
}
|
||||
|
||||
@ -85,38 +79,4 @@ class SetController extends Controller
|
||||
'brset' => $bricksetSet,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{number}/download", name="set_download")
|
||||
*/
|
||||
public function downloadZipAction(Request $request, $number) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$inventoryParts = $em->getRepository(Inventory_Part::class)->findAllRegularBySetNumber($number);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$zipName = 'set_'.$number.'.zip';
|
||||
$zip->open($zipName, \ZipArchive::CREATE);
|
||||
/** @var Inventory_Part $part */
|
||||
foreach ($inventoryParts as $part) {
|
||||
$filename = $part->getPart()->getNumber().'_('.$part->getColor()->getName().'_'.$part->getQuantity().'x).stl';
|
||||
|
||||
try {
|
||||
if($part->getPart()->getModel()) {
|
||||
$zip->addFromString($filename, $this->get('oneup_flysystem.media_filesystem')->read($part->getPart()->getModel()->getPath()));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
$response = new Response(file_get_contents($zipName));
|
||||
$response->headers->set('Content-Type', 'application/zip');
|
||||
$response->headers->set('Content-Disposition', 'attachment;filename="' . $zipName . '"');
|
||||
$response->headers->set('Content-length', filesize($zipName));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ class Inventory
|
||||
*/
|
||||
protected $inventorySets;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->inventoryParts = new ArrayCollection();
|
||||
|
@ -2,18 +2,19 @@
|
||||
|
||||
namespace AppBundle\Exception;
|
||||
|
||||
|
||||
use Exception;
|
||||
|
||||
class ConvertingFailedException extends \Exception
|
||||
{
|
||||
private $filepath;
|
||||
|
||||
public function __construct($filepath = "", $message = "", $code = 0, Exception $previous = null)
|
||||
public function __construct($form = '', $to = '', $message = '', $code = 0, Exception $previous = null)
|
||||
{
|
||||
$message = sprintf('Error converting "%s" file to "%s".', $form, $to);
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
$this->filepath = $filepath;
|
||||
$this->filepath = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,6 +32,4 @@ class ConvertingFailedException extends \Exception
|
||||
{
|
||||
$this->filepath = $filepath;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class InventoryRepository extends BaseRepository
|
||||
{
|
||||
public function findNewestInventoryBySetNumber($number) {
|
||||
|
||||
public function findNewestInventoryBySetNumber($number)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('inventory')
|
||||
->where('inventory.set = :setNumber')
|
||||
->setParameter('setNumber', $number)
|
||||
->orderBy('inventory.version','DESC')
|
||||
->orderBy('inventory.version', 'DESC')
|
||||
->setMaxResults(1);
|
||||
|
||||
return $queryBuilder->getQuery()->getOneOrNullResult();
|
||||
|
@ -6,7 +6,6 @@ use AppBundle\Entity\LDraw\Category;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
@ -18,7 +17,7 @@ class Inventory_PartRepository extends BaseRepository
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('inventory_part')
|
||||
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory')
|
||||
->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number')
|
||||
->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number')
|
||||
->where('part.category != 17')
|
||||
->andWhere('inventory.id = :inventoryId')
|
||||
->setParameter('inventoryId', $inventory->getId())
|
||||
@ -34,7 +33,7 @@ class Inventory_PartRepository extends BaseRepository
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('inventory_part')
|
||||
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory')
|
||||
->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number')
|
||||
->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number')
|
||||
->where('part.category != 17')
|
||||
->andWhere('inventory.id = :inventoryId')
|
||||
->setParameter('inventoryId', $inventory->getId())
|
||||
|
@ -3,21 +3,18 @@
|
||||
namespace AppBundle\Repository\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class Inventory_SetRepository extends BaseRepository
|
||||
{
|
||||
public function findAllBySetNumber($number) {
|
||||
|
||||
public function findAllBySetNumber($number)
|
||||
{
|
||||
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number);
|
||||
|
||||
if($inventory) {
|
||||
if ($inventory) {
|
||||
$queryBuilder = $this->createQueryBuilder('inventory_set')
|
||||
->where('inventory_set.inventory = :inventory')
|
||||
->setParameter('inventory',$inventory->getId());
|
||||
->setParameter('inventory', $inventory->getId());
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace AppBundle\Repository\Rebrickable;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Set;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Entity\Rebrickable\Theme;
|
||||
@ -14,12 +13,12 @@ use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class SetRepository extends BaseRepository
|
||||
{
|
||||
public function findAllByTheme(Theme $theme) {
|
||||
|
||||
public function findAllByTheme(Theme $theme)
|
||||
{
|
||||
dump($this->getEntityManager()->getRepository(Theme::class)->findAllSubthemes($theme));
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('s')
|
||||
->join(Theme::class, 'theme',Join::WITH, 's.theme = theme')
|
||||
->join(Theme::class, 'theme', Join::WITH, 's.theme = theme')
|
||||
->where('theme.id = :id')
|
||||
->setParameter('id', $theme->getId());
|
||||
|
||||
|
@ -8,12 +8,12 @@ use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class ThemeRepository extends BaseRepository
|
||||
{
|
||||
public function findAllSubthemes(Theme $theme) {
|
||||
|
||||
$subQueryBuilder = $this->createQueryBuilder('subtheme');
|
||||
public function findAllSubthemes(Theme $theme)
|
||||
{
|
||||
$subQueryBuilder = $this->createQueryBuilder('subtheme');
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('subtheme')
|
||||
->leftJoin(Theme::class,'theme', Join::WITH, 'subtheme.parent = theme.id')
|
||||
->leftJoin(Theme::class, 'theme', Join::WITH, 'subtheme.parent = theme.id')
|
||||
->where('subtheme.parent = :id')
|
||||
->setParameter('id', $theme->getId());
|
||||
|
||||
|
@ -3,9 +3,6 @@
|
||||
namespace AppBundle\Twig;
|
||||
|
||||
use AppBundle\Api\Manager\RebrickableManager;
|
||||
use AppBundle\Entity\Rebrickable\Color;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
|
||||
class AppExtension extends \Twig_Extension
|
||||
{
|
||||
@ -30,7 +27,8 @@ class AppExtension extends \Twig_Extension
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions() {
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFunction('remoteSize', [$this, 'remoteSize']),
|
||||
new \Twig_SimpleFunction('remoteFilename', [$this, 'remoteFilename']),
|
||||
@ -39,7 +37,7 @@ class AppExtension extends \Twig_Extension
|
||||
|
||||
public function partImage($number, $color = null)
|
||||
{
|
||||
return '/parts/ldraw/'.($color ? $color :'-1').'/'.$number.'.png';
|
||||
return '/parts/ldraw/'.($color ? $color : '-1').'/'.$number.'.png';
|
||||
}
|
||||
|
||||
public function setImage($number)
|
||||
@ -47,21 +45,24 @@ class AppExtension extends \Twig_Extension
|
||||
return '/sets/'.strtolower($number).'.jpg';
|
||||
}
|
||||
|
||||
public function remoteSize($url) {
|
||||
public function remoteSize($url)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HEADER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||
|
||||
$data = curl_exec($ch);
|
||||
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function remoteFilename($url) {
|
||||
return basename($url);
|
||||
public function remoteFilename($url)
|
||||
{
|
||||
return basename($url);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user