function views_json_query_plugin_query_json::execute in Views JSON Query 7
Execute.
Overrides views_plugin_query::execute
File
- ./
views_json_query_plugin_query_json.inc, line 154 - Query plugin for views_json_query.
Class
- views_json_query_plugin_query_json
- @file Query plugin for views_json_query.
Code
function execute(&$view) {
$start = microtime(TRUE);
// Avoid notices about $view->execute_time being undefined if the query
// doesn't finish.
$view->execute_time = NULL;
// Make sure that an xml file exists.
// This could happen if you come from the add wizard to the actual views
// edit page.
if (empty($this->options['json_file'])) {
return FALSE;
}
$data = new stdClass();
try {
$data->contents = $this
->fetch_file($this->options['json_file']);
} catch (Exception $e) {
if ($this->options['show_errors']) {
drupal_set_message(t('Views Json Query') . ': ' . $e
->getMessage(), 'error');
}
return;
}
// When content is empty, parsing it is pointless.
if (!$data->contents) {
if ($this->options['show_errors']) {
drupal_set_message(t('Views Json Backend: File is empty.'), 'warning');
}
return;
}
// Go!
$ret = $this
->parse($view, $data);
$view->execute_time = microtime(TRUE) - $start;
if (!$ret) {
if (version_compare(phpversion(), '5.3.0', '>=')) {
$tmp = array(
JSON_ERROR_NONE => t('No error has occurred'),
JSON_ERROR_DEPTH => t('The maximum stack depth has been exceeded'),
JSON_ERROR_STATE_MISMATCH => t('Invalid or malformed JSON'),
JSON_ERROR_CTRL_CHAR => t('Control character error, possibly incorrectly encoded'),
JSON_ERROR_SYNTAX => t('Syntax error'),
JSON_ERROR_UTF8 => t('Malformed UTF-8 characters, possibly incorrectly encoded'),
);
if (json_last_error() != 0) {
$msg = $tmp[json_last_error()] . ' - ' . $this->options['json_file'];
drupal_set_message($msg, 'error');
}
}
else {
drupal_set_message(t('Views Json Backend: Parse json error') . ' - ' . $this->options['json_file'], 'error');
}
}
}