本文整理汇总了PHP中Doctrine\Common\Collections\ArrayCollection类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCollection类的具体用法?PHP ArrayCollection怎么用?PHP ArrayCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getParentPagesQuery
/**
* @param $locale
* @param null $id
* @param bool $showHome
* @param bool $showChildren
* @return \Doctrine\ORM\QueryBuilder|mixed
*/
public function getParentPagesQuery($locale, $id = null, $showHome = false, $showChildren = false)
{
$qb = $this->createQueryBuilder('p');
if (!$showHome) {
$qb->where($qb->expr()->isNull('p.isHome') . ' OR p.isHome <> 1');
}
if ($id) {
if (!$showChildren) {
/** @var $page PageInterface */
$page = $this->find($id);
$collection = new ArrayCollection($page->getAllChildren());
$childrenIds = $collection->map(function (PageInterface $p) {
return $p->getId();
});
if ($childrenIds->count()) {
$qb->andWhere($qb->expr()->notIn('p.id', $childrenIds->toArray()));
}
}
$qb->andWhere($qb->expr()->neq('p.id', $id));
}
$qb->andWhere('p.locale = :locale');
$qb->orderBy('p.path', 'ASC');
$qb->setParameter(':locale', $locale);
return $qb;
}
示例2: search
/**
* @param string $str
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function search($str)
{
$res = new TestResult();
$ac = new ArrayCollection();
$ac->add($res);
return $ac;
}
示例3: chooseAction
/**
* Show main page.
*
* @EXT\Route("/choose/{id}", name="cpasimusante_choose_item", requirements={"id" = "\d+"}, options={"expose"=true})
* @EXT\ParamConverter("itemselector", class="CPASimUSanteItemSelectorBundle:ItemSelector", options={"id" = "id"})
* @EXT\Template("CPASimUSanteItemSelectorBundle:ItemSelector:choose.html.twig")
*
* @param Request $request
* @param ItemSelector $itemSelector
*
* @return array
*/
public function chooseAction(Request $request, ItemSelector $itemSelector)
{
$em = $this->getDoctrine()->getManager();
// Create an ArrayCollection of the current Item objects in the database
$originalItems = new ArrayCollection();
foreach ($itemSelector->getItems() as $item) {
$originalItems->add($item);
}
//retrieve ItemSelector configuration for this WS
$config = $this->getConfig($itemSelector->getResourceNode()->getWorkspace()->getId());
$mainResourceType = $config['mainResourceType'];
$resourceType = $config['resourceType'];
$namePattern = $config['namePattern'];
$form = $this->get('form.factory')->create(new ItemSelectorType($mainResourceType, $resourceType, $namePattern), $itemSelector);
$form->handleRequest($request);
if ($form->isValid()) {
// remove the relationship between the item and the ItemSelector
foreach ($originalItems as $item) {
if (false === $itemSelector->getItems()->contains($item)) {
// in a a many-to-one relationship, remove the relationship
$item->setItemSelector(null);
$em->persist($item);
// to delete the Item entirely, you can also do that
$em->remove($item);
}
}
$em->persist($itemSelector);
$em->flush();
}
return ['_resource' => $itemSelector, 'form' => $form->createView(), 'itemCount' => $config['itemCount']];
}
示例4: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$this->em = $manager;
$this->countries = $this->loadStructure('OroAddressBundle:Country', 'getIso2Code');
$this->regions = $this->loadStructure('OroAddressBundle:Region', 'getCombinedCode');
$this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
$this->createTransport()->createIntegration()->createChannel()->createWebSite()->createCustomerGroup()->createStore();
$magentoAddress = $this->createMagentoAddress($this->regions['US-AZ'], $this->countries['US']);
$account = $this->createAccount();
$customer = $this->createCustomer(1, $account, $magentoAddress);
$cartAddress1 = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 1);
$cartAddress2 = $this->createCartAddress($this->regions['US-AZ'], $this->countries['US'], 2);
$cartItem = $this->createCartItem();
$status = $this->getStatus();
$items = new ArrayCollection();
$items->add($cartItem);
$cart = $this->createCart($cartAddress1, $cartAddress2, $customer, $items, $status);
$this->updateCartItem($cartItem, $cart);
$order = $this->createOrder($cart, $customer);
$this->setReference('customer', $customer);
$this->setReference('integration', $this->integration);
$this->setReference('cart', $cart);
$this->setReference('order', $order);
$baseOrderItem = $this->createBaseOrderItem($order);
$order->setItems([$baseOrderItem]);
$this->em->persist($order);
$this->em->flush();
}
示例5: saveMultipleImages
/**
*
* @param string $paramName
* @return ArrayCollection
*/
public function saveMultipleImages($paramName = 'files')
{
$time = new \DateTime();
$list = new ArrayCollection();
foreach ($_FILES[$paramName]['name'] as $i => $v) {
$name = $_FILES[$paramName]['name'][$i];
$name2 = strtolower($name);
$type = $_FILES[$paramName]['type'][$i];
$tmp = $_FILES[$paramName]['tmp_name'][$i];
$error = $_FILES[$paramName]['error'][$i];
$size = $_FILES[$paramName]['size'][$i];
$md5 = md5_file($tmp);
$image = new Image();
$md5Check = $this->findOneBy(array('md5' => $md5));
if (empty($md5Check)) {
$image->setMd5($md5);
$image->setSizeKb(floatval($size / 1024));
$image->setKey($this->getAvailableKey());
move_uploaded_file($tmp, realpath(PUBLIC_PATH . '/uploaded-images') . '/' . $image->getKey());
} else {
$image->setReferenceImage($md5Check);
}
$image->setName(basename($name));
$image->setUploadedTime($time);
$this->save($image);
$list->add($image);
}
return $list;
}
示例6: createTagCollection
public function createTagCollection()
{
$tags = new ArrayCollection();
$tags->add(new Tag("foo"));
$tags->add(new Tag("bar"));
return $tags;
}
示例7: reverseTransform
public function reverseTransform($string)
{
if (!$string) {
return;
}
$tags = new ArrayCollection();
foreach (explode(',', $string) as $tagTitle) {
$tag = $this->om->getRepository('AppBundle:Tag')->findOneByTitle($tagTitle);
if (!$tag && ($tagTranslation = $this->om->getRepository('AppBundle:Translations\\TagTranslation')->findOneByContent($tagTitle))) {
$tag = $tagTranslation->getObject();
}
if (!$tag) {
$tag = new Tag();
$tag->setTitle($tagTitle);
$tag->setLocale($this->defaultLocale);
foreach ($this->localeCollection as $locale) {
if ($locale !== $this->defaultLocale) {
$tagTranslation = new TagTranslation();
$tagTranslation->setLocale($locale);
$tagTranslation->setField('title');
$tagTranslation->setContent($tagTitle);
$tagTranslation->setObject($tag);
$tag->addTranslation($tagTranslation);
$this->om->persist($tagTranslation);
}
}
$this->om->persist($tag);
}
$tags->add($tag);
}
return $tags;
}
示例8: testTransformArticleToDocument
/**
* Test method for articles.
*/
public function testTransformArticleToDocument()
{
$attributes = new ArrayCollection();
$expected = [];
/** @var Article|MockObject $mockArticle */
$mockArticle = $this->getMockForAbstractClass('\\ONGR\\OXIDConnectorBundle\\Entity\\Article');
for ($i = 1; $i <= 10; $i++) {
$artToAttr = new ArticleToAttribute();
$artToAttr->setId($i);
$artToAttr->setPos($i);
$artToAttr->setArticle($mockArticle);
$attr = new Attribute();
$attr->setPos($i + 2);
$attr->setTitle('Some other title ' . $i);
$artToAttr->setAttribute($attr);
$attributes->add($artToAttr);
$expected[] = $artToAttr;
}
$result = $this->service->transform($attributes);
foreach ($result as $idx => $actual) {
$this->assertInstanceOf('\\ONGR\\OXIDConnectorBundle\\Document\\AttributeObject', $actual);
$this->assertEquals('Some other title ' . ($idx + 1), $actual->getTitle());
$this->assertEquals($idx + 3, $actual->getPos());
}
}
示例9: editAction
/**
* Edit a ContentType.
*
* @param Request $request
* @param int $id
*
* @return RedirectResponse|Response
*/
public function editAction(Request $request, $id)
{
$contentTypeManager = $this->get('opifer.content.content_type_manager');
$em = $this->get('doctrine.orm.entity_manager');
/** @var ContentTypeInterface $contentType */
$contentType = $contentTypeManager->getRepository()->find($id);
if (!$contentType) {
return $this->createNotFoundException();
}
$originalAttributes = new ArrayCollection();
foreach ($contentType->getSchema()->getAttributes() as $attributes) {
$originalAttributes->add($attributes);
}
$form = $this->createForm(ContentTypeType::class, $contentType);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Remove deleted attributes
foreach ($originalAttributes as $attribute) {
if (false === $contentType->getSchema()->getAttributes()->contains($attribute)) {
$em->remove($attribute);
}
}
// Add new attributes
foreach ($form->getData()->getSchema()->getAttributes() as $attribute) {
$attribute->setSchema($contentType->getSchema());
foreach ($attribute->getOptions() as $option) {
$option->setAttribute($attribute);
}
}
$contentTypeManager->save($contentType);
$this->addFlash('success', 'Content type has been updated successfully');
return $this->redirectToRoute('opifer_content_contenttype_edit', ['id' => $contentType->getId()]);
}
return $this->render($this->getParameter('opifer_content.content_type_edit_view'), ['content_type' => $contentType, 'form' => $form->createView()]);
}
示例10: process
/**
* Process form
*
* @param CalendarEvent $entity
*
* @throws \LogicException
*
* @return bool True on successful processing, false otherwise
*/
public function process(CalendarEvent $entity)
{
$this->form->setData($entity);
if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
$originalChildren = new ArrayCollection();
foreach ($entity->getChildEvents() as $childEvent) {
$originalChildren->add($childEvent);
}
$this->form->submit($this->request);
if ($this->form->isValid()) {
$this->ensureCalendarSet($entity);
$targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
if ($targetEntityClass) {
$targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
$targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
$action = $this->entityRoutingHelper->getAction($this->request);
if ($action === 'activity') {
$this->activityManager->addActivityTarget($entity, $targetEntity);
}
if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
/** @var Calendar $defaultCalendar */
$defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
$entity->setCalendar($defaultCalendar);
}
}
$this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
return true;
}
}
return false;
}
示例11: load
static function load(Config $config)
{
$scenes = new ArrayCollection();
// Start with the entry scene
$stack = array();
$scene = $config['entry_scene'];
array_push($stack, $scene);
// Loop until our stack is empty
while (count($stack)) {
// Load a scene from the stack
$scenePath = array_pop($stack);
$data = Yaml::load($config['base_directory'] . '/' . $scenePath . '.yml');
// Create a scene from the data
$newScene = new Scene($scenePath, $data);
$scenes->set($scenePath, $newScene);
// If we have exit-scenes, add them to the stack so we can load them
foreach ($data['scene']['exit'] as $direction => $exitScene) {
$tmp['exit'][strtolower($direction)] = $exitScene;
// Only add to stack when we haven't already processed that scene
if (!$scenes->containsKey($exitScene)) {
array_push($stack, $exitScene);
}
}
}
return $scenes;
}
示例12: testUpdatePath
/**
* Test update path
*/
public function testUpdatePath()
{
$siteId = $this->currentSiteManager->getCurrentSiteId();
$parentNodeId = 'parent';
$parentPath = 'parentPath';
$son1NodeId = 'son1NodeId';
$son2NodeId = 'son2NodeId';
$parent = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\NodeInterface');
Phake::when($parent)->getNodeId()->thenReturn($parentNodeId);
Phake::when($parent)->getPath()->thenReturn($parentPath);
$son1 = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\NodeInterface');
Phake::when($son1)->getNodeId()->thenReturn($son1NodeId);
$son2 = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\NodeInterface');
Phake::when($son2)->getNodeId()->thenReturn($son2NodeId);
$son3 = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\NodeInterface');
Phake::when($son3)->getNodeId()->thenReturn($son2NodeId);
$sons = new ArrayCollection();
$sons->add($son1);
$sons->add($son2);
$sons->add($son3);
Phake::when($this->nodeRepository)->findByParent($parentNodeId, $siteId)->thenReturn($sons);
$event = Phake::mock('OpenOrchestra\\ModelInterface\\Event\\NodeEvent');
Phake::when($event)->getNode()->thenReturn($parent);
$this->subscriber->updatePath($event);
Phake::verify($son1)->setPath($parentPath . '/' . $son1NodeId);
Phake::verify($son2)->setPath($parentPath . '/' . $son2NodeId);
Phake::verify($son3)->setPath($parentPath . '/' . $son2NodeId);
Phake::verify($this->eventDispatcher, Phake::times(2))->dispatch(Phake::anyParameters());
}
开发者ID:open-orchestra,项目名称:open-orchestra-cms-bundle,代码行数:32,代码来源:UpdateChildNodePathSubscriberTest.php
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var EntityManager em */
$em = $this->getContainer()->get('doctrine')->getManager();
$users = $em->getRepository('ESNUserBundle:User')->findBy(array("esner" => 1));
$concerned_users = new ArrayCollection();
/** @var User $user */
foreach ($users as $user) {
/** @var EsnerFollow $follow */
$follow = $user->getFollow();
if ($follow) {
$trial = $follow->getTrialstarted();
$end_trial = $trial;
date_add($trial, date_interval_create_from_date_string('21 days'));
$now = new \DateTime();
if ($end_trial->format('d/m/Y') == $now->format('d/m/Y')) {
$concerned_users->add($user);
}
}
}
/** @var User $concerned_user */
foreach ($concerned_users as $concerned_user) {
$message = \Swift_Message::newInstance()->setSubject('[ESN Lille][ERP] Periode d\'essaie terminé pour ' . $concerned_user->getFullname())->setFrom($this->getContainer()->getParameter('mailer_from'))->setTo($user->getEmail())->setBody($this->getContainer()->get('templating')->render('ESNHRBundle:Emails:trial_ended.html.twig', array('user' => $concerned_user)), 'text/html');
$this->getContainer()->get('mailer')->send($message);
}
}
示例14: testGettersSetters
/**
* Test entity getters & setters
*/
public function testGettersSetters()
{
$entity = new User();
$entity->setActivationKey('activation-key');
$entity->setDisplayName('display name');
$entity->setEmail('user@email.com');
$entity->setLogin('login');
$collection = new ArrayCollection();
$meta1 = new UserMeta();
$meta1->setKey('meta-key');
$meta1->setValue('meta-value');
$meta1->setUser($entity);
$collection->add($entity);
$entity->setMetas($collection);
$entity->setNicename('nice name');
$entity->setPass('pass');
$date = new \DateTime();
$entity->setRegistered($date);
$entity->setStatus(2);
$entity->setUrl('http://www.url.com');
$this->assertEquals('activation-key', $entity->getActivationKey());
$this->assertEquals('display name', $entity->getDisplayName());
$this->assertEquals('user@email.com', $entity->getEmail());
$this->assertEquals('login', $entity->getLogin());
$this->assertEquals($collection, $entity->getMetas());
$this->assertEquals('nice name', $entity->getNicename());
$this->assertEquals('pass', $entity->getPass());
$this->assertEquals($date, $entity->getRegistered());
$this->assertEquals(2, $entity->getStatus());
$this->assertEquals('http://www.url.com', $entity->getUrl());
}
示例15: getContent
/**
*
* Returns an ArrayCollection containing three keys :
* - self::BASKETS : an ArrayCollection of the actives baskets
* (Non Archived)
* - self::STORIES : an ArrayCollection of working stories
* - self::VALIDATIONS : the validation people are waiting from me
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getContent($sort)
{
/* @var $repo_baskets Alchemy\Phrasea\Model\Repositories\BasketRepository */
$repo_baskets = $this->app['repo.baskets'];
$sort = in_array($sort, ['date', 'name']) ? $sort : 'name';
$ret = new ArrayCollection();
$baskets = $repo_baskets->findActiveByUser($this->app['authentication']->getUser(), $sort);
// force creation of a default basket
if (0 === count($baskets)) {
$basket = new BasketEntity();
$basket->setName($this->app->trans('Default basket'));
$basket->setUser($this->app['authentication']->getUser());
$this->app['EM']->persist($basket);
$this->app['EM']->flush();
$baskets = [$basket];
}
$validations = $repo_baskets->findActiveValidationByUser($this->app['authentication']->getUser(), $sort);
/* @var $repo_stories Alchemy\Phrasea\Model\Repositories\StoryWZRepository */
$repo_stories = $this->app['repo.story-wz'];
$stories = $repo_stories->findByUser($this->app, $this->app['authentication']->getUser(), $sort);
$ret->set(self::BASKETS, $baskets);
$ret->set(self::VALIDATIONS, $validations);
$ret->set(self::STORIES, $stories);
return $ret;
}