Created
May 14, 2013 13:22
-
-
Save tworzenieweb/5575810 to your computer and use it in GitHub Desktop.
code example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Luxodo\Bundle\ProductionBundle\Tests; | |
use Luxodo\Bundle\ProductionBundle\Entity\Product; | |
use Luxodo\Bundle\ProductionBundle\Manager\StatusManager; | |
class ProductTest extends \PHPUnit_Framework_TestCase | |
{ | |
protected function getEmMock() | |
{ | |
return \Mockery::mock('\Doctrine\ORM\EntityManager'); | |
} | |
public function testCummulative() | |
{ | |
$product = new Product(); | |
$product->addCumulativeStatus(Product::BASIC_STATUS_MODEL_SHOOT_DONE); | |
$product->setCheckingStatus('STATUS_RFS'); | |
$this->assertTrue(count($product->getCumulativeStatuses()) == 1); | |
$em = $this->getEmMock(); | |
$manager = new StatusManager($em); | |
$manager->changeStatus($product, 'product-shooting'); | |
// status should be removed | |
$this->assertEquals(0, count($product->getCumulativeStatuses())); | |
// checking status should be RFQC_I | |
$this->assertEquals(Product::STATUS_RFQC_I, $product->getCheckingStatus()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="twig.extension.text" class="Twig_Extensions_Extension_Text"> | |
<tag name="twig.extension" /> | |
</service> | |
<service id="luxodo.production.menu_builder" class="Luxodo\Bundle\ProductionBundle\Menu\MenuBuilder"> | |
<argument type="service" id="knp_menu.factory" /> | |
<argument type="service" id="security.context" /> | |
</service> | |
<service id="luxodo.production.menu" class="Knp\Menu\MenuItem" factory-service="luxodo.production.menu_builder" factory-method="createMenu" scope="request"> | |
<argument id="request" type="service" /> | |
<tag name="knp_menu.menu" alias="main" /> | |
</service> | |
<service id="luxodo.production.form.type.money_split" class="Luxodo\Bundle\ProductionBundle\Form\Type\MoneySplitType"> | |
<tag name="form.type" alias="money_split" /> | |
</service> | |
<service id="luxodo.production.form.type.retailer" class="Luxodo\Bundle\ProductionBundle\Form\Type\RetailerType"> | |
<tag name="form.type" alias="retailer_type" /> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<service id="luxodo.production.form.type.date_time_picker" class="Luxodo\Bundle\ProductionBundle\Form\Type\DateTimePickerType"> | |
<tag name="form.type" alias="datetime_picker" /> | |
</service> | |
<!--This two form types need to use rest at the and because processing with soap takes to much time --> | |
<service id="luxodo.production.form.type.attribute_set" class="Luxodo\Bundle\ProductionBundle\Form\Type\AttributeSetType"> | |
<tag name="form.type" alias="attribute_set" /> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<service id="luxodo.production.form.type.product_type" class="Luxodo\Bundle\ProductionBundle\Form\Type\ProductType"> | |
<tag name="form.type" alias="product_type" /> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<service id="luxodo.production.product_data_listener2" class="Luxodo\Bundle\ProductionBundle\Entity\ProductApi"> | |
<tag name="doctrine.event_listener" event="prePersist" /> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</service> | |
<service id="luxodo.production.product_data_listener3" class="Luxodo\Bundle\ProductionBundle\Entity\ProductApi"> | |
<tag name="doctrine.event_listener" event="preUpdate" /> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</service> | |
<!-- this service will be replaced by rest api as soon as desired service will be ready | |
<service id="luxodo.production.magento_api" class="Luxodo\Bundle\ProductionBundle\Api\Magento"> | |
<argument>%api_dsn%</argument> | |
<argument>%api_user%</argument> | |
<argument>%api_key%</argument> | |
<argument type="service" id="session" /> | |
<argument type="service" id="logger" /> | |
<argument type="service" id="kernel" /> | |
</service>--> | |
<service id="luxodo.production.magento_rest_api" class="Luxodo\Bundle\ProductionBundle\Api\Rest"> | |
<argument>%api_rest_dsn%</argument> | |
<argument>%api_rest_user%</argument> | |
<argument>%api_rest_key%</argument> | |
<argument type="service" id="logger" /> | |
<argument type="service" id="kernel" /> | |
</service> | |
<service id="luxodo.production.magento_form" class="Luxodo\Bundle\ProductionBundle\Form\Type\GeneralFormType"> | |
<tag name="form.type" alias="magento_form" /> | |
<argument>Luxodo\Bundle\ProductionBundle\Entity\Product</argument> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<service id="luxodo.production.magento_extended_form" class="Luxodo\Bundle\ProductionBundle\Form\Type\ExtendedFormType"> | |
<tag name="form.type" alias="magento_extended_form" /> | |
<argument>Luxodo\Bundle\ProductionBundle\Entity\Product</argument> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<!-- we need to add additional role to list of super roles --> | |
<service id="sonata.admin.security.handler.role" class="%sonata.admin.security.handler.role.class%" public="false"> | |
<argument type="service" id="security.context" on-invalid="null" /> | |
<argument type="collection"> | |
<argument>ROLE_SUPER_ADMIN</argument> | |
<argument>ROLE_PT_ADMIN</argument> | |
</argument> | |
</service> | |
<service id="luxodo.component.twig.extension" class="Luxodo\Bundle\ProductionBundle\Twig\Extension\ComponentExtension" public="false"> | |
<tag name="twig.extension" /> | |
<argument type="service" id="http_kernel" /> | |
</service> | |
<service id="luxodo.admin.builder.orm_datagrid" | |
class="Luxodo\Bundle\ProductionBundle\Builder\DatagridBuilder" | |
parent="sonata.admin.builder.orm_datagrid"> | |
<call method="setMagentoApi"> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</call> | |
</service> | |
<service id="luxodo.manager.general" class="Luxodo\Bundle\ProductionBundle\Manager\GeneralManager" scope="prototype"> | |
<argument type="service" id="luxodo.production.admin.product" /> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
<argument type="service" id="doctrine.orm.entity_manager" /> | |
<argument type="service" id="luxodo.manager.status" /> | |
</service> | |
<service id="luxodo.manager.zip" class="Luxodo\Bundle\ProductionBundle\Manager\ZipManager"> | |
<argument>%kernel.root_dir%</argument> | |
<argument type="service" id="doctrine.orm.entity_manager" /> | |
<argument type="service" id="luxodo.manager.status" /> | |
</service> | |
<service id="luxodo.manager.product" class="Luxodo\Bundle\ProductionBundle\Manager\ProductManager"> | |
<argument type="service" id="doctrine.orm.entity_manager" /> | |
<argument type="service" id="luxodo.production.magento_rest_api" /> | |
</service> | |
<service id="luxodo.manager.status" class="Luxodo\Bundle\ProductionBundle\Manager\StatusManager"> | |
<argument type="service" id="doctrine.orm.entity_manager" /> | |
</service> | |
<service id="luxodo.listener.security_check" class="Luxodo\Bundle\ProductionBundle\EventListener\SecurityCheckListener" > | |
<tag name="kernel.event_listener" event="kernel.request" method="onCoreRequest" priority="-1" /> | |
<argument type="service" id="router" /> | |
<argument type="service" id="security.context" /> | |
</service> | |
</services> | |
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Luxodo\Bundle\ProductionBundle\Manager; | |
use Luxodo\Bundle\ProductionBundle\Entity\Product; | |
use Luxodo\Bundle\ProductionBundle\Entity\ProductionSlot; | |
use Luxodo\Bundle\ProductionBundle\Manager\SectionAndStatusResolver; | |
use Luxodo\Bundle\ProductionBundle\Manager\ButtonSet; | |
class StatusManager { | |
private static $actions = array( | |
'arrived-and-ok' => array('Arrived and ok', Product::STATUS_RFP), | |
'arrived-and-not-ok' => array('Arrived and not ok', | |
array('route' => '#arrived-and-not-ok', 'attributes' => array('class' => 'flaw-modal', 'title' => 'Description of the flaw', 'role' => 'button', 'data-toggle' => 'modal', 'data-status' => 'arrived-and-not-ok-finished'))), | |
'arrived-and-not-ok-finished' => array('Arrived and not ok', Product::STATUS_ARRIVED_AND_NOT_OK), | |
'did-not-arrive' => array('Did not arrive', Product::STATUS_NOT_RECEIVED), | |
'add-data' => array('Add data', array('route' => 'general', 'nextStatus' => Product::STATUS_RFW)), | |
'confirm&rfp' => array('Confirm & RFP', Product::STATUS_RFP), | |
'confirm&stop' => array('Confirm & Stop', Product::STATUS_STOP), | |
'prestyled-and-ok' => array('Prestyled and ok', Product::STATUS_RFS), | |
'prestyled-and-not-ok' => array('Prestyled and not ok', array('route' => '#prestyled-and-not-ok', 'attributes' => array('class' => 'flaw-modal', 'title' => 'Description of the flaw', 'role' => 'button', 'data-toggle' => 'modal', 'data-status' => 'prestyled-and-not-ok-finished'))), | |
'prestyled-and-not-ok-finished' => array('Prestyled and not ok', Product::STATUS_PRESTYLED_AND_NOT_OK), | |
'confirm&rfs' => array('Confirm & RFS', Product::STATUS_RFS), | |
'product-shooting' => array('Product shooting', array('route' => 'product_shooting', 'nextStatus' => Product::BASIC_STATUS_PRODUCT_SHOOT_DONE)), | |
'product-shooting-done-and-not-ok' => array('Product shooting done and not ok', Product::BASIC_STATUS_PRODUCT_SHOOT_DONE_AND_NOT_OK), | |
'model-shooting-done-and-not-ok' => array('Product shooting done and not ok', Product::BASIC_STATUS_MODEL_SHOOT_DONE_AND_NOT_OK), | |
'model-shooting' => array('Model shooting', array('route' => 'model_shooting', 'nextStatus' => Product::BASIC_STATUS_MODEL_SHOOT_DONE)), | |
'no-model-shooting' => array('No Model shooting', Product::BASIC_STATUS_NO_MODEL_SHOOTING), | |
'no-product-shooting' => array('No Model shooting', Product::BASIC_STATUS_NO_PRODUCT_SHOOTING), | |
'ok-and-packed' => array('Ok and packed', Product::BASIC_STATUS_OK_AND_PACKED), | |
'not-ok-and-packed' => array('Not ok and packed', array('route' => '#not-ok-and-packed', 'attributes' => array('class' => 'flaw-modal', 'title' => 'Description of the flaw', 'role' => 'button', 'data-toggle' => 'modal', 'data-status' => 'not-ok-and-packed-finished'))), | |
'not-ok-and-packed-finished' => array('Not ok and packed', Product::BASIC_STATUS_NOT_OK_AND_PACKED), | |
'not-packed' => array('Not packed', Product::BASIC_STATUS_NOT_PACKED), | |
'describe-products' => array('Describe products', array('route' => 'describe_products')), | |
'choose-related-products' => array('Choose related products', array('route' => 'related_offers')), | |
'choose-categories' => array('Choose categories', array('route' => 'categories')), | |
'categories-done' => array('Categories done', Product::BASIC_STATUS_CATEGORIES_DONE), | |
'rfco&rfr&rfd' => array('Ready for Checkout & Retouch & Description', Product::STATUS_RFCO_AND_RFR_AND_RFD), | |
'shoot-again' => array('Shoot again', array('route' => '#shoot-again', 'attributes' => array('class' => 'shoot-again-modal', 'title' => 'Shoot again', 'role' => 'button', 'data-toggle' => 'modal', 'data-status' => 'STATUS_RFS'))), | |
'offers-done' => array('Offers done', Product::BASIC_STATUS_RELATED_OFFERS_DONE), | |
'download-raw-data' => array('Download Raw data', array('route' => 'download_raw_data', 'nextStatus' => Product::BASIC_STATUS_RAW_DATA_DOWNLOADED)), | |
'upload-retouched' => array('Upload retouched', array('route' => '#upload-retouched', 'attributes' => array('class' => 'upload-retouched-modal', 'title' => 'Upload retouched photos', 'role' => 'button', 'data-toggle' => 'modal', 'data-status' => 'STATUS_RFD'))), | |
'retouched-uploaded' => array('Retouched uploaded', Product::BASIC_STATUS_RETOUCHING_DONE), | |
'print-shipping-documents' => array('Print shipping documents', array('route' => 'print_shipping_documents')), | |
'shipped' => array('Printed', Product::BASIC_STATUS_SHIPPED), | |
'quality-control-live-data' => array('Quality Control Live Data',array('route' => 'quality_control_live_data')), | |
); | |
private static $cumulativeConditions = array( | |
Product::STATUS_RFQC_I => array(Product::BASIC_STATUS_MODEL_SHOOT_DONE, Product::BASIC_STATUS_PRODUCT_SHOOT_DONE), | |
Product::STATUS_RFQC_II => array( | |
Product::BASIC_STATUS_RAW_DATA_DOWNLOADED, | |
Product::BASIC_STATUS_OK_AND_PACKED, | |
Product::BASIC_STATUS_CATEGORIES_DONE, | |
Product::BASIC_STATUS_RELATED_OFFERS_DONE, | |
Product::BASIC_STATUS_RETOUCHING_DONE, | |
Product::BASIC_STATUS_SHIPPED), | |
); | |
private static $sectionStatuses = array( | |
ProductionSlot::SECTION_LIST_NEW_PRODUCTS => array( | |
), | |
ProductionSlot::SECTION_CHECK_IN => array( | |
Product::STATUS_NEW, | |
Product::STATUS_ARRIVED_AND_NOT_OK, | |
), | |
ProductionSlot::SECTION_ADD_GENERAL_PRODUCT_DATA => array( | |
Product::STATUS_RFP, | |
Product::STATUS_NOT_RECEIVED, | |
Product::STATUS_STOP | |
), | |
ProductionSlot::SECTION_WARDROBE => array( | |
Product::STATUS_RFW, | |
Product::STATUS_STOP, | |
Product::STATUS_NOT_RECEIVED, | |
Product::STATUS_PRESTYLED_AND_NOT_OK | |
), | |
ProductionSlot::SECTION_SHOOTING => array( | |
Product::STATUS_RFS, | |
Product::STATUS_STOP, | |
Product::STATUS_NOT_RECEIVED | |
), | |
ProductionSlot::SECTION_QUALITY_CONTROL_RAW_DATA => array( | |
Product::STATUS_RFQC_I, | |
Product::STATUS_STOP, | |
Product::STATUS_NOT_RECEIVED | |
), | |
ProductionSlot::SECTION_CHECK_OUT => array( | |
Product::STATUS_RFCO_AND_RFR_AND_RFD, | |
Product::STATUS_STOP, | |
Product::STATUS_NOT_RECEIVED, | |
), | |
ProductionSlot::SECTION_RETOUCH_PRODUCTS => array( | |
Product::STATUS_RFCO_AND_RFR_AND_RFD, | |
Product::STATUS_NOT_RECEIVED, | |
Product::STATUS_STOP, | |
), | |
ProductionSlot::SECTION_ADD_DETAILS => array( | |
Product::STATUS_RFCO_AND_RFR_AND_RFD, | |
Product::STATUS_STOP, | |
Product::STATUS_NOT_RECEIVED, | |
), | |
ProductionSlot::SECTION_QUALITY_CONTROL_LIVE_DATA => array( | |
Product::STATUS_RFQC_II, | |
) | |
); | |
/** | |
* | |
* @var \Doctrine\ORM\EntityManager | |
*/ | |
private $em; | |
function __construct(\Doctrine\ORM\EntityManager $em) { | |
$this->em = $em; | |
} | |
public function getActions($section, Product $product) | |
{ | |
$className = get_class($product); | |
$status = constant("{$className}::{$product->getCheckingStatus()}"); | |
$sectionResolver = new SectionAndStatusResolver(); | |
// section list new products | |
$sectionResolver->add(new ButtonSet(array(), array('arrived-and-ok', 'arrived-and-not-ok', 'did-not-arrive')), ProductionSlot::SECTION_LIST_NEW_PRODUCTS, Product::STATUS_NEW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfp', 'confirm&stop')), ProductionSlot::SECTION_LIST_NEW_PRODUCTS, Product::STATUS_ARRIVED_AND_NOT_OK); | |
$sectionResolver->add(new ButtonSet(array(), array('arrived-and-ok', 'arrived-and-not-ok', 'did-not-arrive')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_NEW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfp', 'confirm&stop')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_ARRIVED_AND_NOT_OK); | |
// section check in | |
$sectionResolver->add(new ButtonSet(array(), array('arrived-and-ok', 'arrived-and-not-ok', 'did-not-arrive')), ProductionSlot::SECTION_CHECK_IN, Product::STATUS_NEW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfp', 'confirm&stop')), ProductionSlot::SECTION_CHECK_IN, Product::STATUS_ARRIVED_AND_NOT_OK); | |
$sectionResolver->add(new ButtonSet(array(), array('arrived-and-ok', 'arrived-and-not-ok', 'did-not-arrive')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_NEW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfp', 'confirm&stop')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_ARRIVED_AND_NOT_OK); | |
// section Add General | |
$sectionResolver->add(new ButtonSet(array(), array('add-data')), ProductionSlot::SECTION_ADD_GENERAL_PRODUCT_DATA, Product::STATUS_RFP); | |
$sectionResolver->add(new ButtonSet(array(), array('add-data')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_RFP); | |
// section Wardrobe | |
$sectionResolver->add(new ButtonSet(array(), array('prestyled-and-ok', 'prestyled-and-not-ok')), ProductionSlot::SECTION_WARDROBE, Product::STATUS_RFW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfs', 'confirm&stop')), ProductionSlot::SECTION_WARDROBE, Product::STATUS_PRESTYLED_AND_NOT_OK); | |
$sectionResolver->add(new ButtonSet(array(), array('prestyled-and-ok', 'prestyled-and-not-ok')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_RFW); | |
$sectionResolver->add(new ButtonSet(array(), array('confirm&rfs', 'confirm&stop')), ProductionSlot::SECTION_DASHBOARD, Product::STATUS_PRESTYLED_AND_NOT_OK); | |
// section Shooting | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_MODEL_SHOOT_DONE), array('product-shooting')), ProductionSlot::SECTION_SHOOTING, Product::STATUS_RFS); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_PRODUCT_SHOOT_DONE), array('model-shooting')), ProductionSlot::SECTION_SHOOTING, Product::STATUS_RFS); | |
$sectionResolver->add(new ButtonSet(array(), array('product-shooting', 'model-shooting')), ProductionSlot::SECTION_SHOOTING, Product::STATUS_RFS); | |
// section quality control raw data | |
$sectionResolver->add(new ButtonSet(array(), array('rfco&rfr&rfd', 'shoot-again')), ProductionSlot::SECTION_QUALITY_CONTROL_RAW_DATA, Product::STATUS_RFQC_I); | |
// section check out | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_SHIPPED), array()), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_SHIPPED), array()), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_STOP); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_SHIPPED), array()), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_NOT_RECEIVED); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_NOT_RECEIVED); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_NOT_RECEIVED); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_NOT_RECEIVED); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_STOP); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_OK_AND_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_STOP); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_NOT_PACKED), array('print-shipping-documents')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_STOP); | |
$sectionResolver->add(new ButtonSet(array(), array('ok-and-packed', 'not-ok-and-packed', 'not-packed')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(), array('ok-and-packed', 'not-ok-and-packed', 'not-packed')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_NOT_RECEIVED); | |
$sectionResolver->add(new ButtonSet(array(), array('ok-and-packed', 'not-ok-and-packed', 'not-packed')), ProductionSlot::SECTION_CHECK_OUT, Product::STATUS_STOP); | |
// section add details | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_CATEGORIES_DONE, Product::BASIC_STATUS_RELATED_OFFERS_DONE), array()), ProductionSlot::SECTION_ADD_DETAILS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_CATEGORIES_DONE), array('choose-related-products')), ProductionSlot::SECTION_ADD_DETAILS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_RELATED_OFFERS_DONE), array('choose-related-categories')), ProductionSlot::SECTION_ADD_DETAILS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(), array('choose-categories', 'choose-related-products')), ProductionSlot::SECTION_ADD_DETAILS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
// section retouch | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_RETOUCHING_DONE), array()), ProductionSlot::SECTION_RETOUCH_PRODUCTS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(Product::BASIC_STATUS_RAW_DATA_DOWNLOADED), array('upload-retouched')), ProductionSlot::SECTION_RETOUCH_PRODUCTS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
$sectionResolver->add(new ButtonSet(array(), array('download-raw-data')), ProductionSlot::SECTION_RETOUCH_PRODUCTS, Product::STATUS_RFCO_AND_RFR_AND_RFD); | |
// quality control live data | |
$sectionResolver->add(new ButtonSet(array(), array('quality-control-live-data')), ProductionSlot::SECTION_QUALITY_CONTROL_LIVE_DATA, Product::STATUS_RFQC_II); | |
return $sectionResolver->setSection($section) | |
->setStatus($status) | |
->accept($product->getCumulativeStatuses()); | |
} | |
public function getAction($key) | |
{ | |
return isset(self::$actions[$key]) ? self::$actions[$key] : null; | |
} | |
/** | |
* This method is changing status based on provided action name | |
* It's based on status structures like actions | |
* @param type $actionName | |
* @return \Luxodo\Bundle\ProductionBundle\Entity\Product | |
*/ | |
public function changeStatus(Product $product, $actionName) | |
{ | |
$nextStatus = $this->determineCumulativeStatus($product, $this->determineStatus($product, $actionName)); | |
$product->setCheckingStatus($nextStatus); | |
return $this; | |
} | |
public function determineCumulativeStatus(Product $product, $nextStatus) | |
{ | |
if(strstr($nextStatus, 'BASIC_STATUS')) | |
{ | |
$product->addCumulativeStatus($nextStatus); | |
$nextStatus = $product->getCheckingStatus(); | |
foreach(self::$cumulativeConditions as $key => $rules) | |
{ | |
$output = array_intersect($rules, $product->getCumulativeStatuses()); | |
// all rules are matched | |
if(count($output) == count($rules)) | |
{ | |
$nextStatus = $key; | |
$product->removeCumulativeStatuses($rules); | |
} | |
} | |
} | |
return $nextStatus; | |
} | |
public function determineStatus(Product $product, $actionName) | |
{ | |
$className = get_class($product); | |
$status = constant("{$className}::{$product->getCheckingStatus()}"); | |
list($label, $nextStatus) = self::getAction($actionName); | |
if(is_array($nextStatus) && isset($nextStatus['nextStatus'])) | |
{ | |
$nextStatus = $nextStatus['nextStatus']; | |
} | |
return $nextStatus; | |
} | |
public function getStatusesForSection($section) | |
{ | |
if(isset(self::$sectionStatuses[$section])) | |
return self::$sectionStatuses[$section]; | |
throw new \Exception("Section {$section} doesn't exist"); | |
} | |
public function nextSection(Product $object) | |
{ | |
foreach(self::$sectionStatuses as $section => $statuses) | |
{ | |
$status = $object->getCheckingStatus(); | |
if(!is_numeric($status)) | |
{ | |
$status = $object->getCheckingStatusName(); | |
} | |
$cumulative = array( | |
'BASIC_STATUS_SHIPPED' => ProductionSlot::SECTION_CHECK_OUT, | |
'BASIC_STATUS_RETOUCHING_DONE' => ProductionSlot::SECTION_RETOUCH_PRODUCTS, | |
'BASIC_STATUS_CATEGORIES_DONE' => ProductionSlot::SECTION_ADD_DETAILS, | |
'BASIC_STATUS_RELATED_OFFERS_DONE' => ProductionSlot::SECTION_ADD_DETAILS, | |
); | |
$keys = array_keys($cumulative); | |
// find first matching section for object | |
if(in_array($status, $statuses)) | |
{ | |
if($status == Product::STATUS_RFCO_AND_RFR_AND_RFD) | |
{ | |
$next = array_diff($keys, $object->getCumulativeStatus()); | |
if(count($next) > 1) | |
{ | |
return isset($cumulative[current($next)]) ? $cumulative[current($next)] : false; | |
} | |
else | |
return ProductionSlot::SECTION_QUALITY_CONTROL_LIVE_DATA; | |
} | |
return $section; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment