本文整理汇总了PHP中Propel\Runtime\Collection\ObjectCollection类的典型用法代码示例。如果您正苦于以下问题:PHP ObjectCollection类的具体用法?PHP ObjectCollection怎么用?PHP ObjectCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLoad
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);
}
示例2: testWithPaginate
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());
}
示例3: __construct
/**
* 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);
}
示例4: testTransformWithData
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]);
}
示例5: testGetGetterRelatedBy
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());
}
示例6: createBooks
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);
}
示例7: reverseTransform
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;
}
示例8: insertChunk
/**
* @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();
}
示例9: filterByAuthor
/**
* 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');
}
}
示例10: testFromArray
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);
}
示例11: save
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();
}
}
}
示例12: testConstruct
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;
}
示例13: removeType
/**
* @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;
}
示例14: removeTeams
/**
* @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;
}
示例15: removeBook
/**
* @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;
}