Exemplo n.º 1
0
 /**
  * Page Dashboard.
  */
 public function dashboard()
 {
     $nbacteurs = Actors::count();
     $nbcommentaires = Comments::count();
     $nbmovies = Movies::count();
     $nbseances = Sessions::count();
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'laravel', 'videos');
     $videos = collect($collection->find()->toArray())->shuffle();
     $collection = new \MongoDB\Collection($manager, 'laravel', 'stats');
     $youtubeinfo = collect($collection->find(['origin' => 'Youtube'])->toArray())->first();
     $collection = new \MongoDB\Collection($manager, 'laravel', 'stats');
     $tweeterinfo = collect($collection->find(['origin' => 'Twitter', 'type' => 'infos'])->toArray())->first();
     $actor = new Actors();
     // Je récpere mon modèle
     $comment = new Comments();
     // Je récpere mon modèle
     $movie = new Movies();
     // Je récpere mon modèle
     $session = new Sessions();
     // Je récpere mon modèle
     $user = new User();
     // Je récpere mon modèle
     $avgacteurs = $actor->getAvgActors();
     $avgnotecommentaire = $comment->getAvgNote();
     $avgnotepresse = $movie->getAvgNotePresse();
     $avghour = $session->getAvgHourDate();
     $seances = $session->getNextSession();
     $users = $user->getLastUsers();
     return view('Main/dashboard', ['avgnotecommentaire' => $avgnotecommentaire->avgnote, 'avgnotepresse' => $avgnotepresse->avgpress, 'avgacteurs' => $avgacteurs->age, 'videos' => $videos, 'video' => $videos[0], 'youtubeinfo' => $youtubeinfo->data, 'tweeterinfo' => $tweeterinfo['data'][0], 'youtubeinfodateupdated' => $youtubeinfo->created, 'tweeterinfodateupdated' => $tweeterinfo['created_at'], 'avghour' => $avghour->avghour, 'nbacteurs' => $nbacteurs, 'nbcommentaires' => $nbcommentaires, 'nbmovies' => $nbmovies, 'nbseances' => $nbseances, 'seances' => $seances, 'users' => $users]);
 }
Exemplo n.º 2
0
 /**
  * List ads
  */
 public function ads()
 {
     $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
     $collection = new \MongoDB\Collection($manager, 'builders', 'ads');
     $result = $collection->find()->toArray();
     $tab = [];
     foreach ($result as $one) {
         $tab[] = $one->bsonSerialize();
     }
     return response()->json($tab);
 }
Exemplo n.º 3
0
$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;
}
try {
    $cursor = $collection->find();
    echo "Find all docs, should be 3, verify 1x USA citizen, 2x Icelandic\n";
    foreach ($cursor as $document) {
        var_dump($document);
    }
Exemplo n.º 4
0
 /**
  * --------------------------------------------------------------------------------
  * // Get
  * --------------------------------------------------------------------------------
  *
  * Get the documents based upon the passed parameters
  *
  * @usage : $this->mongo_db->get('foo');
  */
 public function get($collection = "")
 {
     if (empty($collection)) {
         show_error("In order to retrieve documents from MongoDB, a collection name must be passed", 500);
     }
     try {
         $options = ['limit' => (int) $this->limit, 'skip' => (int) $this->offset, 'sort' => $this->sorts, 'batchSize' => (int) $this->limit, 'cursorType' => 2, ['projection' => $this->selects]];
         $collection = new MongoDB\Collection($this->connect, $this->config[$this->activate]['database'] . "." . $collection);
         //$this->db->selectCollection($collection);
         $documents = $collection->find($this->wheres, $options);
         $this->explain($documents, $collection);
         // Clear
         $this->_clear();
         $returns = $documents->toArray();
         if ($this->return_as == 'object') {
             return (object) $returns;
         } else {
             return $returns;
         }
     } catch (MongoDB\Driver\Exception\BulkWriteException $e) {
         if (isset($this->debug) == TRUE && $this->debug == TRUE) {
             show_error("MongoDB query failed: {$e->getMessage()}", 500);
         } else {
             show_error("MongoDB query failed.", 500);
         }
     }
 }
Exemplo n.º 5
0
 $coordinates = [
     "north" => "56.97457345228613",
     "south" => "56.9511767654851",
     "west" => "24.115977287292477",
     "east" => "24.20009136199951"
     ];
 */
 //Read coordinates from $_GET variable:
 $coordinates = $_GET;
 $match = null;
 //creat $match variable for MongoDB
 //coordinates must be converted to (double) as in MongoDB records are stored asn double
 // and in PHP coordinates comes as string
 $match = ["lng" => ['$gte' => (double) $coordinates["west"], '$lte' => (double) $coordinates["east"]], "lat" => ['$gte' => (double) $coordinates["south"], '$lte' => (double) $coordinates["north"]]];
 //execute query:
 $cursor = $collection->find($match, []);
 //just convert stdClass to array:
 $iterator = iterator_to_array($cursor);
 $array = json_decode(json_encode($iterator), true);
 //Now build data array and format each record as needed:
 $nodes = [];
 $count = 0;
 foreach ($array as $doc) {
     $r = ["id" => $doc["id"], "type" => "point", "loaded" => true, "name" => $doc["caption"], "population" => (int) $doc["population"], "coordinates" => [(double) $doc["lng"], (double) $doc["lat"]]];
     $nodes[] = $r;
     $count++;
 }
 $chartResult = ['nodes' => $nodes];
 //Use cache control:
 //header("Cache-Control: no-cache");
 header("Cache-Control: private, max-age=300");