/**
  * Create a new Neo4j client
  *
  * @return Everyman\Neo4j\Client
  */
 public function createConnection()
 {
     $client = new NeoClient($this->getHost(), $this->getPort());
     $client->getTransport()->setAuth($this->getUsername(), $this->getPassword());
     $client->getTransport()->useHttps(true);
     return $client;
 }
예제 #2
0
 public function logoutDonatur(Request $request)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $donaturId = $request->input('donaturId');
     $status = 'failed';
     if (count($donaturId) > 0) {
         $node = $client->getNode($donaturId);
         if (count($node) > 0) {
             $labels = $node->getLabels();
             $labelName = $labels[0]->getName();
             if ($labelName == HelperController::getLabelDonatur()) {
                 $node->setProperty('gcmId', '')->setProperty('isLogin', 0)->save();
                 $status = 'success';
             } else {
                 $status = 'failed, label not match check your id';
             }
         } else {
             $status = 'failed, nothing to return check your id';
         }
     } else {
         $status = 'failed, id is empty check your id';
     }
     return response()->json(array('status' => $status));
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     // Register 'neo4j' instance container to our 'neo4j' object
     $this->app['neo4j'] = $this->app->share(function ($app) {
         // connection credentials loaded from config
         // if neo4j key exists in database.php config use this one
         if (Config::get('database.neo4j') != null) {
             $host = Config::get('database.neo4j.default.host');
             $port = Config::get('database.neo4j.default.port');
             $username = Config::get('database.neo4j.default.username');
             $password = Config::get('database.neo4j.default.password');
             // esle try to find config in packages configs
         } else {
             $host = Config::get('neo4j-4-laravel::default.host');
             $port = Config::get('neo4j-4-laravel::default.port');
             $username = Config::get('neo4j-4-laravel::default.username');
             $password = Config::get('neo4j-4-laravel::default.password');
         }
         // create mew neo4j node
         $neo4j = new Client($host, $port);
         $neo4j->getTransport()->setAuth($username, $password);
         // return pusher
         return $neo4j;
     });
     // Shortcut so developers don't need to add an Alias in app/config/app.php
     $this->app->booting(function () {
         $loader = AliasLoader::getInstance();
         $loader->alias('Neo4j', 'Artdarek\\Neo4j\\Facades\\Neo4j');
     });
 }
 public function getNotifikasi($id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $status = 'failed';
     $properties = array();
     $result = array();
     if (count($id) > 0) {
         $cypher = 'MATCH (n:Notifikasi) where n.donaturId="' . $id . '" RETURN n LIMIT 100';
         $query = new Query($client, $cypher);
         $nodes = $query->getResultSet();
         if (count($nodes) > 0) {
             $status = 'success';
             foreach ($nodes as $node) {
                 $properties['id'] = $node['r']->getId();
                 $properties['properties'] = $node['r']->getProperties();
                 array_push($result, $properties);
             }
         } else {
             $status = 'failed, return value is empty check your donatur id';
         }
     } else {
         $status = 'failed, notifikasi id is empty please check your parameter';
     }
     return response()->json(array('status' => $status, 'data' => $result));
 }
예제 #5
0
 public function run()
 {
     $neo4j_config = \Config::get('database.connections.neo4j');
     // Create an admin user
     $client = new Everyman\Neo4j\Client($neo4j_config['host'], $neo4j_config['port']);
     $client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);
     foreach ($this->listNames as $listName) {
         $labels = [$client->makeLabel('E32'), $client->makeLabel('AuthorityDocument'), $client->makeLabel('MEDEA_NODE')];
         $nameLabel = $client->makeLabel($listName);
         $labels[] = $nameLabel;
         // Avoid duplicates
         $duplicates = $nameLabel->getNodes();
         foreach ($duplicates as $duplicate) {
             $relationships = $duplicate->getRelationships();
             foreach ($relationships as $rel) {
                 $rel->delete();
             }
             $this->command->info("Found duplicate for {$listName}, deleting it first in order to reseed.");
             $duplicate->delete();
         }
         $node = $client->makeNode();
         $node->save();
         $node->addLabels($labels);
         $functionName = 'get' . $listName;
         $node->setProperty('values', $this->{$functionName}());
         $node->save();
         $this->command->info("Seeded node, {$listName}");
     }
 }
예제 #6
0
 protected function getClient()
 {
     $neo4j_config = \Config::get('database.connections.neo4j');
     // Create a new client with user and password
     $client = new Client($neo4j_config['host'], $neo4j_config['port']);
     $client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);
     return $client;
 }
예제 #7
0
 private function getPersonLabel()
 {
     $neo4j_config = \Config::get('database.connections.neo4j');
     // Create an admin
     $client = new Client($neo4j_config['host'], $neo4j_config['port']);
     $client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);
     // Set a label configured client, equivalent of only returning a certain eloquent model
     return $client->makeLabel('E21');
 }
예제 #8
0
 public function __construct(array $settings = [])
 {
     parent::__construct($settings);
     $this['view'] = function ($container) {
         return new \Slim\Views\JsonView();
     };
     $this['log'] = function ($container) {
         return new \App\Service\Logger();
     };
     $this['errorHandler'] = function ($container) {
         return new \App\Handlers\Error($container['log']);
     };
     $this['friendship'] = function ($container) {
         $client = new Client(NEO4J_HOST, NEO4J_PORT);
         $client->getTransport()->setAuth(NEO4J_LOGIN, NEO4J_PASSWORD);
         return new \App\Service\Friendship($client);
     };
 }
예제 #9
0
 public function createDonatur(Request $request)
 {
     // $Book = Book::create($request->all());
     $client = new Client('localhost', 7474);
     $client->getTransport()->setAuth('neo4j', 'soulmate');
     $transaction = $client->beginTransaction();
     // Add a single query to a transaction, $result is a single ResultSet object
     $label = 'Muzakki';
     $param = 'nanda';
     $cypher = 'CREATE (n:' . $label . ' {username:"******",password:"******"}) return n';
     $query = new Query($client, $cypher);
     $result = $query->getResultSet();
     $status = 'failed';
     if ($transaction->commit()) {
         $status = 'success';
     }
     return response()->json(array('status' => $status));
 }
예제 #10
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $neo4j_config = \Config::get('database.connections.neo4j');
     // Create an admin
     $client = new Everyman\Neo4j\Client($neo4j_config['host'], $neo4j_config['port']);
     $client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);
     // Check if the admin user already exists, if not create one.
     // Use the Person label, as described by the vocabulary the MEDEA project handles
     // Get the Person label
     $label = $client->makeLabel('Person');
     // Get all of the Person node with the admin email
     $nodes = $label->getNodes("email", "*****@*****.**");
     if ($nodes->count() == 0) {
         $users = new UserRepository();
         $admin = ['firstName' => 'Medea', 'lastName' => 'Admin', 'password' => 'foobar', 'email' => '*****@*****.**', 'verified' => true, 'description' => 'Dit is de generieke admin user van het MEDEA platform.', 'personType' => ['detectorist', 'validator', 'administrator', 'registrator', 'onderzoeker', 'vondstexpert'], 'showContactInfo' => 'never', 'passContactInfoToAgency' => false];
         $users->store($admin);
         $this->command->info("An admin user was created.");
     } else {
         $this->command->info("The admin user already exists.");
     }
     // Seed the values in the lists of MEDEA
     $this->call(ListValueSeeder::class);
 }
예제 #11
0
파일: Neo4td.php 프로젝트: TeachDate/Neo4td
 public function getClient()
 {
     $client = new Client();
     $client->getTransport()->setAuth('neo4j', 'ubuntu');
     return $client;
 }
예제 #12
0
 public function updateDonatur(Request $request, $id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $username = $request->input('username');
     $email = $request->input('email');
     $nama = $request->input('nama');
     $notelp = $request->input('notelp');
     $imagePath = $request->input('imagePath');
     $gcmId = $request->input('gcmId');
     $status = 'failed';
     if (count($username) > 0 && count($id) > 0) {
         $cypherCek = 'MATCH (n:' . HelperController::getLabelDonatur() . ') where n.username="******" RETURN n';
         $queryCek = new Query($client, $cypherCek);
         $resultCek = $queryCek->getResultSet();
         if (count($resultCek) > 0) {
             $status = 'failed, data already exist';
         } else {
             $node = $client->getNode($id);
             $node->setProperty('username', $username)->setProperty('email', $email)->setProperty('nama', $nama)->setProperty('notelp', $notelp)->setProperty('imagePath', $imagePath)->setProperty('gcmId', $gcmId)->save();
             $status = 'success';
         }
     } else {
         $status = 'failed, username or id is empty please check your parameter';
     }
     return response()->json(array('status' => $status));
 }
예제 #13
0
 public function unvalidasiDonasi($id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $status = 'failed';
     if (count($id) > 0) {
         $nodes = $client->getRelationship($id);
         $properties = array();
         if (count($nodes) > 0) {
             $donaturId = $nodes->getProperty('donaturId');
             $nodeDonatur = $client->getNode($donaturId);
             $gcmId = $nodeDonatur->getProperty('gcmId');
             $status = 'success';
             $nodes->setProperty('isValidate', 2)->save();
         } else {
             $status = 'failed, return value is empty check your donasi id';
         }
     } else {
         $status = 'failed, donasi id is empty';
     }
     return response()->json(array('status' => $status));
 }
예제 #14
0
 /**
  * Make Neo4j Client Connection.
  * 
  * @return Client
  */
 public function makeClient()
 {
     $client = new Client($this->getHost(), $this->getPort());
     $client->getTransport()->setAuth($this->getUsername(), $this->getPassword());
     return $client;
 }
<?php

use Silex\Application, Symfony\Component\HttpFoundation\Request, Everyman\Neo4j\Client, Everyman\Neo4j\Cypher\Query;
require __DIR__ . '/vendor/autoload.php';
$app = new Application();
$app->after(function (Request $request, Symfony\Component\HttpFoundation\Response $response) {
    $response->headers->set('Access-Control-Allow-Origin', '*');
    // header('Access-Control-Allow-Origin: *');
    // header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    // header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
    // header('Access-Control-Allow-Credentials: true');
});
$app['debug'] = true;
$neo4j = new Client();
$neo4j->getTransport()->setAuth('neo4j', 'asdf');
$app->get('/', function () {
    return file_get_contents(__DIR__ . '/static/index.html');
});
$app->get('/graph', function (Request $request) use($neo4j) {
    $limit = (int) $request->get('limit', 50);
    $queryTemplate = <<<QUERY
MATCH (m:Movie)<-[:ACTED_IN]-(a:Person)
 RETURN m.title as movie, collect(a.name) as cast
 LIMIT {limit}
QUERY;
    $cypher = new Query($neo4j, $queryTemplate, array('limit' => $limit));
    $results = $cypher->getResultSet();
    $actors = [];
    $nodes = [];
    $rels = [];
    foreach ($results as $result) {
예제 #16
0
 public function updateMustahiq(Request $request, $id)
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $nama = $request->input('nama');
     $desc = $request->input('desc');
     $tempatLahir = $request->input('tempatLahir');
     $tanggalLahir = $request->input('tanggalLahir');
     $nominal = $request->input('nominal');
     $alamat = $request->input('alamat');
     $latlong = $request->input('latlong');
     $status = $request->input('status');
     $jenjangPendidikan = $request->input('jenjangPendidikan');
     $asalSekolah = $request->input('asalSekolah');
     $alamatSekolah = $request->input('alamatSekolah');
     $namaOrangTua = $request->input('namaOrangTua');
     $alamatOrangTua = $request->input('alamatOrangTua');
     $pekerjaanOrangTua = $request->input('pekerjaanOrangTua');
     $kategori = $request->input('kategori');
     $persentaseBantuan = $request->input('persentaseBantuan');
     $prioritas = $request->input('prioritas');
     $imagePath = $request->input('imagePath');
     $isApproved = $request->input('isApproved');
     $tahunLahir = $request->input('tahunLahir');
     $statusRequest = 'failed';
     if (count($id) > 0) {
         $node = $client->getNode($id);
         $node->setProperty('nama', $nama)->setProperty('desc', $desc)->setProperty('tempatLahir', $tempatLahir)->setProperty('tanggalLahir', $tanggalLahir)->setProperty('alamat', $alamat)->setProperty('latlong', $latlong)->setProperty('status', $status)->setProperty('jenjangPendidikan', $jenjangPendidikan)->setProperty('asalSekolah', $asalSekolah)->setProperty('alamatSekolah', $alamatSekolah)->setProperty('namaOrangTua', $namaOrangTua)->setProperty('alamatOrangTua', $alamatOrangTua)->setProperty('pekerjaanOrangTua', $pekerjaanOrangTua)->setProperty('kategori', $kategori)->setProperty('persentaseBantuan', $persentaseBantuan)->setProperty('prioritas', $prioritas)->setProperty('imagePath', $imagePath)->setProperty('nominal', $nominal)->setProperty('isApproved', $isApproved)->setProperty('tahunLahir', $tahunLahir)->save();
         $statusRequest = 'success';
     }
     return response()->json(array('status' => $statusRequest));
 }
예제 #17
0
<?php

use Silex\Application, Symfony\Component\HttpFoundation\Request, Everyman\Neo4j\Client, Everyman\Neo4j\Cypher\Query;
require __DIR__ . '/vendor/autoload.php';
$app = new Application();
$app->after(function (Request $request, Symfony\Component\HttpFoundation\Response $response) {
    $response->headers->set('Access-Control-Allow-Origin', '*');
    // header('Access-Control-Allow-Origin: *');
    // header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    // header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
    // header('Access-Control-Allow-Credentials: true');
});
$app['debug'] = true;
$neo4j = new Client('52.10.156.36', 7474);
$neo4j->getTransport()->setAuth('neo4j', 'rootpass');
$app->get('/', function () {
    return file_get_contents(__DIR__ . '/static/index.html');
});
$app->get('/graph', function (Request $request) use($neo4j) {
    $limit = (int) $request->get('limit', 50);
    $queryTemplate = <<<QUERY
MATCH (n)-[r]->(p)
 RETURN n.name as name, n.email as email,
\tcollect({email:p.email, name:p.name, frequency:r.frequency, sugar:r.sugarScore}) as knows
\tLIMIT {limit}
QUERY;
    $cypher = new Query($neo4j, $queryTemplate, array('limit' => $limit));
    $results = $cypher->getResultSet();
    $knows = [];
    $nodes = [];
    $rels = [];
예제 #18
0
<?php

require_once 'config.php';
require_once 'vendor/autoload.php';
use Everyman\Neo4j\Client;
use Everyman\Neo4j\Cypher;
$usersCount = 1000;
$client = new Client(NEO4J_HOST, NEO4J_PORT);
$client->getTransport()->setAuth(NEO4J_LOGIN, NEO4J_PASSWORD);
$queryString = "CREATE (n:User { id : 1, name : 'Root User' })";
$query = new Cypher\Query($client, $queryString);
$query->getResultSet();
$queryString = "CREATE CONSTRAINT ON (n:User) ASSERT n.id IS UNIQUE";
$query = new Cypher\Query($client, $queryString);
$query->getResultSet();
$faker = Faker\Factory::create();
for ($i = 2; $i <= $usersCount; $i++) {
    $name = $faker->name;
    $queryString = "CREATE (n:User { id : {$i}, name : \"{$name}\" })";
    $query = new Cypher\Query($client, $queryString);
    $query->getResultSet();
    if (mt_rand(0, 4) > 1) {
        $toUserId = mt_rand(1, $i - 1);
        $queryString = "MATCH (lft { id: {$i} }),(rgt { id: {$toUserId} })\n                    CREATE UNIQUE (lft)-[r:friend]->(rgt)\n                    RETURN r";
        $query = new Cypher\Query($client, $queryString);
        $query->getResultSet();
    } elseif (mt_rand(0, 4) > 3) {
        $toUserId = mt_rand(1, $i);
        $queryString = "MATCH (lft { id: {$i} }),(rgt { id: {$toUserId} })\n                    CREATE UNIQUE (lft)-[r:requestFriendship]->(rgt)\n                    RETURN r";
        $query = new Cypher\Query($client, $queryString);
        $query->getResultSet();
예제 #19
0
});
/**
 * Setting up the view component
 */
$di->setShared('view', function () use($config) {
    $view = new View();
    $view->disable();
    return $view;
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
$di->set('router', function () {
    require __DIR__ . '/routes.php';
    return $router;
});
$di->setShared('redis', function () use($config) {
    $redis = new Redis();
    $redis->connect($config->redis->host, $config->redis->port);
    return $redis;
});
$di->setShared('Neo4jClient', function () use($config) {
    $neo4jClient = new \Everyman\Neo4j\Client($config->neo4j->host, $config->neo4j->port);
    $neo4jClient->getTransport()->setAuth('neo4j', 'toor');
    //        die;
    return $neo4jClient;
});
$di->get('dispatcher')->setDefaultNamespace('FriendsApi\\controllers');
예제 #20
0
 /**
  * @Route("/posts/save/{id}", name="admin_posts_save")
  */
 public function savePostAction(Request $request, $id = null)
 {
     /*
     $em = $this->container->get('neo4j.manager');
     $postRepo = $em->getRepository('AppBundle\\Entity\\Post');
     $authorRepo = $em->getRepository('AppBundle\\Entity\\Author');
     
     $form = $request->request->all();
     
     if($id)
         $post = $postRepo->find($id);
     else
         $post = new Post();
     
     
     $author = $authorRepo->find($form['author']);
     
     $post->setTitle($form['title']);
     $post->setContent($form['content']);
     $post->setAuthor( $author );
     
     $em->persist($post);
     $em->flush();
     */
     $client = new Client();
     $client->getTransport()->setAuth('neo4j', 'password');
     $form = $request->request->all();
     if ($id) {
         $query = new Query($client, "MATCH (n:Post) WHERE n.id = {id} RETURN n", ["id" => $id]);
         $post = $query->getResultSet()->current()['n'];
     }
     if (!$id || !$post) {
         $post = (object) ['id' => null, 'title' => null, 'content' => null, 'author' => null];
     }
     if (!$post->id) {
         // Create new post
         $query = new Query($client, "CREATE n =(post {title:{title}, content:{content}})" . "RETURN n", ["title" => $form['title'], "content" => $form['content']]);
         $post = $query->getResultSet()->current()['n'];
         $query = new Query($client, "MATCH (a:Author),(p:Post)" . "WHERE a.name = {authorName} AND id(p) = {postId}" . "CREATE (a)-[r:AUTHOR {authored_on: {timestamp}}]->(p)" . "RETURN r", ["authorId" => $form['author'], "postId" => $post->getProperty('id'), "timestamp" => strtotime('now')]);
         $relation = $query->getResultSet()->current()['r'];
     } else {
         // Update post
         $query = new Query($client, "MATCH (n {id: {id}})" . "SET n.title = {title}" . "SET n.content = {content}" . "RETURN n");
         $post = $query->getResultSet()->current()['n'];
     }
     return $this->redirectToRoute('admin_posts');
 }
예제 #21
0
 public function getAllDonasi()
 {
     $client = new Client(HelperController::getHost(), HelperController::getPort());
     $client->getTransport()->setAuth(HelperController::getUserNeo4j(), HelperController::getPassNeo4j());
     $status = 'failed';
     $properties = array();
     $result = array();
     $cypher = 'MATCH (DONATUR)-[r:DONASI]->(MUSTAHIQ) RETURN r LIMIT 100';
     $query = new Query($client, $cypher);
     $nodes = $query->getResultSet();
     if (count($nodes) > 0) {
         $status = 'success';
         foreach ($nodes as $node) {
             $properties['id'] = $node['r']->getId();
             $properties['properties'] = $node['r']->getProperties();
             array_push($result, $properties);
         }
     }
     return response()->json(array('status' => $status, 'data' => $result));
 }
예제 #22
0
 /**
  * @param Client $client
  */
 public function __construct(Client $client = null)
 {
     $this->_client = is_null($client) ? new Client(self::NEO4J_HOST, self::NEO4J_PORT) : $client;
     $this->_client->getTransport()->setAuth(self::NEO4J_USER, self::NEO4J_PASS);
 }