Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_delete_future_permission.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 
31 {
32 
33 
51  public static function execute($settings, &$state)
52  {
53  // check settings, permission
54  if (empty($settings['permission'])) {
55  // if no settings, fail
56  return FALSE;
57  }
58 
59  if (empty($state['asset'])) {
60  // grab the asset if assetid is given, but not the asset.
61  if (empty($state['assetid'])) {
62  return FALSE;
63  } else {
64  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
65  }
66  }
67 
68  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
69  if (is_null($cron_mgr)) return FALSE;
70 
71  //get the future permission cron jobs of this asset
72  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_permission');
73  $fp_jobs = Cron_Job_Future_Permission::getActiveJobs($state['asset']);
74  if (empty($fp_jobs)) return TRUE;
75 
76  $jobids = Array();
77 
78  foreach ($fp_jobs as $job) {
79  if ($job->attr('permission') == $settings['permission']) {
80  if ($cron_mgr->removeJob($job)) {
81  $jobids[] = $job->id;
82  } else {
83  trigger_localised_error('CRON0065', E_USER_WARNING, $job->id);
84  }
85  }
86  }
87 
88  return Array(
89  'jobids' => $jobids,
90  );
91 
92  }//end execute()
93 
94 
105  public static function getInterface($settings, $prefix, $write_access=FALSE)
106  {
107  if (empty($settings['permission'])) {
108  // set to default
109  $selected_permission = SQ_PERMISSION_READ;
110  } else {
111  $selected_permission = $settings['permission'];
112  }
113 
114  $permission_list = self::_getPermissionList();
115 
116  if (!$write_access) {
117  $form_element_extras = 'disabled="disabled"';
118  } else {
119  $form_element_extras = '';
120  }
121 
122  ob_start();
123  echo translate('trigger_delete_future_permission').'&nbsp;';
124  combo_box($prefix.'[permission]', $permission_list, FALSE, $selected_permission, NULL, $form_element_extras);
125  echo '&nbsp;'.translate('permission');
126  $html = ob_get_contents();
127  ob_end_clean();
128 
129  return $html;
130 
131  }//end getInterface()
132 
133 
145  public static function processInterface(&$settings, $request_data)
146  {
147  $permission = array_get_index($request_data, 'permission', NULL);
148  if (is_null($permission)) {
149  return 'Permission has not been specified';
150  }
151 
152  $permission_list = self::_getPermissionList();
153 
154  // check if the permission is valid
155  if (!isset($permission_list[$permission])) {
156  return 'Specified permission is invalid';
157  }
158  $settings['permission'] = $permission;
159 
160  return FALSE;
161 
162  }//end processInterface()
163 
164 
173  protected static function _getPermissionList()
174  {
175  return Array(SQ_PERMISSION_READ => 'Read', SQ_PERMISSION_WRITE => 'Write', SQ_PERMISSION_ADMIN => 'Admin');
176 
177  }//end _getPermissionList()
178 
179 
180 }//end class
181 
182 ?>