public static function isValid(&$properties_dictionary, $limit_to_keys, &$error) { // Check each property is valid // if (isset($properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION])) { $properties = array('rawIdentifier' => $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]); if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueIdentifier::isValid($properties, true, $error)) { // Identifier was not valid // return false; } } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED], $error)) { // Date created was not valid // return false; } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary, true, $limit_to_keys) && !UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED], $error)) { // Date updated was not valid // return false; } if (ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $properties_dictionary, true, $limit_to_keys)) { // Date updated cannot be before date created // if ($properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED] > $properties_dictionary[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]) { // Updated was before created // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED . ' was before ' . UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED); return false; } } return true; }
public static function destroy(Inputter $inputter, JSONOutputter $outputter) { // User ID // // 1) Test all data is available and valid // // identification // $identification_error = null; if (!UniversallyUniqueIdentifier::isValid($propertiesDictionary['identification'], true, $identification_error)) { $outputter->print_error($identification_error); } $validPropertiesDictionary['identification'] = $propertiesDictionary['identification']; // 2) Check user to update exists // // User might exist (check against identification) // // Create query // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_user = '******' . 'WHERE user.' . UNIVERSALLY_UNIQUE_IDENTIFIER_KEY_IDENTIFICATION . ' = \'' . $validPropertiesDictionary['identification'] . '\' ' . 'RETURN user'; $query_check_user = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_user); // Run query // $result_check_user = $query_check_user->getResultSet(); // Do something based on the results // if ($result_check_user->count() < 1) { // No users exist // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'A user with the identification ' . $validPropertiesDictionary['identification'] . ' doesn\'t exist.'); $outputter->print_error($error); } // 3) We've got the go ahead to process the request as it's intended - delete the user from the data store // // Create query string // $query_string_delete_account = 'MATCH (user:User) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_IDENTIFIER_KEY_IDENTIFICATION . ' = \'' . $validPropertiesDictionary['identification'] . '\' ' . 'DELETE user '; // Query // $query_delete_account = new Everyman\Neo4j\Cypher\Query($client, $query_string_delete_account); // Run query // $result_delete_account = $query_delete_account->getResultSet(); // 4) Output our final response // if ($result_delete_account != null) { $outputter->print_data(); } else { // Throw error, no result // $error = Error(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, HTTP_INTERNAL_SERVER_ERROR); $outputter->print_error($error); } }