/** * @param Itinerary $other * @return bool */ public function sameValueAs(Itinerary $other) : bool { //We use doctrine's ArrayCollection only to ease comparison //If Legs would be stored in an ArrayCollection hole the time //Itinerary itself would not be immutable, //cause a client could call $itinerary->legs()->add($anotherLeg); //Keeping ValueObjects immutable is a rule of thumb $myLegs = new ArrayCollection($this->legs()); $otherLegs = new ArrayCollection($other->legs()); if ($myLegs->count() !== $otherLegs->count()) { return false; } return $myLegs->forAll(function ($index, Leg $leg) use($otherLegs) { return $otherLegs->exists(function ($otherIndex, Leg $otherLeg) use($leg) { return $otherLeg->sameValueAs($leg); }); }); }
public function testBind01() { $expectedJSON = file_get_contents(dirname(__DIR__) . '/../../Resources/json/client_aftership_couriers_response_handler_01.json'); $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue(200)); $this->response->expects($this->once())->method('getContent')->will($this->returnValue($expectedJSON)); $this->responseHandler->bind($this->response, $this->collection); $this->assertEquals(26, $this->collection->count()); $courier0 = $this->collection[0]; $this->assertEquals('USPS', $courier0->getName()); $this->assertEquals('United States Postal Service', $courier0->getOtherName()); $this->assertEquals('+1 800-275-8777', $courier0->getPhone()); $this->assertEquals(['USA'], $courier0->getServiceCountries()); $this->assertEquals('usps', $courier0->getSlug()); $this->assertEquals(['en'], $courier0->getSupportLanguages()); $this->assertNotNull($courier0->getUpdatedAt()); $this->assertEquals("https://www.usps.com", $courier0->getUrl()); $courier13 = $this->collection[13]; $this->assertEquals('Hong Kong Post', $courier13->getName()); $this->assertEquals('香港郵政', $courier13->getOtherName()); $this->assertEquals('+852 2921 2222', $courier13->getPhone()); $this->assertEquals(['HKG'], $courier13->getServiceCountries()); $this->assertEquals('hong-kong-post', $courier13->getSlug()); $this->assertEquals(['en'], $courier13->getSupportLanguages()); $this->assertNotNull($courier13->getUpdatedAt()); $this->assertEquals("http://hongkongpost.com", $courier13->getUrl()); }
public function count() { if (null === $this->entries) { return $this->repository->countByFeeds($this->feeds); } return $this->entries->count(); }
public function testOnSubmitDoNothing() { $submittedData = array('test'); $event = new FormEvent($this->getForm(), $submittedData); $this->dispatcher->dispatch(FormEvents::SUBMIT, $event); $this->assertTrue($this->collection->contains('test')); $this->assertSame(1, $this->collection->count()); }
public function add(IEntity $entity) { $this->errorOnInvalidEntityType($entity); if ($this->getIdentityValue($entity) < 1) { $this->setIdentityValue($entity, $this->collection->count() + 1); } $this->collection->set($entity->getId(), $entity); }
/** * Gets whether the user has read this thread since the last post * * @param User $user * * @return boolean */ public function isUnread(User $user) { if ($this->posts->count() === 0) { return false; } return $this->posts->last()->isUnread($user); }
public function getQBAliasReference($class, $attribute = NULL) { if (!is_object($class)) { throw new \Exception("object must be of type object, type %s given.", gettype($class)); } $class_name = get_class($class); // get alias of class $alias = NULL; foreach ($this->qb_alias_reference->toArray() as $_class => $_alias) { if (isset($_alias[$class_name])) { $alias = $_alias[$class_name]; } } // if not found if ($alias === NULL) { // if empty, set new if ($this->qb_alias_reference->count() == 0) { $alias = 'a'; // get last and then count up } else { $lastAlias = $this->qb_alias_reference->last(); $alias = ++$lastAlias[key($lastAlias)]; } // add new $this->qb_alias_reference->add(array($class_name => $alias)); } return $attribute === NULL ? $alias : $alias . '.' . $attribute; }
/** * @param array $deadEntities * @return bool */ protected function isAllDead(array $deadEntities) { if (count($deadEntities) == $this->existEntityCollection->count()) { return true; } return false; }
/** * @return AbstractMediaEntity|null */ public function getMediaForThumbnail() { if ($this->media->count() > 0) { return $this->media->first(); } return null; }
/** * {@inheritdoc} */ public function removeChannel(ChannelInterface $channel) { $this->channels->removeElement($channel); if ($this->channels->count() === 0) { $this->activated = false; } return $this; }
/** * Set Comments * * @param array $comments * * @return $this */ public function setComments(array $comments) { foreach ($comments as $comment) { $this->addComments($comment); } $this->nbComments = $this->comments->count(); return $this; }
public function getRoles() { if (!$this->roles->count()) { return array(parent::ROLE_DEFAULT); } $roles = $this->roles->toArray(); foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); } foreach ($roles as $k => $role) { /* * Ensure String[] to prevent bad unserialized UsernamePasswordToken with for instance * UPT#roles:{Role('ROLE_USER'), 'ROLE_USER'} which ends in Error: Call to a member * function getRole() on a non-object */ $roles[$k] = $role instanceof RoleInterface ? $role->getRole() : (string) $role; } return array_flip(array_flip($roles)); }
/** * @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)); }
/** * @return Category */ public function getCategory() { if ($this->enrollments->count() > 1) { throw new ValidationException("INVALIDENROLLMENT", "A team can not be enrolled for more than one category - team id=" . $this->id); } if ($this->enrollments->count() == 1) { return $this->enrollments->first()->getCategory(); } return null; }
/** * @param ArrayCollection $articles * @param Integer $batch_size */ public function bulkInserts(ArrayCollection $articles, $batch_size = 20) { $length = $articles->count(); for ($i = 1; $i < $length; ++$i) { $this->merge($articles->get($i)); if (0 === $i % $batch_size) { $this->detaches(); } } $this->detaches(); }
public function __toString() { if ($this->children->count()) { $childNameList = array(); foreach ($this->children as $child) { $childNameList[] = $child->getName(); } return sprintf('%s [%s]', $this->role, implode(', ', $childNameList)); } return sprintf('%s', $this->role); }
/** * @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); }
/** * @JMS\VirtualProperty * @JMS\SerializedName("alive") * @JMS\Groups({"finished"}) * * @return bool | null */ public function isAlive() { if (!$this->game->hasFinished()) { return true; } $myVotedCount = $this->voteSources->count(); $players = $this->game->getGamePlayers(); $maxVotedCount = Ginq::from($players)->map(function (GamePlayer $player) { return $player->getVoteSources()->count(); })->max(); return $myVotedCount < $maxVotedCount; }
/** * @see ExecutableInterface::start() */ public function start() { if (!$this->started) { $this->batch->startTimer($this->name, 'start'); $this->setStarted(); // Start first UnitProcedure if ($this->unitProcedures->count()) { $unitProcedure = $this->unitProcedures->first(); $unitProcedure->setEventDispatcher($this->eventDispatcher); $unitProcedure->start(); } } }
/** * @see ExecutableInterface::start() */ public function start() { if (!$this->started) { $this->batch->startTimer($this->name, 'start'); $this->setStarted(); // Start first Operation if ($this->operations->count()) { $operation = $this->operations->first(); $operation->setEventDispatcher($this->eventDispatcher); $operation->start(); } } }
/** * Starts the operation */ public function start() { if (!$this->started) { $this->batch->startTimer($this->name, 'start'); // Set flag that we are started $this->setStarted(); // Start first UnitProcedure if ($this->phases->count()) { $phase = $this->phases->first(); $phase->setEventDispatcher($this->eventDispatcher); $phase->start(); } } }
/** * Returns a count of Key/Value pairs in the Collection * * Optionally you can pass a an case-insensitive Expression to filter the * count by * * @param string $match An expression to filter on * @param boolean $exact Whether to do an exact match * * @return integer */ public function count($match = null, $exact = false) { if (!is_null($match)) { $keys = $this->index->getKeys(); if ($exact) { $match = "^{$match}\$"; } $matches = array_filter($keys, function ($key) use($match) { return preg_match("/{$match}/i", $key); }); return sizeof($matches); } return $this->index->count(); }
public function buildForm(FormBuilderInterface $builder, array $options) { $this->factory = $builder->getFormFactory(); if ($billingSpec = $this->user->getAppointedBillingSpec()) { $fees = $billingSpec->getFees(); } else { $fees = new ArrayCollection(); } if (!$fees->count()) { $fee = new Fee(); $fees[] = $fee; } $builder->add('fees', 'collection', array('type' => new FeeFormType($this->user), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_name' => '__name__', 'by_reference' => false, 'property_path' => false, 'data' => $fees))->add('minimum_billing_fee', 'number', array('precision' => 2, 'grouping' => true, 'required' => false)); $builder->addEventListener(FormEvents::BIND, array($this, 'onBind')); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('title_first', 'text', array('constraints' => array(new NotBlank())))->add('title_middle', 'text', array('constraints' => array(new NotBlank())))->add('title_last', 'text', array('constraints' => array(new NotBlank())))->add('transfer_from', 'choice', array('choices' => TransferInformation::getTransferFromChoices(), 'expanded' => true, 'multiple' => false, 'required' => false))->add('account_number', 'text', array('required' => true))->add('firm_address', 'text', array('required' => true))->add('phone_number', 'text', array('required' => true))->add('is_include_policy', 'choice', array('choices' => array(true => 'Yes', false => 'No'), 'expanded' => true, 'label' => ' ', 'constraints' => array(new NotBlank())))->add('transfer_shares_cash', 'choice', array('choices' => array(1 => 'Transfer my shares in-kind OR', 0 => 'sell my shares, and then transfer cash'), 'expanded' => true, 'multiple' => false, 'required' => false))->add('insurance_policy_type', 'choice', array('choices' => TransferInformation::getInsurancePolicyTypeChoices(), 'expanded' => true, 'multiple' => false, 'required' => false))->add('penalty_amount', 'number', array('required' => false))->add('redeem_certificates_deposit', 'radio', array('required' => false))->add('statementDocument', new PdfDocumentFormType()); $factory = $builder->getFormFactory(); $adm = $this->adm; $updateFields = function (FormInterface $form, TransferInformation $data) use($factory, $adm) { $account = $data->getClientAccount(); if ($account) { if (!$adm->isUsedDocusign($account->getId())) { $form->add($factory->createNamed('delivering_account_title', 'text', null, array('required' => false)))->add($factory->createNamed('ameritrade_account_title', 'text', null, array('required' => false))); } $form->add($factory->createNamed('financial_institution', 'text', null, array('required' => true, 'read_only' => true, 'data' => $account->getFinancialInstitution()))); if ($account->isJointType()) { $form->add($factory->createNamed('joint_title_first', 'text', null, array('constraints' => array(new NotBlank()))))->add($factory->createNamed('joint_title_middle', 'text', null, array('constraints' => array(new NotBlank()))))->add($factory->createNamed('joint_title_last', 'text', null, array('constraints' => array(new NotBlank())))); } } if ($data->getTransferCustodian()) { $answers = $data->getQuestionnaireAnswers(); if ($answers->isEmpty()) { $questions = array($data->getTransferCustodian()->getTransferCustodianQuestion()); $answers = new ArrayCollection(); foreach ($questions as $question) { if (null !== $question) { $answer = new TransferCustodianQuestionAnswer(); $answer->setQuestion($question); $answer->setTransferInformation($data); $answers->add($answer); } } } if ($answers->count()) { $form->add($factory->createNamed('questionnaireAnswers', 'collection', $answers, array('type' => new TransferInformationQuestionAnswerFormType(), 'label' => ' '))); } } }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($updateFields) { /** @var TransferInformation $data */ $data = $event->getData(); $form = $event->getForm(); if (null === $data) { return; } $updateFields($form, $data); }); if (!$this->isPreSaved) { $builder->addEventListener(FormEvents::BIND, array($this, 'validate')); } }
/** * Generates the parameters section of the services.xml file. * * @param string $dir base bundle dir * * @return void */ protected function generateParameters($dir) { if ($this->xmlParameters->count() > 0) { $services = $this->loadServices($dir); foreach ($this->xmlParameters as $parameter) { switch ($parameter['type']) { case 'collection': $this->addCollectionParam($services, $parameter['key'], $parameter['content']); break; case 'string': default: $this->addParam($services, $parameter['key'], $parameter['content']); } } } $this->persistServicesXML($dir); }
protected function execute(InputInterface $input, OutputInterface $output) { /* @var MailChimpApi $mailchimp */ /* @var TicketRepository $ticketRepo */ /* @var EventRepository $eventRepo */ $mailchimp = $this->getContainer()->get('mailchimp'); // There is no "clear subscribers" api endpoint, so we have to batch unsubscribe the non-participants $output->writeln('Fetching subscribers …'); $subscribers = new ArrayCollection(); $page = 0; do { $result = $mailchimp->listsMembers(array('id' => $input->getArgument('list'), 'opts' => array('start' => $page++))); foreach ($result->data as $subscriber) { $subscribers->add(strtolower($subscriber->email)); } } while (count($result->data) > 0); $output->writeln(sprintf("%d subscribers in list.", $subscribers->count())); $eventRepo = $this->getContainer()->get('bcrm.backend.repo.event'); $ticketRepo = $this->getContainer()->get('bcrm.backend.repo.ticket'); $participants = new ArrayCollection(); foreach ($ticketRepo->getTicketsForEvent($eventRepo->getNextEvent()->getOrThrow(new BadMethodCallException('No event.'))) as $ticket) { if ($participants->contains(strtolower($ticket->getEmail()))) { continue; } $participants->add(strtolower($ticket->getEmail())); } // Unsubscribe former participants $unsubscribe = new ArrayCollection(array_diff($subscribers->toArray(), $participants->toArray())); $output->writeln(sprintf('Unsubscribing %d participants.', $unsubscribe->count())); $result = $mailchimp->listsBatch_unsubscribe(array('id' => $input->getArgument('list'), 'batch' => $this->toBatch($unsubscribe, false), 'delete_member' => true, 'send_goodbye' => false)); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { $output->writeln(print_r($result, true)); } if ($result->error_count > 0) { throw new CommandException(sprintf('Failed to unsubscribe %d participants!', $result->error_count)); } // Subscribe new participiants $newSubcsribers = new ArrayCollection(array_diff($participants->toArray(), $subscribers->toArray())); $output->writeln(sprintf('Subscribing %d new participants.', $newSubcsribers->count())); $result = $mailchimp->listsBatch_subscribe(array('id' => $input->getArgument('list'), 'batch' => $this->toBatch($newSubcsribers), 'double_optin' => false)); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { $output->writeln(print_r($result, true)); } }
public function showAction($id) { $em = $this->getDoctrine()->getManager(); $data = $em->getRepository('GameBaseBundle:Championship')->getChampionshipById($id); $fights = new ArrayCollection(); foreach ($data as $key => $datum) { if ($key == 0) { $championship = $datum; for ($i = 0; $i < 16 - $championship->getMaxFighters(); $i++) { $fights->add(null); } } else { $fights->add($datum); } } for ($i = $fights->count(); $i <= 15; $i++) { $fights->add(null); } return $this->render('GameBaseBundle:Championship:show.html.twig', array('manager' => $_SESSION['manager'], 'championship' => $championship, 'fights' => $fights)); }
public function testGetSetMembers() { unset($this->team->{'members'}); $this->assertEmpty($this->team->getMembers()->toArray()); $member1 = new User(); $member2 = new Team(); $members = new ArrayCollection(); $members->add($member1); $members->add($member1); $members->add($member2); $this->assertEquals(3, $members->count()); $this->assertTrue($this->team->setMembers($members) instanceof Team); $returnedMembers = $this->team->getMembers(); $this->assertEquals(array($member1, $member2), $returnedMembers->toArray()); unset($this->team->{'members'}); $this->assertEquals($returnedMembers, $this->team->addMembers($members)->getMembers()); $this->assertEquals($returnedMembers[0]->getTeams()->toArray()[0], $this->team); unset($this->team->{'teams'}); $this->assertEquals(0, $this->team->getTeams()->count()); unset($this->team->{'members'}); $this->assertTrue($this->team->removeMember($member1) instanceof TeamStub); }
/** * @return UserApi[] */ public function getApiKeys() { return $this->apiKeys->count() ? $this->apiKeys : uniqid('undefined'); }
/** * Check for users. * * @return bool */ public function hasUsers() { return (bool) ($this->users->count() > 0 ?: false); }