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

Source for file ImplyRights.php

Documentation is available at ImplyRights.php

  1. <?php
  2. require_once 'index.php';
  3. echo '<h3>ImplyRights</h3>';
  4.  
  5. $rights $admin->perm->getRights();
  6. if  (empty($rights)) {
  7.     echo 'Run the <b>Right</b> test first<br />';
  8.     exit;
  9. }
  10. echo '<hr />';
  11.  
  12. // add
  13. for ($i = 0; $i < 5; $i++{
  14.     $right array_rand($rights);
  15.     $imright array_rand($rights);
  16.     $data = array(
  17.         'right_id' => $rights[$right]['right_id'],
  18.         'implied_right_id' => $rights[$imright]['right_id']
  19.     );
  20.     $result $admin->perm->implyRight($data);
  21.     if ($result === false{
  22.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  23.         print_r($admin->getErrors());
  24.     else {
  25.         echo '<strong>' $rights[$imright]['right_id''</strong> is now
  26.               implied right from <strong>'$rights[$right]['right_id'.'</strong><br />';
  27.     }
  28. }
  29.  
  30. $right_id $rights[$right]['right_id'];
  31. // view all with hierarchy
  32. echo 'All the rights with hierarchy:<br />';
  33. $rights $admin->perm->getRights(array(
  34.     'hierarchy' => true,
  35.     'rekey' => true,
  36.     'fields' => array('*''has_implied'),
  37.     'filters' => array('right_id' => $right_id),
  38. ));
  39. if ($rights === false{
  40.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  41.     print_r($admin->getErrors());
  42. else {
  43.     Var_Dump::display($rights);
  44.     echo '<br />';
  45. }
  46.  
  47. // view all with implied and without hierarchy
  48. echo 'All the rights with implied and without hierarchy:<br />';
  49. $rights $admin->perm->getRights(array(
  50.     'implied' => true,
  51.     'rekey' => true,
  52.     'fields' => array('*''has_implied'),
  53.     'filters' => array('right_id' => $right_id),
  54. ));
  55. if ($rights === false{
  56.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  57.     print_r($admin->getErrors());
  58. else {
  59.     Var_Dump::display($rights);
  60.     echo '<br />';
  61. }
  62.  
  63. // view all
  64. echo 'All the rights:<br />';
  65. $rights $admin->perm->getRights();
  66. if ($rights === false{
  67.     echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  68.     print_r($admin->getErrors());
  69. elseif (empty($rights)) {
  70.     echo 'No rights were found, thus we\'ve halted the rest of the test<br />';
  71. else {
  72.     Var_Dump::display($rights);
  73.     echo '<br />';
  74.  
  75.     // delete
  76.     // By right id
  77.     $id array_rand($rights);
  78.     $filters = array('right_id' => $rights[$id]['right_id']);
  79.     $unimply $admin->perm->unimplyRight($filters);
  80.  
  81.     if ($unimply === false{
  82.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  83.         print_r($admin->getErrors());
  84.     else {
  85.         echo 'Removed all records with the right id <strong>' $rights[$id]['right_id''</strong><br />';
  86.         unset($rights[$id]);
  87.     }
  88.  
  89.     // By implied right id
  90.     $id array_rand($rights);
  91.     $filters = array('implied_right_id' => $rights[$id]['right_id']);
  92.     $unimply $admin->perm->unimplyRight($filters);
  93.  
  94.     if ($unimply === false{
  95.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  96.         print_r($admin->getErrors());
  97.     else {
  98.         echo 'Removed all records with the implied right id <strong>' $rights[$id]['right_id''</strong><br />';
  99.         unset($rights[$id]);
  100.     }
  101.  
  102.     // By implied right id and right id
  103.     $right array_rand($rights);
  104.     $impliedRight array_rand($rights);
  105.  
  106.     $filters = array(
  107.         'right_id' => $rights[$right]['right_id'],
  108.         'implied_right_id' => $rights[$impliedRight]['right_id']
  109.     );
  110.     $unimply $admin->perm->unimplyRight($filters);
  111.  
  112.     if ($unimply === false{
  113.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  114.         print_r($admin->getErrors());
  115.     else {
  116.         echo 'Removed the record that has <strong>' $rights[$right]['right_id''</strong>
  117.               as right id  and <strong>' $rights[$impliedRight]['right_id''</strong> as implied right id<br />';
  118.     }
  119.  
  120.     // view all
  121.     echo 'All the rights:<br />';
  122.     $rights $admin->perm->getRights();
  123.     if ($rights === false{
  124.         echo '<strong>Error on line: '.__LINE__.'</strong><br />';
  125.         print_r($admin->getErrors());
  126.     elseif (empty($rights)) {
  127.         echo 'No rights were found<br />';
  128.     else {
  129.         Var_Dump::display($rights);
  130.         echo '<br />';
  131.     }
  132. }
  133. echo '<hr />';

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