private function getStockLevel(Part $part) { /** * @var Query $query */ $query = $this->getContainer()->get("doctrine")->getManager()->createQuery("SELECT p.stockLevel FROM PartKeeprPartBundle:Part p WHERE p.id = :id")->setParameter("id", $part->getId()); return $query->getSingleScalarResult(); }
public function testAssociationRemoval() { $part = new Part(); $part->setName("TEST"); $part->setCategory($this->getContainer()->get("partkeepr.part.category_service")->getRootNode()); $part->setStorageLocation($this->fixtures->getReference("storagelocation.first")); $partManufacturer = new PartManufacturer(); $partManufacturer->setManufacturer($this->fixtures->getReference("manufacturer.first")); $part->addManufacturer($partManufacturer); $partDistributor = new PartDistributor(); $partDistributor->setDistributor($this->fixtures->getReference("distributor.first")); $part->addDistributor($partDistributor); $partAttachment = new PartAttachment(); $fileService = $this->getContainer()->get("partkeepr_uploadedfile_service"); $fileService->replaceFromData($partAttachment, "BLA", "test.txt"); $part->addAttachment($partAttachment); $this->getContainer()->get("doctrine.orm.default_entity_manager")->persist($part); $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part); $part->removeDistributor($partDistributor); $part->removeManufacturer($partManufacturer); $part->removeAttachment($partAttachment); $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part); $storage = $fileService->getStorage($partAttachment); $this->assertNull($partDistributor->getId()); $this->assertNull($partDistributor->getId()); $this->assertNull($partAttachment->getId()); $this->assertFalse($storage->has($partAttachment->getFullFilename())); }
public function load(ObjectManager $manager) { $partUnit = new PartMeasurementUnit(); $partUnit->setName('pieces'); $partUnit->setShortName('pcs'); $partUnit->setDefault(true); $this->addReference("partunit.default", $partUnit); $part = new Part(); $part->setName('FOOBAR'); $part->setPartUnit($partUnit); $category = $this->getReference('partcategory.first'); $storageLocation = $this->getReference('storagelocation.first'); $part->setCategory($category); $part->setStorageLocation($storageLocation); $part2 = new Part(); $part2->setName('FOOBAR2'); $category = $this->getReference('partcategory.first'); $storageLocation = $this->getReference('storagelocation.second'); $part2->setCategory($category); $part2->setStorageLocation($storageLocation); $part2->setPartUnit($partUnit); $manager->persist($partUnit); $manager->persist($part); $manager->persist($part2); $manager->flush(); $this->addReference('part.1', $part); $this->addReference('part.2', $part2); }
public function load(ObjectManager $manager) { $partUnit = new PartMeasurementUnit(); $partUnit->setName("pieces"); $partUnit->setShortName("pcs"); $partUnit->setDefault(true); $part = new Part(); $part->setName("FOOBAR"); $part->setPartUnit($partUnit); $category = $this->getReference("partcategory.first"); $storageLocation = $this->getReference("storagelocation.first"); $part->setCategory($category); $part->setStorageLocation($storageLocation); $part2 = new Part(); $part2->setName("FOOBAR2"); $category = $this->getReference("partcategory.first"); $storageLocation = $this->getReference("storagelocation.first"); $part2->setCategory($category); $part2->setStorageLocation($storageLocation); $part2->setPartUnit($partUnit); $manager->persist($partUnit); $manager->persist($part); $manager->persist($part2); $manager->flush(); $this->addReference("part.1", $part); $this->addReference("part.2", $part2); }
/** * Checks if the given internal part number is unique * * @param string $internalPartNumber The internal part number to checkl * @param Part|null $part An optional part to exclude within the check * * @return bool */ public function isInternalPartNumberUnique($internalPartNumber, Part $part = null) { if (!$this->checkInternalPartNumberUniqueness) { return true; } /** * Empty internal part numbers aren't checked. If you want to require an internal part number, set the * field internalPartNumber to mandatory. */ if ($internalPartNumber == "") { return true; } $dql = 'SELECT COUNT(p) FROM PartKeepr\\PartBundle\\Entity\\Part p WHERE p.internalPartNumber = :internalPartNumber'; if ($part !== null) { $dql .= " AND p.id != :partId"; } $query = $this->entityManager->createQuery($dql)->setParameter('internalPartNumber', $internalPartNumber); if ($part !== null) { $query->setParameter('partId', $part->getId()); } return $query->getSingleScalarResult() == 0 ? true : false; }
/** * Updates the stock level for a specific part * * @param Part $part The part to update * @param OnFlushEventArgs $eventArgs The event arguments */ protected function updateStockLevel(Part $part, OnFlushEventArgs $eventArgs) { $entityManager = $eventArgs->getEntityManager(); $part->recomputeStockLevels(); $entityManager->getUnitOfWork()->recomputeSingleEntityChangeSet($entityManager->getClassMetadata(get_class($part)), $part); }