Ejemplo n.º 1
2
 public function adAnnounce(Request $request)
 {
     $data = ["name" => $request->name, "email" => $request->email, "phone" => $request->phone, "description" => $request->description, "chambres" => $request->chambres, "pieces" => $request->pieces, "surface" => $request->surface, "prix" => $request->prix, "aid" => $request->aid];
     $file = null;
     $data["email"] = $request->email;
     $input = array('image' => Input::file('image'));
     $rules = array('image' => 'image');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return response()->json(['data' => 'Fichier invalid', 'state' => false]);
     } else {
         if ($request->hasFile('image')) {
             $file = $request->file('image');
             $filename = $file->getClientOriginalName();
             $destinationPath = public_path() . '/uploads/ad';
             $file->move($destinationPath, $filename);
             $data['image'] = asset('uploads/ad/' . $filename);
             $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
             $collection = new \MongoDB\Collection($manager, 'builders', 'ads');
             $stat = ['email' => $request->email, 'data' => $data, 'created' => new \DateTime("now")];
             try {
                 $collection->insertOne($stat);
             } catch (\Exception $e) {
                 return response()->json(['state' => false]);
             }
             return response()->json(['data' => $data, 'state' => true]);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $keyword = $this->argument('keyword');
     $channel = Yt::getChannelByName('allocine');
     if (!empty($channel)) {
         $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $collection->deleteMany([]);
         $collection = new \MongoDB\Collection($manager, 'laravel.stats');
         $stat = ['origin' => 'Youtube', 'type' => 'search', 'data' => $channel, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
         $collection->insertOne($stat);
     }
     $params = ['q' => $keyword, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 30];
     $videos = Yt::searchAdvanced($params, true)['results'];
     if (!empty($videos)) {
         $collection = new \MongoDB\Collection($manager, 'laravel.videos');
         $collection->deleteMany([]);
         foreach ($videos as $video) {
             $collection = new \MongoDB\Collection($manager, 'laravel.videos');
             $stat = ['data' => $video, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     Log::info("Import de l'API Youtube video done! ");
 }
Ejemplo n.º 3
0
 /**
  * Create account
  */
 public function createAccount(Request $request)
 {
     $data = ["name" => $request->name, "cp" => $request->cp, "phone" => $request->phone, "sexe" => $request->sexe, "news" => $request->news];
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'builders', 'account');
     $stat = ['email' => $request->email, 'data' => $data, 'created' => new \DateTime("now")];
     try {
         $collection->insertOne($stat);
     } catch (\Exception $e) {
         return response()->json(['state' => false]);
     }
     $data["email"] = $request->email;
     return response()->json(['data' => $data, 'state' => true]);
 }
Ejemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']);
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'laravel.tweets');
     if (!empty($infos)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'infos']);
         $stat = ['origin' => 'Twitter', 'type' => 'infos', 'data' => $infos, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
         $collection->insertOne($stat);
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'dmsout']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'dmsout', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'favorites']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'favorites', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'mentionstimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'mentionstimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline(['count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'hometimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'hometimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
     $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline(['screen_name' => 'allocine', 'count' => 15, 'format' => 'php']);
     if (!empty($tweets)) {
         $collection->deleteMany(['origin' => 'Twitter', 'type' => 'usertimeline']);
         foreach ($tweets as $tweet) {
             $stat = ['origin' => 'Twitter', 'type' => 'usertimeline', 'data' => $tweet, 'created' => new \MongoDB\BSON\UTCDatetime(time())];
             $collection->insertOne($stat);
         }
     }
 }
Ejemplo n.º 5
0
<?php

require_once __DIR__ . "/bootstrap.php";
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$collection = new MongoDB\Collection($manager, "phplib_demo.write");
$hannes = ["name" => "Hannes", "nick" => "bjori", "citizen" => "Iceland"];
$hayley = ["name" => "Hayley", "nick" => "Ninja", "citizen" => "USA"];
$bobby = ["name" => "Robert Fischer", "nick" => "Bobby Fischer", "citizen" => "USA"];
$kasparov = ["name" => "Garry Kimovich Kasparov", "nick" => "Kasparov", "citizen" => "Russia"];
$spassky = ["name" => "Boris Vasilievich Spassky", "nick" => "Spassky", "citizen" => "France"];
try {
    $result = $collection->insertOne($hannes);
    printf("Inserted _id: %s\n\n", $result->getInsertedId());
    $result = $collection->insertOne($hayley);
    printf("Inserted _id: %s\n\n", $result->getInsertedId());
    $result = $collection->insertOne($bobby);
    printf("Inserted _id: %s\n\n", $result->getInsertedId());
    $count = $collection->count(["nick" => "bjori"]);
    printf("Searching for nick => bjori, should have only one result: %d\n\n", $count);
    $result = $collection->updateOne(["citizen" => "USA"], ['$set' => ["citizen" => "Iceland"]]);
    printf("Updated: %s (out of expected 1)\n\n", $result->getModifiedCount());
    $cursor = $collection->find(["citizen" => "Iceland"], ["comment" => "Excellent query"]);
    echo "Searching for citizen => Iceland, verify Hayley is now Icelandic\n";
    foreach ($cursor as $document) {
        var_dump($document);
    }
    echo "\n";
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}