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

Source for file GroupRights.php

Documentation is available at GroupRights.php

  1. <?php
  2. require_once 'index.php';
  3. echo '<h3>GroupRights</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. elseif  (empty($groups)) {
  10.     echo 'Run the <strong>Group</strong> test first<br />';
  11.     exit;
  12. }
  13.  
  14. $rights $admin->perm->getRights();
  15. if ($rights === false{
  16.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  17.     print_r($admin->getErrors());
  18. elseif  (empty($rights)) {
  19.     echo 'Run the <strong>Right</strong> test first<br />';
  20.     exit;
  21. }
  22.  
  23.  
  24. for ($i = 0; $i < 20; $i++{
  25.     $right   array_rand($rights);
  26.     $group array_rand($groups);
  27.     $data = array(
  28.         'group_id' => $groups[$group]['group_id'],
  29.         'right_id' => $rights[$right]['right_id']
  30.     );
  31.     $granted $admin->perm->grantGroupRight($data);
  32.  
  33.     if ($granted === false{
  34.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  35.     else {
  36.         echo 'Group <strong>' $groups[$group]['group_id''</strong> was granted the right <strong>'.$rights[$right]['right_id'].'</strong><br />';
  37.     }
  38.     unset($rights[$right]);
  39.     $rights array_values($rights);
  40. }
  41.  
  42. $group array_rand($groups);
  43. $params = array(
  44.     'fields' => array(
  45.         'right_id',
  46.         'right_define_name',
  47.     ),
  48.     'with' => array(
  49.         'group_id' => array(
  50.             'fields' => array(
  51.                 'group_id'
  52.             ),
  53.         ),
  54.     ),
  55.     'filters' => array(
  56.         'group_id' => $groups[$group]['group_id']
  57.     ),
  58.     'limit' => 10,
  59.     'offset' => 0,
  60. );
  61. $allGroupRights $admin->perm->getRights($params);
  62.  
  63. if ($allGroupRights === false{
  64.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  65. elseif (empty($allGroupRights)) {
  66.     echo 'Group <stong>' $groups[$group]['group_id''</strong> had no rights<br />';
  67. else {
  68.     echo '<hr />Here is/are <strong>' count($allGroupRights'</strong> group right(s) for the group <strong>' $groups[$group]['group_id''</strong>:<br />';
  69.     Var_Dump::display($allGroupRights);
  70.     echo '<br />';
  71. }
  72.  
  73. $right   array_rand($rights);
  74. $group array_rand($groups);
  75. $filters = array(
  76.     'right_id' => $rights[$right]['right_id'],
  77.     'group_id' => $groups[$group]['group_id']
  78. );
  79. $removed $admin->perm->revokeGroupRight($filters);
  80.  
  81. if ($removed === false{
  82.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  83.     print_r($admin->getErrors());
  84. else {
  85.     echo 'Removed the right <strong>'.$right.'</strong> on group <strong>'.$group.'</strong><br />';
  86. }
  87.  
  88.  
  89. $group array_rand($groups);
  90. $params = array(
  91.     'fields' => array(
  92.         'right_id'
  93.     ),
  94.     'filters' => array(
  95.         'group_id' => $groups[$group]['group_id']
  96.     )
  97. );
  98. $rights_group $admin->perm->getRights($params);
  99. if ($rights_group === false{
  100.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  101.     print_r($admin->getErrors());
  102. elseif (empty($rights_group)) {
  103.     echo 'Group <strong>' $groups[$group]['group_id''</strong> had no rights<br />';
  104. else {
  105.     $right array_rand($rights_group);
  106.     $data = array('right_level' => 2);
  107.     $filters = array(
  108.         'right_id' => $rights_group[$right]['right_id'],
  109.         'group_id' => $groups[$group]['group_id']
  110.     );
  111.     $updated $admin->perm->updateGroupRight($data$filters);
  112.  
  113.     if ($updated === false{
  114.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  115.         print_r($admin->getErrors());
  116.     else {
  117.         echo 'Updated the right level of <strong>' $groups[$group]['group_id''</strong><br />';
  118.         $params = array(
  119.             'fields' => array(
  120.                 'right_id'
  121.             ),
  122.             'filters' => array(
  123.                 'right_id' => $rights_group[$right]['right_id'],
  124.                 'group_id' => $groups[$group]['group_id']
  125.             )
  126.         );
  127.         $result $admin->perm->getRights($params);
  128.  
  129.         if ($result === false{
  130.             echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  131.             print_r($admin->getErrors());
  132.         elseif (empty($result)) {
  133.             echo 'Nothing was found with the right id <strong>' $rights_group[$right]['right_id''</strong> 
  134.                   and group id <strong>' $groups[$group]['group_id']'</strong><br />';
  135.         else {
  136.             Var_Dump::display($result);
  137.         }
  138.     }
  139. }
  140.  
  141. $params = array(
  142.     'fields' => array(
  143.         'right_id',
  144.     ),
  145.     'with' => array(
  146.         'group_id' => array(
  147.             'fields' => array(
  148.                 'group_id',
  149.                 'right_level',
  150.             )
  151.         ),
  152.     ),
  153. );
  154.  
  155. $allGroups $admin->perm->getRights($params);
  156. echo 'Here are all the group rights after the changes:<br />';
  157. if ($allGroups === false{
  158.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  159.     print_r($admin->getErrors());
  160. elseif (empty($allGroups)) {
  161.     echo 'Found no groups<br />';
  162. else {
  163.     Var_Dump::display($allGroups);
  164. }
  165. echo '<hr />';

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