include_once dirname(__FILE__) . '/../database/TripAttribute.php';
$auth = new AuthB();
if (!$auth->canGetTripAttribute()) {
    $response = errorResponse(RESPONSE_UNAUTHORIZED);
} else {
    $tripId = '';
    if (isset($_GET['tripId'])) {
        $tripId = $_GET['tripId'];
    }
    $name = '';
    if (isset($_GET['name'])) {
        $name = $_GET['name'];
    }
    if ($tripId === '' || $name === '') {
        $response = errorResponse(RESPONSE_BAD_REQUEST);
    } else {
        $object = new TripAttribute($tripId, $name);
        if ($object->getCreated() === null) {
            $response = errorResponse(RESPONSE_NOT_FOUND);
        } else {
            $response = successResponse();
            $response['tripId'] = $object->getTripId();
            $response['name'] = $object->getName();
            $response['created'] = $object->getCreated();
            $response['updated'] = $object->getUpdated();
            $response['value'] = $object->getValue();
            $response['deleted'] = $object->getDeleted();
        }
    }
}
echo json_encode($response);
 /**
  * Test #9. PUT request update existing object.
  * @depends testPutCreate
  */
 public function testUpdateTripAttribute()
 {
     global $testTripId1;
     global $testName1;
     $object = new TripAttribute($testTripId1, $testName1);
     $object->setValue('value');
     $object->setDeleted('N');
     $object->save();
     $this->assertEquals(1, $this->countTestRows());
     $data = array('tripId' => $testTripId1, 'name' => $testName1, 'created' => '2015-10-01', 'updated' => '2015-10-02', 'value' => '2015-10-01', 'deleted' => 'Y', 'hash' => 'forced hash');
     $result = putApi('putTripAttribute.php', $data);
     $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']);
     $this->assertEquals(2, $this->countTestRows());
     $object = new TripAttribute($testTripId1, $testName1);
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($testName1, $object->getName());
     $this->assertEquals('2015-10-01', $object->getValue());
     $this->assertEquals('Y', $object->getDeleted());
 }
 /**
  * test #14.
  * Overriding automatic attributes using a future date. Because
  * a future date is used, the record can no longer be changed after
  * it was saved.
  * @depends testSaveEmptyObject
  * @depends testSetAttributes
  * @depends testUpdate
  * @depends testOverrideAutomaticAttributesNewRecord
  */
 public function testOverrideAutomaticAttributesFutureDate()
 {
     global $testTripId1;
     // Create the object, which automatically gets the current date
     $object = new TripAttribute($testTripId1, 'name');
     $object->setValue('value');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     $originalCreated = $object->getCreated();
     $originalUpdated = $object->getUpdated();
     $originalHash = $object->getHash();
     // Change the object with different values, using a guaranteed
     // future date for the Created and Updated fields. Note that
     // the mySQL timestamp values allow for dates up to January 19,
     // 2038. Select as the future date for this test January 18, 2038
     // values after first save are unchanged
     $object->setCreated('2038-01-18 10:10:10.000000');
     $object->setUpdated('2038-01-18 10:10:11.000000');
     $object->setValue('value 2');
     $object->setDeleted('N');
     $object->setHash('future date hash');
     // Check the values before saving
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('value 2', $object->getValue());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals('future date hash', $object->getHash());
     // update the record, this adds a row in the database
     $this->assertTrue($object->save());
     $this->assertEquals(2, $this->countTestRows());
     // after the update, the information has been saved
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('value 2', $object->getValue());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals('future date hash', $object->getHash());
     // Try to update the record. This will add a row in the database
     $object->setValue('value 3');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(3, $this->countTestRows());
     // but the new information is not saved. The previously saved
     // information cannot be overwritten without manually setting the
     // updated field.
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals('2038-01-18 10:10:10.000000', $object->getCreated());
     $this->assertEquals('2038-01-18 10:10:11.000000', $object->getUpdated());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('value 2', $object->getValue());
     $this->assertEquals('N', $object->getDeleted());
     // Note: this will FAIL in the current implementation!
     //$this->assertEquals('future date hash', $object->getHash());
 }