first() public method

{@inheritDoc}
public first ( )
 public function first()
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->first();
 }
 /**
  * @param DiamanteUser|null $user
  *
  * @return string
  */
 public function getAuditEntryFieldClass(DiamanteUser $user = null)
 {
     if ($user === null) {
         return $this->entryFieldMap->first();
     }
     $userClass = ClassUtils::getRealClass($user);
     if (!$this->entryFieldMap->containsKey($userClass)) {
         throw new \InvalidArgumentException(sprintf('Audit entry field not found for "%s"', $userClass));
     }
     return $this->entryFieldMap->get($userClass);
 }
Example #3
0
 /**
  * Get preview image
  *
  * @return Image
  */
 public function getPreviewImage()
 {
     if ($this->images->containsKey($this->previewImageKey)) {
         return $this->images->get($this->previewImageKey);
     }
     return $this->images->first();
 }
 /**
  * Get first enabled referral rule, given a DateTime
  *
  * @param DateTime $dateTime DateTime instance
  *
  * @return ReferralRule Instance found
  */
 public function findEnabledReferralRuleFromDateTime(DateTime $dateTime)
 {
     $queryBuilder = $this->createQueryBuilder('r');
     $queryResults = $queryBuilder->where('r.enabled = :enabled')->andWhere('r.validFrom <= :datetime')->andWhere($queryBuilder->expr()->orx($queryBuilder->expr()->gte('r.validTo', ':datetime'), $queryBuilder->expr()->isNull('r.validTo')))->orderBy('r.id', 'DESC')->setMaxResults(1)->setParameters(array('enabled' => true, 'datetime' => $dateTime))->getQuery()->getResult();
     $rules = new ArrayCollection($queryResults);
     return $rules->first();
 }
Example #5
0
 /**
  * @return AbstractMediaEntity|null
  */
 public function getMediaForThumbnail()
 {
     if ($this->media->count() > 0) {
         return $this->media->first();
     }
     return null;
 }
Example #6
0
 /**
  * @return Column
  */
 public function getDefaultColumn()
 {
     if (!empty($this->defaultColumn)) {
         return $this->defaultColumn;
     } else {
         return $this->columnCollection->first();
     }
 }
Example #7
0
 function it_adds_new_inventory_units_to_existing_shipment(OrderInterface $order, ShipmentInterface $shipment, ArrayCollection $shipments, InventoryUnitInterface $inventoryUnit, InventoryUnitInterface $inventoryUnitWithoutShipment)
 {
     $shipments->first()->willReturn($shipment)->shouldBeCalled();
     $inventoryUnit->getShipment()->willReturn($shipment);
     $order->getInventoryUnits()->willReturn(array($inventoryUnit, $inventoryUnitWithoutShipment));
     $order->getShipments()->willReturn($shipments)->shouldBeCalled();
     $shipment->addItem($inventoryUnitWithoutShipment)->shouldBeCalled();
     $shipment->addItem($inventoryUnit)->shouldNotBeCalled();
     $this->createShipment($order);
 }
Example #8
0
 /**
  * Guestimate the title field of the model.
  *
  * @return mixed
  */
 function titleField()
 {
     $keys = ['title', 'name', 'host', 'url', 'email'];
     foreach ($keys as $key) {
         if ($this->fields->containsKey($key)) {
             return $key;
         }
     }
     return $this->fields->first()->name;
 }
Example #9
0
 /**
  * @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;
 }
 function it_adds_new_item_units_to_existing_shipment(OrderInterface $order, ShipmentInterface $shipment, ArrayCollection $shipments, OrderItemUnitInterface $itemUnit, OrderItemUnitInterface $itemUnitWithoutShipment)
 {
     $shipments->first()->willReturn($shipment)->shouldBeCalled();
     $order->hasShipments()->willReturn(true)->shouldBeCalled();
     $itemUnit->getShipment()->willReturn($shipment);
     $order->getItemUnits()->willReturn([$itemUnit, $itemUnitWithoutShipment]);
     $order->getShipments()->willReturn($shipments)->shouldBeCalled();
     $shipment->addUnit($itemUnitWithoutShipment)->shouldBeCalled();
     $shipment->addUnit($itemUnit)->shouldNotBeCalled();
     $this->createForOrder($order);
 }
 /**
  * @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();
         }
     }
 }
Example #14
0
 /**
  * @dataProvider getNodes
  *
  * @param int $total_pages
  * @param string|\Closure $page_link
  * @param string $first_page_link
  * @param ArrayCollection $list
  */
 public function testGetIterator($total_pages, $page_link, $first_page_link, $list)
 {
     $current_page = 1;
     foreach ($list as $node) {
         /** @var $node Node */
         if ($node->isCurrent()) {
             $current_page = $node->getPage();
         }
     }
     $left_offset = $current_page - $list->first()->getPage();
     $right_offset = $list->last()->getPage() - $current_page;
     if ($list->first()->getPage() == 1) {
         $this->config->expects($this->once())->method('getFirstPageLink')->will($this->returnValue($first_page_link));
     } else {
         $this->config->expects($this->never())->method('getFirstPageLink');
     }
     $this->config->expects($this->once())->method('getTotalPages')->will($this->returnValue($total_pages));
     $this->config->expects($this->atLeastOnce())->method('getCurrentPage')->will($this->returnValue($current_page));
     $this->config->expects($this->atLeastOnce())->method('getPageLink')->will($this->returnValue($page_link));
     $this->range->expects($this->once())->method('getLeftOffset')->will($this->returnValue($left_offset));
     $this->range->expects($this->once())->method('getRightOffset')->will($this->returnValue($right_offset));
     $this->assertEquals($list, $this->view->getIterator());
 }
Example #15
0
 /**
  * @dataProvider provideDifferentElements
  */
 public function testFirst($elements)
 {
     $collection = new ArrayCollection($elements);
     $this->assertSame(reset($elements), $collection->first());
 }
 /**
  * Tests IdentityWrapper->first()
  */
 public function testFirst()
 {
     $expected = reset($this->entries);
     $this->assertSame($expected, $this->identityWrapper->first());
     $this->assertSame($expected, $this->wrappedCollection->first());
 }
Example #17
0
 /**
  * Fetchs current user baskets
  *
  * @param  Application $app
  * @param  Request     $request
  * @return Response
  */
 public function getBaskets(Application $app, Request $request)
 {
     $selectedBasketId = trim($request->get('courChuId', ''));
     $baskets = new ArrayCollection($app['EM']->getRepository('Phraseanet:Basket')->findActiveByUser($app['authentication']->getUser()));
     $selectedBasket = null;
     if ('' === $selectedBasketId && $baskets->count() > 0) {
         $selectedBasketId = $baskets->first()->getId();
     }
     if ('' !== $selectedBasketId) {
         $selectedBasket = $app['converter.basket']->convert($selectedBasketId);
         $app['acl.basket']->isOwner($selectedBasket, $app['authentication']->getUser());
     }
     $basketCollections = $baskets->partition(function ($key, $basket) {
         return null !== $basket->getPusher();
     });
     return $app['twig']->render('client/baskets.html.twig', ['total_baskets' => $baskets->count(), 'user_baskets' => $basketCollections[1], 'recept_user_basket' => $basketCollections[0], 'selected_basket' => $selectedBasket, 'selected_basket_elements' => $selectedBasket ? $selectedBasket->getElements() : new ArrayCollection()]);
 }
Example #18
0
 /**
  * Get cached email body
  *
  * @return EmailBody
  */
 public function getEmailBody()
 {
     if ($this->emailBody->count() === 0) {
         return null;
     }
     return $this->emailBody->first();
 }
Example #19
0
 /**
  * @JMS\VirtualProperty
  * @JMS\SerializedName("actualRole")
  * @JMS\Groups({"finished"})
  *
  * @return Role | null
  */
 public function getActualRole()
 {
     if (!$this->game->hasFinished()) {
         return null;
     }
     if ($this->swapDestination !== null) {
         return $this->swapDestination->getRole();
     }
     if (!$this->swapSources->isEmpty()) {
         return $this->swapSources->first()->getRole();
     }
     return $this->role;
 }
Example #20
0
 /**
  * Get estimate points
  *
  * @param EloPlayerInterface $player
  *
  * @return integer
  */
 private function estimateRange(EloPlayerInterface $player)
 {
     $baseRange = new ArrayCollection($this->configuration->getBaseRange());
     $keys = array_keys($this->configuration->getBaseRange());
     $estimatedRange = $baseRange->first();
     $i = 0;
     foreach ($baseRange as $eloMin => $range) {
         if (!isset($keys[$i + 1]) && $player->getElo() > $baseRange->last()) {
             $estimatedRange = $baseRange->last();
             break;
         }
         if ($player->getElo() >= $eloMin && isset($keys[$i + 1]) && $player->getElo() <= $keys[$i + 1]) {
             $estimatedRange = $range;
             break;
         }
         $i++;
     }
     return $estimatedRange;
 }
Example #21
0
 /**
  * Get owner_email
  *
  * @return string
  */
 public function getOwnerEmail()
 {
     return $this->entries->first()->getEmail();
 }
 /** {@inheritDoc} */
 public function first()
 {
     $this->initialize();
     return $this->collection->first();
 }
Example #23
0
 /**
  * Sets the internal iterator to the first element in the collection and returns this element.
  *
  * @return mixed
  */
 public function first()
 {
     return $this->collection->first();
 }
Example #24
0
 /**
  * Checks if the user is an administrator
  *
  * @return bool
  */
 public function isAdmin()
 {
     $role = $this->roles->first();
     $result = FALSE;
     if ($role instanceof Role && $role->getName() === 'ROLE_ADMIN') {
         $result = TRUE;
     }
     return $result;
 }
Example #25
0
 /**
  * @return null|\Program\Entity\Call\Call
  */
 public function getCall()
 {
     if (is_null($this->call)) {
         return;
     }
     return $this->call->first();
 }
 function first()
 {
     return $this->fields->first();
 }