Example #1
0
 function getNeo4jUser($uuid)
 {
     $this->client = new Everyman\Neo4j\Client();
     $this->client->getTransport()->setAuth("neo4j", "neo4j");
     $query = new Everyman\Neo4j\Cypher\Query($this->client, "MATCH (n:`User`) where n.uuid = \"{$uuid}\" match (n)-[:`HAS_ROLE`]-(role) RETURN \n                n.username as username, n.password as password, id(n) as node_id, role.authority");
     $results = $query->getResultSet();
     if (empty($results)) {
         return array();
     } else {
         $user = array();
         $roles = array();
         foreach ($results as $result) {
             $columns = $result->columns();
             foreach ($columns as $column) {
                 if ($column == "role.authority") {
                     $roles[] = $result[$column];
                     continue;
                 }
                 $user[$column] = $result[$column];
             }
         }
         $user["roles"] = $roles;
         return $user;
     }
 }
Example #2
0
 /**
  * Implement the R in CRUD. Calls to ``Model::find()`` arrive here.
  */
 public function read(Model $model, $queryData = array(), $recursive = null)
 {
     /**
      * Here we do the actual count as instructed by our calculate()
      * method above. We could either check the remote source or some
      * other way to get the record count. Here we'll simply return 1 so
      * ``update()`` and ``delete()`` will assume the record exists.
      */
     if ($queryData['fields'] === 'COUNT') {
         return array(array(array('count' => 1)));
     }
     /**
      * Now we get, decode and return the remote data.
      */
     $queryString = "MATCH (n:`" . $model->name . "`) RETURN n LIMIT 25";
     $query = new Everyman\Neo4j\Cypher\Query($this->client, $queryString);
     $results = $query->getResultSet();
     $data = array();
     foreach ($results as $result) {
         $res = array();
         // Model fields
         foreach ($model->schema as $key => $value) {
             $res[$model->name][$key] = $result['n']->getProperty($key);
         }
         $data[] = $res;
     }
     return array($model->alias => $data);
 }
    public static function show(Inputter $inputter, JSONOutputter $outputter)
    {
        //	Show
        //
        $id = $inputter->additional_uri_arguments[0];
        $error = null;
        UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $id, $error);
        if (isset($error)) {
            $outputter->print_error($error);
        }
        //	User ID
        //
        $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789);
        $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq');
        $query_string = 'MATCH (object:Album)
						 WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . ' = \'' . $id . '\'
						 RETURN object';
        $query = new Everyman\Neo4j\Cypher\Query($client, $query_string);
        $result = $query->getResultSet();
        if (count($result) > 0) {
            //	Compare sent data is equal to data retrieved
            //
            $object = $result[0]['object'];
            //	Print data
            //
            $outputter->print_data(array(Album::printer_dictionary($object)));
        } 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, 'Album with ID does not exist.');
            $outputter->print_error($error);
        }
    }
Example #4
0
 public static function checkEmailAlreadyExist($email)
 {
     $client = new Everyman\Neo4j\Client('localhost', 7474);
     $queryString = "MATCH (n :USER) WHERE n.email = '" . $email . "' RETURN count (n) as count";
     $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
     $result = $query->getResultSet();
     return $result[0]['count'];
 }
Example #5
0
 public function add()
 {
     $this->load->library('form_validation');
     $data = array();
     //if save button was clicked, get the data sent via post
     if ($this->input->server('REQUEST_METHOD') === 'POST') {
         //form validation
         $this->form_validation->set_rules('current_password', 'current password', 'trim|required');
         $this->form_validation->set_rules('new_password', 'new password', 'trim|required|min_length[5]');
         $this->form_validation->set_rules('confirm_password', 'confirm password', 'trim|required|matches[new_password]');
         $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">x</a><strong>', '</strong></div>');
         //echo $this->form_validation->run(); die('run');
         //if the form has passed through the validation
         if ($this->form_validation->run()) {
             $old_password = $this->input->post('current_password');
             $new_password = $this->input->post('new_password');
             $match = 0;
             $queryMatch = "MATCH user where user:admin and user.password='******' RETURN user;";
             $query = new Everyman\Neo4j\Cypher\Query($this->client, $queryMatch);
             $result = $query->getResultSet();
             foreach ($result as $row) {
                 //echo "<pre>"; print_r($row['user']);
                 if ($row['user']->getProperty('password') == $old_password) {
                     $match = 1;
                 }
             }
             if ($match == 1) {
                 $queryMatch = "MATCH user where user:admin and user.password='******' set user.password='******' RETURN user;";
                 $query = new Everyman\Neo4j\Cypher\Query($this->client, $queryMatch);
                 $result = $query->getResultSet();
                 $data['flash_message'] = TRUE;
             } else {
                 $data['flash_message'] = FALSE;
             }
             /*if($check_oldpass != md5($old_password))
             		{
             			$data['flash_message'] = FALSE;
             		}
             		else
             		{
             			if($this->changepassword_model->change_password($new_password,$this->session->userdata['id']))
             			{
             				$data['flash_message'] = TRUE; 
             			}
             		}*/
         }
     }
     $this->session->set_flashdata('message', 'Password has been changed Successfully.');
     //echo ($this->session->flashdata('message')!='');
     //echo $this->session->flashdata('message'); die;
     redirect(base_url('admin/dashboard/changepassword'));
     //unset($this->_field_data);
     //$this->load->view('includes/header');
     //$this->load->view('admin/changepassword', $data);
     //$this->load->view('includes/footer');
 }
 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)));
 }
Example #7
0
 /**
  * Flush all database records.
  *
  * @return void
  */
 protected function flushDb()
 {
     $connection = (new Stub())->getConnection();
     $client = $connection->getClient();
     // Remove all relationships and related nodes
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n)-[r]-(c) DELETE n,r,c');
     $query->getResultSet();
     // Remove singular nodes with no relations
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n) DELETE n');
     $query->getResultSet();
 }
Example #8
0
 protected function flushDb()
 {
     // Empty all the nodes before seeding
     $connection = (new User())->getConnection();
     $client = $connection->getClient();
     $batch = $client->startBatch();
     // Remove all relationships and related nodes
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n), (m)-[r]-(c) DELETE n,m,r,c');
     $query->getResultSet();
     // Remove singular nodes with no relations
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n) DELETE n');
     $query->getResultSet();
     $batch->commit();
 }
Example #9
0
 public static function getStudentsDetails($sid)
 {
     $client = new Everyman\Neo4j\Client('localhost', 7474);
     $queryString = "MATCH (n :STUDENT) WHERE n.id = '" . $sid . "' RETURN n";
     $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
     $result = $query->getResultSet();
     $arr = array();
     if ($result->count()) {
         $arr = $result[0]['n']->getProperties();
         return $arr;
     } else {
         return false;
     }
 }
Example #10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     NeoEloquent::unguard();
     // Empty all the nodes before seeding
     $connection = (new Role())->getConnection();
     $client = $connection->getClient();
     $batch = $client->startBatch();
     // Remove all relationships and related nodes
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n), (m)-[r]-(c) DELETE n,m,r,c');
     $query->getResultSet();
     // Remove singular nodes with no relations
     $query = new \Everyman\Neo4j\Cypher\Query($client, 'MATCH (n) DELETE n');
     $query->getResultSet();
     $batch->commit();
     $this->call('CmsSectionsSeeder');
     $this->call('RoleAndPermissionsSeeder');
     $this->call('AdminSeeder');
 }
 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);
     }
 }
Example #12
0
 public static function addInternship($input)
 {
     $employer = Self::getEmployersDetails(Session::get('eid'));
     $post = Neo4j::makeNode();
     $date = new DateTime();
     $timestamp = $date->getTimestamp();
     $id = uniqid();
     $post->setProperty('id', $id)->setProperty('title', $input['title'])->setProperty('forThePost', $input['forThePost'])->setProperty('moreInfo', $input['moreInfo'])->setProperty('company', $employer['company'])->setProperty('timestamp', $timestamp)->save();
     $label = Neo4j::makeLabel('POST');
     $post->addLabels(array($label));
     $postDetails = $post->getProperties();
     $client = new Everyman\Neo4j\Client('localhost', 7474);
     $queryString = "MATCH (n: POST {id: '" . $postDetails['id'] . "'}),(m:EMPLOYER {id: '" . $employer['id'] . "'}) CREATE (m)-[r :ADDED]->n";
     $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
     $result = $query->getResultSet();
     if ($post) {
         return $post;
     } else {
         return false;
     }
 }
<?php

// This script php implements
// find all artists listened by a user’s friend but not the user, order them by the
// number of friends listening to them, recommend the top 5
// Include library of functions
include "functions.php";
// connection to neo4j
require 'vendor/autoload.php';
$client = new Everyman\Neo4j\Client('localhost', 7474);
printHeader();
printSearchForm($uid);
echo "<b>User: {$uid} - All Artist Listened by my friends</b><br><br>";
$queryString = "MATCH (u:user {id:{$uid}})-[:ADD_FRIEND_TO]-(:user)-[listen: WEIGHT]-(a:artist)\r\nWHERE NOT (u)-[:WEIGHT]-(a)\r\nWITH a, count(u) as count\r\nRETURN a\r\nORDER BY count desc LIMIT 5";
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result = $query->getResultSet();
foreach ($result as $row) {
    $artist = $client->getNode($row['x']->getId());
    $artistId = $artist->getProperty('id');
    $artistName = $artist->getProperty('name');
    echo "Artist Name: " . $artistName . "</br>";
    printArtistInfo($artistId);
    ?>
	<form action="listen.php" method="post">
	<input type="hidden" name="action" value="addlisten">
	<input type="hidden" name="userId" value="<?php 
    echo $uid;
    ?>
">
	<input type="hidden" name="artistId" value="<?php 
    echo $artistId;
 public static function create(Inputter $inputter, JSONOutputter $outputter)
 {
     //	Create
     //
     //	1) Test all data is available and valid
     //
     //		Availability
     //
     $required_keys = array(LOCATION_KEY_COORDINATE_LATITUDE => '', LOCATION_KEY_COORDINATE_LONGITUDE => '');
     $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'));
     //			Validate input
     //
     $inputter->validate_input($required_keys, $optional_dictionary);
     //		Valid
     //
     $creation_error = null;
     //			Location
     //
     Location::isValid($inputter->variables_array, false, $creation_error);
     //		Print error
     //
     if (isset($creation_error)) {
         $outputter->print_error($creation_error);
         return;
     }
     //	2) Check request we want to process CAN go ahead
     //
     //		Location identification must not exist
     //
     $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789);
     $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq');
     $query_string_check_location = "MATCH (uniqueObject:UniversallyUniqueObject) " . "WHERE uniqueObject." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array[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
     //
     //		Location
     //
     $location_to_create = $client->makeNode();
     $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION]);
     $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_CREATED]);
     $location_to_create->setProperty(UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED, $inputter->variables_array[UNIVERSALLY_UNIQUE_OBJECT_KEY_DATE_UPDATED]);
     $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LATITUDE, $inputter->variables_array[LOCATION_KEY_COORDINATE_LATITUDE]);
     $location_to_create->setProperty(LOCATION_KEY_COORDINATE_LONGITUDE, $inputter->variables_array[LOCATION_KEY_COORDINATE_LONGITUDE]);
     $location_to_create->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);
     }
     //	4) Output results
     //
     $outputter->print_data(array(Location::printer_dictionary($location_to_create)));
 }
 function runNeoQuery($query)
 {
     $time1 = time();
     $this->client = new Everyman\Neo4j\Client();
     $this->client->getTransport()->setAuth("neo4j", "neo4j");
     $query = new Everyman\Neo4j\Cypher\Query($this->client, $query);
     $results = $query->getResultSet();
     $tasks = array();
     foreach ($results as $result) {
         $columns = $result->columns();
         $item = array();
         foreach ($columns as $column) {
             $item[$column] = $result[$column];
         }
         $tasks[] = $item;
     }
     $time2 = time();
     if (!isset($this->timeLog["query_time"])) {
         $this->timeLog["query_time"] = array();
     }
     $this->timeLog["query_time"][] = $time2 - $time1;
     return $tasks;
 }
 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))));
 }
Example #17
0
 public static function getCountOfStudentsAppliedToInternship($id)
 {
     $eid = Session::get('eid');
     $client = new Everyman\Neo4j\Client('localhost', 7474);
     $queryString = "MATCH (s: STUDENT)-[a: APPLIED]-(n: POST {id:'" . $id . "'})-[r:ADDED]-(m:EMPLOYER {id: '" . $eid . "'}) RETURN count (s) as count";
     $query = new Everyman\Neo4j\Cypher\Query($client, $queryString);
     $result = $query->getResultSet();
     if ($result[0]['count']) {
         return true;
     } else {
         return false;
     }
 }
 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);
     }
 }
Example #20
0
 /**
  * 查询
  * @param $queryTemplate
  * @param $timeout
  * @return bool|Everyman\Neo4j\Query\Row|\Everyman\Neo4j\Query|\Everyman\Neo4j\Query\ResultSet
  */
 private function _graph_query($queryTemplate, $timeout = 0)
 {
     try {
         require APPPATH . 'vendor/neo4jphp/bootstrap.php';
         $client = new Everyman\Neo4j\Client(Kohana::config('mining.host'), Kohana::config('mining.port'), array('timeout' => $timeout ? $timeout : Kohana::config('mining.timeout')));
         $query = new Everyman\Neo4j\Cypher\Query($client, $queryTemplate);
         $result = $query->getResultSet();
         return $result;
     } catch (Everyman\Neo4j\Exception $e) {
         //索引不存在或者出现其他异常
         api::log('error', 'query ' . $queryTemplate . ' error! ' . $e->getTraceAsString(), 'graph');
     }
     return false;
 }