Permalink
Browse files

Merge branch 'master' of github.com:ushahidi/Ushahidi_Web

  • Loading branch information...
2 parents 5d6733e + 2ec6dd6 commit 7b912fcec0b5466df33a935147f1ff8a5741c0de @dkobia dkobia committed Jul 25, 2011
Showing with 155 additions and 11 deletions.
  1. +0 −1 .gitignore
  2. +118 −0 application/config/config.php
  3. +32 −7 application/helpers/category.php
  4. +5 −3 application/helpers/reports.php
View
1 .gitignore
@@ -5,6 +5,5 @@
application/logs/*
application/cache/*
media/uploads/*
-application/config/config.php
application/config/database.php
tests/phpunit/phpunit.xml
View
118 application/config/config.php
@@ -0,0 +1,118 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Base path of the web site. If this includes a domain, eg: localhost/ushahidi/
+ * then a full URL will be used, eg: http://localhost/ushahidi/. If it only includes
+ * the path, and a site_protocol is specified, the domain will be auto-detected.
+ */
+$config['site_domain'] = '/';
+
+/**
+ * Force a default protocol to be used by the site. If no site_protocol is
+ * specified, then the current protocol is used, or when possible, only an
+ * absolute path (with no protocol/domain) is used.
+ */
+$config['site_protocol'] = 'http';
+
+/**
+ * Name of the front controller for this application. Default: index.php
+ *
+ * This can be removed by using URL rewriting.
+ */
+$config['index_page'] = 'index.php';
+
+/**
+ * Fake file extension that will be added to all generated URLs. Example: .html
+ */
+$config['url_suffix'] = '';
+
+/**
+ * Length of time of the internal cache in seconds. 0 or FALSE means no caching.
+ * The internal cache stores file paths and config entries across requests and
+ * can give significant speed improvements at the expense of delayed updating.
+ */
+$config['internal_cache'] = TRUE;
+
+/**
+ * Enable or disable gzip output compression. This can dramatically decrease
+ * server bandwidth usage, at the cost of slightly higher CPU usage. Set to
+ * the compression level (1-9) that you want to use, or FALSE to disable.
+ *
+ * Do not enable this option if you are using output compression in php.ini!
+ */
+$config['output_compression'] = TRUE;
+
+/**
+ * Enable or disable global XSS filtering of GET, POST, and SERVER data. This
+ * option also accepts a string to specify a specific XSS filtering tool.
+ */
+$config['global_xss_filtering'] = TRUE;
+
+/**
+ * Enable or disable hooks. Setting this option to TRUE will enable
+ * all hooks. By using an array of hook filenames, you can control
+ * which hooks are enabled. Setting this option to FALSE disables hooks.
+ */
+$config['enable_hooks'] = TRUE;
+
+/**
+ * Log thresholds:
+ * 0 - Disable logging
+ * 1 - Errors and exceptions
+ * 2 - Warnings
+ * 3 - Notices
+ * 4 - Debugging
+ */
+$config['log_threshold'] = 1;
+
+/**
+ * Message logging directory.
+ */
+$config['log_directory'] = APPPATH.'logs';
+
+if (@!is_writable($config["log_directory"])) {
+ $config["log_threshold"] = 0;
+}
+
+/**
+ * Enable or disable displaying of Kohana error pages. This will not affect
+ * logging. Turning this off will disable ALL error pages.
+ */
+$config['display_errors'] = TRUE;
+
+/**
+ * Enable or disable statistics in the final output. Stats are replaced via
+ * specific strings, such as {execution_time}.
+ *
+ * @see http://docs.kohanaphp.com/general/configuration
+ */
+$config['render_stats'] = TRUE;
+
+/**
+ * Turn MHI on or off. This is an advanced feature that will drastically alter
+ * the way your instance works. Please read documentation before proceeding.
+ *
+ * @see [A URL not yet created]
+ */
+$config['enable_mhi'] = FALSE;
+
+/**
+ * Filename prefixed used to determine extensions. For example, an
+ * extension to the Controller class would be named MY_Controller.php.
+ */
+$config['extension_prefix'] = 'MY_';
+
+/**
+ * Additional resource paths, or "modules". Each path can either be absolute
+ * or relative to the docroot. Modules can include any resource that can exist
+ * in your application directory, configuration files, controllers, views, etc.
+ */
+$config['modules'] = array
+(
+ MODPATH.'auth', // Authentication
+ // MODPATH.'forge', // Form generation
+ // MODPATH.'formation', // Form generation
+ // MODPATH.'kodoc', // Self-generating documentation
+ // MODPATH.'media', // Media caching and compression
+ // MODPATH.'archive', // Archive utility
+ // MODPATH.'unit_test', // Unit testing
+);
View
39 application/helpers/category.php
@@ -112,25 +112,55 @@ public static function get_category_tree_view()
// To hold the category data
$category_data = array();
+ // Database instance
+ $db = new Database();
+
// Fetch all the top level parent categories
foreach (Category_Model::get_categories() as $category)
{
self::_extend_category_data($category_data, $category);
}
+ // Query to fetch the report totals for the parent categories
+ $sql = "SELECT c2.id, COUNT(DISTINCT ic.incident_id) report_count "
+ . "FROM category c, category c2, incident_category ic "
+ . "INNER JOIN incident i ON (ic.incident_id = i.id) "
+ . "WHERE (ic.category_id = c.id OR ic.category_id = c2.id) "
+ . "AND c.parent_id = c2.id "
+ . "AND i.incident_active = 1 "
+ . "AND c2.category_visible = 1 "
+ . "AND c.category_visible = 1 "
+ . "AND c2.parent_id = 0 "
+ . "AND c2.category_title != \"Trusted Reports\" "
+ . "GROUP BY c2.id "
+ . "ORDER BY c2.id ASC";
+
+ // Update the report_count field of each top-level category
+ foreach ($db->query($sql) as $category_total)
+ {
+ // Check if the category exists
+ if (array_key_exists($category_total->id, $category_data))
+ {
+ // Update
+ $category_data[$category_total->id]['report_count'] = $category_total->report_count;
+ }
+ }
+
// Get the table prefix
$table_prefix = Kohana::config('database.default.table_prefix');
// Fetch the other categories
- $sql = "SELECT c.id, c.parent_id, c.category_title, c.category_color, COUNT(ic.incident_id) report_count "
+ $sql = "SELECT c.id, c.parent_id, c.category_title, c.category_color, COUNT(c.id) report_count "
. "FROM ".$table_prefix."category c "
. "INNER JOIN ".$table_prefix."incident_category ic ON (ic.category_id = c.id) "
+ . "INNER JOIN ".$table_prefix."incident i ON (ic.incident_id = i.id) "
. "WHERE c.category_visible = 1 "
+ . "AND i.incident_active = 1 "
. "GROUP BY c.category_title "
. "ORDER BY c.category_title ASC";
// Add child categories
- foreach (Database::instance()->query($sql) as $category)
+ foreach ($db->query($sql) as $category)
{
// Extend the category data array
self::_extend_category_data($category_data, $category);
@@ -145,10 +175,6 @@ public static function get_category_tree_view()
'report_count' => $category->report_count,
'children' => array()
);
-
- // Update the report count
- // Kohana::log('debug', Kohana::debug($category));
- $category_data[$category->parent_id]['report_count'] += $category->report_count;
}
}
@@ -185,7 +211,6 @@ private static function _extend_category_data(array & $array, $category)
return TRUE;
}
- // Garbage collection
return FALSE;
}
View
8 application/helpers/reports.php
@@ -594,7 +594,7 @@ public static function fetch_incidents($paginate = FALSE)
}
}
- //> BEGIN PAAMETER FETCH
+ //> BEGIN PARAMETER FETCH
//
// Check for the category parameter
@@ -606,7 +606,8 @@ public static function fetch_incidents($paginate = FALSE)
// Add category parameter to the parameter list
array_push(self::$params,
- 'c.id = '.$category_id.' OR c.parent_id = '.$category_id
+ 'c.id = '.$category_id.' OR c.parent_id = '.$category_id,
+ 'c.category_visible = 1'
);
}
elseif (isset($url_data['c']) AND is_array($url_data['c']))
@@ -627,7 +628,8 @@ public static function fetch_incidents($paginate = FALSE)
$category_ids = implode(",", $category_ids);
array_push(self::$params,
- 'c.id IN ('.$category_ids.') OR c.parent_id IN ('.$category_ids.')'
+ 'c.id IN ('.$category_ids.') OR c.parent_id IN ('.$category_ids.')',
+ 'c.category_visible = 1'
);
}
}

0 comments on commit 7b912fc

Please sign in to comment.