1<?php 2require_once 'index.php'; 3echo '<h3>GroupRights</h3>'; 4 5$groups = $admin->perm->getGroups(); 6if ($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(); 15if ($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 24for ($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 'group_id' 48 ), 49 'with' => array( 50 'group_id' => array( 51 'fields' => array( 52 'group_id' 53 ), 54 ), 55 ), 56 'filters' => array( 57 'group_id' => $groups[$group]['group_id'] 58 ), 59 'by_group' => true, 60 'limit' => 10, 61 'offset' => 0, 62); 63$allGroupRights = $admin->perm->getRights($params); 64 65if ($allGroupRights === false) { 66 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 67} elseif (empty($allGroupRights)) { 68 echo 'Group <stong>' . $groups[$group]['group_id'] . '</strong> had no rights<br />'; 69} else { 70 echo '<hr />Here is/are <strong>' . count($allGroupRights) . '</strong> group right(s) for the group <strong>' . $groups[$group]['group_id'] . '</strong>:<br />'; 71 Var_Dump::display($allGroupRights); 72 echo '<br />'; 73} 74 75$right = array_rand($rights); 76$group = array_rand($groups); 77$filters = array( 78 'right_id' => $rights[$right]['right_id'], 79 'group_id' => $groups[$group]['group_id'] 80); 81$removed = $admin->perm->revokeGroupRight($filters); 82 83if ($removed === false) { 84 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 85 print_r($admin->getErrors()); 86} else { 87 echo 'Removed the right <strong>'.$right.'</strong> on group <strong>'.$group.'</strong><br />'; 88} 89 90 91$group = array_rand($groups); 92$params = array( 93 'fields' => array( 94 'right_id' 95 ), 96 'filters' => array( 97 'group_id' => $groups[$group]['group_id'] 98 ), 99 'by_group' => true, 100); 101$rights_group = $admin->perm->getRights($params); 102if ($rights_group === false) { 103 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 104 print_r($admin->getErrors()); 105} elseif (empty($rights_group)) { 106 echo 'Group <strong>' . $groups[$group]['group_id'] . '</strong> had no rights<br />'; 107} else { 108 $right = array_rand($rights_group); 109 $data = array('right_level' => 2); 110 $filters = array( 111 'right_id' => $rights_group[$right]['right_id'], 112 'group_id' => $groups[$group]['group_id'] 113 ); 114 $updated = $admin->perm->updateGroupRight($data, $filters); 115 116 if ($updated === false) { 117 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 118 print_r($admin->getErrors()); 119 } else { 120 echo 'Updated the right level of <strong>' . $groups[$group]['group_id'] . '</strong><br />'; 121 $params = array( 122 'fields' => array( 123 'right_id' 124 ), 125 'filters' => array( 126 'right_id' => $rights_group[$right]['right_id'], 127 'group_id' => $groups[$group]['group_id'] 128 ), 129 'by_group' => true, 130 ); 131 $result = $admin->perm->getRights($params); 132 133 if ($result === false) { 134 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 135 print_r($admin->getErrors()); 136 } elseif (empty($result)) { 137 echo 'Nothing was found with the right id <strong>' . $rights_group[$right]['right_id'] . '</strong> 138 and group id <strong>' . $groups[$group]['group_id']. '</strong><br />'; 139 } else { 140 Var_Dump::display($result); 141 } 142 } 143} 144 145$params = array( 146 'fields' => array( 147 'right_id', 148 'group_id', 149 ), 150 'with' => array( 151 'group_id' => array( 152 'fields' => array( 153 'group_id', 154 'right_level', 155 ) 156 ), 157 ), 158 'by_group' => true, 159); 160 161$allGroups = $admin->perm->getRights($params); 162echo 'Here are all the group rights after the changes:<br />'; 163if ($allGroups === false) { 164 echo '<strong>Error on line: '.__LINE__.'</strong><br />'; 165 print_r($admin->getErrors()); 166} elseif (empty($allGroups)) { 167 echo 'Found no groups<br />'; 168} else { 169 Var_Dump::display($allGroups); 170} 171echo '<hr />'; 172