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');
     }
 }
Exemplo n.º 2
0
 public function testFormatNoResult()
 {
     $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'));
     $books = $formatter->format($stmt);
     $this->assertTrue($books instanceof Collection, 'ObjectFormatter::format() returns a PropelCollection');
     $this->assertEquals(0, count($books), 'ObjectFormatter::format() returns as many rows as the results in the query');
 }
Exemplo n.º 3
0
    $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");
});
Exemplo n.º 4
0
    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());
    if ($contact == null) {
        return err_general_error($response, "Venue Id " . $id . " not found");
    }