Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_access_permission.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 
31 {
32 
33 
51  public static function evaluate($settings, &$state)
52  {
53  // grab the data we need to check the condition, if it's not already cached
54  // note that new state is modified and new data is available to other conditions
55  if (empty($state['asset'])) {
56  // grab the asset if assetid is given, but not the asset
57  if (empty($state['assetid'])) {
58  return FALSE;
59  } else {
60  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
61  }
62  }
63 
64  // check the access permission (granted/not granted)
65  $condition = FALSE;
66  switch ($settings['perm']) {
67  case SQ_PERMISSION_READ:
68  $condition = $state['asset']->readAccess();
69  break;
70 
71  case SQ_PERMISSION_WRITE:
72  $condition = $state['asset']->writeAccess();
73  break;
74 
75  case SQ_PERMISSION_ADMIN:
76  $condition = $state['asset']->adminAccess();
77  break;
78  }
79 
80  return $settings['grant'] ? $condition : !$condition;
81 
82  }//end evaluate()
83 
84 
95  public static function getInterface($settings, $prefix, $write_access=FALSE)
96  {
97  $perm = Array(
98  SQ_PERMISSION_READ => translate('read').' '.translate('permission'),
99  SQ_PERMISSION_WRITE => translate('write').' '.translate('permission'),
100  SQ_PERMISSION_ADMIN => translate('admin').' '.translate('permission'),
101  );
102  $grant = Array(
103  1 => 'has',
104  0 => 'does not have',
105  );
106 
107  $selected_perm = array_get_index($settings, 'perm', SQ_PERMISSION_READ);
108  $selected_grant = array_get_index($settings, 'grant', 1);
109 
110  // begin buffering basic options
111  ob_start();
112  if ($write_access) {
113  combo_box($prefix.'[grant]', $grant, FALSE, $selected_grant);
114  } else {
115  echo $grant[$selected_grant];
116  }
117  $part1 = ob_get_contents();
118  ob_end_clean();
119  ob_start();
120  if ($write_access) {
121  combo_box($prefix.'[perm]', $perm, FALSE, $selected_perm);
122  } else {
123  echo $perm[$selected_perm];
124  }
125  $part2 = ob_get_contents();
126  ob_end_clean();
127 
128  // has read/write/admin permission
129  // does not have
130  return 'Current user '.$part1.' '.$part2.' on the asset that the action is executing on.';
131 
132  }//end getInterface()
133 
134 
144  public static function processInterface(&$settings, $request_data)
145  {
146  $settings['perm'] = array_get_index($request_data, 'perm', SQ_PERMISSION_READ);
147  $settings['grant'] = array_get_index($request_data, 'grant', 1);
148 
149  return FALSE;
150 
151  }//end processInterface()
152 
153 
154 }//end class
155 
156 ?>