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 list_created(Inputter $inputter, JSONOutputter $outputter) { // List Created // // Constants // $creating_user_identification = 'creating_user_identification'; // Verify input // $required_keys = array($creating_user_identification => ''); $inputter->validate_input($required_keys, null); // Validate input // $validate_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array[$creating_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 (creator:CreatingUser)-[:event]-(event:Event)-[:type]-(eventType:EventType), (event)-[:occurrence]-(occurrence:EventSpaceTimeOccurrence) ' . 'WHERE creator.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[$creating_user_identification] . "' " . 'RETURN creator, event, eventType, collect(occurrence) as eventoccurrences'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); $creator = $result[0]['creator']; if (count($creator) > 0) { $event_prints = array(); foreach ($result as $row) { $event_print = array(); if ($event_print != Event::printer_dictionary($row['event'])) { $event_print = Event::printer_dictionary($row['event']); $event_print[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($row['eventType']); $event_print[EVENT_RELATIONSHIP_NAME_OCCURRENCE] = array(); } foreach ($row['eventoccurrences'] as $occurrence) { array_push($event_print[EVENT_RELATIONSHIP_NAME_OCCURRENCE], EventSpaceTimeOccurrence::printer_dictionary($occurrence)); } if ($event_print != Event::printer_dictionary($row['event'])) { array_push($event_prints, $event_print); } } // Print data // $outputter->print_data($event_prints); } 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 ' . $creating_user_identification . '.'); $outputter->print_error($error); } }
public static function list_event(Inputter $inputter, JSONOutputter $outputter) { // List for event // // Verify input // $required_dictionary = array('event_identification' => ''); $inputter->validate_input($required_dictionary, null); // Validate // $event_id = $inputter->variables_array['event_identification']; $event_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $event_id, $event_error); if (isset($event_error)) { $outputter->print_error($event_error); } // Event ID // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string = 'MATCH (occurrence:EventSpaceTimeOccurrence)-[:event]-(event:Event), (occurrence)-[:location]-(location:Location), (occurrence)-[:confined_date]-(confinedDate:ConfinedDate), (occurrence)-[:attendees_range]-(attendeesRange:Range) ' . 'WHERE event.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $event_id . "' " . 'RETURN occurrence, location, confinedDate, attendeesRange'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); if (count($result) > 0) { $event_occurrence_prints = array(); foreach ($result as $row) { $event_occurrence_print = EventSpaceTimeOccurrence::printer_dictionary($row['occurrence']); $event_occurrence_print[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION] = Location::printer_dictionary($row['location']); $event_occurrence_print[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE] = ConfinedDate::printer_dictionary($row['confinedDate']); $event_occurrence_print[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE] = Range::printer_dictionary($row['attendeesRange']); array_push($event_occurrence_prints, $event_occurrence_print); } // Print data // $outputter->print_data($event_occurrence_prints); } 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 Event Occurrences for Event with identification ' . $event_id . ' does not exist.'); $outputter->print_error($error); } }