コード例 #1
0
ファイル: attributes.php プロジェクト: funkyidol/usergrid
 * service which is still available, so for example you would first get the user then once you had the user you create a
 * array that contained the uuid of the user the related collection name and the relationship name then call the api passing in the
 * array but for the default relationships we already have the data that we need to make the api call so that is what
 * I've done.
 * <pre>
 * <?php
 *  $user = Usergrid::users()->findById(['uuid' => '1234abcd']) ;
 *  $device = $user->device;
 * ?>
 * </pre>
 *  That's all you need to do to get a device for the user this only works when you have one user in your user collection
 *  if you call this with more then one user in your user collection it will return the device for the first user in the
 *  collection.
 *
 */
$user = Usergrid::users()->findById(['uuid' => '1234abcd']);
echo "device" . PHP_EOL;
var_dump($user->device);
var_dump('=================================================================');
echo "roles" . PHP_EOL;
var_dump($user->roles);
var_dump('=================================================================');
echo "groups" . PHP_EOL;
var_dump($user->groups);
var_dump('=================================================================');
echo "connections" . PHP_EOL;
var_dump($user->connections);
var_dump('=================================================================');
var_dump('=================================================================');
echo "GROUPS" . PHP_EOL;
var_dump('=================================================================');
コード例 #2
0
ファイル: users.php プロジェクト: funkyidol/usergrid
    //    var_dump($user['uuid']); // as array
}
// find user by query
$find_user_by_query = Usergrid::users()->find(['ql' => "select * where email='*****@*****.**'"]);
var_dump($find_user_by_query->entities->fetch('uuid'));
$find_user_by_uuid = Usergrid::users()->findById(['uuid' => $find_user_by_query->entities->fetch('uuid')->first()]);
var_dump($find_user_by_uuid->entities);
// AS all results as PHP Collections and the entities property is always returned as a PHP Collection you can fetch nested records
$user_addr = Usergrid::users()->findById(['uuid' => 'Jason']);
echo $user_addr->entities->fetch('adr.addr1');
//or
echo $user_addr->entities->fetch('adr.city');
// get users device URL -- nested fetch on php collection
$users_nested = Usergrid::users()->all();
var_dump($users_nested->entities->fetch('metadata.collections.devices')->first());
// The response that is returned is a PHP collection that has a Zero indexed $item property.
// but as its a collection class it has some methods that can help you find what you need and one
// of my fav feature is changing the Zero indexed collection to be indexed by the entity uuid or name or any other property.
$users_by = Usergrid::users()->all();
$users_by_uuid = $users_by->entities->keyBy('uuid');
var_dump($users_by_uuid->get('add uuid of user'));
$users_by_name = $users_by->entities->keyBy('username');
var_dump($users_by_name->get('jasonk'));
$users_by_email = $users_by->entities->keyBy('email');
var_dump($users_by_email->get('*****@*****.**'));
// sort by key
$sorted_by_email = $users_by->sortBy('username');
var_dump($sorted_by_email);
// add user to group
//$user_to_group = Usergrid::groups()->addUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
//$user_remove_group = Usergrid::groups()->removeUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
コード例 #3
0
ファイル: examples.php プロジェクト: funkyidol/usergrid
$fUser = Usergrid::users()->find(['ql' => 'select * where activated=true']);
$fUser_iterator = Usergrid::usersIterator();
foreach ($fUser_iterator as $iUser) {
    var_dump($iUser);
    var_dump("---------------------------------------------------------------------------------");
}
// create new user
$fNew_user = ['name' => 'jasonk', 'username' => 'JasonK2', 'email' => '*****@*****.**', 'password' => 'some_password'];
$fCreated_user = Usergrid::users()->create($fNew_user);
//var_dump($fCreated_user->entities);
//Update Users by name or uuid
$fNew_email = ['email' => 'jason@example', 'entity_name_or_uuid' => 'benn'];
$fUpdated_user = Usergrid::users()->update($fNew_email);
//var_dump($fUpdated_user->entities);
// delete a user
$fDeleted_user = Usergrid::users()->delete(['entity_name_or_uuid' => 'benn']);
//var_dump($fDeleted_user->entities);
//get custom collection
$fCustom_collection = Usergrid::application()->EntityGet(['collection' => 'shops']);
//var_dump($custom_collection->get('entities'));
//get custom collection with query
$fCustom_collection_query = Usergrid::application()->EntityGet(['collection' => 'shops', 'ql' => "select * where country='aus'"]);
//var_dump($custom_collection_query->get('name'));
// Post custom collection as JSON data
$fCustom_entity = ['collection' => 'shops', 'name' => 'shop_name3', 'adr' => ['street' => '1 main st', 'location' => 'sydney', 'post_code' => '2323'], 'type' => 'pet_shop'];
$fCreated_entity = Usergrid::applictions()->EntityJsonPost($custom_entity);
//var_dump($fCreated_entity->entities);
// update entity
$fCustom_entity_edit = ['collection' => 'shops', 'entity_name_or_uuid' => 'shop_name2', ['adr' => ['street' => '3 main st', 'location' => 'act', 'post_code' => '3323']]];
$fEdited_entity = Usergrid::applications()->EntityPut($fCustom_entity_edit);
//var_dump($fEdited_entity->entities);
コード例 #4
0
 */
$config = ['usergrid' => ['url' => 'https://api.usergrid.com', 'version' => '1.0.1', 'orgName' => '', 'appName' => '', 'manifestPath' => null, 'clientId' => '', 'clientSecret' => '', 'username' => '', 'password' => '', 'auth_type' => 'organization', 'grant_type' => 'client_credentials', 'enable_oauth2_plugin' => true]];
$bootstrapper = new UsergridBootstrapper($config);
Usergrid::instance($bootstrapper);
// call user by page size 20
$users_paged = Usergrid::users()->all();
var_dump(get_class($users_paged->entities));
//// get user 50 page size
$users_paged_50 = Usergrid::users()->all(['limit' => 50]);
var_dump($users_paged_50->entities);
// get all users
$all_users = Usergrid::usersIterator();
foreach ($all_users as $user) {
    //    var_dump($user['uuid']); // as array
}
// find user by query
$find_user_by_query = Usergrid::users()->find(['ql' => "select * where email='*****@*****.**'"]);
var_dump($find_user_by_query->entities->fetch('uuid'));
$find_user_by_uuid = Usergrid::users()->findById(['uuid' => $find_user_by_query->entities->fetch('uuid')->first()]);
var_dump($find_user_by_uuid->entities);
// AS all results as PHP Collections and the entities property is always returned as a PHP Collection you can fetch nested records
$user_addr = Usergrid::users()->findById(['uuid' => 'Jason']);
echo $user_addr->entities->fetch('adr.addr1');
//or
echo $user_addr->entities->fetch('adr.city');
// get users device URL -- nested fetch on php collection
$users_nested = Usergrid::users()->all();
var_dump($users_nested->entities->fetch('metadata.collections.devices')->first());
// add user to group
//$user_to_group = Usergrid::groups()->addUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);
//$user_remove_group = Usergrid::groups()->removeUser(['entity_name_or_uuid' => 'group_name_or_uuid', 'user_name_or_uuid' => 'user name or uuid']);