public function testLoad() { $collection = new ObjectCollection(); $collection->setModel('\\Thelia\\Model\\RewritingArgument'); for ($i = 0; $i < 3; $i++) { $ra = new RewritingArgument(); $ra->setParameter('foo' . $i); $ra->setValue('bar' . $i); $ra->setVirtualColumn('ru_view', 'view'); $ra->setVirtualColumn('ru_viewId', 'viewId'); $ra->setVirtualColumn('ru_locale', 'locale'); $ra->setVirtualColumn('ru_redirected_to_url', null); $collection->append($ra); } $resolverQuery = $this->getMock('\\Thelia\\Model\\RewritingUrlQuery', array('getResolverSearch')); $resolverQuery->expects($this->any())->method('getResolverSearch')->with('foo.html')->will($this->returnValue($collection)); $resolver = new RewritingResolver(); $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery'); $rewritingUrlQuery->setValue($resolver, $resolverQuery); $resolver->load('foo.html'); $this->assertEquals('view', $resolver->view); $this->assertEquals('viewId', $resolver->viewId); $this->assertEquals('locale', $resolver->locale); $this->assertEquals(array('foo0' => 'bar0', 'foo1' => 'bar1', 'foo2' => 'bar2'), $resolver->otherParameters); }
public function testWithPaginate() { QuerycacheTable1Query::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\QuerycacheTable1'); for ($i = 0; $i < 5; $i++) { $b = new QuerycacheTable1(); $b->setTitle('Title' . $i); $coll[] = $b; } $coll->save(); $pager = $this->getPager(2, 1); $this->assertEquals(5, $pager->getNbResults()); $results = $pager->getResults(); $this->assertEquals('query cache with paginate offset 0 limit 2', $pager->getQuery()->getQueryKey()); $this->assertEquals(2, count($results)); $this->assertEquals('Title1', $results[1]->getTitle()); //jump to page 3 $pager = $this->getPager(2, 3); $this->assertEquals(5, $pager->getNbResults()); $results = $pager->getResults(); $this->assertEquals('query cache with paginate offset 4 limit 2', $pager->getQuery()->getQueryKey()); $this->assertEquals(1, count($results)); $this->assertEquals('Title4', $results[0]->getTitle()); }
/** * Constructor. * * @param ObjectCollection $entries * @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity * @param \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface $permissionGrantingStrategy * @param array $loadedSecurityIdentities * @param \Symfony\Component\Security\Acl\Model\AclInterface $parentAcl * @param bool $inherited */ public function __construct(ObjectCollection $entries, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true) { if ($entries->getFullyQualifiedModel() !== $this->model) { throw new AclException(sprintf('The given collection does not contain models of class "%s" but of class "%s".', $this->model, $entries->getFullyQualifiedModel())); } foreach ($entries as $eachEntry) { if (null === $eachEntry->getFieldName() and null === $eachEntry->getObjectIdentityId()) { $this->classAces[] = new Entry($eachEntry, $this); } if (null !== $eachEntry->getFieldName() and null === $eachEntry->getObjectIdentityId()) { if (empty($this->classFieldAces[$eachEntry->getFieldName()])) { $this->classFieldAces[$eachEntry->getFieldName()] = array(); $this->updateFields($eachEntry->getFieldName()); } $this->classFieldAces[$eachEntry->getFieldName()][] = new FieldEntry($eachEntry, $this); } if (null === $eachEntry->getFieldName() and null !== $eachEntry->getObjectIdentityId()) { $this->objectAces[] = new Entry($eachEntry, $this); } if (null !== $eachEntry->getFieldName() and null !== $eachEntry->getObjectIdentityId()) { if (empty($this->objectFieldAces[$eachEntry->getFieldName()])) { $this->objectFieldAces[$eachEntry->getFieldName()] = array(); $this->updateFields($eachEntry->getFieldName()); } $this->objectFieldAces[$eachEntry->getFieldName()][] = new FieldEntry($eachEntry, $this); } } $this->objectIdentity = $objectIdentity; $this->permissionGrantingStrategy = $permissionGrantingStrategy; $this->parentAcl = $parentAcl; $this->inherited = $inherited; $this->loadedSecurityIdentities = $loadedSecurityIdentities; $this->fields = array_unique($this->fields); }
public function testTransformWithData() { $coll = new ObjectCollection(); $coll->setData(array($a = new \stdClass(), $b = new \stdClass())); $result = $this->transformer->transform($coll); $this->assertTrue(is_array($result)); $this->assertEquals(2, count($result)); $this->assertSame($a, $result[0]); $this->assertSame($b, $result[1]); }
public function testGetGetterRelatedBy() { $objectA = new \Issue656TestObject(); $objectA->setName('A'); $objectB = new \Issue656TestObject(); $objectB->setName('B'); $collection = new ObjectCollection(); $collection->push($objectB); $objectA->setIssue656TestObjectsRelatedByTo($collection); $this->assertEquals($collection, $objectA->getIssue656TestObjectsRelatedByTo()); }
protected function createBooks($nb = 15, $con = null) { BookQuery::create()->deleteAll($con); $books = new ObjectCollection(); $books->setModel('\\Propel\\Tests\\Bookstore\\Book'); for ($i = 0; $i < $nb; $i++) { $b = new Book(); $b->setTitle('Book' . $i); $books[] = $b; } $books->save($con); }
public function reverseTransform($array) { $collection = new ObjectCollection(); if ('' === $array || null === $array) { return $collection; } if (!is_array($array)) { throw new TransformationFailedException('Expected an array.'); } $collection->setData($array); return $collection; }
/** * @param string $itemType * @param string $itemEvent * @param array $itemIds * * @return int */ protected function insertChunk($itemType, $itemEvent, array $itemIds) { $propelCollection = new ObjectCollection(); $propelCollection->setModel(SpyTouch::class); foreach ($itemIds as $itemId) { $touchEntity = new SpyTouch(); $touchEntity->setItemEvent($itemEvent)->setItemId($itemId)->setItemType($itemType)->setTouched(new \DateTime()); $propelCollection->append($touchEntity); } $propelCollection->save(); return $propelCollection->count(); }
/** * Filter the query by a related \Author object. * * @param \Author|ObjectCollection $author The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * @return $this|BookQuery The current query, for fluid interface */ public function filterByAuthor($author, $comparison = null) { if ($author instanceof \Author) { return $this->addUsingAlias(BookEntityMap::COL_AUTHORID, $author->getid(), $comparison); } elseif ($author instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(BookEntityMap::COL_AUTHORID, $author->toKeyValue('PrimaryKey', 'id'), $comparison); } else { throw new PropelException('filterByAuthor() only accepts arguments of type \\Author or Collection'); } }
public function testFromArray() { $author = new Author(); $author->setFirstName('Jane'); $author->setLastName('Austen'); $author->save(); $books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId())); $col = new ObjectCollection(); $col->setModel('Propel\\Tests\\Bookstore\\Book'); $col->fromArray($books); $col->save(); $nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count(); $this->assertEquals(6, $nbBooks); $booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count(); $this->assertEquals(2, $booksByJane); }
public function save($key = null) { if ($key === null) { $data = []; foreach (array_keys($this->preferences) as $key) { $data[] = $this->getPreference($key); } $collection = new ObjectCollection($data); $collection->setModel(PreferenceTableMap::CLASS_NAME); $collection->save(); } else { if ($this->has($key)) { $p = $this->getPreference($key); $p->save(); } } }
public function testConstruct() { $collection = new ObjectCollection(); $collection->setModel('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Entry'); $acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy()); $model = $this->createEntry(); $model->setAuditFailure(true); $model->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity())); $entry = new Entry($model, $acl); $this->assertEquals($model->getMask(), $entry->getMask()); $this->assertEquals($model->getGranting(), $entry->isGranting()); $this->assertEquals($model->getGrantingStrategy(), $entry->getStrategy()); $this->assertEquals($model->getAuditFailure(), $entry->isAuditFailure()); $this->assertEquals($model->getAuditSuccess(), $entry->isAuditSuccess()); $this->assertEquals($this->getRoleSecurityIdentity(), $entry->getSecurityIdentity()); return $entry; }
/** * @param ChildRegionType $type The ChildRegionType object to remove. * @return $this|ChildRegionArea The current object (for fluent API support) */ public function removeType(ChildRegionType $type) { if ($this->getTypes()->contains($type)) { $pos = $this->collTypes->search($type); $this->collTypes->remove($pos); if (null === $this->typesScheduledForDeletion) { $this->typesScheduledForDeletion = clone $this->collTypes; $this->typesScheduledForDeletion->clear(); } $this->typesScheduledForDeletion[] = clone $type; $type->setArea(null); } return $this; }
/** * @param ChildTeams $teams The ChildTeams object to remove. * @return $this|ChildLeagueRef The current object (for fluent API support) */ public function removeTeams(ChildTeams $teams) { if ($this->getTeamss()->contains($teams)) { $pos = $this->collTeamss->search($teams); $this->collTeamss->remove($pos); if (null === $this->teamssScheduledForDeletion) { $this->teamssScheduledForDeletion = clone $this->collTeamss; $this->teamssScheduledForDeletion->clear(); } $this->teamssScheduledForDeletion[] = $teams; $teams->setLeagueRef(null); } return $this; }
/** * @param ChildBook $book The ChildBook object to remove. * @return $this|ChildPublisher The current object (for fluent API support) */ public function removeBook(ChildBook $book) { if ($this->getBooks()->contains($book)) { $pos = $this->collBooks->search($book); $this->collBooks->remove($pos); if (null === $this->booksScheduledForDeletion) { $this->booksScheduledForDeletion = clone $this->collBooks; $this->booksScheduledForDeletion->clear(); } $this->booksScheduledForDeletion[] = clone $book; $book->setPublisher(null); } return $this; }
/** * @param ChildLanguage $language The ChildLanguage object to remove. * @return $this|ChildLanguageType The current object (for fluent API support) */ public function removeLanguage(ChildLanguage $language) { if ($this->getLanguages()->contains($language)) { $pos = $this->collLanguages->search($language); $this->collLanguages->remove($pos); if (null === $this->languagesScheduledForDeletion) { $this->languagesScheduledForDeletion = clone $this->collLanguages; $this->languagesScheduledForDeletion->clear(); } $this->languagesScheduledForDeletion[] = $language; $language->setType(null); } return $this; }
/** * @param ChildFitEntry $fitEntry The ChildFitEntry object to remove. * @return $this|ChildFitEntryType The current object (for fluent API support) */ public function removeFitEntry(ChildFitEntry $fitEntry) { if ($this->getFitEntries()->contains($fitEntry)) { $pos = $this->collFitEntries->search($fitEntry); $this->collFitEntries->remove($pos); if (null === $this->fitEntriesScheduledForDeletion) { $this->fitEntriesScheduledForDeletion = clone $this->collFitEntries; $this->fitEntriesScheduledForDeletion->clear(); } $this->fitEntriesScheduledForDeletion[] = clone $fitEntry; $fitEntry->setFitEntryType(null); } return $this; }
/** * @param ChildExpertGroupMembers $expertGroupMembers The ChildExpertGroupMembers object to remove. * @return $this|ChildExpertGroup The current object (for fluent API support) */ public function removeExpertGroupMembers(ChildExpertGroupMembers $expertGroupMembers) { if ($this->getExpertGroupMemberss()->contains($expertGroupMembers)) { $pos = $this->collExpertGroupMemberss->search($expertGroupMembers); $this->collExpertGroupMemberss->remove($pos); if (null === $this->expertGroupMemberssScheduledForDeletion) { $this->expertGroupMemberssScheduledForDeletion = clone $this->collExpertGroupMemberss; $this->expertGroupMemberssScheduledForDeletion->clear(); } $this->expertGroupMemberssScheduledForDeletion[] = clone $expertGroupMembers; $expertGroupMembers->setExpertGroup(null); } return $this; }
/** * @param ChildInvMetaTypes $invMetaTypes The ChildInvMetaTypes object to remove. * @return $this|ChildInvMetaGroups The current object (for fluent API support) */ public function removeInvMetaTypes(ChildInvMetaTypes $invMetaTypes) { if ($this->getInvMetaTypess()->contains($invMetaTypes)) { $pos = $this->collInvMetaTypess->search($invMetaTypes); $this->collInvMetaTypess->remove($pos); if (null === $this->invMetaTypessScheduledForDeletion) { $this->invMetaTypessScheduledForDeletion = clone $this->collInvMetaTypess; $this->invMetaTypessScheduledForDeletion->clear(); } $this->invMetaTypessScheduledForDeletion[] = clone $invMetaTypes; $invMetaTypes->setInvMetaGroups(null); } return $this; }
/** * @param ChildGroupAccess $groupAccess The ChildGroupAccess object to remove. * @return $this|ChildEntityType The current object (for fluent API support) */ public function removeGroupAccess(ChildGroupAccess $groupAccess) { if ($this->getGroupAccesses()->contains($groupAccess)) { $pos = $this->collGroupAccesses->search($groupAccess); $this->collGroupAccesses->remove($pos); if (null === $this->groupAccessesScheduledForDeletion) { $this->groupAccessesScheduledForDeletion = clone $this->collGroupAccesses; $this->groupAccessesScheduledForDeletion->clear(); } $this->groupAccessesScheduledForDeletion[] = clone $groupAccess; $groupAccess->setEntityType(null); } return $this; }
/** * @param ChildStock $stock The ChildStock object to remove. * @return $this|ChildUnit The current object (for fluent API support) */ public function removeStock(ChildStock $stock) { if ($this->getStocks()->contains($stock)) { $pos = $this->collStocks->search($stock); $this->collStocks->remove($pos); if (null === $this->stocksScheduledForDeletion) { $this->stocksScheduledForDeletion = clone $this->collStocks; $this->stocksScheduledForDeletion->clear(); } $this->stocksScheduledForDeletion[] = $stock; $stock->setUnit(null); } return $this; }
/** * @param ChildUserAttributeValues $userAttributeValues The ChildUserAttributeValues object to remove. * @return $this|ChildUserAttributes The current object (for fluent API support) */ public function removeUserAttributeValues(ChildUserAttributeValues $userAttributeValues) { if ($this->getUserAttributeValuess()->contains($userAttributeValues)) { $pos = $this->collUserAttributeValuess->search($userAttributeValues); $this->collUserAttributeValuess->remove($pos); if (null === $this->userAttributeValuessScheduledForDeletion) { $this->userAttributeValuessScheduledForDeletion = clone $this->collUserAttributeValuess; $this->userAttributeValuessScheduledForDeletion->clear(); } $this->userAttributeValuessScheduledForDeletion[] = clone $userAttributeValues; $userAttributeValues->setUserAttributes(null); } return $this; }
/** * @param ChildRigAttributeValue $rigAttributeValue The ChildRigAttributeValue object to remove. * @return $this|ChildRigAttribute The current object (for fluent API support) */ public function removeRigAttributeValue(ChildRigAttributeValue $rigAttributeValue) { if ($this->getRigAttributeValues()->contains($rigAttributeValue)) { $pos = $this->collRigAttributeValues->search($rigAttributeValue); $this->collRigAttributeValues->remove($pos); if (null === $this->rigAttributeValuesScheduledForDeletion) { $this->rigAttributeValuesScheduledForDeletion = clone $this->collRigAttributeValues; $this->rigAttributeValuesScheduledForDeletion->clear(); } $this->rigAttributeValuesScheduledForDeletion[] = clone $rigAttributeValue; $rigAttributeValue->setRigAttribute(null); } return $this; }
/** * @param ChildPlayers $players The ChildPlayers object to remove. * @return $this|ChildMlbTeamRef The current object (for fluent API support) */ public function removePlayers(ChildPlayers $players) { if ($this->getPlayerss()->contains($players)) { $pos = $this->collPlayerss->search($players); $this->collPlayerss->remove($pos); if (null === $this->playerssScheduledForDeletion) { $this->playerssScheduledForDeletion = clone $this->collPlayerss; $this->playerssScheduledForDeletion->clear(); } $this->playerssScheduledForDeletion[] = $players; $players->setMlbTeamRef(null); } return $this; }
public function checkCombination(ObjectCollection $productSaleElements) { $pse = $productSaleElements->getFirst(); $colorAttributeId = GoogleShopping::getConfigValue('attribute_color'); $sizeAttributeId = GoogleShopping::getConfigValue('attribute_size'); $color = false; $size = false; if (null !== $colorAttributeId) { $colorCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $colorAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne(); if (null !== $colorCombination) { $color = true; } } if (null !== $sizeAttributeId) { $sizeCombination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $sizeAttributeId), Criteria::IN)->filterByProductSaleElementsId($pse->getId())->endUse()->findOne(); if (null !== $sizeCombination) { $size = true; } } if (true === $color || true === $size) { return true; } return false; }
public function testIssue1133OffsetSet() { $testCollection = new ObjectCollection(); $testCollection->setModel(DummyObject::class); for ($i = 0; $i < 3; $i++) { $testCollection->append(new DummyObject($i)); } $firstToRemove = $testCollection[0]; $objectThatShouldNotBeRemoved = $testCollection[2]; // breaks index numbering $testCollection->removeObject($firstToRemove); $objectThatWillBeRemoved = new DummyObject(3); // calls offsetSet $testCollection[] = $objectThatWillBeRemoved; $testCollection->removeObject($objectThatWillBeRemoved); $this->assertContains($objectThatShouldNotBeRemoved, $testCollection, 'ObjectCollection does not contain item that should be in collection.'); $this->assertNotContains($objectThatWillBeRemoved, $testCollection, 'ObjectCollection contains item that should be removed.'); }
public function getUntaxedPrice($taxedPrice) { if (null === $this->taxRulesCollection) { throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION); } if (null === $this->product) { throw new TaxEngineException('Product is empty in Calculator::getTaxedPrice', TaxEngineException::UNDEFINED_PRODUCT); } if (false === filter_var($taxedPrice, FILTER_VALIDATE_FLOAT)) { throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT); } $taxRule = $this->taxRulesCollection->getLast(); if (null === $taxRule) { throw new TaxEngineException('Tax rules collection got no tax ', TaxEngineException::NO_TAX_IN_TAX_RULES_COLLECTION); } $untaxedPrice = $taxedPrice; $currentPosition = (int) $taxRule->getTaxRuleCountryPosition(); $currentFixTax = 0; $currentTaxFactor = 0; do { $position = (int) $taxRule->getTaxRuleCountryPosition(); $taxType = $taxRule->getTypeInstance(); if ($currentPosition !== $position) { $untaxedPrice -= $currentFixTax; $untaxedPrice = $untaxedPrice / (1 + $currentTaxFactor); $currentFixTax = 0; $currentTaxFactor = 0; $currentPosition = $position; } $currentFixTax += $taxType->fixAmountRetriever($this->product); $currentTaxFactor += $taxType->pricePercentRetriever(); } while ($taxRule = $this->taxRulesCollection->getPrevious()); $untaxedPrice -= $currentFixTax; $untaxedPrice = $untaxedPrice / (1 + $currentTaxFactor); return $untaxedPrice; }
/** * Filter the query by a related \GoogleShopping\Model\GoogleshoppingAccount object * * @param \GoogleShopping\Model\GoogleshoppingAccount|ObjectCollection $googleshoppingAccount The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildGoogleshoppingProductSynchronisationQuery The current query, for fluid interface */ public function filterByGoogleshoppingAccount($googleshoppingAccount, $comparison = null) { if ($googleshoppingAccount instanceof \GoogleShopping\Model\GoogleshoppingAccount) { return $this->addUsingAlias(GoogleshoppingProductSynchronisationTableMap::GOOGLESHOPPING_ACCOUNT_ID, $googleshoppingAccount->getId(), $comparison); } elseif ($googleshoppingAccount instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(GoogleshoppingProductSynchronisationTableMap::GOOGLESHOPPING_ACCOUNT_ID, $googleshoppingAccount->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByGoogleshoppingAccount() only accepts arguments of type \\GoogleShopping\\Model\\GoogleshoppingAccount or Collection'); } }
/** * Remove a ChildFolder object to this object * through the content_folder cross reference table. * * @param ChildFolder $folder The ChildContentFolder object to relate * @return ChildContent The current object (for fluent API support) */ public function removeFolder(ChildFolder $folder) { if ($this->getFolders()->contains($folder)) { $this->collFolders->remove($this->collFolders->search($folder)); if (null === $this->foldersScheduledForDeletion) { $this->foldersScheduledForDeletion = clone $this->collFolders; $this->foldersScheduledForDeletion->clear(); } $this->foldersScheduledForDeletion[] = $folder; } return $this; }
/** * Filter the query by a related \App\Models\TranslationKeyword object * * @param \App\Models\TranslationKeyword|ObjectCollection $translationKeyword the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildTranslationCatalogQuery The current query, for fluid interface */ public function filterByTranslationKeyword($translationKeyword, $comparison = null) { if ($translationKeyword instanceof \App\Models\TranslationKeyword) { return $this->addUsingAlias(TranslationCatalogTableMap::COL_ID, $translationKeyword->getCatalogId(), $comparison); } elseif ($translationKeyword instanceof ObjectCollection) { return $this->useTranslationKeywordQuery()->filterByPrimaryKeys($translationKeyword->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByTranslationKeyword() only accepts arguments of type \\App\\Models\\TranslationKeyword or Collection'); } }