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));
 }
 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));
 }
 /**
  * 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');
     });
 }
 /**
  * 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;
 }
Example #5
0
 /**
  * Proxy creation to a cypher query that does what we want
  *
  * @param Client   $client
  * @param Node     $node
  * @param array    $labels
  * @param boolean  $remove
  */
 public function __construct(Client $client, Node $node, $labels, $remove = false)
 {
     if (!$client->hasCapability(Client::CapabilityLabel)) {
         throw new \RuntimeException('The connected Neo4j version does not have label capability');
     }
     $nodeId = $node->getId();
     if (!is_numeric($nodeId)) {
         throw new \InvalidArgumentException("Cannot set labels on an unsaved node");
     }
     if (!$labels) {
         throw new \InvalidArgumentException("No labels given to set on node");
     }
     $labelSet = implode(':', array_map(function ($label) {
         if (!$label instanceof Label) {
             throw new \InvalidArgumentException("Cannot set a non-label");
         }
         $name = str_replace('`', '``', $label->getName());
         return "`{$name}`";
     }, $labels));
     $setCommand = $remove ? 'REMOVE' : 'SET';
     $query = "START n=node({nodeId}) {$setCommand} n:{$labelSet} RETURN labels(n) AS labels";
     $params = array('nodeId' => $nodeId);
     $cypher = new Query($client, $query, $params);
     parent::__construct($client, $cypher);
 }
Example #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;
 }
Example #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');
 }
 /**
  * Start a new database transaction.
  *
  * @return void
  */
 public function beginTransaction()
 {
     ++$this->transactions;
     if ($this->transactions == 1) {
         $this->transaction = $this->neo->beginTransaction();
     }
     $this->fireConnectionEvent('beganTransaction');
 }
Example #9
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}");
     }
 }
Example #10
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);
     };
 }
 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));
 }
Example #12
0
 /**
  * Convert a model to a Node object.
  *
  * @param  \Vinelab\NeoEloquent\Eloquent\Model $model
  * @return \Everyman\Neo4j\Node
  */
 public function asNode(Model $model)
 {
     $node = $this->client->makeNode();
     // If the key name of the model is 'id' we will need to set it properly with setId()
     // since setting it as a regular property with setProperty() won't cut it.
     if ($model->getKeyName() == 'id') {
         $node->setId($model->getKey());
     } else {
         $node->setProperty($model->getKeyName(), $model->getKey());
     }
     return $node;
 }
Example #13
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);
 }
 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));
 }
 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));
 }
<?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) {
Example #17
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();
Example #18
0
{$argv[0]} map
\tDisplay the available points and the connections and distances between them.

{$argv[0]} path <start> <end> [<algorithm>]
\tFind a path from one node to another.
\talgorithm is optional, and can be one of:
\t\toptimal: Find the shortest paths by distance.  Default.
\t\tsimple:  Find the shortest paths by number of nodes.
\t\tall:     Find all paths, regardless of length.


HELP;
    exit(0);
}
$client = new Client();
$intersections = new NodeIndex($client, 'intersections1');
$inters = array('A' => null, 'B' => null, 'C' => null, 'D' => null, 'E' => null, 'F' => null);
$streets = array(array('A', 'B', array('direction' => 'east', 'distance' => 2.1, 'name' => 'AB')), array('A', 'D', array('direction' => 'south', 'distance' => 2.1, 'name' => 'AD')), array('A', 'E', array('direction' => 'south', 'distance' => 3.1, 'name' => 'AE')), array('B', 'A', array('direction' => 'west', 'distance' => 2.1, 'name' => 'AB')), array('B', 'C', array('direction' => 'east', 'distance' => 2.1, 'name' => 'BC')), array('B', 'E', array('direction' => 'south', 'distance' => 2.1, 'name' => 'BE')), array('C', 'B', array('direction' => 'west', 'distance' => 2.1, 'name' => 'BC')), array('C', 'F', array('direction' => 'south', 'distance' => 1.1, 'name' => 'CF')), array('D', 'A', array('direction' => 'north', 'distance' => 2.1, 'name' => 'AD')), array('D', 'E', array('direction' => 'east', 'distance' => 2.1, 'name' => 'DE')), array('E', 'D', array('direction' => 'west', 'distance' => 2.1, 'name' => 'DE')), array('E', 'B', array('direction' => 'north', 'distance' => 2.1, 'name' => 'BE')), array('F', 'C', array('direction' => 'north', 'distance' => 1.1, 'name' => 'CF')), array('F', 'E', array('direction' => 'west', 'distance' => 2.1, 'name' => 'FE')));
$turns = array('east' => array('north' => 'left', 'south' => 'right', 'west' => 'u-turn'), 'west' => array('north' => 'right', 'south' => 'left', 'east' => 'u-turn'), 'north' => array('east' => 'right', 'west' => 'left', 'south' => 'u-turn'), 'south' => array('east' => 'left', 'west' => 'right', 'north' => 'u-turn'));
// Initialize the data
if ($cmd == 'init') {
    echo "Initializing data.\n";
    foreach ($inters as $inter => $temp) {
        $node = $client->makeNode()->setProperty('name', $inter)->save();
        $intersections->add($node, 'name', $node->getProperty('name'));
        $inters[$inter] = $node;
    }
    foreach ($streets as $info) {
        $start = $inters[$info[0]];
        $end = $inters[$info[1]];
<?php

require __DIR__ . '/vendor/autoload.php';
use Everyman\Neo4j\Client;
$client = new Client('localhost', 7474);
print_r($client->getServerInfo());
 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));
 }
 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));
 }
Example #22
0
\tInitialize the data.  This only needs to be done once.

{$argv[0]} parts
\tDisplay the available parts in the system.

{$argv[0]} stores <part> [<language>]
\tFind all the stores where the given part was sold.
\tLanguage can be one of:
\t\ttraverse: use the javascript traversal. Default.
\t\tcypher: use a cypher query


HELP;
    exit(0);
}
$client = new Client();
$partsIndex = new NodeIndex($client, 'parts3');
$parts = array('widget', 'gadget', 'gizmo');
$stores = array("Bob's Old Houseware", "Mainstreet Hardware", "Nutz N' Boltz", "Doodad Emporium");
// Store, part list
$orders = array(array(0, array(0, 1)), array(0, array(1)), array(1, array(1, 2)), array(1, array(0, 2)), array(2, array(0, 1, 2)), array(3, array(2)), array(3, array(0)));
// Initialize the data
if ($cmd == 'init') {
    echo "Initializing data.\n";
    $p = array();
    $s = array();
    foreach ($parts as $part) {
        $node = $client->makeNode()->setProperty('name', $part)->save();
        $partsIndex->add($node, 'name', $node->getProperty('name'));
        $p[] = $node;
    }
Example #23
0
 /**
  * @param string $query
  * @return \Everyman\Neo4j\Query\ResultSet
  */
 public function executeQuery($query)
 {
     return $this->client->executeCypherQuery(new Query($this->client, $query));
 }
Example #24
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);
 }
Example #25
0
 /**
  * @param array $r
  */
 private function deleteRelationship($r)
 {
     if ($relationship = $this->client->getRelationship(basename($r['self']))) {
         $relationship->delete();
     }
 }
Example #26
0
 public function getClient()
 {
     $client = new Client();
     $client->getTransport()->setAuth('neo4j', 'ubuntu');
     return $client;
 }
Example #27
0
#!/usr/bin/env php
<?php 
use Everyman\Neo4j\Client, Everyman\Neo4j\Index\NodeIndex, Everyman\Neo4j\Index\RelationshipIndex, Everyman\Neo4j\Index\NodeFulltextIndex, Everyman\Neo4j\Node, Everyman\Neo4j\Batch;
require_once 'example_bootstrap.php';
$client = new Client();
$actorIndex = new NodeIndex($client, 'actors');
$roleIndex = new RelationshipIndex($client, 'roles');
$plotIndex = new NodeFulltextIndex($client, 'plots');
$plotIndex->save();
$leslie = $client->makeNode()->setProperty('name', 'Leslie Nielsen')->save();
$airplane = $client->makeNode()->setProperty('title', 'Airplane')->save();
$rumack = $leslie->relateTo($airplane, 'PLAYED')->setProperty('character', 'Dr. Rumack')->save();
$actorIndex->add($leslie, 'name', $leslie->getProperty('name'));
$roleIndex->add($rumack, 'character', $rumack->getProperty('character'));
$plotIndex->add($airplane, 'synopsis', 'An airplane crew takes ill. Surely the only person capable of landing the plane is an ex-pilot afraid to fly. But don\'t call him Shirley.');
echo $actorIndex->queryOne('name:Leslie*')->getProperty('name') . "\n";
echo $roleIndex->queryOne('character:*u*')->getProperty('character') . "\n";
echo $plotIndex->queryOne('synopsis:lend~0.2')->getProperty('title') . "\n";
 /**
  * @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');
 }
Example #29
0
    echo <<<HELP
Usage:
{$argv[0]}
\tDisplay usage instructions

{$argv[0]} init
\tInitialize the data.  This only needs to be done once.

{$argv[0]} actors <movie_name>
\tGet a list of all actors in the movie.


HELP;
    exit(0);
}
$client = new Client();
$actors = new NodeIndex($client, 'actors');
// Initialize the data
if ($cmd == 'init') {
    $keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();
    $laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();
    $jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();
    $kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();
    $actors->add($keanu, 'name', $keanu->getProperty('name'));
    $actors->add($laurence, 'name', $laurence->getProperty('name'));
    $actors->add($jennifer, 'name', $jennifer->getProperty('name'));
    $actors->add($kevin, 'name', $kevin->getProperty('name'));
    $matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();
    $higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();
    $mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();
    $keanu->relateTo($matrix, 'IN')->save();
Example #30
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');