LiveUser_Admin
[ class tree: LiveUser_Admin ] [ index: LiveUser_Admin ] [ all elements ]

Source for file UserGroup.php

Documentation is available at UserGroup.php

  1. <?php
  2. require_once 'index.php';
  3. echo '<h3>UserGroup</h3>';
  4.  
  5. $groups $admin->perm->getGroups();
  6. if ($groups === false{
  7.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  8.     print_r($admin->getErrors());
  9.     exit;
  10. elseif  (empty($groups)) {
  11.     echo 'Run the <b>Group</b> test first<br />';
  12.     exit;
  13. }
  14.  
  15. $users $admin->getUsers(array('container' => 'auth'));
  16. if ($users === false{
  17.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  18.     print_r($admin->getErrors());
  19.     exit;
  20. elseif  (empty($users)) {
  21.     echo 'Run the <b>User</b> test first<br />';
  22.     exit;
  23. }
  24. // Add
  25.  
  26. foreach ($groups as $group{
  27.     $rand array_rand($users);
  28.     $result $admin->perm->addUserToGroup(array('perm_user_id' => $users[$rand]['perm_user_id']'group_id' => $group['group_id']));
  29.  
  30.     if ($result === false{
  31.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  32.         print_r($admin->getErrors());
  33.     else {
  34.         echo '<b>' $users[$rand]['name''</b> was added to group <b>' $group['group_id''</b><br />';
  35.     }
  36. }
  37. // Get users from one group
  38. $group array_rand($groups);
  39.  
  40. $params = array(
  41.     'filters' => array(
  42.         'group_id' => $groups[$group]['group_id']
  43.     )
  44. );
  45. $usersGroup $admin->perm->getUsers($params);
  46.  
  47. if ($usersGroup === false{
  48.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  49.     print_r($admin->getErrors());
  50. elseif (empty($usersGroup)) {
  51.     echo 'No users were found for the group id <strong>' $groups[$group]['group_id''</strong>';
  52. else {
  53.     echo 'Perm ID\'s of the users in group <b>' $groups[$group]['group_id''</b><br />';
  54.     Var_Dump::display($usersGroup);
  55.     echo '<br />';
  56. }
  57.  
  58. // Remove user from one group
  59. $group array_rand($groups);
  60. $user array_rand($users);
  61.  
  62. $filters = array(
  63.     'group_id' => $groups[$group]['group_id'],
  64.     'perm_user_id' => $users[$user]['perm_user_id']
  65. );
  66. $removed $admin->perm->removeUserFromGroup($filters);
  67.  
  68. if ($removed === false{
  69.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  70.     print_r($admin->getErrors());
  71. else {
  72.     echo '<b>' $users[$user]['name''</b> was removed from group <b>'.$groups[$group]['group_id'].'</b><br />';
  73. }
  74.  
  75. // Remove user from all his groups
  76. $user array_rand($users);
  77. $filters = array(
  78.     'perm_user_id' => $users[$user]['perm_user_id']
  79. );
  80. $removed $admin->perm->removeUserFromGroup($filters);
  81.  
  82. if ($removed === false{
  83.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  84.     print_r($admin->getErrors());
  85. else {
  86.     echo '<b>' $users[$user]['name''</b> was removed from <b>ALL</b> his groups<br />';
  87. }
  88.  
  89. // Get users from all groups
  90. foreach ($groups as $group{
  91.     $params = array(
  92.         'filters' => array(
  93.             'group_id' => $group['group_id']
  94.         )
  95.     );
  96.     $usersGroup $admin->perm->getGroups($params);
  97.  
  98.     if ($usersGroup === false{
  99.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  100.         print_r($admin->getErrors());
  101.     elseif (empty($usersGroup)) {
  102.         echo 'No users were found for the group id <strong>' $group['group_id''</strong>';
  103.     else {
  104.         echo 'Perm ID\'s of the users in group <b>' $group['group_id''</b><br />';
  105.         Var_Dump::display($usersGroup);
  106.         echo '<br />';
  107.     }
  108. }
  109. echo '<hr />';

Documentation generated on Mon, 11 Mar 2019 15:39:44 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.