public function testFormatNoResult() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $stmt = $con->query('SELECT * FROM book WHERE book.TITLE = "foo"'); $formatter = new PropelObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof PropelCollection, 'PropelObjectFormatter::format() returns a PropelCollection'); $this->assertEquals(0, count($books), 'PropelObjectFormatter::format() returns as many rows as the results in the query'); }
public function testFormat() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); BookstoreEmployeePeer::clearInstancePool(); $stmt = $con->query('SELECT * FROM bookstore_employee'); $formatter = new PropelObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', 'BookstoreEmployee')); $emps = $formatter->format($stmt); $expectedClass = array('b1' => 'BookstoreEmployee', 'b2' => 'BookstoreManager', 'b3' => 'BookstoreCashier'); foreach ($emps as $emp) { $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance'); } }
public function getOpenCollectingTransfers(PropelPDO $con) { $sql = "SELECT * FROM " . TransferPeer::TABLE_NAME . " WHERE" . " member_id = :member_id AND" . " state = :state" . " FOR UPDATE"; $stmt = $con->prepare($sql); $stmt->execute(array(':member_id' => $this->getId(), ':state' => Transfer::STATE_COLLECT)); $formatter = new PropelObjectFormatter(); $formatter->setClass('Transfer'); return $formatter->format($stmt); }
public function testFormaWithRelatedObjects() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $con->useDebug(false); $con->useDebug(true); $this->assertEquals(0, $con->getQueryCount()); $stmt = $con->query('SELECT * FROM author LEFT JOIN book ON (author.id = book.author_id)'); $formatter = new PropelObjectFormatter(); $criteria = new ModelCriteria('bookstore', 'Author'); $criteria->joinWith('Book'); $formatter->init($criteria); $authors = $formatter->format($stmt); $this->assertEquals(1, $con->getQueryCount()); $this->assertTrue($authors instanceof PropelObjectCollection, 'PropelObjectFormatter::formatOne() returns a model object'); foreach ($authors as $author) { $this->assertTrue($author->getBooks() instanceof PropelCollection); if ('Grass' === $author->getLastName()) { $this->assertEquals(2, $author->countBooks()); } else { $this->assertEquals(1, $author->countBooks()); } } $this->assertEquals(1, $con->getQueryCount()); }
/** * Override formatter function for one item. * * @param PDOStatement $stmt * @return mixed */ public function formatOne(PDOStatement $stmt) { $item = parent::format($stmt); if ($this->formatterFunction) { return call_user_func($this->formatterFunction, $item); } if (is_object($item) && $item instanceof BaseObject) { return Propel::toTwig($item); } return $item; }
/** * * Retourne la liste de toutes les période de notes pour lesquelles l'eleve a ete affecte * * * @return PropelObjectCollection PeriodeNote[] */ public function getPeriodeNotes() { if(null === $this->collPeriodeNotes) { if ($this->isNew() && null === $this->collPeriodeNotes) { // return empty collection $this->initPeriodeNotes(); } else { $sql = "SELECT /* log pour sql manuel */ DISTINCT periodes.NOM_PERIODE, periodes.NUM_PERIODE, periodes.VEROUILLER, periodes.ID_CLASSE, periodes.DATE_VERROUILLAGE, periodes.DATE_FIN FROM `periodes` INNER JOIN classes ON (periodes.ID_CLASSE=classes.ID) INNER JOIN j_eleves_classes ON (classes.ID=j_eleves_classes.ID_CLASSE) WHERE j_eleves_classes.LOGIN='******' AND j_eleves_classes.periode = periodes.num_periode ORDER by periodes.NUM_PERIODE"; $con = Propel::getConnection(null, Propel::CONNECTION_READ); $stmt = $con->prepare($sql); $stmt->execute(); $formatter = new PropelObjectFormatter(); $formatter->setDbName(PeriodeNotePeer::DATABASE_NAME); $formatter->setClass('PeriodeNote'); $formatter->setPeer('PeriodeNotePeer'); $formatter->setAsColumns(array()); $formatter->setHasLimit(false); $this->collPeriodeNotes = $formatter->format($stmt); // $collPeriodeNotes = PeriodeNoteQuery::create()->useClasseQuery()->useJEleveClasseQuery()->filterByEleve($this)->endUse()->endUse() // ->where('j_eleves_classes.periode = periodes.num_periode') // ->setComment('log pour sql manuel') // ->distinct()->find(); // $this->collPeriodeNotes = $collPeriodeNotes; } } return $this->collPeriodeNotes; }