/** * @return array */ private function getList() { $return = array(); $total = 0; $pages = 0; try { $this->paginate(); if (null !== $this->list) { $return = $this->list->toArray(); $total = $this->list->getNbResults(); $pages = $this->list->getLastPage(); } } catch (\Exception $e) { Logger::getInstance(get_class($this))->errorLog($e->getMessage()); } return array($return, $total, $pages); }
/** * Synonym for toArray(), to provide a similar interface to PropelObjectCollection * * @param string $keyColumn * @param boolean $usePrefix * * @return array */ public function getArrayCopy($keyColumn = null, $usePrefix = false) { if (null === $keyColumn && false === $usePrefix) { return parent::getArrayCopy(); } return $this->toArray($keyColumn, $usePrefix); }
/** * Método que hidrata los campos de un formulario desde un modelo * @param string $key * @param mixed $value * @return void */ private function hydrateModelField($key, $value) { $setter = "set" . ucfirst($key); $getter = "get" . ucfirst($key); if (method_exists($this->model, $setter)) { if (method_exists($this->model, $getter)) { $tmp = $this->model->{$getter}(); if ($tmp instanceof Collection && is_object($tmp) && gettype($value) !== gettype($tmp)) { $collection = new Collection(); $collection->append($value); $value = $collection; } } $this->model->{$setter}($value); } }
/** * generates a folder and its contents to be used in Position tests * * @return Folder the parent folder */ protected function getFolderForPositionTest() { if (null === self::$folderForPositionTest) { $folder = new Folder(); $folder->setParent(0); $folder->setVisible(1); $folder->setPosition(1); $this->setI18n($folder); $folder->save(); for ($i = 0; $i < 4; $i++) { $content = new \Thelia\Model\Content(); $content->addFolder($folder); $content->setVisible(1); $content->setPosition($i + 1); $this->setI18n($content); $contentFolders = $content->getContentFolders(); $collection = new Collection(); $collection->prepend($contentFolders[0]->setDefaultFolder(1)); $content->setContentFolders($collection); $content->save(); } self::$folderForPositionTest = $folder; } return self::$folderForPositionTest; }
public function testDiffWithACollectionHavingObjectsNotPresentInTheFirstCollection() { $col1 = new Collection(); $col2 = new Collection(); $b = new Book(); $col2[] = $b; $result = $col1->diff($col2); $this->assertInstanceOf('\\Propel\\Runtime\\Collection\\Collection', $result); $this->assertEquals(0, count($result)); }
/** * {@inheritdoc} */ public function contains($element) { if (!is_object($element)) { return parent::contains($element); } return isset($this->indexSplHash[spl_object_hash($element)]) || isset($this->index[$element->hashCode()]); }
/** * {@inheritdoc} */ public function search($element) { if ($element instanceof ActiveRecordInterface) { $hashCode = $element->hashCode(); foreach ($this as $pos => $obj) { if ($hashCode === $obj->hashCode()) { return $pos; } } return false; } else { return parent::search($element); } }
/** * Returns an array of objects present in the collection that * are not presents in the given collection. * * @param Collection $collection A Propel collection. * @return Collection An array of Propel objects from the collection that are not presents in the given collection. */ public function diff(Collection $collection) { $diff = clone $this; $diff->clear(); foreach ($this as $object) { if (!$collection->contains($object)) { $diff[] = $object; } } return $diff; }
/** * {@inheritdoc} */ public function contains($element) { if ($element instanceof ActiveRecordInterface) { if (null !== ($elt = $this->getIdenticalObject($element))) { $element = $elt; } } return parent::contains($element); }
/** * 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; }