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
|
||||
|
||||
namespace AppBundle\Service;
|
||||
namespace AppBundle\Service;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\Rebrickable\Inventory_PartRepository;
|
||||
use AppBundle\Repository\Rebrickable\PartRepository;
|
||||
|
||||
class SetService
|
||||
{
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
/**
|
||||
* SetService constructor.
|
||||
*
|
||||
* @param Inventory_PartRepository $inventoryPartRepository
|
||||
*/
|
||||
public function __construct(Inventory_PartRepository $inventoryPartRepository)
|
||||
@ -21,12 +22,22 @@
|
||||
$this->inventoryPartRepository = $inventoryPartRepository;
|
||||
}
|
||||
|
||||
|
||||
public function getUniqueModelCount(Set $set) {
|
||||
|
||||
}
|
||||
|
||||
public function getModels(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,
|
||||
* '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 = [];
|
||||
|
||||
@ -34,27 +45,43 @@
|
||||
|
||||
/** @var Inventory_Part $inventoryPart */
|
||||
foreach ($inventoryParts as $inventoryPart) {
|
||||
$model = $inventoryPart->getPart()->getModel();
|
||||
$color = $inventoryPart->getColor();
|
||||
if($model) {
|
||||
$models[$model->getNumber()]['model'] = $model;
|
||||
|
||||
$quantity = 0;
|
||||
if(isset($models[$model->getNumber()]['colors'][$color->getId()]['quantity'])) {
|
||||
$quantity = $models[$model->getNumber()]['colors'][$color->getId()]['quantity'];
|
||||
}
|
||||
|
||||
$models[$model->getNumber()]['colors'][$color->getId()] = [
|
||||
'color' => $color,
|
||||
'quantity' => $quantity+$inventoryPart->getQuantity()
|
||||
if ($model = $inventoryPart->getPart()->getModel()) {
|
||||
if (isset($models[$model->getNumber()])) {
|
||||
$models[$model->getNumber()]['quantity'] += $inventoryPart->getQuantity();
|
||||
} else {
|
||||
$models[$model->getNumber()] = [
|
||||
'model' => $model,
|
||||
'quantity' => $inventoryPart->getQuantity(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = [];
|
||||
|
||||
@ -62,23 +89,78 @@
|
||||
|
||||
/** @var Inventory_Part $inventoryPart */
|
||||
foreach ($inventoryParts as $inventoryPart) {
|
||||
$model = $inventoryPart->getPart()->getModel();
|
||||
if ($model = $inventoryPart->getPart()->getModel()) {
|
||||
$color = $inventoryPart->getColor();
|
||||
if($model) {
|
||||
$models[$model->getNumber()]['model'] = $model;
|
||||
|
||||
$quantity = 0;
|
||||
if(isset($models[$model->getNumber()]['colors'][$color->getId()]['quantity'])) {
|
||||
$quantity = $models[$model->getNumber()]['colors'][$color->getId()]['quantity'];
|
||||
if (!isset($models[$model->getNumber()]['model'])) {
|
||||
$models[$model->getNumber()]['model'] = $model;
|
||||
}
|
||||
|
||||
if (isset($models[$model->getNumber()]['colors'][$color->getId()])) {
|
||||
$models[$model->getNumber()]['colors'][$color->getId()]['quantity'] += $inventoryPart->getQuantity();
|
||||
} else {
|
||||
$models[$model->getNumber()]['colors'][$color->getId()] = [
|
||||
'color' => $color,
|
||||
'quantity' => $quantity+$inventoryPart->getQuantity()
|
||||
'quantity' => $inventoryPart->getQuantity(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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