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