Commit 2e9e4aa9 authored by David Metzler's avatar David Metzler
Browse files

Fully plugged in, but still havent removed the db save functions.

parent ad9eb48a
......@@ -124,29 +124,6 @@ class FrxDrupalApplication {
$r_text = Frx::File()->contents($filename);
$modified = filemtime(Frx::File()->path($filename));
}
$result = db_query("SELECT * FROM {forena_reports} WHERE report_name=:report_name AND language=:language",
array(':report_name' => $report_name, ':language' => $language->language));
$save = FALSE;
if ($rpt = $result->fetchObject()) {
// If the file modification time has changed then save.
if ($modified && $rpt->modified != $modified) {
$save = TRUE;
}
// If the report has been altered by a user then use that.
if ($rpt->altered == -1) {
if ($rpt->src) {
$r_text = $rpt->src;
}
}
}
elseif ($r_text) {
$save = TRUE;
}
if ($save) {
require_once('forena.admin.inc');
forena_save_report($i_report_name, $r_text, FALSE);
}
return $r_text;
}
}
......
......@@ -36,7 +36,6 @@ class FrxFile {
if (is_file($src_file)) {
@list($base_file, $ext) = explode('.', $rpt_file, 2);
if (array_search($ext, $this->cached_extensions) !== FALSE) {
$files[$ext][$src_file] = filemtime($src_file);
}
}
......@@ -69,6 +68,16 @@ class FrxFile {
$this->cache[$ext][$base_name] = $obj;
}
else {
// If its our first pas on this replace the entry
if (isset($this->filesToDelete[$ext][$base_name])) {
$entry = $this->cache[$ext][$base_name];
if ($entry->file != $file) {
$entry->file = $file;
$entry->cache = NULL;
$entry->mtime = $mtime;
}
}
unset($this->filesToDelete[$ext][$base_name]);
}
}
......
......@@ -138,23 +138,18 @@ class FrxMenu {
public function addMenuItems(&$items) {
GLOBAL $language;
$result = db_query("SELECT report_name, path, title, cache FROM {forena_reports} where path<>'' AND language='en' ORDER BY path asc");
$result = Frx::File()->menuReports();
$reports = array();
foreach ($result AS $row) {
$access = TRUE;
$cache = $row->cache;
if ($cache) {
$cache = unserialize($cache);
// Load menu item defaults
$menu = @$cache['menu'];
$path = $menu['path'];
$path_args = @$menu['args'];
$type = @$menu['type'];
$title = @$menu['title'] ? $menu['title']: $row->title;
if (module_exists('locale')) {
}
$title = isset($menu['title']) ? $menu['title']: $row->cache['title'];
//Default type
switch ($type) {
......@@ -182,7 +177,7 @@ class FrxMenu {
$parts = explode( '/', $new_path);
$page_args = array_keys($parts, '%');
$path_args = $path_args ? rtrim($path,'/') . '/' . ltrim($path_args, '/') : $path;
$page_args = array_merge(array($path_args, $row->report_name), $page_args);
$page_args = array_merge(array($path_args, $row->name), $page_args);
// Set the access callback
$access_callback = isset($cache['access']) ? 'forena_check_all_access' : TRUE;
......@@ -197,7 +192,7 @@ class FrxMenu {
if (!isset($items[$parent_path])) {
$items[$parent_path] = array(
'type' => MENU_CALLBACK,
'title' => $row->title,
'title' => $row->cache['title'],
'access callback' => $access_callback,
'access arguments' => array($cache['access']),
'page callback' => 'forena_report_menu_callback',
......@@ -205,7 +200,7 @@ class FrxMenu {
);
if (module_exists('locale')) {
$items[$parent_path]['title callback'] = 'forena_report_title_callback';
$items[$parent_path]['title arguments'] = array($row->report_name, FALSE);
$items[$parent_path]['title arguments'] = array($row->name, FALSE);
}
if ($access_callback === 'forena_check_all_access') $items[$parent_path]['access arguments'][] = $cache['access'];
}
......@@ -221,7 +216,7 @@ class FrxMenu {
);
if (module_exists('locale')) {
$items[$new_path]['title callback'] = 'forena_report_title_callback';
$items[$new_path]['title arguments'] = array($row->report_name, TRUE);
$items[$new_path]['title arguments'] = array($row->name, TRUE);
}
if ($access_callback === 'forena_check_all_access') $items[$new_path]['access arguments'][] = $cache['access'];
}
......
......@@ -43,6 +43,12 @@ class FrxReportFile extends FrxFile {
return $reports;
}
/**
* Sort compare function for sorting data by category then title.
* @param unknown $a
* @param unknown $b
* @return number
*/
static public function reportCompare($a, $b) {
$c = strnatcasecmp($a->cache['category'], $b->cache['category']);
if (!$c) {
......@@ -50,6 +56,35 @@ class FrxReportFile extends FrxFile {
}
return $c;
}
/**
* Get the cached information for a single report.
* @param unknown $name
* @return unknown
*/
public function getReportCacheInfo($name) {
GLOBAL $language;
$data = $this->validateAllCache('frx');
if ($language->language != 'en') {
$lang = $language->language;
$name = "$lang/$name";
}
return $data[$name];
}
public function menuReports() {
GLOBAL $language;
$data = $this->validateAllCache('frx');
$reports = array();
foreach ($data as $base_name => $obj) {
if ($obj->cache && $obj->cache['language'] == $language->language && isset($obj->cache['menu']['path'])) {
$obj->name = $base_name;
$reports[] = $obj;
}
}
return $reports;
}
/**
* Generate an ordered list of reports by category
......
......@@ -2486,34 +2486,8 @@ function forena_admin_params_form_submit($form, &$form_state) {
* @return An array containing all matching categories
*/
function forena_get_categories($string='') {
$result = db_query("SELECT * FROM {forena_reports} where hidden=0 AND category LIKE :category ORDER BY category, title asc",
array(':category' => $string . '%'));
$categories = array();
foreach ($result as $row) {
$access = TRUE;
$cache = $row->cache;
if ($cache) {
$cache = unserialize($cache);
// Check each callback function to see if we have an error.
if ($cache['access']) foreach ($cache['access'] as $callback => $args) {
if ($callback) foreach ($args as $arg) {
$access = FALSE;
if (function_exists($callback)) {
$a = $callback($arg);
}
if ($a) $access = TRUE;
}
else {
$access = TRUE;
}
}
}
if ($access && !isset($categories[$row->category])) {
$categories[$row->category] = $row->category;
}
}
$data = Frx::File()->reportsByCategory();
$categories = array_keys($data);
return $categories;
}
......
......@@ -375,37 +375,11 @@ function forena_reports_autocomplete($string='', $string2='') {
$mode = $string;
$string = $string2;
}
$string = '%' .$string .'%';
$result = db_query('SELECT * FROM {forena_reports} where language=:language
AND report_name like :string
ORDER BY category,title', array(':language' => $language->language, ':string' => $string));
$string = '*' .$string .'*';
$result = Frx::File()->allReports();
foreach ($result as $row) {
$access = TRUE;
$cache = $row->cache;
if ($cache) {
$cache = unserialize($cache);
// Check each callback function to see if we have an error.
if ($cache['access']) foreach ($cache['access'] as $callback => $args) {
if ($callback) foreach ($args as $arg) {
$access = FALSE;
if (function_exists($callback)) {
$a = @$callback($arg);
}
if ($a) $access = TRUE;
}
else {
$access = TRUE;
}
}
}
if ($access) {
$key = $row->report_name;
if ($mode == 'link') {
$key = 'reports/' . str_replace('/', '.', $key);
}
$reports[$key] = $key . ' - ' . $row->title;
if (drupal_match_path($row->name, $string)) {
$reports[$row->name] = $row->name . ' - ' . $row->cache['title'];
}
}
return drupal_json_output($reports);
......@@ -930,20 +904,9 @@ function forena_check_all_access($checks) {
* @param $use_menu_title boolean indicate wether to use menu title attribute.
*/
function forena_report_title_callback($report_name, $use_menu_title=TRUE) {
GLOBAL $language;
$title = '';
$lang = $language->language;
$result = db_query('SELECT * FROM {forena_reports} where report_name = :name and language=:language',
array(':name' => $report_name, 'language' => $lang));
foreach ($result as $row) {
$cache = $row->cache;
if ($cache) {
$cache = unserialize($cache);
// Load menu item defaults
$menu = $cache['menu'];
}
$title = $use_menu_title && @$menu['title'] ? $menu['title']: $row->title;
}
$info = Frx::File()->getReportCacheInfo($report_name);
$title = $use_menu_title && $info && isset($info->cache['menu']['title']) ? $info->cache['menu']['title']: $info->cache['title'];
return $title;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment