public function testFormat() { $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME); BookstoreEmployeeTableMap::clearInstancePool(); $stmt = $con->query('SELECT id, class_key, name, job_title, supervisor_id, photo FROM bookstore_employee'); $formatter = new ObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookstoreEmployee')); $emps = $formatter->format($stmt); $expectedClass = ['b1' => 'Propel\\Tests\\Bookstore\\BookstoreEmployee', 'b2' => 'Propel\\Tests\\Bookstore\\BookstoreManager', 'b3' => 'Propel\\Tests\\Bookstore\\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 init(ModelCriteria $criteria) { parent::init($criteria); $this->isSingleTableInheritance = $criteria->getTableMap()->isSingleTableInheritance(); return $this; }
$contactid = $request->getAttribute('contactid'); $gigid = $request->getAttribute('gigid'); $assignment = ContactAssigmentToGigQuery::query()->filterByGigId($gigid)->filterByContactId($contactid); if ($assignment == null) { return err_general_error($response, "ContactAssignment with ContactId {$contactid} and GigId {$gigid} not found"); } $assignment->delete(); return success($response, "ContactAssignmentToGig deleted"); }); $app->get('/contacts/{id}/venues', function ($request, $response, $args) { $id = $request->getAttribute('id'); $con = Propel::getWriteConnection('productionSource'); $sql = "SELECT * FROM Venue WHERE id IN " . "(SELECT ContactAssignmentToVenue.VenueId FROM ContactAssignmentToVenue" . " WHERE ContactAssignmentToVenue.ContactId = :contactid)"; $stmt = $con->prepare($sql); $stmt->execute(array('contactid' => $id)); $formatter = new ObjectFormatter(); $formatter->setClass('\\Venue'); //full qualified class name $venues = $formatter->format($con->getDataFetcher($stmt)); $response->getBody()->write(parseToJSONArray($venues)); return $response; }); $app->delete('/contacts/{contactid}/venues/{venuesid}', function ($request, $response, $args) { $contactid = $request->getAttribute('contactid'); $venueid = $request->getAttribute('venueid'); $assignment = ContactAssigmentToVenueQuery::query()->filterByVenueId($venueid)->filterByContactId($contactid); if ($assignment == null) { return err_general_error($response, "ContactAssignment with ContactId {$contactid} and VenueId {$venueid} not found"); } $assignment->delete(); return success($response, "ContactAssignmentToVenue deleted");
public function testFormatOneNoResult() { $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME); $stmt = $con->query('SELECT * FROM book WHERE book.TITLE = "foo"'); $formatter = new ObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book')); $book = $formatter->formatOne($stmt); $this->assertNull($book, 'ObjectFormatter::formatOne() returns null when no result'); }
$app->delete('/venues/{id}', function ($request, $response, $args) { $id = $request->getAttribute('id'); $venue = VenueQuery::create()->findPK($id); if ($venue == null) { return err_general_error($response, "Venue Id {$id} not found"); } $venue->delete(); return success($response, "Venue deleted"); }); $app->get('/venues/{id}/contacts', function ($request, $response, $args) { $id = $request->getAttribute('id'); $con = Propel::getWriteConnection('productionSource'); $sql = "SELECT * FROM Contact WHERE id IN " . "(SELECT ContactAssignmentToVenue.ContactId FROM ContactAssignmentToVenue" . " WHERE ContactAssignmentToVenue.VenueId = :venueid)"; $stmt = $con->prepare($sql); $stmt->execute(array(':venueid' => $id)); $formatter = new ObjectFormatter(); $formatter->setClass('\\Contact'); //full qualified class name $contacts = $formatter->format($con->getDataFetcher($stmt)); $response->getBody()->write(parseToJSONArray($contacts)); return $response; }); $app->post('/venues/{id}/contacts', function ($request, $response, $args) { $venueid = $request->getAttribute('id'); $parsedBody = $request->getParsedBody(); if ($parsedBody == null) { return err_general_error($response, "Provide a body to assign a contact to this venues"); } $contact = new Contact(); $contact->fromArray($parsedBody); $contact = ContactQuery::create()->findPK($contact->getId());
public function init(BaseModelCriteria $criteria = null, DataFetcherInterface $dataFetcher = null) { parent::init($criteria, $dataFetcher); $this->isSingleTableInheritance = $criteria->getTableMap()->isSingleTableInheritance(); return $this; }
/** * Gets the current Model object in the collection * This is where the hydration takes place. * * @see ObjectFormatter::getAllObjectsFromRow() * * @return ActiveRecordInterface */ public function current() { return $this->formatter->getAllObjectsFromRow($this->currentRow); }