Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_workflow_schema.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 
30 {
31 
32 
54  public static function execute($settings, &$state)
55  {
56  $am =& $GLOBALS['SQ_SYSTEM']->am;
57  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
58 
59  // check required settings
60  if (empty($settings['schemaid'])) return FALSE;
61 
62  if (empty($state['asset'])) {
63  // grab the asset if assetid is given, but not the asset.
64  if (empty($state['assetid'])) {
65  return FALSE;
66  } else {
67  $state['asset'] = $am->getAsset($state['assetid']);
68  }
69  }
70 
71  if (is_null($state['asset'])) return FALSE;
72 
73  $granted = array_get_index($settings, 'granted', TRUE);
74  $cascade_to_dependents = array_get_index($settings, 'cascade_to_dependents', FALSE);
75  $cascade = array_get_index($settings, 'cascade', FALSE);
76  $cascade_to_new = array_get_index($settings, 'cascade_to_new', TRUE);
77 
78  $schema = $am->getAsset($settings['schemaid']);
79  if (is_null($schema)) return FALSE;
80  if ($schema->type() != 'workflow_schema') return FALSE;
81 
82  if (!$cascade_to_dependents && !$cascade) {
83  $result = $wfm->setSchema($state['asset']->id, $schema->id, $granted, $cascade_to_new);
84  } else {
85  $schema_vars[] = Array(
86  'assetids' => Array($state['asset']->id),
87  'granted' => $granted,
88  'schemaid' => $settings['schemaid'],
89  'cascades' => $cascade_to_new,
90  'previous_access' => NULL,
91  'dependants_only' => $cascade_to_dependents,
92  );
93  $vars = Array(
94  'schema_changes' => $schema_vars,
95  );
96 
97  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
98  $errors = $hh->freestyleHIPO('hipo_job_edit_workflow_schemas', $vars);
99  $result = empty($errors);
100  }
101 
102 
103  if (!$result) {
104  return FALSE;
105  } else {
106  return Array(
107  'assetid' => $state['asset']->id,
108  'schemaid' => $settings['schemaid'],
109  'granted' => $granted,
110  'cascade' => $cascade,
111  'cascade_to_dependents' => $cascade_to_dependents,
112  'cascade_to_new' => $cascade_to_new,
113  );
114  }
115 
116  }//end execute()
117 
118 
129  public static function getInterface($settings, $prefix, $write_access=FALSE)
130  {
131  $current_schemaid = array_get_index($settings, 'schemaid', 0);
132  $granted = array_get_index($settings, 'granted', 1);
133  $cascade = array_get_index($settings, 'cascade', FALSE);
134  $cascade_to_dependents = array_get_index($settings, 'cascade_to_dependents', FALSE);
135  $cascade_to_new = array_get_index($settings, 'cascade_to_new', TRUE);
136 
137  $options = Array(
138  TRUE => translate('apply'),
139  FALSE => translate('deny'),
140  );
141 
142  ob_start();
143  if ($write_access) {
144  ob_start();
145  combo_box($prefix.'[granted]', $options, FALSE, $granted);
146  $combo_box = ob_get_clean();
147  echo translate('trigger_schema_apply-deny_the_following_schema', $combo_box).' ';
148  asset_finder($prefix.'[schemaid]', $current_schemaid, Array('workflow_schema' => 'I'));
149  echo '<br />';
150  check_box($prefix.'[cascade]', '1', $cascade);
151  label(translate('cascade_schema_changes'), $prefix.'[cascade]');
152 
153  echo '<br />';
154  check_box($prefix.'[cascade_to_dependents]', '1', $cascade_to_dependents);
155  label(translate('cascade_schema_changes_to_dependents'), $prefix.'[cascade_to_dependents]');
156 
157  echo '<br />';
158  check_box($prefix.'[cascade_to_new]', '1', $cascade_to_new);
159  label(translate('cascade_schema_changes_to_new_children'), $prefix.'[cascade_to_new]');
160  } else {
161  if (!empty($current_schemaid)) {
162  $schema_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($current_schemaid));
163  echo translate('trigger_schema_apply-deny_the_following_schema', $options[$granted]).' ';
164  echo '<b>'.$schema_info[$current_schemaid]['name'].' (#'.$current_schemaid.')</b>';
165  } else {
166  echo translate('trigger_schema_apply-deny_the_following_schema', $options[$granted]).' ';
167  echo '<b>'.translate('trigger_schema_no_schema_specified').'</b>';
168  }
169 
170  echo '<br />';
171  echo '<img src="'.sq_web_path('lib').'/web/images/'.($cascade ? 'tick' : 'cross').'.gif" alt="'.($cascade ? translate('yes') : translate('no')).'" /> ';
172  echo translate('cascade_schema_changes');
173 
174  echo '<br />';
175  echo '<img src="'.sq_web_path('lib').'/web/images/'.($cascade_to_dependents ? 'tick' : 'cross').'.gif" alt="'.($cascade_to_dependents ? translate('yes') : translate('no')).'" /> ';
176  echo translate('cascade_schema_changes_to_dependents');
177 
178  echo '<br />';
179  echo '<img src="'.sq_web_path('lib').'/web/images/'.($cascade_to_new ? 'tick' : 'cross').'.gif" alt="'.($cascade_to_new ? translate('yes') : translate('no')).'" /> ';
180  echo translate('cascade_schema_changes_to_new_children');
181  }
182 
183  $output = ob_get_contents();
184  ob_end_clean();
185 
186  return $output;
187 
188  }//end getInterface()
189 
190 
202  public static function processInterface(&$settings, $request_data)
203  {
204  $schema_info = array_get_index($request_data, 'schemaid', Array('assetid' => 0));
205  $settings['schemaid'] = array_get_index($schema_info, 'assetid', 0);
206  $settings['granted'] = array_get_index($request_data, 'granted', TRUE);
207  $settings['cascade'] = array_get_index($request_data, 'cascade', FALSE);
208  if ($settings['cascade']) {
209  $settings['cascade_to_dependents'] = TRUE;
210  } else {
211  $settings['cascade_to_dependents'] = array_get_index($request_data, 'cascade_to_dependents', FALSE);
212  }
213  $settings['cascade_to_new'] = array_get_index($request_data, 'cascade_to_new', FALSE);
214  return FALSE;
215 
216  }//end processInterface()
217 
218 
228  public static function getLocks($settings, &$state)
229  {
230  return Array($state['assetid'] => Array('workflow'));
231 
232  }//end getLocks()
233 
234 
235 }//end class
236 
237 ?>