当前位置: 首页>>代码示例>>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;未经允许,请勿转载。