getIterator() public method

{@inheritDoc}
public getIterator ( )
Example #1
1
 /**
  * Get widgets
  *
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 public function getWidgets()
 {
     // we order by position value.
     $iterator = $this->widgets->getIterator();
     $iterator->uasort(function ($first, $second) {
         if ($first === $second) {
             return 0;
         }
         return (int) $first->getPosition() < (int) $second->getPosition() ? -1 : 1;
     });
     $this->widgets = new \Doctrine\Common\Collections\ArrayCollection(iterator_to_array($iterator));
     return $this->widgets;
 }
 protected function sortCollection()
 {
     $iterator = $this->collection->getIterator();
     $iterator->uasort(function (ShippingMethodCostInterface $a, ShippingMethodCostInterface $b) {
         return $a->getCost()->getGrossAmount() < $b->getCost()->getGrossAmount() ? -1 : 1;
     });
     return new ArrayCollection(iterator_to_array($iterator));
 }
 public function createComponent($pres, $name)
 {
     $c = new PublicMenuControl($pres, $name, $this->sportGroupService, $this->sportTypeService);
     $iterator = $this->items->getIterator();
     $iterator->uasort(function ($a, $b) {
         return $a->getLabel() < $b->getLabel() ? -1 : 1;
     });
     $this->items = new ArrayCollection(iterator_to_array($iterator));
     $c->setBrands($this->items);
     $c->setTreeData($this->getTreeData());
     return $c;
 }
 function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier)
 {
     $values->getIterator()->willReturn($iterator);
     $family->getCode()->willReturn('my_family');
     $product->getFamily()->willReturn($family);
     $product->getGroupCodes()->willReturn([]);
     $product->getVariantGroup()->willReturn(null);
     $product->getCategoryCodes()->willReturn([]);
     $product->isEnabled()->willReturn(true);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('name');
     $product->getIdentifier()->willReturn($identifier);
     $identifier->getData()->willReturn('my_code');
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
     $iterator->rewind()->willReturn(null);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($value);
     $iterator->next()->willReturn(null);
     $context = ['filter_types' => ['pim.transform.product_value.structured']];
     $serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $created = new \DateTime('2010-06-23');
     $product->getCreated()->willReturn($created);
     $serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00');
     $updated = new \DateTime('2010-06-23 23:00:00');
     $product->getUpdated()->willReturn($updated);
     $serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00');
     $this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']);
 }
 function it_normalizes_groups($normalizer, $structureVersionProvider, $versionManager, $versionNormalizer, $localizedConverter, GroupInterface $tshirt, GroupTypeInterface $groupType, Version $oldestLog, Version $newestLog, ArrayCollection $products, ProductInterface $product, \ArrayIterator $productsIterator)
 {
     $options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy'];
     $tshirt->getType()->willReturn($groupType);
     $groupType->isVariant()->willReturn(true);
     $variantNormalized = ['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => ['number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]];
     $valuesLocalized = ['number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,50', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]];
     $normalizer->normalize($tshirt, 'json', $options)->willReturn($variantNormalized);
     $localizedConverter->convertToLocalizedFormats($variantNormalized['values'], $options)->willReturn($valuesLocalized);
     $structureVersionProvider->getStructureVersion()->willReturn(1);
     $versionManager->getOldestLogEntry($tshirt)->willReturn($oldestLog);
     $versionManager->getNewestLogEntry($tshirt)->willReturn($newestLog);
     $versionNormalizer->normalize($oldestLog, 'internal_api')->willReturn('normalized_oldest_log');
     $versionNormalizer->normalize($newestLog, 'internal_api')->willReturn('normalized_newest_log');
     $products->getIterator()->willReturn($productsIterator);
     $productsIterator->rewind()->shouldBeCalled();
     $productsCount = 1;
     $productsIterator->valid()->will(function () use(&$productsCount) {
         return $productsCount-- > 0;
     });
     $productsIterator->next()->shouldBeCalled();
     $productsIterator->current()->will(new ReturnPromise([$product]));
     $product->getId()->willReturn(42);
     $tshirt->getId()->willReturn(12);
     $tshirt->getProducts()->willReturn($products);
     $this->normalize($tshirt, 'internal_api', $options)->shouldReturn(['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => $valuesLocalized, 'products' => [42], 'meta' => ['id' => 12, 'form' => 'pim-variant-group-edit-form', 'structure_version' => 1, 'model_type' => 'variant_group', 'created' => 'normalized_oldest_log', 'updated' => 'normalized_newest_log']]);
 }
 public function getIterator()
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->getIterator();
 }
 function it_allows_to_get_errors_if_the_copy_went_wrong($mediaFetcher, $filesystemProvider, $fileExporterPath, FileInfoInterface $fileInfo, FileInfoInterface $fileInfo2, ArrayCollection $productValuesCollection, \ArrayIterator $valuesIterator, ProductValueInterface $productValue, ProductValueInterface $productValue2, AttributeInterface $attribute, FilesystemInterface $filesystem)
 {
     $fileInfo->getStorage()->willReturn('storageAlias');
     $fileInfo->getKey()->willReturn('a/b/c/d/product.jpg');
     $fileInfo->getOriginalFilename()->willReturn('my product.jpg');
     $fileInfo2->getStorage()->willReturn('storageAlias');
     $fileInfo2->getKey()->willReturn('wrong-path.jpg');
     $fileInfo2->getOriginalFilename()->willReturn('my-second-media.jpg');
     $productValue->getAttribute()->willReturn($attribute);
     $productValue->getMedia()->willReturn($fileInfo);
     $productValue->getLocale()->willReturn('en_US');
     $productValue->getScope()->willReturn(null);
     $productValue2->getAttribute()->willReturn($attribute);
     $productValue2->getMedia()->willReturn($fileInfo2);
     $productValue2->getLocale()->willReturn('fr_FR');
     $productValue2->getScope()->willReturn('ecommerce');
     $attribute->getAttributeType()->willReturn('pim_catalog_image');
     $attribute->getCode()->willReturn('my_picture');
     $productValuesCollection->getIterator()->willReturn($valuesIterator);
     $valuesIterator->rewind()->shouldBeCalled();
     $valuesCount = 2;
     $valuesIterator->valid()->will(function () use(&$valuesCount) {
         return $valuesCount-- > 0;
     });
     $valuesIterator->next()->shouldBeCalled();
     $valuesIterator->current()->will(new ReturnPromise([$productValue, $productValue2]));
     $filesystemProvider->getFilesystem('storageAlias')->willReturn($filesystem);
     $mediaFetcher->fetch($filesystem, 'a/b/c/d/product.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'])->willThrow(new FileTransferException());
     $fileExporterPath->generate(['locale' => 'en_US', 'scope' => null], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/en_US/');
     $mediaFetcher->fetch($filesystem, 'wrong-path.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'])->willThrow(new \LogicException('Something went wrong.'));
     $fileExporterPath->generate(['locale' => 'fr_FR', 'scope' => 'ecommerce'], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/fr_FR/ecommerce/');
     $this->fetchAll($productValuesCollection, $this->directory, 'the_sku');
     $this->getErrors()->shouldBeEqualTo([['message' => 'The media has not been found or is not currently available', 'media' => ['from' => 'a/b/c/d/product.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'], 'storage' => 'storageAlias']], ['message' => 'The media has not been copied. Something went wrong.', 'media' => ['from' => 'wrong-path.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'], 'storage' => 'storageAlias']]]);
 }
Example #8
0
 /**
  * @return array
  */
 public function getGroups()
 {
     $groups = [];
     /** @var AbstractGroup $group */
     foreach ($this->groups->getIterator() as $group) {
         if ($group->isActive()) {
             $groups[] = $group;
         }
     }
     return $groups;
 }
 function it_normalizes_the_values_of_product(AbstractProduct $product, AbstractAttribute $attribute, ProductValueInterface $value, ArrayCollection $values, \ArrayIterator $iterator, $filter, $serializer)
 {
     $values->getIterator()->willReturn($iterator);
     $product->getAssociations()->willReturn([]);
     $product->getFamily()->willReturn(null);
     $product->getGroupCodes()->willReturn([]);
     $product->getCategoryCodes()->willReturn([]);
     $product->isEnabled()->willReturn(true);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('name');
     $product->getValues()->willReturn($values);
     $filter->filter($values, Argument::any())->shouldBeCalled()->willReturn($values);
     $iterator->rewind()->willReturn(null);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($value);
     $iterator->next()->willReturn(null);
     $serializer->normalize($value, 'json', Argument::any())->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
     $this->normalize($product, 'json')->shouldReturn(['family' => null, 'groups' => [], 'categories' => [], 'enabled' => true, 'associations' => [], 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]]);
 }
 function it_normalizes_the_properties_of_the_product(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, ArrayCollection $values, \ArrayIterator $iterator, $filter, $normalizer)
 {
     $values->getIterator()->willReturn($iterator);
     $product->getFamily()->willReturn(null);
     $product->getGroupCodes()->willReturn([]);
     $product->getVariantGroup()->willReturn(null);
     $product->getCategoryCodes()->willReturn([]);
     $product->isEnabled()->willReturn(true);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('name');
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
     $iterator->rewind()->willReturn(null);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($value);
     $iterator->next()->willReturn(null);
     $normalizer->normalize($values, 'json', Argument::any())->willReturn(['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]);
     $this->normalize($product, 'json')->shouldReturn(['family' => null, 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]]]);
 }
Example #11
0
 /**
  * @dataProvider provideDifferentElements
  */
 public function testIterator($elements)
 {
     $collection = new ArrayCollection($elements);
     $iterations = 0;
     foreach ($collection->getIterator() as $key => $item) {
         $this->assertSame($elements[$key], $item, "Item {$key} not match");
         $iterations++;
     }
     $this->assertEquals(count($elements), $iterations, "Number of iterations not match");
 }
 /**
  * Sorts the given privileges by name in alphabetical order.
  * The root privilege is moved at the top of the list.
  *
  * @param ArrayCollection|AclPrivilege[] $privileges [input/output]
  */
 protected function sortPrivileges(ArrayCollection &$privileges)
 {
     /** @var \ArrayIterator $iterator */
     $iterator = $privileges->getIterator();
     $iterator->uasort(function (AclPrivilege $a, AclPrivilege $b) {
         if (strpos($a->getIdentity()->getId(), ObjectIdentityFactory::ROOT_IDENTITY_TYPE)) {
             return -1;
         }
         if (strpos($b->getIdentity()->getId(), ObjectIdentityFactory::ROOT_IDENTITY_TYPE)) {
             return 1;
         }
         return strcmp($this->translator->trans($a->getIdentity()->getName()), $this->translator->trans($b->getIdentity()->getName()));
     });
     $result = new ArrayCollection();
     foreach ($iterator as $item) {
         $result->add($item);
     }
     $privileges = $result;
 }
Example #13
0
 /**
  * Required by interface IteratorAggregate.
  *
  * {@inheritDoc}
  */
 public function getIterator()
 {
     return $this->collection->getIterator();
 }
 /**
  * {@inheritDoc}
  */
 public function getIterator()
 {
     return $this->features->getIterator();
 }
Example #15
0
 /**
  * @param \Doctrine\Common\Collections\ArrayCollection $collection
  */
 public function it_will_return_null_if_no_branch_with_name_exists_on_repo($collection)
 {
     $collection->getIterator()->willReturn(new \ArrayIterator([]));
     $this->setBranches($collection);
     $this->getBranchByName('dev')->shouldReturn(null);
 }
Example #16
0
 public function jsonSerialize()
 {
     $accessibleFrom = $this->getAccessibleFrom();
     $accessibleUntil = $this->getAccessibleUntil();
     // Initialize data array
     $jsonArray = ['id' => $this->id, 'resourceId' => $this->id, 'activityId' => null, 'activityHeight' => $this->activityHeight, 'lvl' => $this->lvl, 'name' => $this->getName(), 'description' => $this->getDescription(), 'primaryResource' => [], 'resources' => [], 'excludedResources' => [], 'children' => [], 'withTutor' => false, 'who' => null, 'where' => null, 'duration' => null, 'accessibleFrom' => $accessibleFrom instanceof \DateTime ? $accessibleFrom->format('Y-m-d H:i:s') : null, 'accessibleUntil' => $accessibleUntil instanceof \DateTime ? $accessibleUntil->format('Y-m-d H:i:s') : null, 'evaluationType' => null];
     // Get activity properties
     if (!empty($this->activity)) {
         // Get activity ID
         $jsonArray['activityId'] = $this->activity->getId();
         // The ID of the linked Activity
         // Get primary resource
         $primaryResource = $this->activity->getPrimaryResource();
         if (!empty($primaryResource)) {
             $jsonArray['primaryResource'] = [['id' => $primaryResource->getId(), 'resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType()]];
         }
     }
     // Get parameters
     if (!empty($this->parameters)) {
         // Get parameters of the step
         $parameters = $this->parameters;
     } elseif (!empty($this->activity)) {
         // Get parameters of the Activity
         $parameters = $this->activity->getParameters();
     }
     if (!empty($parameters)) {
         // Secondary resources
         $secondaryResources = $parameters->getSecondaryResources();
         if (!empty($secondaryResources)) {
             // Get propagated resources of the current step
             $propagatedResources = $this->getPropagatedResources($this->lvl);
             foreach ($secondaryResources as $secondaryResource) {
                 $jsonArray['resources'][] = ['id' => $secondaryResource->getId(), 'resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => in_array($secondaryResource->getId(), $propagatedResources)];
             }
         }
         // Global Parameters
         $jsonArray['withTutor'] = $parameters->isWithTutor();
         $jsonArray['who'] = $parameters->getWho();
         $jsonArray['where'] = $parameters->getWhere();
         $jsonArray['duration'] = $parameters->getMaxDuration();
         // Duration in seconds
         $jsonArray['evaluationType'] = $parameters->getEvaluationType();
         // manual/automatic
     }
     // Excluded resources
     $parentResources = $this->getParentsSecondaryResources();
     /** @var \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource */
     foreach ($parentResources as $resource) {
         $exist = false;
         /** @var \Innova\PathBundle\Entity\InheritedResource $inherited */
         foreach ($this->inheritedResources as $inherited) {
             if ($inherited->getResource()->getId() === $resource->getId()) {
                 $exist = true;
                 break;
             }
         }
         // Parent resource not found in step
         if (!$exist) {
             $jsonArray['excludedResources'][] = $resource->getId();
         }
     }
     // Get condition
     if (!empty($this->condition)) {
         // Get condition of the step
         $jsonArray['condition'] = $this->condition;
     }
     // Get step children
     if (!empty($this->children)) {
         // Reorder children
         // The property OrderBy only works when we grab data from the DB,
         // so if we have modified the Path after it, children may be not ordered
         $iterator = $this->children->getIterator();
         $iterator->uasort(function ($a, $b) {
             /*
              * @var \Innova\PathBundle\Entity\Step $a
              * @var \Innova\PathBundle\Entity\Step $b
              */
             return $a->getOrder() < $b->getOrder() ? -1 : 1;
         });
         $this->children = new ArrayCollection(iterator_to_array($iterator));
         $jsonArray['children'] = array_values($this->children->toArray());
     }
     return $jsonArray;
 }
Example #17
0
 /**
  * Returns inventory iterator
  *
  * @return \ArrayIterator
  */
 public function getIterator()
 {
     return new \ArrayIterator($this->container->getIterator());
 }
 public function getIterator()
 {
     return $this->fields->getIterator();
 }
Example #19
0
 /**
  * Implements IteratorAggregate
  */
 public function getIterator()
 {
     return $this->children->getIterator();
 }
 /**
  * Sorts the given privileges by name in alphabetical order.
  * The root privilege is moved at the top of the list.
  *
  * @param ArrayCollection $privileges
  */
 protected function sortPrivileges(ArrayCollection $privileges)
 {
     $data = [];
     /** @var AclPrivilege $privilege */
     foreach ($privileges->getIterator() as $privilege) {
         $isRoot = false !== strpos($privilege->getIdentity()->getId(), ObjectIdentityFactory::ROOT_IDENTITY_TYPE);
         $label = !$isRoot ? $this->translator->trans($privilege->getIdentity()->getName()) : null;
         $data[] = [$privilege, $isRoot, $label];
     }
     uasort($data, function ($a, $b) {
         if ($a[1]) {
             return -1;
         }
         if ($b[1]) {
             return 1;
         }
         return strcmp($a[2], $b[2]);
     });
     $privileges->clear();
     foreach ($data as $item) {
         $privileges->add($item[0]);
     }
 }
 /**
  * Build iterator
  *
  * NOTE : The submission fields are added as export fields as well ...
  */
 public function buildIterator()
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('fs')->from('KunstmaanFormBundle:FormSubmission', 'fs')->innerJoin('fs.node', 'n', 'WITH', 'fs.node = n.id')->andWhere('n.id = :node')->andWhere('fs.lang = :lang')->setParameter('node', $this->nodeTranslation->getNode()->getId())->setParameter('lang', $this->nodeTranslation->getLang())->addOrderBy('fs.created', 'DESC');
     $iterableResult = $qb->getQuery()->iterate();
     $isHeaderWritten = false;
     $collection = new ArrayCollection();
     foreach ($iterableResult as $row) {
         /* @var FormSubmission $submission */
         $submission = $row[0];
         // Write row data
         $data = array('id' => $submission->getId(), 'date' => $submission->getCreated()->format('d/m/Y H:i:s'), 'language' => $submission->getLang());
         foreach ($submission->getFields() as $field) {
             $header = $this->translator->trans($field->getLabel());
             if (!$isHeaderWritten) {
                 $this->addExportField($header, $header);
             }
             $data[$header] = $field->__toString();
         }
         $isHeaderWritten = true;
         $collection->add(array($data));
     }
     $this->iterator = $collection->getIterator();
 }
 /** {@inheritDoc} */
 public function getIterator()
 {
     $this->initialize();
     return $this->collection->getIterator();
 }
 function it_normalizes_a_multi_select(SerializerInterface $serializer, ProductValueInterface $productValue, AttributeInterface $attribute, AttributeOptionInterface $multiSelect, ArrayCollection $values, \ArrayIterator $iterator)
 {
     $multiSelect->getCode()->willReturn('optionA');
     $serializer->normalize($multiSelect, null, [])->shouldNotBeCalled();
     $this->setSerializer($serializer);
     $values->getIterator()->willReturn($iterator);
     $iterator->rewind()->willReturn($multiSelect);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $iterator->current()->willReturn($multiSelect);
     $iterator->next()->willReturn(null);
     $productValue->getData()->willReturn($values);
     $productValue->getLocale()->willReturn(null);
     $productValue->getScope()->willReturn(null);
     $productValue->getAttribute()->willReturn($attribute);
     $attribute->getAttributeType()->willReturn(AttributeTypes::OPTION_MULTI_SELECT);
     $attribute->isDecimalsAllowed()->willReturn(false);
     $this->normalize($productValue)->shouldReturn(['locale' => null, 'scope' => null, 'data' => ['optionA']]);
 }