public static function isValid(&$properties_dictionary, $limit_to_keys, &$error)
 {
     //	Check each property is valid
     //
     if (!parent::isValid($properties_dictionary, $limit_to_keys, $error)) {
         return false;
     }
     //		First name, surname, name
     //
     if (ValidationC::should_test_property(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary[CREATINGUSER_KEY_FIRST_NAME], $error)) {
         return false;
     }
     if (ValidationC::should_test_property(CREATINGUSER_KEY_SURNAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_SURNAME, $properties_dictionary[CREATINGUSER_KEY_SURNAME], $error)) {
         return false;
     }
     if (ValidationC::should_test_property(CREATINGUSER_KEY_NAME, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_NAME, $properties_dictionary[CREATINGUSER_KEY_NAME], $error)) {
         return false;
     }
     if (ValidationC::should_test_property(CREATINGUSER_KEY_GENDER, $properties_dictionary, true, $limit_to_keys) && !CreatingUser::propertyIsValid(CREATINGUSER_KEY_GENDER, $properties_dictionary[CREATINGUSER_KEY_GENDER], $error)) {
         return false;
     }
     $should_test_all_names = ValidationC::should_test_property(CREATINGUSER_KEY_FIRST_NAME, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(CREATINGUSER_KEY_SURNAME, $properties_dictionary, true, $limit_to_keys) && ValidationC::should_test_property(CREATINGUSER_KEY_NAME, $properties_dictionary, true, $limit_to_keys);
     if ($should_test_all_names && (empty($properties_dictionary[CREATINGUSER_KEY_FIRST_NAME]) || isset($properties_dictionary[CREATINGUSER_KEY_SURNAME])) && isset($properties_dictionary[CREATINGUSER_KEY_NAME])) {
         //	Set either first name and surname, or, just a name
         //
         $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'When setting a name, set either ' . CREATINGUSER_KEY_FIRST_NAME . ' and ' . CREATINGUSER_KEY_SURNAME . ', or, just a ' . CREATINGUSER_KEY_NAME . '.');
         return false;
     }
     return true;
 }
 public static function update(Inputter $inputter, JSONOutputter $outputter)
 {
     //	Update
     //
     //	1) Test all data is available and valid
     //
     $required_dictionary = array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => '');
     $optional_dictionary = array(USER_KEY_EMAIL => null, USER_KEY_PASSWORD => null, 'notificationDeviceIdentifiersToRemove' => array(), 'notificationDeviceIdentifiersToAdd' => array(), USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS => array(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c'), CREATINGUSER_KEY_FIRST_NAME => null, CREATINGUSER_KEY_SURNAME => null, CREATINGUSER_KEY_NAME => null, CREATINGUSER_KEY_GENDER => null);
     $inputter->validate_input($required_dictionary, $optional_dictionary);
     //			Remove things that shouldn't be updated
     //
     if (isset($inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED])) {
         unset($inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
     }
     //		Valid
     //
     $update_error = null;
     //		Email
     //
     if (isset($inputter->variables_array[USER_KEY_EMAIL])) {
         Email::propertyIsValid('rawEmail', $inputter->variables_array[USER_KEY_EMAIL], $update_error);
     }
     //		Password
     //
     if (isset($inputter->variables_array[USER_KEY_PASSWORD])) {
         Password::propertyIsValid('rawPassword', $inputter->variables_array[USER_KEY_PASSWORD], $update_error);
     }
     //		Notification device identifiers
     //
     if (isset($inputter->variables_array[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS])) {
         User::propertyIsValid(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $inputter->variables_array[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS], $update_error);
     }
     if (isset($inputter->variables_array['notificationDeviceIdentifiersToRemove'])) {
         User::propertyIsValid(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $inputter->variables_array['notificationDeviceIdentifiersToRemove'], $update_error);
     }
     if (isset($inputter->variables_array['notificationDeviceIdentifiersToAdd'])) {
         User::propertyIsValid(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $inputter->variables_array['notificationDeviceIdentifiersToAdd'], $update_error);
     }
     //		Creating user
     //
     if (isset($inputter->variables_array[CREATINGUSER_KEY_FIRST_NAME]) || isset($inputter->variables_array[CREATINGUSER_KEY_SURNAME]) || isset($inputter->variables_array[CREATINGUSER_KEY_NAME])) {
         CreatingUser::isValid(array(CREATINGUSER_KEY_FIRST_NAME => $inputter->variables_array[CREATINGUSER_KEY_FIRST_NAME], CREATINGUSER_KEY_SURNAME => $inputter->variables_array[CREATINGUSER_KEY_SURNAME], CREATINGUSER_KEY_NAME => $inputter->variables_array[CREATINGUSER_KEY_NAME], CREATINGUSER_KEY_GENDER => $inputter->variables_array[CREATINGUSER_KEY_GENDER]), true, $update_error);
     }
     if (isset($update_error)) {
         $outputter->print_error($update_error);
         return;
     }
     //	2) Get user
     //
     //		User might exist (check against ID)
     //
     //			Create query
     //
     $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789);
     $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq');
     $query_string_get_user = '******' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "'" . 'RETURN user';
     $query_get_user = new Everyman\Neo4j\Cypher\Query($client, $query_string_get_user);
     $result_get_user = $query_get_user->getResultSet();
     if ($result_get_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 ' . $inputter->variables_array[UNIVERSALLY_UNIQUE_IDENTIFIER_KEY_IDENTIFICATION] . " doesn\\'t exist.");
         $outputter->print_error($error);
     }
     //	3) Update the user
     //
     //		Existing properties
     //
     $account_to_update = $result_get_user[0]['user'];
     $account_to_update->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, date('c'));
     if (isset($inputter->variables_array[USER_KEY_EMAIL])) {
         $account_to_update->setProperty(USER_KEY_EMAIL, $inputter->variables_array[USER_KEY_EMAIL]);
     }
     if (isset($inputter->variables_array[USER_KEY_PASSWORD])) {
         $account_to_update->setProperty(USER_KEY_PASSWORD, $inputter->variables_array[USER_KEY_PASSWORD]);
     }
     //          Identifiers
     //
     $existing = $account_to_update->getProperty(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS);
     $new = array();
     if (isset($inputter->variables_array[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS])) {
         $new = $inputter->variables_array[USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS];
     }
     if (isset($existing) && is_array($existing)) {
         //	Merge
         //
         $new = array_merge($new, $existing);
     }
     $new = array_unique($new);
     //              Add
     //
     if (isset($inputter->variables_array['notificationDeviceIdentifiersToAdd']) && is_array($inputter->variables_array['notificationDeviceIdentifiersToAdd'])) {
         $new = array_merge($new, $inputter->variables_array['notificationDeviceIdentifiersToAdd']);
         $new = array_unique($new);
     }
     //              Remove
     //
     if (isset($inputter->variables_array['notificationDeviceIdentifiersToRemove']) && is_array($inputter->variables_array['notificationDeviceIdentifiersToRemove'])) {
         $new = array_diff($new, $inputter->variables_array['notificationDeviceIdentifiersToRemove']);
         $new = array_unique($new);
     }
     //              Update
     //
     if (isset($new) && is_array($new)) {
         $account_to_update->setProperty(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS, $new);
     }
     //          First name
     //
     if (isset($inputter->variables_array[CREATINGUSER_KEY_FIRST_NAME])) {
         $account_to_update->setProperty(CREATINGUSER_KEY_FIRST_NAME, $inputter->variables_array[CREATINGUSER_KEY_FIRST_NAME]);
     }
     if (isset($inputter->variables_array[CREATINGUSER_KEY_SURNAME])) {
         $account_to_update->setProperty(CREATINGUSER_KEY_SURNAME, $inputter->variables_array[CREATINGUSER_KEY_SURNAME]);
     }
     if (isset($inputter->variables_array[CREATINGUSER_KEY_NAME])) {
         $account_to_update->setProperty(CREATINGUSER_KEY_NAME, $inputter->variables_array[CREATINGUSER_KEY_NAME]);
     }
     if (isset($inputter->variables_array[CREATINGUSER_KEY_GENDER])) {
         $account_to_update->setProperty(CREATINGUSER_KEY_GENDER, $inputter->variables_array[CREATINGUSER_KEY_GENDER]);
     }
     //	Save
     //
     $account_to_update->save();
     //	4) Output results
     //
     $outputter->print_data(array(AttendingUser::printer_dictionary($account_to_update)));
 }
 public static function labels()
 {
     $labels = parent::labels();
     array_push($labels, 'AttendingUser');
     return $labels;
 }
 public static function create(Inputter $inputter, JSONOutputter $outputter)
 {
     //	Create
     //
     //	1) Test all data is available and valid
     //
     //		Availability
     //
     $required_keys = array(EVENT_KEY_DRESS_CODE => array(), EVENT_KEY_PRIVACY => '', 'creating_user_identification' => '', EVENT_RELATIONSHIP_NAME_OCCURRENCE => array(array(SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION => array(LOCATION_KEY_COORDINATE_LATITUDE => '', LOCATION_KEY_COORDINATE_LONGITUDE => ''), SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE => array(CONFINED_DATE_START => '', CONFINED_DATE_END => ''))), EVENT_RELATIONSHIP_NAME_TYPE => array(EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME => ''));
     //          Optional
     //
     $optional_dictionary = array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c'), EVENT_RELATIONSHIP_NAME_OCCURRENCE => array(), EVENT_RELATIONSHIP_NAME_TYPE => array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c')));
     //              Add to optional
     //
     $total_occurrences = 1 + (isset($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE]) && is_array($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE])) ? count($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE]) : 0;
     for ($i = 0; $i < $total_occurrences; $i++) {
         $optional_dictionary[EVENT_RELATIONSHIP_NAME_OCCURRENCE][$i] = array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c'), SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION => array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c')), SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE => array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c')), EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE => array(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION => uniqid(), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED => date('c'), UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED => date('c'), RANGE_POSITION => 0, RANGE_LENGTH => 0));
     }
     //			Validate input
     //
     $inputter->validate_input($required_keys, $optional_dictionary);
     //		Valid
     //
     $create_event_error = null;
     //			Identifiers
     //
     UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array['creating_user_identification'], $create_event_error);
     //			Event
     //
     Event::isValid($inputter->variables_array, false, $create_event_error);
     //			Occurrence(s)
     //
     foreach ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE] as &$occurrence_dictionary) {
         EventSpaceTimeOccurrence::isValid($occurrence_dictionary, false, $create_event_error);
     }
     //			Event type
     //
     EventTypeFactory::isValid($inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE], false, $create_event_error);
     //		Print error
     //
     if (isset($create_event_error)) {
         $outputter->print_error($create_event_error);
         return;
     }
     //	2) Check request we want to process CAN go ahead
     //
     //		IDs are all different
     //
     $identifications_array = array($inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION], $inputter->variables_array['creating_user_identification'], $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
     foreach ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE] as $occurrence) {
         array_push($identifications_array, $occurrence[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
         array_push($identifications_array, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
     }
     if (count(array_unique($identifications_array)) !== count($identifications_array)) {
         $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_NOT_UNIQUE, 'identifications provided are not unique.');
         $outputter->print_error($identification_exists);
     }
     //		Event identification might exist
     //
     $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789);
     $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq');
     $query_string_check_event = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "' " . "RETURN uniqueObject";
     $query_check_event = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_event);
     $result_check_event = $query_check_event->getResultSet();
     if ($result_check_event->count() > 0) {
         $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'Identifier is not unique.');
         $outputter->print_error($identification_exists);
     }
     //		Creating user must exist
     //
     $query_string_check_creator = "MATCH (creator:CreatingUser) " . "WHERE creator." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['creating_user_identification'] . "' " . "RETURN creator";
     $query_check_creator = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_creator);
     $result_check_creator = $query_check_creator->getResultSet();
     if ($result_check_creator->count() < 1) {
         //	No creating user exists
         //
         $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'creating_user_identification should be of a valid user.');
         $outputter->print_error($error);
     }
     //		Event type must not exist
     //
     $query_string_check_event_type = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "' " . "RETURN uniqueObject";
     $query_check_event_type = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_event_type);
     $result_check_event_type = $query_check_event_type->getResultSet();
     if ($result_check_event_type->count() > 0) {
         //	Event type identification exists
         //
         $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_EXISTS, 'Identifier is not unique.');
         $outputter->print_error($identification_exists);
     }
     //		Event occurrences
     //
     foreach ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE] as $occurrence) {
         //	Occurrence
         //
         $query_string_check_occurrence = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $occurrence[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "' " . "RETURN uniqueObject";
         $query_check_occurrence = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_occurrence);
         $result_check_occurrence = $query_check_occurrence->getResultSet();
         if ($result_check_occurrence->count() > 0) {
             $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_EXISTS, 'Identifier is not unique.');
             $outputter->print_error($identification_exists);
         }
         //	Location identification must not exist
         //
         $query_string_check_location = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION] . "' " . "RETURN uniqueObject";
         $query_check_location = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_location);
         $result_check_location = $query_check_location->getResultSet();
         if ($result_check_location->count() > 0) {
             //	Location identification exists
             //
             $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_EXISTS, 'Identifier is not unique.');
             $outputter->print_error($identification_exists);
         }
     }
     //	3) We've got the go ahead to process the request as it's intended - create a new user in the data store
     //
     //		Event
     //
     $event_to_create = $client->makeNode();
     $event_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
     $event_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
     $event_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
     $event_to_create->setProperty(EVENT_KEY_DRESS_CODE, $inputter->variables_array[EVENT_KEY_DRESS_CODE]);
     $event_to_create->setProperty(EVENT_KEY_PRIVACY, $inputter->variables_array[EVENT_KEY_PRIVACY]);
     $event_to_create->save();
     //			Relationship
     //
     $creator = $result_check_creator[0]['creator'];
     if (isset($creator)) {
         $event_to_create->relateTo($creator, EVENT_RELATIONSHIP_NAME_CREATOR)->save();
         $creator->relateTo($event_to_create, CREATINGUSER_RELATIONSHIP_NAME_EVENT)->save();
     } else {
         $identification_exists = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'An event creator is required.');
         $outputter->print_error($identification_exists);
     }
     //			Add labels
     //
     $event_label_objects = array();
     foreach (Event::labels() as $name) {
         array_push($event_label_objects, new Everyman\Neo4j\Label($client, $name));
     }
     if (count($event_label_objects) > 0) {
         $event_to_create->addLabels($event_label_objects);
     }
     //		Event type
     //
     $event_type_to_create = $client->makeNode();
     $event_type_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
     $event_type_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
     $event_type_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
     $event_type_label_names = EventTypeFactory::labels($inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME]);
     if ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeAnniversary') {
         $event_type_to_create->setProperty(EVENT_TYPE_ANNIVERSARY_KEY_YEAR, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_ANNIVERSARY_KEY_YEAR]);
     } else {
         if ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypeBirthday') {
             $event_type_to_create->setProperty(EVENT_TYPE_BIRTHDAY_KEY_DATE_OF_BIRTH, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_BIRTHDAY_KEY_DATE_OF_BIRTH]);
         } else {
             if ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_FACTORY_KEY_EVENT_TYPE_NAME] === 'EventTypePartyLaunch') {
                 $event_type_to_create->setProperty(EVENT_TYPE_PARTY_LAUNCH_KEY_LAUNCH_ITEM_TITLE, $inputter->variables_array[EVENT_RELATIONSHIP_NAME_TYPE][EVENT_TYPE_PARTY_LAUNCH_KEY_LAUNCH_ITEM_TITLE]);
             }
         }
     }
     $event_type_to_create->save();
     //			Relationship
     //
     $event_type_to_create->relateTo($event_to_create, EVENT_TYPE_RELATIONSHIP_NAME_EVENT)->save();
     $event_to_create->relateTo($event_type_to_create, EVENT_RELATIONSHIP_NAME_TYPE)->save();
     //			Add labels
     //
     $event_type_label_objects = array();
     foreach ($event_type_label_names as $name) {
         array_push($event_type_label_objects, new Everyman\Neo4j\Label($client, $name));
     }
     if (count($event_type_label_objects) > 0) {
         $event_type_to_create->addLabels($event_type_label_objects);
     }
     //		Occurrences
     //
     $occurrences_to_create = array();
     $locations_to_create = array();
     $ranges_to_create = array();
     $confined_dates_to_create = array();
     //			Create
     //
     foreach ($inputter->variables_array[EVENT_RELATIONSHIP_NAME_OCCURRENCE] as $occurrence) {
         //	Occurrence
         //
         $occurrence_to_create = $client->makeNode();
         $occurrence_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $occurrence[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
         $occurrence_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $occurrence[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
         $occurrence_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $occurrence[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
         $occurrence_to_create->save();
         //		Relationship
         //
         $occurrence_to_create->relateTo($event_to_create, EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_EVENT)->save();
         $event_to_create->relateTo($occurrence_to_create, EVENT_RELATIONSHIP_NAME_OCCURRENCE)->save();
         //		Add labels
         //
         $occurrence_label_objects = array();
         foreach (EventSpaceTimeOccurrence::labels() as $name) {
             array_push($occurrence_label_objects, new Everyman\Neo4j\Label($client, $name));
         }
         if (count($occurrence_label_objects) > 0) {
             $occurrence_to_create->addLabels($occurrence_label_objects);
         }
         //	Location
         //
         $location_to_create = $client->makeNode();
         $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
         $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
         $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
         $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LATITUDE, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][LOCATION_KEY_COORDINATE_LATITUDE]);
         $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LONGITUDE, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][LOCATION_KEY_COORDINATE_LONGITUDE]);
         if (isset($occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][LOCATION_KEY_NAME])) {
             $location_to_create->setProperty(LOCATION_KEY_NAME, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION][LOCATION_KEY_NAME]);
         }
         $location_to_create->save();
         //		Relationship
         //
         $location_to_create->relateTo($occurrence_to_create, LOCATION_RELATIONSHIP_NAME_EVENT_OCCURRENCE)->save();
         $occurrence_to_create->relateTo($location_to_create, SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION)->save();
         //		Add labels
         //
         $location_label_objects = array();
         foreach (Location::labels() as $name) {
             array_push($location_label_objects, new Everyman\Neo4j\Label($client, $name));
         }
         if (count($location_label_objects) > 0) {
             $location_to_create->addLabels($location_label_objects);
         }
         //	Range
         //
         $range_to_create = $client->makeNode();
         $range_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $occurrence[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
         $range_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $occurrence[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
         $range_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $occurrence[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
         $range_to_create->setProperty(RANGE_POSITION, $occurrence[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE][RANGE_POSITION]);
         $range_to_create->setProperty(RANGE_LENGTH, $occurrence[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE][RANGE_LENGTH]);
         $range_to_create->save();
         //		Relationship
         //
         $occurrence_to_create->relateTo($range_to_create, EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE)->save();
         //		Add labels
         //
         $range_label_objects = array();
         foreach (Range::labels() as $name) {
             array_push($range_label_objects, new Everyman\Neo4j\Label($client, $name));
         }
         if (count($range_label_objects) > 0) {
             $range_to_create->addLabels($range_label_objects);
         }
         //	Confined date
         //
         $confined_date_to_create = $client->makeNode();
         $confined_date_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE][UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
         $confined_date_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
         $confined_date_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE][UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
         $confined_date_to_create->setProperty(CONFINED_DATE_START, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE][CONFINED_DATE_START]);
         $confined_date_to_create->setProperty(CONFINED_DATE_END, $occurrence[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE][CONFINED_DATE_END]);
         $confined_date_to_create->save();
         //		Relationship
         //
         $occurrence_to_create->relateTo($confined_date_to_create, SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE)->save();
         //		Add labels
         //
         $confined_date_label_objects = array();
         foreach (ConfinedDate::labels() as $name) {
             array_push($confined_date_label_objects, new Everyman\Neo4j\Label($client, $name));
         }
         if (count($confined_date_label_objects) > 0) {
             $confined_date_to_create->addLabels($confined_date_label_objects);
         }
         //	Add occurrence
         //
         array_push($occurrences_to_create, $occurrence_to_create);
         array_push($locations_to_create, $location_to_create);
         array_push($ranges_to_create, $range_to_create);
         array_push($confined_dates_to_create, $confined_date_to_create);
     }
     //	4) Output results
     //
     $output = Event::printer_dictionary($event_to_create);
     $output[EVENT_RELATIONSHIP_NAME_CREATOR] = CreatingUser::printer_dictionary($creator);
     $output[EVENT_RELATIONSHIP_NAME_TYPE] = EventType::printer_dictionary($event_type_to_create);
     $output[EVENT_RELATIONSHIP_NAME_OCCURRENCE] = array();
     for ($i = 0; $i < count($occurrences_to_create); $i++) {
         $occurrence_output = EventSpaceTimeOccurrence::printer_dictionary($occurrences_to_create[$i]);
         $occurrence_output[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_LOCATION] = Location::printer_dictionary($locations_to_create[$i]);
         $occurrence_output[EVENT_SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_RANGE] = EventSpaceTimeOccurrence::printer_dictionary($ranges_to_create[$i]);
         $occurrence_output[SPACE_TIME_OCCURRENCE_RELATIONSHIP_NAME_CONFINED_DATE] = ConfinedDate::printer_dictionary($confined_dates_to_create[$i]);
         array_push($output[EVENT_RELATIONSHIP_NAME_OCCURRENCE], $occurrence_output);
     }
     $outputter->print_data(array($output));
 }
 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))));
 }