当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectCollection::setModel方法代码示例

本文整理汇总了PHP中Propel\Runtime\Collection\ObjectCollection::setModel方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectCollection::setModel方法的具体用法?PHP ObjectCollection::setModel怎么用?PHP ObjectCollection::setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Runtime\Collection\ObjectCollection的用法示例。


在下文中一共展示了ObjectCollection::setModel方法的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);
 }
开发者ID:margery,项目名称:thelia,代码行数:25,代码来源:RewritingResolverTest.php

示例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());
 }
开发者ID:naldz,项目名称:cyberden,代码行数:25,代码来源:QueryCacheTest.php

示例3: 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);
 }
开发者ID:norfil,项目名称:Propel2,代码行数:12,代码来源:PropelModelPagerTest.php

示例4: 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();
 }
开发者ID:spryker,项目名称:Touch,代码行数:19,代码来源:BulkTouchHandlerInsert.php

示例5: 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);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:16,代码来源:ObjectCollectionWithFixturesTest.php

示例6: 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();
         }
     }
 }
开发者ID:keeko,项目名称:framework,代码行数:17,代码来源:Preferences.php

示例7: 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;
 }
开发者ID:naldz,项目名称:cyberden,代码行数:17,代码来源:EntryTest.php

示例8: testIssue1133OffsetSet

 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.');
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:18,代码来源:Issue1133Test.php

示例9: populateCreatedAt

 protected function populateCreatedAt()
 {
     Table2Query::create()->deleteAll();
     $ts = new ObjectCollection();
     $ts->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\Table2');
     for ($i = 0; $i < 10; $i++) {
         $t = new Table2();
         $t->setTitle('CreatedAt' . $i);
         $t->setCreatedAt(time() - $i * 24 * 60 * 60 - 30);
         $ts[] = $t;
     }
     $ts->save();
 }
开发者ID:malukenho,项目名称:Propel2,代码行数:13,代码来源:TimestampableBehaviorTest.php

示例10: testContentsDeletion

 /**
  * Basic deletion of a 1-to-n relation through set<RelationName>().
  *
  */
 public function testContentsDeletion()
 {
     $contentCollection = new ObjectCollection();
     $contentCollection->setModel('MoreRelationTest\\Content');
     $content = new \MoreRelationTest\Content();
     $content->setTitle('I should be alone :-(');
     $contentCollection[] = $content;
     $page = \MoreRelationTest\PageQuery::create()->findOne();
     $id = $page->getId();
     $count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
     $this->assertEquals(3, $count, 'We created for each page 3 contents.');
     $page->setContents($contentCollection);
     $page->save();
     unset($page);
     $count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count();
     $this->assertEquals(1, $count, 'We assigned a collection of only one item.');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:21,代码来源:GeneratedObjectMoreRelationTest.php

示例11: testToArrayDeep

 public function testToArrayDeep()
 {
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $coll = new ObjectCollection();
     $coll->setModel('\\Propel\\Tests\\Bookstore\\Book');
     $coll[] = $book;
     $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*'))));
     $this->assertEquals($expected, $coll->toArray());
 }
开发者ID:norfil,项目名称:Propel2,代码行数:18,代码来源:ObjectCollectionTest.php

示例12: testToStringUsesCustomStringFormat

    public function testToStringUsesCustomStringFormat()
    {
        $coll = new ObjectCollection();
        $coll->setModel('\\Propel\\Tests\\Bookstore\\Publisher');
        $publisher = new Publisher();
        $publisher->setId(12345);
        $publisher->setName('Penguinoo');
        $coll[] = $publisher;
        $expected = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<Publishers>
  <Publisher>
    <Id>12345</Id>
    <Name><![CDATA[Penguinoo]]></Name>
  </Publisher>
</Publishers>

EOF;
        $this->assertEquals($expected, (string) $coll);
    }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:20,代码来源:CollectionConvertTest.php

示例13: populateRelation

 /**
  * Makes an additional query to populate the objects related to the collection objects
  * by a certain relation
  *
  * @param string              $relation Relation name (e.g. 'Book')
  * @param Criteria            $criteria Optional Criteria object to filter the related object collection
  * @param ConnectionInterface $con      Optional connection object
  *
  * @return ObjectCollection The list of related objects
  */
 public function populateRelation($relation, $criteria = null, $con = null)
 {
     if (!Propel::isInstancePoolingEnabled()) {
         throw new RuntimeException(__METHOD__ . ' needs instance pooling to be enabled prior to populating the collection');
     }
     $relationMap = $this->getFormatter()->getTableMap()->getRelation($relation);
     if ($this->isEmpty()) {
         // save a useless query and return an empty collection
         $coll = new ObjectCollection();
         $coll->setModel($relationMap->getRightTable()->getClassName());
         return $coll;
     }
     $symRelationMap = $relationMap->getSymmetricalRelation();
     $query = PropelQuery::from($relationMap->getRightTable()->getClassName());
     if (null !== $criteria) {
         $query->mergeWith($criteria);
     }
     // query the db for the related objects
     $filterMethod = 'filterBy' . $symRelationMap->getName();
     $relatedObjects = $query->{$filterMethod}($this)->find($con);
     if (RelationMap::ONE_TO_MANY === $relationMap->getType()) {
         // initialize the embedded collections of the main objects
         $relationName = $relationMap->getName();
         foreach ($this as $mainObj) {
             $mainObj->initRelation($relationName);
         }
         // associate the related objects to the main objects
         $getMethod = 'get' . $symRelationMap->getName();
         $addMethod = 'add' . $relationName;
         foreach ($relatedObjects as $object) {
             $mainObj = $object->{$getMethod}();
             // instance pool is used here to avoid a query
             $mainObj->{$addMethod}($object);
         }
     } elseif (RelationMap::MANY_TO_ONE === $relationMap->getType()) {
         // nothing to do; the instance pool will catch all calls to getRelatedObject()
         // and return the object in memory
     } else {
         throw new UnsupportedRelationException(__METHOD__ . ' does not support this relation type');
     }
     return $relatedObjects;
 }
开发者ID:malukenho,项目名称:Propel2,代码行数:52,代码来源:ObjectCollection.php

示例14: mapValues

 /**
  * @param $item propel object
  * @param array $values
  * @param bool $ignoreNotExistingValues
  */
 public function mapValues(&$item, &$values, $ignoreNotExistingValues = false)
 {
     $setted = [];
     $applyColumn = function ($name) use(&$item, &$values, &$setted, &$ignoreNotExistingValues) {
         $fieldName = lcfirst($name);
         $setted[] = $fieldName;
         $fieldValue = @$values[$fieldName];
         if (!isset($values[$fieldName]) && $ignoreNotExistingValues) {
             return;
         }
         $fieldName = ucfirst($fieldName);
         $set = 'set' . $fieldName;
         $methodExist = method_exists($item, $set);
         if ($methodExist) {
             $item->{$set}($fieldValue);
         }
     };
     $pluralizer = new StandardEnglishPluralizer();
     $self = $this;
     /**
      * @param RelationDefinition $relation
      *
      * @throws ObjectNotFoundException
      * @throws \Exception
      */
     $applyRelation = function ($relation) use($self, $pluralizer, &$item, &$values, &$setted, &$ignoreNotExistingValues) {
         $fieldName = lcfirst($relation->getName());
         $fieldValue = isset($values[$fieldName]) ? $values[$fieldName] : null;
         if (!isset($values[$fieldName]) && $ignoreNotExistingValues) {
             return;
         }
         if ($relation->getType() == AbstractStorage::MANY_TO_MANY || $relation->getType() == AbstractStorage::ONE_TO_MANY) {
             $name = $pluralizer->getPluralForm($pluralizer->getSingularForm(Tools::underscore2Camelcase($fieldName)));
             $setItems = 'set' . $name;
             $clearItems = 'clear' . $name;
             if (is_array($fieldValue)) {
                 $foreignQuery = $self->getQueryClass($relation->getForeignObjectKey());
                 $foreignClass = $self->getPhpName($relation->getForeignObjectKey());
                 $foreignObjClass = $self->objects->getStorageController($relation->getForeignObjectKey());
                 if ($relation->getType() == AbstractStorage::ONE_TO_MANY) {
                     $coll = new ObjectCollection();
                     $coll->setModel(ucfirst($foreignClass));
                     if (!is_array($fieldValue)) {
                         throw new \LogicException(sprintf('Relation `%s` on object %s requires array value, not %s', $relation->getName(), $this->getObjectKey(), gettype($fieldValue)));
                     }
                     foreach ($fieldValue as $foreignItem) {
                         $pk = $self->objects->getObjectPk($relation->getForeignObjectKey(), $foreignItem);
                         $item2 = null;
                         if ($pk) {
                             $propelPk = $self->getPropelPk($pk, $relation->getForeignObjectKey());
                             $item2 = $foreignQuery->findPk($propelPk);
                         }
                         if (!$item2) {
                             $item2 = new $foreignClass();
                         }
                         $item2->fromArray($foreignItem, TableMap::TYPE_CAMELNAME);
                         $coll[] = $item2;
                     }
                     $item->{$setItems}($coll);
                 } else {
                     $primaryKeys = array();
                     if (is_array($fieldValue)) {
                         foreach ($fieldValue as $value) {
                             $primaryKeys[] = $foreignObjClass->normalizePrimaryKey($value);
                         }
                     }
                     $propelPks = array();
                     foreach ($primaryKeys as $primaryKey) {
                         $propelPks[] = $self->getPropelPk($primaryKey, $relation->getForeignObjectKey());
                     }
                     $collItems = $foreignQuery->findPks($propelPks);
                     $item->{$setItems}($collItems);
                 }
             } elseif ($ignoreNotExistingValues) {
                 $item->{$clearItems}();
             }
         }
         if ($relation->getType() == AbstractStorage::MANY_TO_ONE || $relation->getType() == AbstractStorage::ONE_TO_ONE) {
             if (!$self->tableMap->hasRelation(ucfirst($fieldName))) {
                 throw new \Exception(sprintf('Relation %s not found in propel object %s (%s)', ucfirst($fieldName), $self->getObjectKey(), $self->getPhpName()));
             }
             //try to set the local column of the relation directly, when we get only primary keys
             $propelRelation = $self->tableMap->getRelation(ucfirst($fieldName));
             $localColumns = $propelRelation->getLocalColumns();
             $firstColumn = current($localColumns);
             $hasPrimaryKey = false;
             if (is_array($fieldValue)) {
                 $foreignColumns = $propelRelation->getForeignColumns();
                 $firstForeignColumn = current($foreignColumns);
                 $key = lcfirst($firstForeignColumn->getPhpName());
                 if (isset($fieldValue[$key])) {
                     $fieldValue = $fieldValue[$key];
                     $hasPrimaryKey = true;
                 }
             } else {
//.........这里部分代码省略.........
开发者ID:jarves,项目名称:jarves,代码行数:101,代码来源:Propel.php

示例15: testSetterOneToManyWithFkRequired

 public function testSetterOneToManyWithFkRequired()
 {
     // Ensure no data
     BookSummaryQuery::create()->deleteAll();
     BookQuery::create()->deleteAll();
     $coll = new ObjectCollection();
     $coll->setModel('BookSummary');
     for ($i = 0; $i < 3; $i++) {
         $coll[] = new BookSummary();
     }
     $this->assertEquals(3, $coll->count());
     $b = new Book();
     $b->setTitle('myBook');
     $b->setBookSummaries($coll);
     $b->save();
     $this->assertInstanceOf('Propel\\Runtime\\Collection\\ObjectCollection', $b->getBookSummaries());
     $this->assertEquals(3, $b->getBookSummaries()->count());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(3, BookSummaryQuery::create()->count());
     $coll->shift();
     $this->assertEquals(2, $coll->count());
     $b->setBookSummaries($coll);
     $b->save();
     $this->assertEquals(2, $b->getBookSummaries()->count());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(2, BookSummaryQuery::create()->count());
     $newBookSammary = new BookSummary();
     $newBookSammary->setSummary('My sammary');
     // Kind of new collection
     $coll = clone $coll;
     $coll[] = $newBookSammary;
     $b->setBookSummaries($coll);
     $b->save();
     $this->assertEquals(3, $coll->count());
     $this->assertEquals(3, $b->getBookSummaries()->count());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(3, BookSummaryQuery::create()->count());
     // Add a new object
     $newBookSammary1 = new BookSummary();
     $newBookSammary1->setSummary('My sammary 1');
     // Existing collection - The fix around reference is tested here.
     $coll[] = $newBookSammary1;
     $b->setBookSummaries($coll);
     $b->save();
     $this->assertEquals(4, $coll->count());
     $this->assertEquals(4, $b->getBookSummaries()->count());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(4, BookSummaryQuery::create()->count());
     // Add the same collection
     $bookSummaries = $b->getBookSummaries();
     $b->setBookSummaries($bookSummaries);
     $b->save();
     $this->assertEquals(4, $coll->count());
     $this->assertEquals(4, $b->getBookSummaries()->count());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(4, BookSummaryQuery::create()->count());
 }
开发者ID:robin850,项目名称:Propel2,代码行数:57,代码来源:GeneratedObjectTest.php


注:本文中的Propel\Runtime\Collection\ObjectCollection::setModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。