mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-29 10:10:25 -07:00
Add SetService metods for managing models in set
This commit is contained in:
parent
844b848670
commit
ba9ec87585
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace AppBundle\Service;
|
namespace AppBundle\Service;
|
||||||
|
|
||||||
|
use AppBundle\Entity\LDraw\Model;
|
||||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||||
use AppBundle\Entity\Rebrickable\Set;
|
use AppBundle\Entity\Rebrickable\Set;
|
||||||
use AppBundle\Repository\Rebrickable\Inventory_PartRepository;
|
use AppBundle\Repository\Rebrickable\Inventory_PartRepository;
|
||||||
use AppBundle\Repository\Rebrickable\PartRepository;
|
|
||||||
|
|
||||||
class SetService
|
class SetService
|
||||||
{
|
{
|
||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SetService constructor.
|
* SetService constructor.
|
||||||
|
*
|
||||||
* @param Inventory_PartRepository $inventoryPartRepository
|
* @param Inventory_PartRepository $inventoryPartRepository
|
||||||
*/
|
*/
|
||||||
public function __construct(Inventory_PartRepository $inventoryPartRepository)
|
public function __construct(Inventory_PartRepository $inventoryPartRepository)
|
||||||
@ -21,12 +22,22 @@
|
|||||||
$this->inventoryPartRepository = $inventoryPartRepository;
|
$this->inventoryPartRepository = $inventoryPartRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public function getUniqueModelCount(Set $set) {
|
* Get array of all known models in the kit(set) with quantity. Ignores colors and groups parts with the same shape.
|
||||||
|
* [
|
||||||
}
|
* modelNumber => [
|
||||||
|
* 'model' => Model,
|
||||||
public function getModels(Set $set)
|
* 'quantity => int
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* ].
|
||||||
|
*
|
||||||
|
* @param Set $set
|
||||||
|
* @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getModels(Set $set, $spare = null)
|
||||||
{
|
{
|
||||||
$models = [];
|
$models = [];
|
||||||
|
|
||||||
@ -34,27 +45,43 @@
|
|||||||
|
|
||||||
/** @var Inventory_Part $inventoryPart */
|
/** @var Inventory_Part $inventoryPart */
|
||||||
foreach ($inventoryParts as $inventoryPart) {
|
foreach ($inventoryParts as $inventoryPart) {
|
||||||
$model = $inventoryPart->getPart()->getModel();
|
if ($model = $inventoryPart->getPart()->getModel()) {
|
||||||
$color = $inventoryPart->getColor();
|
if (isset($models[$model->getNumber()])) {
|
||||||
if($model) {
|
$models[$model->getNumber()]['quantity'] += $inventoryPart->getQuantity();
|
||||||
$models[$model->getNumber()]['model'] = $model;
|
} else {
|
||||||
|
$models[$model->getNumber()] = [
|
||||||
$quantity = 0;
|
'model' => $model,
|
||||||
if(isset($models[$model->getNumber()]['colors'][$color->getId()]['quantity'])) {
|
'quantity' => $inventoryPart->getQuantity(),
|
||||||
$quantity = $models[$model->getNumber()]['colors'][$color->getId()]['quantity'];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$models[$model->getNumber()]['colors'][$color->getId()] = [
|
|
||||||
'color' => $color,
|
|
||||||
'quantity' => $quantity+$inventoryPart->getQuantity()
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $models;
|
return $models;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSpareModels(Set $set)
|
/**
|
||||||
|
* Get array of all known models in the kit(set).
|
||||||
|
* [
|
||||||
|
* modelNumber => [
|
||||||
|
* 'model' => Model,
|
||||||
|
* 'colors => [
|
||||||
|
* colorID => [
|
||||||
|
* 'color' => Color,
|
||||||
|
* 'quantity => int
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* ]
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* ].
|
||||||
|
*
|
||||||
|
* @param Set $set
|
||||||
|
* @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getModelsWithColors(Set $set, $spare = null)
|
||||||
{
|
{
|
||||||
$models = [];
|
$models = [];
|
||||||
|
|
||||||
@ -62,23 +89,78 @@
|
|||||||
|
|
||||||
/** @var Inventory_Part $inventoryPart */
|
/** @var Inventory_Part $inventoryPart */
|
||||||
foreach ($inventoryParts as $inventoryPart) {
|
foreach ($inventoryParts as $inventoryPart) {
|
||||||
$model = $inventoryPart->getPart()->getModel();
|
if ($model = $inventoryPart->getPart()->getModel()) {
|
||||||
$color = $inventoryPart->getColor();
|
$color = $inventoryPart->getColor();
|
||||||
if($model) {
|
|
||||||
$models[$model->getNumber()]['model'] = $model;
|
|
||||||
|
|
||||||
$quantity = 0;
|
if (!isset($models[$model->getNumber()]['model'])) {
|
||||||
if(isset($models[$model->getNumber()]['colors'][$color->getId()]['quantity'])) {
|
$models[$model->getNumber()]['model'] = $model;
|
||||||
$quantity = $models[$model->getNumber()]['colors'][$color->getId()]['quantity'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$models[$model->getNumber()]['colors'][$color->getId()] = [
|
if (isset($models[$model->getNumber()]['colors'][$color->getId()])) {
|
||||||
'color' => $color,
|
$models[$model->getNumber()]['colors'][$color->getId()]['quantity'] += $inventoryPart->getQuantity();
|
||||||
'quantity' => $quantity+$inventoryPart->getQuantity()
|
} else {
|
||||||
];
|
$models[$model->getNumber()]['colors'][$color->getId()] = [
|
||||||
|
'color' => $color,
|
||||||
|
'quantity' => $inventoryPart->getQuantity(),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $models;
|
return $models;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get array models grouped by color.
|
||||||
|
* [
|
||||||
|
* 'colorID' => [
|
||||||
|
* 'color' => Color,
|
||||||
|
* 'models => [
|
||||||
|
* modelNumber => [
|
||||||
|
* 'model' => Model,
|
||||||
|
* 'quantity' => int
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* ]
|
||||||
|
* ]
|
||||||
|
* ...
|
||||||
|
* ].
|
||||||
|
*
|
||||||
|
* @param Set $set
|
||||||
|
* @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getModelsGroupedByColor(Set $set, $spare = null)
|
||||||
|
{
|
||||||
|
$colors = [];
|
||||||
|
|
||||||
|
$inventoryParts = $this->inventoryPartRepository->findAllBySetNumber($set->getNumber(), $spare, true);
|
||||||
|
|
||||||
|
/** @var Inventory_Part $inventoryPart */
|
||||||
|
foreach ($inventoryParts as $inventoryPart) {
|
||||||
|
if ($model = $inventoryPart->getPart()->getModel()) {
|
||||||
|
$color = $inventoryPart->getCOlor();
|
||||||
|
|
||||||
|
if (!isset($colors[$color->getId()]['color'])) {
|
||||||
|
$colors[$color->getId()]['color'] = $color;
|
||||||
|
$colors[$color->getId()]['quantity'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$colors[$color->getId()]['quantity'] += $inventoryPart->getQuantity();
|
||||||
|
|
||||||
|
if (isset($colors[$color->getId()]['models'][$model->getNumber()])) {
|
||||||
|
$colors[$color->getId()]['models'][$model->getNumber()]['quantity'] += $inventoryPart->getQuantity();
|
||||||
|
} else {
|
||||||
|
$colors[$color->getId()]['models'][$model->getNumber()] = [
|
||||||
|
'model' => $model,
|
||||||
|
'quantity' => $inventoryPart->getQuantity(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user