예제 #1
0
 public function prepareExplorer()
 {
     $m = new Mongo();
     $r['databases'] = $m->_listdb();
     //var_dump($r);
     foreach ($r['databases']['list'] as $database) {
         $r['databases'][$database['name']]['collection'] = $m->_listCollection($database['name']);
     }
     return $r;
 }
예제 #2
0
 public function api(Application $app, $action = null, $database = null, $collection = null, Request $request)
 {
     $result = array();
     $allget = $request->query->all();
     $debug = true;
     if ($debug == false) {
     }
     foreach ($allget as $key => $value) {
         if (is_numeric($value)) {
             settype($allget[$key], 'integer');
         }
     }
     $m = new Mongo();
     //if ($request->isMethod('POST')) {
     switch ($action) {
         case 'search':
             $result['message'] = true;
             if (empty($database)) {
                 $result['result'] = $this->search();
             } else {
                 if (empty($collection)) {
                     $result['result'] = $this->search($database);
                 } else {
                     $result['result'] = $this->search($database, $collection, $allget);
                 }
             }
             break;
         case 'create':
             $array = $allget;
             $array['action'] = 'create';
             $array['database'] = $database;
             $array['collection'] = $collection;
             $result = $m->MongoObject($array);
             break;
         case 'drop':
             $array = $allget;
             $array['action'] = 'drop';
             $array['database'] = $database;
             $array['collection'] = $collection;
             $result = $m->MongoObject($array);
             break;
         case 'insert':
             //$array=$allget;
             $array['action'] = 'insert';
             $array['database'] = $database;
             $array['collection'] = $collection;
             $array['data'] = json_encode($allget['data']);
             $result = $m->MongoObject($array);
             break;
         case 'update':
             //valeur obligatoire;
             $array['action'] = 'update';
             $array['database'] = $database;
             $array['collection'] = $collection;
             $array['data'] = json_decode($allget['data'], true);
             //valeur par défaut
             if (!empty($allget['_id'])) {
                 $array['search']['_id'] = $allget['_id'];
             } else {
                 $array['search'] = json_encode($allget['search']);
             }
             if (!empty($allget['options'])) {
                 $array['options'] = json_decode($allget['options'], true);
             } else {
                 $array['options'] = array();
             }
             $result = $m->MongoObject($array);
             break;
         case 'delete':
             $array = $allget;
             $array['action'] = 'delete';
             $array['database'] = $database;
             $array['collection'] = $collection;
             if (!empty($allget['_id'])) {
                 $array['search']['_id'] = $allget['_id'];
             } else {
                 $array['search'] = json_encode($allget['search'], true);
             }
             $result = $m->MongoObject($array);
             break;
         default:
             $result = array('message' => 'bad action');
     }
     //}
     /**else {
            $result = array('message' => 'false');
        }**/
     return $app['twig']->render('page/json_template.twig', array('json' => $result));
 }
예제 #3
0
 private function prepareview()
 {
     $m = new Mongo();
     $config = $m->MongoObject(array('action' => 'prepareview'));
     return $config;
 }