public static function show(Inputter $inputter, JSONOutputter $outputter) { // Validate // $user_id = $inputter->additional_uri_arguments[0]; $user_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $user_id, $user_error); if (isset($user_error)) { $outputter->print_error($user_error); } // User ID // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (user:User) WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . ' = \'' . $user_id . '\' RETURN user'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result_show_user = $query->getResultSet(); if (count($result_show_user) > 0) { // Compare sent data is equal to data retrieved // $user = $result_show_user[0]['user']; // Print data // $outputter->print_data(array(AttendingUser::printer_dictionary($user))); } else { // Throw error, user doesn't exists // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'User with ID does not exist.'); $outputter->print_error($error); } }
public static function search_list(Inputter $inputter, JSONOutputter $outputter) { // Search string // $search_string = $inputter->additional_uri_arguments[0]; $user_error = null; if (!is_string($search_string)) { // Throw error, search string is not a string // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_UNCONFORMING, 'Search string is not a string.'); $outputter->print_error($error); } // Query // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); // Users // $query_string_search_users = 'MATCH (foundUser:CreatingUser) ' . 'WHERE (foundUser.' . CREATINGUSER_KEY_FIRST_NAME . ' + " " + foundUser.' . CREATINGUSER_KEY_SURNAME . ') =~ "(?i)' . $search_string . '.*" OR foundUser.' . CREATINGUSER_KEY_NAME . ' =~ "(?i)' . $search_string . '.*" OR foundUser.' . USER_KEY_EMAIL . ' =~ "(?i)' . $search_string . '" ' . 'RETURN foundUser'; $query_search_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_users); $result_search_users = $query_search_users->getResultSet(); // Events in scope // $query_string_search_events = 'MATCH (foundCreator:CreatingUser)-[:creator]-(foundEvent:Event)-[:type]-(foundEventType:EventType), (foundOccurrence:EventSpaceTimeOccurrence)-[:occurrence]-(foundEvent) ' . 'WHERE foundEvent.privacy = 1 AND ANY(label IN labels(foundEventType) WHERE label =~ "(?i).*' . $search_string . '.*") ' . 'RETURN foundEvent, foundEventType, foundCreator, collect(foundOccurrence) as foundEventOccurrences'; $query_search_events = new Everyman\Neo4j\Cypher\Query($client, $query_string_search_events); $result_search_events = $query_search_events->getResultSet(); // Output // // Users // $print_users = array(); foreach ($result_search_users as $row) { array_push($print_users, AttendingUser::printer_dictionary($row['foundUser'])); } // Events in scope // $print_events = array(); foreach ($result_search_events as $row) { $event_dictionary = array(); if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) { $event_dictionary = Event::printer_dictionary($row['foundEvent']); $event_dictionary[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($row['foundEventType']); $event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE] = array(); } foreach ($row['foundEventOccurrences'] as $occurrence) { array_push($event_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE], EventSpaceTimeOccurrence::printer_dictionary($occurrence)); } if ($event_dictionary != Event::printer_dictionary($row['foundEvent'])) { array_push($print_events, $event_dictionary); } } // Print data // $outputter->print_data(array(array("users" => $print_users, "events" => $print_events))); }
public static function authenticate(Inputter $inputter, JSONOutputter $outputter) { // Authenticate // // 1) Test all data is available and valid // $required_dictionary = array(USER_KEY_EMAIL => '', USER_KEY_PASSWORD => ''); $inputter->validate_input($required_dictionary, null); // Validate // // User // $user_error = null; User::propertyIsValid(USER_KEY_EMAIL, $inputter->variables_array[USER_KEY_EMAIL], $user_error); User::propertyIsValid(USER_KEY_PASSWORD, $inputter->variables_array[USER_KEY_PASSWORD], $user_error); if (isset($user_error)) { $outputter->print_error($user_error); return; } // 2) Check email and password against data store // // Query string // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_authenticate_account = 'MATCH (user:User) ' . 'WHERE user.' . USER_KEY_EMAIL . ' = \'' . $inputter->variables_array[USER_KEY_EMAIL] . '\' ' . 'AND user.' . USER_KEY_PASSWORD . ' = \'' . $inputter->variables_array[USER_KEY_PASSWORD] . '\' ' . 'RETURN user'; $query_authenticate_account = new Everyman\Neo4j\Cypher\Query($client, $query_string_authenticate_account); // Run query // $result_authenticate_account = $query_authenticate_account->getResultSet(); if ($result_authenticate_account->count() !== 1) { $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'A user with that email and password does not exist.'); $outputter->print_error($error); } // 3) Output the response // $account_to_authenticate = $result_authenticate_account[0]['user']; $outputter->print_data(array(AttendingUser::printer_dictionary($account_to_authenticate))); }
public static function list_invited(Inputter $inputter, JSONOutputter $outputter) { // List Invited // // Constants // $invited_user_identification = 'invited_user_identification'; // Verify input // $required_keys = array($invited_user_identification => ''); $inputter->validate_input($required_keys, null); // Validate input // $validate_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array[$invited_user_identification], $validate_error); if (isset($validate_error)) { $outputter->print_error($validate_error); } // Events // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (invitedUser:AttendingUser)-[:softInvitation]-(event:Event)-[:type]-(eventType:EventType) ' . 'WHERE invitedUser.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[$invited_user_identification] . "' " . 'RETURN invitedUser, event, eventType'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); $creator = $result[0]['invitedUser']; if (count($creator) > 0) { // Compare sent data is equal to data retrieved // $events_printer_dictionaries = array(); foreach ($result as $value) { $event_print = Event::printer_dictionary($value['event']); $event_print[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($value['eventType']); $event_print[EVENT_RELATIONSHIP_NAME_CREATOR] = AttendingUser::printer_dictionary($value['invitedUser']); array_push($events_printer_dictionaries, $event_print); } // Print data // $outputter->print_data($events_printer_dictionaries); } else { // Throw error, user doesn't exists // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'No such user with identification ' . $invited_user_identification . '.'); $outputter->print_error($error); } }
public static function destroy(Inputter $inputter, JSONOutputter $outputter) { // Create // // 1) Test all data is available and valid // // Availability // $required_dictionary = array('user_identification' => '', 'user_to_unfollow_identification' => ''); $inputter->validate_input($required_dictionary, null); // Valid // // Identifiers // $validation_error = null; UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_identification'], $validation_error); UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_to_unfollow_identification'], $validation_error); if (isset($validation_error)) { $outputter->print_error($validation_error); } // Different // if ($inputter->variables_array['user_identification'] === $inputter->variables_array['user_to_unfollow_identification']) { $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_NOT_UNIQUE, 'Users cannot unfollow themselves.')); } // 2) Check request we want to process CAN go ahead // // Identification should exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:AttendingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_identification should be an existing user identification.')); } $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:CreatingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user_to_follow_identification exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_to_unfollow_identification should be an existing user identification.')); } // Connection might exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_connection = 'OPTIONAL MATCH (user:AttendingUser)-[following:' . ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW . ']->(user_to_unfollow:CreatingUser)-[follower: ' . CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER . ']->(user) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_unfollow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN following, follower'; $query_check_connection = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_connection); $result_check_connection = $query_check_connection->getResultSet(); if (!isset($result_check_connection[0]['following']) || !isset($result_check_connection[0]['follower'])) { // At least one object exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_RELATIONSHIP_EXISTS, 'Connection does not exist between users.')); } // 3) We've got the go ahead to process the request as it's intended - destroy the follow connection // // Get objects // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_users = 'MATCH (user:AttendingUser)-[following:' . ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW . ']->(user_to_unfollow:CreatingUser)-[follower:' . CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER . ']->(user) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_unfollow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_unfollow_identification'] . "' " . 'RETURN user, user_to_unfollow, following, follower'; $query_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_users); $result_users = $query_users->getResultSet(); $user = $result_users[0]['user']; $user_to_unfollow = $result_users[0]['user_to_unfollow']; $following_relationship = $result_users[0]['following']; $follower_relationship = $result_users[0]['follower']; // Remove relationships // $following_relationship->delete(); $follower_relationship->delete(); // 4) Output results // // Print data // $outputter->print_data(array(array("user" => AttendingUser::printer_dictionary($user), "user_to_unfollow" => CreatingUser::printer_dictionary($user_to_unfollow)))); }