Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_release_lock.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
19 
32 {
33 
34 
51  public static function execute($settings, &$state)
52  {
53  if (empty($state['asset'])) {
54  // grab the asset if assetid is given, but not the asset.
55  if (empty($state['assetid'])) {
56  return FALSE;
57  } else {
58  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
59  }
60  }
61 
62  // release all locks with the same source_lockid prefix
63  switch ($settings['release_type']) {
64  case 'on_asset':
65  if (!$GLOBALS['SQ_SYSTEM']->am->releaseLock($state['asset']->id, 'all')) {
66  return FALSE;
67  }
68  break;
69 
70  case 'held':
71  // This only works if you're a user
72  if ($state['asset'] instanceof User) {
73  $state['asset']->releaseUserLocks();
74  } else {
75  return FALSE;
76  }
77  break;
78 
79  }//end switch
80 
81  return Array(
82  'assetid' => $state['asset']->id,
83  );
84 
85  }//end execute()
86 
87 
98  public static function getInterface($settings, $prefix, $write_access=FALSE)
99  {
100  $interface = '';
101  $lock_type = array_get_index($settings, 'release_type', 'on_asset');
102 
103  if (!$write_access) {
104  $form_element_extras = 'disabled="disabled"';
105  } else {
106  $form_element_extras = '';
107  }
108 
109  ob_start();
110  echo '<ul style="margin: 0; list-style: none">';
111  echo '<li>';
112  echo radio_button($prefix.'[release_type]', 'on_asset', ($lock_type == 'on_asset'), '', $form_element_extras);
113  echo translate('trigger_action_release_lock_on_asset');
114  echo '</li>';
115  echo '<li>';
116  echo radio_button($prefix.'[release_type]', 'held', ($lock_type == 'held'), '', $form_element_extras);
117  echo translate('trigger_action_release_lock_held');
118  echo '</li>';
119  echo '</ul>';
120  $interface = ob_get_clean();
121 
122  return $interface;
123 
124  }//end getInterface()
125 
126 
138  public static function processInterface(&$settings, $request_data)
139  {
140  $release_type = array_get_index($request_data, 'release_type', FALSE);
141  if (!$release_type) return 'Release type has not been specified';
142 
143  $release_list = Array(
144  'on_asset' => 'Release Locks on Asset',
145  'held' => 'Release Locks Held by Asset',
146  );
147 
148  // check if the status is valid
149  if (isset($release_list[$release_type])) {
150  $settings['release_type'] = $release_type;
151  return FALSE;
152  } else {
153  return 'Specified release type is invalid';
154  }
155 
156  }//end processInterface()
157 
158 
168  public static function getLocks($settings, &$state)
169  {
170  return Array($state['assetid'] => Array('permissions'));
171 
172  }//end getLocks()
173 
174 
175 }//end class
176 
177 ?>