Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_thesaurus_terms.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
20 
33 {
34 
35 
55  public static function execute($settings, &$state)
56  {
57  // check settings, state
58  if (empty($settings['file_path']) || !file_exists($settings['file_path'])) {
59  // if no settings, fail
60  return FALSE;
61  }
62 
63  // check settings, append
64  // NOTE: It does not have any effect in a hipo job at the moment
65  if (empty($settings['append'])) {
66  $append = FALSE;
67  } else {
68  $append = $settings['append'];
69  }
70 
71  // state, design asset
72  if (empty($state['asset'])) {
73  // grab the asset if assetid is given, but not the asset.
74  if (empty($state['assetid'])) {
75  return FALSE;
76  } else {
77  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
78  }
79  }
80 
81  if (is_null($state['asset'])) return FALSE;
82 
83  $asset =& $state['asset'];
84 
85  // copy over the new uploaded file
86  if (is_readable($settings['file_path'])) {
87 
88  // a normal uploaded file
89  if (!copy_file($settings['file_path'], $asset->getXmlFilePath())) {
90  trigger_localised_error('CORE0235', E_USER_WARNING, $info['tmp_name'], $asset->getXmlFilePath());
91  return FALSE;
92  }
93  }
94 
95  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
96  $running_vars = Array(
97  'thesaurus_id' => $asset->id,
98  'append' => $append,
99  'file_path' => $settings['file_path'],
100  );
101  $errors = $hh->freestyleHipo('hipo_job_import_thesaurus_xml', $running_vars);
102 
103  return Array(
104  'assetid' => $state['asset']->id,
105  );
106 
107  }//end execute()
108 
109 
120  public static function getInterface($settings, $prefix, $write_access=FALSE)
121  {
122  $file_path = array_get_index($settings, 'file_path', '');
123  $append = array_get_index($settings, 'append', FALSE);
124  // paint the edit interface
125  ob_start();
126  ?>
127  <table border="0">
128  <tr>
129  <td valign="top"><b><?php echo 'Path to XML File'; ?></b></td>
130  <td valign="top" style="padding-bottom: 10px;"><?php
131  // level
132  if ($write_access) {
133  echo text_box($prefix.'[file_path]', $file_path, '50');
134  echo '&nbsp;&nbsp;';
135  echo check_box($prefix.'[append]', '1', $append).'Append?';
136  } else {
137  echo $file_path.'&nbsp;';
138  echo htmlspecialchars('(Append option is'.($append ? ' ' : ' not ').'selected)');
139  }
140  ?>
141  </td>
142  </tr>
143  </table>
144  <?php
145 
146  return ob_get_clean();
147 
148  }//end getInterface()
149 
150 
162  public static function processInterface(&$settings, $request_data)
163  {
164  $file_path = array_get_index($request_data, 'file_path', '');
165  $file_path = trim($file_path);
166  if ($file_path == '') {
167  return 'file path is not specified.';
168  }
169  $settings['file_path'] = $file_path;
170 
171  $append = array_get_index($request_data, 'append', FALSE);
172  $settings['append'] = $append;
173 
174  return FALSE;
175 
176  }//end processInterface()
177 
178 
188  public static function getLocks($settings, &$state)
189  {
190  return Array(
191  $state['assetid'] => Array(
192  'attributes',
193  ),
194  );
195 
196  }//end getLocks()
197 
198 
199 }//end class
200 
201 ?>