當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DB::collection方法代碼示例

本文整理匯總了PHP中DB::collection方法的典型用法代碼示例。如果您正苦於以下問題:PHP DB::collection方法的具體用法?PHP DB::collection怎麽用?PHP DB::collection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DB的用法示例。


在下文中一共展示了DB::collection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: store

 /**
  * Store to the database the given entities as entities decendent from the given
  * document.
  * 
  * @param $document Parent document -- Must be a document entity on the database.
  * @param $entities List of entities to be created as decendents from the given document. 
  * 
  * @return multitype:string A status array containing the result status information.
  */
 public function store($document, $entities)
 {
     $nEnts = count($entities);
     if ($nEnts <= 0 && $nEnts >= 10000) {
         // We will have problems processing empty files or more than 10,000 entities
         return ['error' => 'Unable to process files with more than 10,000 lines: ' . $nEnts . 'found'];
     }
     $activity = new Activity();
     $activity->softwareAgent_id = $this->softwareComponent->_id;
     $activity->save();
     $format = $document['format'];
     $domain = $document['domain'];
     $docType = $document['documentType'] . '-sentence';
     $title = $document['title'];
     $parentId = $document['_id'];
     $project = $document['project'];
     $activityId = $activity->_id;
     if (Auth::check()) {
         $userId = Auth::user()->_id;
     } else {
         $userId = "crowdwatson";
     }
     $idBase = 'entity/' . $format . '/' . $domain . '/' . $docType . '/';
     $inc = $this->getLastDocumentInc($format, $domain, $docType);
     $fullEntities = [];
     foreach ($entities as $entitiy) {
         $fullEntity = ["_id" => $idBase . $inc, "documentType" => 'unit', "activity_id" => $activityId, "softwareAgent_id" => $this->softwareComponent->_id, "project" => $project, "user_id" => $userId, "type" => $docType, "unitParents" => [$parentId], "jobParents" => [], "children" => [], "judgements" => [], "metrics" => [], "source" => '', "format" => $format, "title" => strtolower($title), "domain" => $domain, "tags" => ['unit'], "content" => $entitiy, "hash" => md5(serialize($entitiy)), "updated_at" => new MongoDate(time()), "created_at" => new MongoDate(time())];
         $inc++;
         array_push($fullEntities, $fullEntity);
     }
     \DB::collection('entities')->insert($fullEntities);
     \MongoDB\Temp::truncate();
     return ['success' => 'Sentences created successfully'];
 }
開發者ID:harixxy,項目名稱:CrowdTruth,代碼行數:43,代碼來源:TextSentencePreprocessor.php

示例2: up

 public function up()
 {
     $appColl = \DB::collection('applications');
     $appColl->where('users', ['$elemMatch' => ['role' => 'admin', 'scope' => ['$nin' => ['update_consumers']]]])->update(['$push' => ['users.$.scope' => 'update_consumers']]);
     $tables = [];
     foreach (\DB::collection('tables')->get() as $table) {
         $tables[(string) $table['_id']] = $table['applications'];
     }
     $bulk = new MongoDB\Driver\BulkWrite();
     $manager = new MongoDB\Driver\Manager(sprintf('mongodb://%s:%s', env('DB_HOST'), env('DB_PORT')));
     $skip = 0;
     $limit = 200;
     while ($decisions = \DB::collection('decisions')->limit($limit)->skip($skip)->get()) {
         if (!$decisions) {
             break;
         }
         foreach ($decisions as $decision) {
             $applications = [];
             if (array_key_exists('table_id', $decision)) {
                 $applications = array_key_exists((string) $decision['table_id'], $tables) ? $tables[(string) $decision['table_id']] : [];
             } elseif (array_key_exists('table', $decision)) {
                 $applications = array_key_exists((string) $decision['table']['_id'], $tables) ? $tables[(string) $decision['table']['_id']] : [];
             }
             $bulk->update(['_id' => $decision['_id']], ['$set' => ['applications' => $applications]]);
         }
         $skip += $limit;
         $manager->executeBulkWrite(env('DB_DATABASE') . '.decisions', $bulk);
     }
 }
開發者ID:Nebo15,項目名稱:gandalf.api,代碼行數:29,代碼來源:2016_05_26_175042_DecisionApplicationable.php

示例3: down

 public function down()
 {
     $tables = \DB::collection('tables')->get();
     foreach ($tables as $table) {
         $variant = $table['variants'][0];
         \DB::collection('tables')->where('_id', strval($table['_id']))->update(['$set' => ['rules' => $variant['rules'], 'default_title' => $variant['default_title'], 'default_decision' => $variant['default_decision'], 'default_description' => $variant['default_description']], '$unset' => ['variants' => null, 'variants_probability' => null]]);
     }
     \DB::collection('decisions')->update(['$unset' => ['table.variant' => null]], ['multiple' => true]);
 }
開發者ID:Nebo15,項目名稱:gandalf.api,代碼行數:9,代碼來源:2016_05_26_180242_AddTableVariants.php

示例4: getEntities

 protected function getEntities()
 {
     $documents = DB::collection('text')->get();
     $entities = array();
     foreach ($documents as $document) {
         $entityID = $document['_id'];
         unset($document['_id']);
         array_push($entities, array($entityID => $document));
     }
     return $entities;
 }
開發者ID:harixxy,項目名稱:CrowdTruth,代碼行數:11,代碼來源:ProvenanceController.php

示例5: run

 public function run()
 {
     $config = app()->make('config');
     $user = DB::collection('users')->first();
     DB::table("oauth_clients")->delete();
     DB::table("oauth_client_endpoints")->delete();
     DB::table("oauth_clients")->insert(['id' => $config->get('secrets.client_id'), 'secret' => $config->get('secrets.client_secret'), 'name' => 'Gemini', 'user_id' => $user['_id']]);
     // DB::table("oauth_client_endpoints")->insert([
     //     'client_id' => $config->get('secrets.client_id'),
     //     'redirect_uri' => $config->get('secrets.redirect_uri')
     // ]);
 }
開發者ID:remusb,項目名稱:gemini,代碼行數:12,代碼來源:OAuthSeeder.php

示例6: statementDays

 /**
  * Get a count of all the days from the first day a statement was submitted to Lrs.
  *
  * @return $days number
  *
  **/
 private function statementDays()
 {
     $firstStatement = \DB::collection('statements')->where('lrs._id', $this->lrs)->orderBy("timestamp")->first();
     if ($firstStatement) {
         $firstDay = date_create(gmdate("Y-m-d", strtotime($firstStatement['statement']['timestamp'])));
         $today = date_create(gmdate("Y-m-d", time()));
         $interval = date_diff($firstDay, $today);
         $days = $interval->days + 1;
         return $days;
     } else {
         return '';
     }
 }
開發者ID:jesposito,項目名稱:learninglocker,代碼行數:19,代碼來源:LrsDashboard.php

示例7: testCache

 public function testCache()
 {
     User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
     User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
     User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
     $users = DB::collection('users')->where('age', '>', 10)->remember(10)->get();
     $this->assertEquals(3, count($users));
     $users = DB::collection('users')->where('age', '>', 10)->getCached();
     $this->assertEquals(3, count($users));
     $users = User::where('age', '>', 10)->remember(10, 'db.users')->get();
     $this->assertEquals(3, count($users));
     $users = Cache::get('db.users');
     $this->assertEquals(3, count($users));
 }
開發者ID:danielheyman,項目名稱:TechDimeProjects,代碼行數:14,代碼來源:CacheTest.php

示例8: run

 public function run()
 {
     DB::collection('users')->delete();
     /**
      * @var Collection $users
      */
     $users = factory(App\User::class, 25)->create();
     foreach ($users as $user) {
         $friends = $users->diff([$user])->random(2);
         foreach ($friends as $friend) {
             $user->friends()->save($friend);
         }
     }
 }
開發者ID:progjp,項目名稱:rest_api,代碼行數:14,代碼來源:UsersTableSeeder.php

示例9: getAllMember

 public function getAllMember()
 {
     $dbs = new MemberDBS();
     $rd = DB::collection($dbs->getTable())->get();
     $result = array();
     for ($i = 0; $i < count($rd); $i++) {
         $mem = $rd[$i];
         if (array_key_exists('Order', $mem)) {
             $mem = array_except($mem, array('Order', 'updated_at'));
         }
         array_push($result, $mem);
     }
     return Response::json($result);
 }
開發者ID:balmmyy,項目名稱:REST_APIservice,代碼行數:14,代碼來源:MemberController.php

示例10: deleteAll

 public function deleteAll()
 {
     $dbs = new MemberDBS();
     if (DB::collection($dbs->getTable())->delete()) {
         $productDbs = new ProductDBS();
         if (DB::collection($productDbs->getTable())->delete()) {
             return Response::json(array('message' => 'success'));
         } else {
             return Response::json(array('message' => 'error'));
         }
     } else {
         return Response::json(array('message' => 'error'));
     }
 }
開發者ID:balmmyy,項目名稱:REST_APIservice,代碼行數:14,代碼來源:HomeController.php

示例11: up

 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $apps = \DB::collection('applications')->get();
     foreach ($apps as $app) {
         if ($app['users']) {
             $users = [];
             foreach ($app['users'] as $k => $user) {
                 $users[$k] = $user;
                 $users[$k]['user_id'] = new \MongoDB\BSON\ObjectID($user['user_id']);
             }
             \DB::collection('applications')->where('_id', strval($app['_id']))->update(['$set' => ['users' => $users]]);
         }
     }
 }
開發者ID:Nebo15,項目名稱:gandalf.api,代碼行數:19,代碼來源:2016_07_01_101134_fixUserIdIntoApplications.php

示例12: testQueryLog

 public function testQueryLog()
 {
     $this->assertEquals(0, count(DB::getQueryLog()));
     DB::collection('items')->get();
     $this->assertEquals(1, count(DB::getQueryLog()));
     DB::collection('items')->insert(array('name' => 'test'));
     $this->assertEquals(2, count(DB::getQueryLog()));
     DB::collection('items')->count();
     $this->assertEquals(3, count(DB::getQueryLog()));
     DB::collection('items')->where('name', 'test')->update(array('name' => 'test'));
     $this->assertEquals(4, count(DB::getQueryLog()));
     DB::collection('items')->where('name', 'test')->delete();
     $this->assertEquals(5, count(DB::getQueryLog()));
 }
開發者ID:reverserob,項目名稱:laravel-mongodb,代碼行數:14,代碼來源:ConnectionTest.php

示例13: up

 public function up()
 {
     $apps = \DB::collection('applications')->get();
     foreach ($apps as $app) {
         if ($app['users']) {
             $users = [];
             foreach ($app['users'] as $k => $user) {
                 $users[$k] = $user;
                 if ($user['role'] == 'admin') {
                     $users[$k]['scope'] = ['create', 'read', 'update', 'delete', 'check', 'create_consumers', 'delete_consumers', 'update_users', 'add_user', 'edit_project', 'delete_project', 'delete_consumers', 'delete_users'];
                 }
             }
             \DB::collection('applications')->where('_id', strval($app['_id']))->update(['$set' => ['users' => $users]]);
         }
     }
 }
開發者ID:Nebo15,項目名稱:gandalf.api,代碼行數:16,代碼來源:2016_05_19_153914_Scopes.php

示例14: up

 public function up()
 {
     $user = \DB::collection('users')->where('username', 'admin')->first();
     if (!$user) {
         \DB::collection('users')->insert(['username' => 'admin', 'password' => '$2y$10$ur/AJm3FpWyCAAIEEcXQbebvMf0cUuT1dOKHC/.UNc9Z4MLe8mXJO', 'email' => 'admin@admin.com']);
     }
     $user = \DB::collection('users')->where('username', 'admin')->first();
     $applicationsCollection = \DB::collection('applications');
     $application = $applicationsCollection->where('title', 'migrated')->first();
     if (!$application) {
         $applicationsCollection->insert(['title' => 'migrated', 'description' => '', 'users' => [['user_id' => (string) $user['_id'], 'role' => 'admin', 'scope' => ['create', 'read', 'update', 'delete', 'check', 'create_consumers', 'delete_consumers', 'update_users', 'add_user', 'edit_project', 'delete_project', 'delete_consumers', 'delete_users']]], 'consumers' => []]);
     }
     $application = $applicationsCollection->where('title', 'migrated')->first();
     $application_id = (string) $application['_id'];
     \DB::collection('tables')->where('applications', ['$exists' => false])->update(['$set' => ['applications' => [$application_id]]], ['multiple' => true]);
     \DB::collection('groups')->where('applications', ['$exists' => false])->update(['$set' => ['applications' => [$application_id]]], ['multiple' => true]);
 }
開發者ID:Nebo15,項目名稱:gandalf.api,代碼行數:17,代碼來源:2016_05_18_115733_Applicationable.php

示例15: testDeprecatedRemind

 public function testDeprecatedRemind()
 {
     $mailer = Mockery::mock('Illuminate\\Mail\\Mailer');
     $this->app->instance('mailer', $mailer);
     $user = User::create(array('name' => 'John Doe', 'email' => 'john@doe.com', 'password' => Hash::make('foobar')));
     $mailer->shouldReceive('send')->once();
     Password::remind(array('email' => 'john@doe.com'));
     DB::collection('password_reminders')->update(array('created_at' => new DateTime()));
     $reminder = DB::collection('password_reminders')->first();
     $this->assertTrue(is_array($reminder['created_at']));
     $credentials = array('email' => 'john@doe.com', 'password' => 'foobar', 'password_confirmation' => 'foobar', 'token' => $reminder['token']);
     $response = Password::reset($credentials, function ($user, $password) {
         $user->password = Hash::make($password);
         $user->save();
     });
     $this->assertEquals('reminders.reset', $response);
     $this->assertEquals(0, DB::collection('password_reminders')->count());
 }
開發者ID:danielheyman,項目名稱:TechDimeProjects,代碼行數:18,代碼來源:AuthTest.php


注:本文中的DB::collection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。