isEmpty() public method

{@inheritDoc}
public isEmpty ( )
 /**
  * @param array $collection
  * @param MapInterface $map
  * @param ObjectFactoryInterface|string $factory
  * @param null $aggregator
  * @throws \InvalidArgumentException
  */
 public function processing(array $collection, MapInterface $map, $factory, $aggregator = null)
 {
     $this->aggregator = $aggregator;
     $this->collection = new ArrayCollection($collection);
     $this->map = $map;
     // Checking type of factory and then set as internal tool
     if (is_string($factory)) {
         $this->factory = $this->container->get($factory);
     } else {
         $this->factory = $factory;
     }
     if (count($collection) == 0) {
         throw new \InvalidArgumentException('Collection can\'t be null');
     }
     // Split collection to "new" and "exists"
     $this->ranking();
     // If collection "exists" not empty, then load items form database
     if (!$this->exists->isEmpty()) {
         $this->loadExistsObjects();
     }
     // If collection "new" not empty, then create new entities
     if (!$this->new->isEmpty()) {
         $this->createNewObjects();
     }
     // Clean internal "common" collection
     $this->collection->clear();
     // Clean aggregator
     $this->aggregator = null;
 }
 /**
  * @group legacy
  */
 public function testLegacyChildClassOnSubmitCallParent()
 {
     $form = $this->getBuilder('name')->setData($this->collection)->addEventSubscriber(new TestClassExtendingMergeDoctrineCollectionListener())->getForm();
     $submittedData = array();
     $event = new FormEvent($form, $submittedData);
     $this->dispatcher->dispatch(FormEvents::SUBMIT, $event);
     $this->assertTrue($this->collection->isEmpty());
     $this->assertTrue(TestClassExtendingMergeDoctrineCollectionListener::$onBindCalled);
 }
 /**
  * Handle
  *
  * @param Transaction                         $transaction Transaction
  * @param CrudEntityInterface|ArrayCollection $data        Data
  * @param ConstraintViolationList|null        $violations  Violations
  *
  * @throws FeatureNotImplementedException
  *
  * @return CrudEntityInterface|CollectionResponse
  */
 public function handle(Transaction $transaction, $data, ConstraintViolationList $violations = null)
 {
     $this->errorBuilder->processViolations($violations);
     $this->errorBuilder->setTransactionErrors($transaction);
     $success = !$this->errorBuilder->hasErrors();
     $status = $success ? Transaction::STATUS_CREATED : Transaction::STATUS_CONFLICT;
     $transaction->setStatus($status);
     $transaction->setSuccess($success);
     if ($data instanceof ArrayCollection) {
         if ($data->isEmpty()) {
             $data = $this->handleEmptyCollection($transaction, $data);
         } else {
             $data = $this->handleCollection($transaction, $data);
         }
     } else {
         if ($data instanceof CrudEntityInterface) {
             $this->handleEntity($transaction, $data);
         } else {
             throw new FeatureNotImplementedException(get_class($data) . ' class is not supported by transactions (POST). Instance of ArrayCollection needed.');
         }
     }
     if (!$transaction->getSuccess()) {
         if ($data instanceof ArrayCollection) {
             $data->getItems()->clear();
         } else {
             $transaction->setRelatedIds(null);
             $data = new CollectionResponse(new ArrayCollection(array()));
             $data->setShowAssociations(true);
         }
     }
     return $data;
 }
Example #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $sources = $em->getRepository('MDSSiteBundle:Source')->findAll();
     $json = new ArrayCollection();
     $flag = '';
     foreach ($sources as $source) {
         try {
             $url = parse_url($source->getSrc());
             if ($flag !== $url['host']) {
                 $flag = $url['host'];
                 $src = $url['scheme'] . '://' . $url['host'] . ':' . $url['port'] . '/status-json.xsl';
                 $json->add(json_decode(file_get_contents($src)));
             }
         } catch (\Exception $e) {
             return false;
         }
     }
     if (!$json->isEmpty()) {
         foreach ($json as $value) {
             $source = $value->icestats->source;
             foreach ($source as $sourcevalue) {
                 //Получили тут все трансляции в массив
                 //Теперь нужно найти одинаковые по ключу и посчитать
                 //нужные данные (listeners) уникальные тут listenurl
                 $allsource[] = $sourcevalue;
             }
         }
         if (count($allsource)) {
             file_put_contents(__DIR__ . '/../../../../web/stats.txt', serialize($allsource));
         }
     }
     $output->writeln('Кудато что то записалось');
 }
Example #5
0
 /**
  * @return bool
  */
 public function isRemovable()
 {
     $ok = true;
     $ok = $ok && $this->applications->isEmpty();
     $ok = $ok && $this->fundraisers->isEmpty();
     return $ok;
 }
 public function isEmpty()
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->isEmpty();
 }
 /**
  * {@inheritdoc}
  */
 public function getValue()
 {
     if (!$this->valueCollection->isEmpty()) {
         return $this->valueCollection;
     } else {
         return parent::getValue();
     }
 }
Example #8
0
 public function isRemovable()
 {
     $removable = true;
     if (!$this->requirements->isEmpty()) {
         $removable = false;
     }
     return $removable;
 }
Example #9
0
 public function isRemovable()
 {
     $removable = true;
     if (!$this->capacities->isEmpty()) {
         $removable = false;
     }
     return $removable;
 }
 /**
  * Tests IdentityWrapper->isEmpty()
  */
 public function testIsEmpty()
 {
     $this->assertFalse($this->identityWrapper->isEmpty());
     $this->assertFalse($this->wrappedCollection->isEmpty());
     $this->identityWrapper->clear();
     $this->assertTrue($this->identityWrapper->isEmpty());
     $this->assertTrue($this->wrappedCollection->isEmpty());
 }
 /**
  * @dataProvider transformDataProvider
  *
  * @param mixed $expected
  * @param mixed $value
  */
 public function testReverseTransform($expected, $value)
 {
     if (!$expected) {
         $expected = new ArrayCollection();
     }
     $this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
         return $this->createDataObject(func_get_arg(1));
     }));
     $this->assertEquals($expected, $this->transformer->reverseTransform($value));
 }
Example #12
0
 /**
  * Set email folder origin
  *
  * @param EmailOrigin $origin
  *
  * @return EmailFolder
  */
 public function setOrigin(EmailOrigin $origin)
 {
     $this->origin = $origin;
     if (!$this->subFolders->isEmpty()) {
         foreach ($this->subFolders as $subFolder) {
             $subFolder->setOrigin($origin);
         }
     }
     return $this;
 }
 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function postAction(Request $request)
 {
     $imService = $this->get('network.store.im_service');
     $formatter = $this->container->get('sonata.formatter.pool');
     $user = $this->getUserAndCheckAccess();
     $text = $request->request->get('text', '');
     $files = $request->request->get('files');
     if (trim($text) == '') {
         return $this->errorJsonResponse('field \'text\' is empty');
     }
     $threadId = $request->request->get('threadId');
     $res = [];
     if ($threadId != null) {
         $thread = $imService->getThreadByIdAndUserIdOrThrow($threadId, $user->getId());
     } else {
         $recipientIds = $request->request->get('recipientId');
         if (!is_array($recipientIds) || empty($recipientIds)) {
             return $this->errorJsonResponse('field \'recipientId\' is empty or not array_type');
         }
         $recipientUsers = $this->getDoctrine()->getRepository('NetworkStoreBundle:User')->findBy(['id' => $recipientIds]);
         if (!$recipientUsers) {
             return $this->errorJsonResponse('users with given ids not found');
         }
         $recipientUsers = new ArrayCollection($recipientUsers);
         $recipientUsers->removeElement($user);
         // to be sure that client does not send yourself
         if ($recipientUsers->isEmpty()) {
             return $this->errorJsonResponse('users with given ids not found');
         }
         if ($recipientUsers->count() == 1) {
             $rUser = $recipientUsers[0];
             $res['topic'] = $rUser->getFirstName() . ' ' . $rUser->getLastName();
         }
         $topic = $request->request->get('topic', '');
         $thread = $imService->createDialogOrConference($user, $recipientUsers, $topic);
         if (!array_key_exists('topic', $res)) {
             $res['topic'] = $thread->getTopic();
         }
     }
     $post = $imService->createPost($user, $thread, $text, $files);
     $normalizedPost = $imService->normalizePost($post);
     $normalizedPost['text'] = $formatter->transform('markdown', $text);
     $res['post'] = $normalizedPost;
     $res['threadId'] = $thread->getId();
     foreach ($thread->getUsers() as $threadUser) {
         if ($user->getId() != $threadUser->getId()) {
             $msg = new ImMessage($thread->getId(), $threadUser->getId(), $normalizedPost);
             $imService->sendMessage($msg);
         }
     }
     if ($user->getId() == $post->getUser()->getId()) {
         $res['post']['editable'] = true;
     }
     return new JsonResponse($res);
 }
Example #14
0
 /**
  * @param ArrayCollection $ingredients
  * @param $offset
  * @param $limit
  *
  * @return array
  */
 public function getRecipesByIngredients($ingredients, $offset, $limit)
 {
     if ($ingredients->isEmpty()) {
         return $this->beforeReturn([], $offset, $limit);
     }
     $moreIngredients = $this->expandIngredients($ingredients);
     $ingIds = $moreIngredients->map(function ($i) {
         return $i->getId();
     })->toArray();
     $recipes = $this->beforeReturn($ingIds, $offset, $limit);
     return $recipes;
 }
 /**
  * @dataProvider submitProvider
  *
  * @param $defaultData
  * @param $viewData
  * @param $submittedData
  * @param ArrayCollection $expected
  */
 public function testSubmit($defaultData, $viewData, $submittedData, ArrayCollection $expected)
 {
     $this->doctrineHelper->expects($expected->isEmpty() ? $this->never() : $this->exactly($expected->count()))->method('getEntityReference')->will($this->returnCallback(function () {
         return $this->createDataObject(func_get_arg(1));
     }));
     $form = $this->factory->create($this->type, $defaultData, ['class' => '\\stdClass']);
     $this->assertEquals($viewData, $form->getViewData());
     $form->submit($submittedData);
     $this->assertTrue($form->isValid());
     $data = $form->getData();
     $this->assertEquals($expected, $data);
 }
Example #16
0
 public function searchBugs()
 {
     $bug = false;
     $descriptions = array();
     if ($this->category == null) {
         $bug = true;
         $descriptions[] = 'Without category';
     }
     if ($this->capacities->isEmpty()) {
         $bug = true;
         $descriptions[] = 'No capacites who implies this requirement';
     }
     return array('bug' => $bug, 'descriptions' => $descriptions);
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function validate()
 {
     //self validate
     # GinnyMapException::300
     if (empty($this->bundle)) {
         throw new GinnyMapException('BaseModel::$bundle empty', 300);
     }
     # GinnyMapException::301
     if ($this->fields->isEmpty()) {
         throw new GinnyMapException('BaseModel::$fields empty', 301);
     }
     foreach ($this->fields as $field) {
         $field->validate();
     }
     foreach ($this->associations as $association) {
         $association->validate();
     }
 }
Example #18
0
 /**
  * @Route("/employee/resume/{id}/edit", name="employee_resume_edit")
  * @Template()
  */
 public function resumeEditAction(Request $request, $id)
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     $resume = $em->getRepository('ApiBundle:Resume')->find($id);
     if ($user->getResume()->contains($resume)) {
         $dateInDate = $resume->getTermfrom();
         if ($dateInDate != null && !is_string($dateInDate)) {
             $dateInString = $dateInDate->format("d.m.Y");
             $resume->setTermfrom($dateInString);
         } else {
             $resume->setTermfrom("");
         }
         $dateInDate = $resume->getTermto();
         if ($dateInDate != null && !is_string($dateInDate)) {
             $dateInString = $dateInDate->format("d.m.Y");
             $resume->setTermto($dateInString);
         } else {
             $resume->setTermto("");
         }
         $originalEducation = new ArrayCollection();
         foreach ($resume->getEducation() as $education) {
             $educationTitle = $education->getUniversities()->getTitle();
             $education->setUniversities($educationTitle);
             $originalEducation->add($education);
         }
         if ($originalEducation->isEmpty()) {
             $resume->getEducation()->add(new \ApiBundle\Entity\Education());
         }
         $originalExperience = new ArrayCollection();
         foreach ($resume->getExperience() as $experience) {
             $originalExperience->add($experience);
         }
         if ($originalExperience->isEmpty()) {
             $resume->getExperience()->add(new \ApiBundle\Entity\Experience());
         }
         $form = $this->createForm(new ResumeType($em), $resume);
         $form->handleRequest($request);
         $img = $resume->getImage();
         if (!empty($img)) {
             $src = $img->getSrc();
         } else {
             $src = null;
         }
         if ($form->isValid()) {
             $stringToDate = $resume->getTermfrom();
             if (trim($stringToDate) != "") {
                 $resume->setTermfrom(new \DateTime($stringToDate));
             } else {
                 $resume->setTermfrom(null);
             }
             $stringToDate = $resume->getTermto();
             if (trim($stringToDate) != "") {
                 $resume->setTermto(new \DateTime($stringToDate));
             } else {
                 $resume->setTermto(null);
             }
             foreach ($originalEducation as $education) {
                 if (false === $resume->getEducation()->contains($education)) {
                     $em->remove($education);
                 }
             }
             foreach ($resume->getEducation() as $education) {
                 if ($education->getUniversities() == null) {
                     $resume->removeEducation($education);
                     $em->remove($education);
                 } else {
                     $eduTitle = $education->getUniversities();
                     $universityObj = $em->getRepository("ApiBundle:Universities")->findOneBy(array('title' => $eduTitle));
                     $resume->removeEducation($education);
                     $education->setUniversities($universityObj);
                     $universityObj->addEducation($education);
                     $education->setResume($resume);
                     $resume->addEducation($education);
                     //                    $em->persist($education);
                     $em->persist($universityObj);
                     $em->persist($education);
                 }
             }
             foreach ($originalExperience as $experience) {
                 if (false === $resume->getExperience()->contains($experience)) {
                     $em->remove($experience);
                 }
             }
             foreach ($resume->getExperience() as $experience) {
                 if ($experience->getTitle() === null) {
                     $resume->removeExperience($experience);
                     $em->remove($experience);
                 } else {
                     $experience->setResume($resume);
                     $em->persist($experience);
                 }
             }
             $imageId = $request->request->get('mainbundle_resume')['imageId'];
             if ($imageId) {
                 $image = $this->getDoctrine()->getRepository('ApiBundle:Image')->findOneById($imageId);
                 if ($image) {
                     $imageObject = $image;
                     $this->cropImage($request, $image);
                     $resume->setImage($imageObject);
                 }
             } else {
                 $img = $this->getUser()->getImage();
                 $resume->setImage($img);
             }
             //                $em->persist($resume);
             $em->flush();
             //                $em->refresh($resume);
             return $this->redirectToRoute('employee_resume', array('from' => "update"), 301);
         }
         return $this->render('MainBundle:Employee:createResume.html.twig', ['form' => $form->createView(), 'imgSrc' => $src]);
     }
     // если резюме не пренадлежит этому человеку
     $countries = $em->getRepository('ApiBundle:Country')->getAllCountries();
     $branches = $em->getRepository('ApiBundle:Branch')->getAllBranches();
     return $this->render('MainBundle:Default:index.html.twig', ["countries" => $countries, "branches" => $branches]);
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function hasProducts()
 {
     return !$this->products->isEmpty();
 }
 /**
  * @return bool
  */
 public function hasParentCollection()
 {
     return !$this->parents->isEmpty();
 }
 function it_normalizes_a_value_with_ordered_options_with_a_option_collection_data(ProductValueInterface $value, AttributeInterface $multiColorAttribute, SerializerInterface $serializer, AttributeOptionInterface $redOption, AttributeOptionInterface $blueOption, ArrayCollection $collection)
 {
     $collection->toArray()->willReturn([$redOption, $blueOption]);
     $collection->isEmpty()->willReturn(false);
     $value->getData()->willReturn($collection);
     $value->getAttribute()->willReturn($multiColorAttribute);
     $value->getLocale()->willReturn('en_US');
     $multiColorAttribute->getCode()->willReturn('colors');
     $multiColorAttribute->isLocaleSpecific()->willReturn(false);
     $multiColorAttribute->isLocalizable()->willReturn(false);
     $multiColorAttribute->isScopable()->willReturn(false);
     $multiColorAttribute->getBackendType()->willReturn('options');
     $redOption->getSortOrder()->willReturn(10)->shouldBeCalled();
     $blueOption->getSortOrder()->willReturn(11)->shouldBeCalled();
     // phpspec raises this php bug https://bugs.php.net/bug.php?id=50688,
     // warning: usort(): Array was modified by the user comparison function in ProductValueNormalizer.php line 178
     $previousReporting = error_reporting();
     error_reporting(0);
     $serializer->normalize(Argument::type('Doctrine\\Common\\Collections\\ArrayCollection'), 'flat', ['field_name' => 'colors'])->shouldBeCalled()->willReturn(['colors' => 'red, blue']);
     $this->normalize($value, 'flat', [])->shouldReturn(['colors' => 'red, blue']);
     error_reporting($previousReporting);
 }
Example #22
0
 public function testEmpty()
 {
     $collection = new ArrayCollection();
     $this->assertTrue($collection->isEmpty(), "Empty collection");
     $collection->add(1);
     $this->assertFalse($collection->isEmpty(), "Not empty collection");
 }
Example #23
0
 /**
  * @return bool
  */
 public function hasChildren()
 {
     return !$this->children->isEmpty() ? true : false;
 }
Example #24
0
 /**
  * This method deletes a channel if there are no closed activities.
  * If there are open activities the location is deactivated.
  *
  * @param $id
  *
  * @throws \Exception
  */
 public function removeChannel($id)
 {
     $channel = $this->em->getRepository('CampaignChainCoreBundle:Channel')->find($id);
     if (!$channel) {
         throw new \Exception('No channel found for id ' . $id);
     }
     //
     $locations = $channel->getLocations();
     $openActivities = new ArrayCollection();
     $closedActivities = new ArrayCollection();
     foreach ($locations as $location) {
         foreach ($location->getActivities() as $activity) {
             if ($activity->getStatus() == 'closed') {
                 $closedActivities->add($activity);
             } else {
                 $openActivities->add($activity);
             }
         }
     }
     if (!$closedActivities->isEmpty()) {
         //deaktivieren
     } else {
         foreach ($openActivities as $activity) {
             $this->activityService->removeActivity($activity);
         }
         foreach ($locations as $location) {
             $this->locationService->removeLocation($location);
         }
         $this->em->remove($channel);
         $this->em->flush();
     }
 }
Example #25
0
 /**
  * Get a documents actual data, flattening all the objects to arrays.
  *
  * @param object $document
  * @return array
  */
 public function getDocumentActualData($document)
 {
     $class = $this->dm->getClassMetadata(get_class($document));
     $actualData = array();
     foreach ($class->reflFields as $name => $refProp) {
         $mapping = $class->fieldMappings[$name];
         $value = $refProp->getValue($document);
         if (isset($mapping['file']) && !$value instanceof GridFSFile) {
             $value = new GridFSFile($value);
             $class->reflFields[$name]->setValue($document, $value);
             $actualData[$name] = $value;
         } elseif (($class->isCollectionValuedReference($name) || $class->isCollectionValuedEmbed($name)) && $value !== null && !$value instanceof PersistentCollection) {
             // If $actualData[$name] is not a Collection then use an ArrayCollection.
             if (!$value instanceof Collection) {
                 $value = new ArrayCollection($value);
             }
             // Inject PersistentCollection
             $coll = new PersistentCollection($value, $this->dm, $this, $this->cmd);
             $coll->setOwner($document, $mapping);
             $coll->setDirty(!$value->isEmpty());
             $class->reflFields[$name]->setValue($document, $coll);
             $actualData[$name] = $coll;
         } else {
             if (!$class->isIdentifier($name) || $class->isIdGeneratorNone()) {
                 $actualData[$name] = $value;
             }
         }
     }
     return $actualData;
 }
Example #26
0
 /**
  * Checks if has any variability option
  *
  * @return boolean
  */
 public function hasVariabilityOptions()
 {
     return !$this->variabilityOptions->isEmpty();
 }
Example #27
0
 /**
  * Get a documents actual data, flattening all the objects to arrays.
  *
  * @param object $document
  * @return array
  */
 public function getDocumentActualData($document)
 {
     $class = $this->dm->getClassMetadata(get_class($document));
     $actualData = array();
     foreach ($class->reflFields as $name => $refProp) {
         $mapping = $class->fieldMappings[$name];
         // skip not saved fields
         if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
             continue;
         }
         $value = $refProp->getValue($document);
         if (isset($mapping['file']) && !$value instanceof GridFSFile) {
             $value = new GridFSFile($value);
             $class->reflFields[$name]->setValue($document, $value);
             $actualData[$name] = $value;
         } elseif (isset($mapping['association']) && $mapping['type'] === 'many' && $value !== null && !$value instanceof PersistentCollection) {
             // If $actualData[$name] is not a Collection then use an ArrayCollection.
             if (!$value instanceof Collection) {
                 $value = new ArrayCollection($value);
             }
             // Inject PersistentCollection
             $coll = new PersistentCollection($value, $this->dm, $this);
             $coll->setOwner($document, $mapping);
             $coll->setDirty(!$value->isEmpty());
             $class->reflFields[$name]->setValue($document, $coll);
             $actualData[$name] = $coll;
         } else {
             $actualData[$name] = $value;
         }
     }
     return $actualData;
 }
Example #28
0
 /**
  * @return bool
  */
 public function hasMessageCollection()
 {
     return (bool) ($this->messageCollection->isEmpty() !== true);
 }
 /**
  * Get families
  *
  * @return ArrayCollection|null
  */
 public function getFamilies()
 {
     return $this->families->isEmpty() ? null : $this->families;
 }
Example #30
0
 /**
  * @return \Datetime
  */
 public function getLastActivity()
 {
     return $this->comments->isEmpty() ? $this->getTopicDate() : $this->getLastComment()->getCommentDate();
 }