コード例 #1
0
 /**
  * Get an array representation of the collection
  *
  * @param     string   $keyColumn  If null, the returned array uses an incremental index.
  *                                 Otherwise, the array is indexed using the specified column
  * @param     boolean  $usePrefix  If true, the returned array prefixes keys
  *                                 with the model class name ('Article_0', 'Article_1', etc).
  *
  * <code>
  *   $bookCollection->getArrayCopy();
  *   array(
  *    0 => $book0,
  *    1 => $book1,
  *   )
  *   $bookCollection->getArrayCopy('Id');
  *   array(
  *    123 => $book0,
  *    456 => $book1,
  *   )
  *   $bookCollection->getArrayCopy(null, true);
  *   array(
  *    'Book_0' => $book0,
  *    'Book_1' => $book1,
  *   )
  * </code>
  *
  * @return    array
  */
 public function getArrayCopy($keyColumn = null, $usePrefix = false)
 {
     if (null === $keyColumn && false === $usePrefix) {
         return parent::getArrayCopy();
     }
     $ret = array();
     $keyGetterMethod = 'get' . $keyColumn;
     foreach ($this as $key => $obj) {
         $key = null === $keyColumn ? $key : $obj->{$keyGetterMethod}();
         $key = $usePrefix ? $this->getModel() . '_' . $key : $key;
         $ret[$key] = $obj;
     }
     return $ret;
 }
コード例 #2
0
 /**
  * Synonym for toArray(), to provide a similar interface to PopelObjectCollection
  *
  * @param     string   $keyColumn
  * @param     boolean  $usePrefix
  *
  * @return    array
  */
 public function getArrayCopy($keyColumn = null, $usePrefix = false)
 {
     if (null === $keyColumn && false === $usePrefix) {
         return parent::getArrayCopy();
     } else {
         return $this->toArray($keyColumn, $usePrefix);
     }
 }
コード例 #3
0
 public function testDiffWithACollectionHavingObjectsNotPresentInTheFirstCollection()
 {
     $col1 = new PropelCollection();
     $col2 = new PropelCollection();
     $b = new Book();
     $col2[] = $b;
     $result = $col1->diff($col2);
     $this->assertInstanceOf('\\Propel\\Runtime\\Collection\\PropelCollection', $result);
     $this->assertEquals(0, count($result));
 }