public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS) { // Check the data is an array of strings // if (!is_array($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Notification device identifiers must be an array'); return false; } // Check each element is a string // foreach ($property_value as $item) { if (!is_string($item)) { // Throw error, each notificationDeviceIdentifiers must be a string // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, 'Each notification device identifier must be a string.'); return false; } } } return true; }
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 propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === LOCATION_KEY_COORDINATE_LATITUDE) { // Should be a number // $property_value = floatval($property_value); if (!is_numeric($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } // Between -90 and 90 // if ($property_value < -90 || $property_value > 90) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be between -90 and 90.'); return false; } } if ($property_name === LOCATION_KEY_COORDINATE_LONGITUDE) { // Should be a number // $property_value = floatval($property_value); if (!is_numeric($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } // Between -180 and 180 // if ($property_value < -180 || $property_value > 180) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be between -180 and 180.'); return false; } } if ($property_name === LOCATION_KEY_NAME) { // Should be a string // if (!isset($property_value) || !is_string($property_value)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a string.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if (!isset($property_value)) { // Not set // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_PROPERTY_NOT_SET, "Invalid property value for '" . $property_name . "'"); return false; } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === EVENT_TYPE_BIRTHDAY_KEY_DATE_OF_BIRTH) { // Date of birth is a date // if (UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $property_value, $error) == false) { return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === CONFINED_DATE_START || $property_name === CONFINED_DATE_END) { // Check the data is an array of strings // $property_value = Cleaner::cleanISO8601String($property_value); if (!UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $property_value, $error)) { return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_ICON || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_SMALL || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_MEDIUM || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_LARGE || $property_name === MULTIDIMENSIONED_IMAGE_KEY_URL_ORIGINAL) { // Valid URL // if (!filter_var($property_value, FILTER_VALIDATE_URL)) { // Unrecognised property name // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a valid URL.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === RANGE_POSITION || $property_name === RANGE_LENGTH) { // Position // $property_value = intval($property_value); if (!is_numeric($property_value)) { // Is a number // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be a number.'); return false; } } return true; }
public static function propertyIsValid($property_name, &$property_value, &$error) { if (!parent::propertyIsValid($property_name, $property_value, $error)) { return false; } if ($property_name === EVENT_KEY_DRESS_CODE) { // Check the dress code is between first and last dress code value // if (!is_array($property_value)) { // Not array // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be an array.'); return false; } else { // Is array // foreach ($property_value as &$value) { $value = intval($value); if (!is_numeric($value)) { // Not unsigned int // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' should be unsigned integers.'); return false; } if ($value < EVENT_VALUE_DRESS_CODE_ANY || $value > EVENT_VALUE_DRESS_CODE_BLACKTIE) { // Dress code is out of bounds // $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . ' is out of bounds.'); return false; } } } } if ($property_name === EVENT_KEY_PRIVACY) { // Privacy is a value // $property_value = intval($property_value); if ($property_value != EVENT_VALUE_EVENT_PRIVACY_PUBLIC && $property_value != EVENT_VALUE_EVENT_PRIVACY_PRIVATE) { $error = Error::withDomain(VALIDATION_ERROR_DOMAIN, VALIDATION_ERROR_CODE_INVALID_PROPERTY, $property_name . " is " . $property_value . " but needs to be '" . EVENT_VALUE_EVENT_PRIVACY_PUBLIC . "' or '" . EVENT_VALUE_EVENT_PRIVACY_PRIVATE . "'."); return false; } } return true; }
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)))); }