Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

T7 Add inactive/active button to Report Filter #17

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions application/controllers/admin/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public function edit($id = FALSE, $saved = FALSE)
'custom_field' => array(),
'incident_active' => '',
'incident_verified' => '',
'incident_status' => '',
'incident_zoom' => ''
);

Expand Down Expand Up @@ -771,6 +772,7 @@ public function edit($id = FALSE, $saved = FALSE)
'custom_field' => customforms::get_custom_form_fields($id, $incident->form_id, TRUE, 'submit'),
'incident_active' => $incident->incident_active,
'incident_verified' => $incident->incident_verified,
'incident_status' => $incident->incident_status,
'incident_zoom' => $incident->incident_zoom
);

Expand Down
11 changes: 10 additions & 1 deletion application/controllers/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function markers_geojson($incidents, $category_id, $color, $icon, $inc
$first_incident_id = (isset($_GET['i']) AND intval($_GET['i']) > 0)? intval($_GET['i']) : 0;

$media_type = (isset($_GET['m']) AND intval($_GET['m']) > 0)? intval($_GET['m']) : 0;

$status = (isset($_GET['st']) AND intval($_GET['st']) > 0)? intval($_GET['st']) : 0;
foreach ($incidents as $marker)
{
// Handle both reports::fetch_incidents() response and actual ORM objects
Expand Down Expand Up @@ -592,6 +592,15 @@ public function timeline($category_id = 0)
$params[':mtype'] = $_GET['m'];
$incident_id_in .= " AND i.id IN ( $query ) ";
}

// Apply project status filters
if (isset($_GET['st']))
{
$query = "SELECT id FROM".$this->table_prefix."incident"
. "WHERE incident_status = :status ";
$params[':status'] = $_GET['st'];
$incident_id_in .= " AND i.id IN ( $query ) ";
}

// Fetch the timeline data
$query = 'SELECT UNIX_TIMESTAMP('.$select_date_text.') AS time, COUNT(i.id) AS number '
Expand Down
30 changes: 29 additions & 1 deletion application/helpers/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ public static function save_report($post, $incident, $location_id)
{
$incident->incident_verified = $post->incident_verified;
}

// Project status: Only set if user has permission
if (isset($post->incident_status) AND Auth::instance()->has_permission('reports_status'))
{
$incident->incident_status = $post->incident_status;
}

// Incident zoom
if ( ! empty($post->incident_zoom))
Expand Down Expand Up @@ -760,7 +766,7 @@ public static function fetch_incidents($paginate = FALSE, $items_per_page = 0)

// Split selected parameters on ","
// For simplicity, always turn them into arrays even theres just one value
$exclude_params = array('c', 'v', 'm', 'mode', 'sw', 'ne', 'start_loc');
$exclude_params = array('c', 'v', 'm', 'mode', 'st', 'sw', 'ne', 'start_loc');
foreach ($url_data as $key => $value)
{
if (in_array($key, $exclude_params) AND ! is_array($value))
Expand Down Expand Up @@ -935,6 +941,28 @@ public static function fetch_incidents($paginate = FALSE, $items_per_page = 0)

}

//
// Check for status parameter
//
if (isset($url_data['st']) AND is_array($url_data['st']))
{
$incident_status = array();
foreach ($url_data['st'] as $status)
{
if (intval($status) >= 0)
{
$incident_status[] = intval($status);
}
}

if (count($incident_status) > 0)
{
array_push(self::$params,
'i.incident_status IN ('.implode(",", $incident_status).')'
);
}
}

//
// Check if the verification status has been specified
//
Expand Down
2 changes: 1 addition & 1 deletion application/i18n
Submodule i18n updated from fc7889 to 82e23c
17 changes: 17 additions & 0 deletions application/views/admin/reports/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,23 @@
<?php echo $form['incident_verified'] ? Kohana::lang('ui_main.yes') : Kohana::lang('ui_main.no');?>
<?php endif; ?>
</div>
<div class="row">
<div class="f-col-bottom-1-col"><?php echo Kohana::lang('ui_main.project_ended');?>?</div>
<?php if (Auth::instance()->has_permission('incident_status')): ?>
<input type="radio" name="incident_status" value="1"
<?php if ($form['incident_status'] == 1)
{
echo " checked=\"checked\" ";
}?>> <?php echo Kohana::lang('ui_main.yes');?>
<input type="radio" name="incident_status" value="2"
<?php if ($form['incident_status'] == 2)
{
echo " checked=\"checked\" ";
}?>> <?php echo Kohana::lang('ui_main.no');?>
<?php else: ?>
<?php echo $form['incident_status'] ? Kohana::lang('ui_main.yes') : Kohana::lang('ui_main.no');?>
<?php endif; ?>
</div>
</div>
<div style="clear:both;"></div>
</div>
Expand Down
1 change: 1 addition & 0 deletions media/js/ushahidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@
* z - {Number} The zoom level
* c - {Number} The category id
* m - {Number} The media type (0 - All, 1 - Pictures, 2 - Video 4 - News)
* st - {Number} Project Status (0 - All, 1 - Ended, 2 - Ongoing)
* s - {Number} Start date - Earliest date by which to filter the reports
* e - {Number} End date - Latest date by which to filter the reports
*/
Expand Down
5 changes: 5 additions & 0 deletions sql/upgrade117-118.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- UPDATE incidents
ALTER TABLE `incident` ADD incident_status tinyint(4);

-- Update DB Version --
UPDATE `settings` SET `value` = '118' WHERE `key` = 'db_version';
1 change: 1 addition & 0 deletions sql/ushahidi.sql
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ CREATE TABLE IF NOT EXISTS `incident` (
`incident_datemodify` datetime DEFAULT NULL,
`incident_alert_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0 - Not Tagged for Sending, 1 - Tagged for Sending, 2 - Alerts Have Been Sent',
`incident_zoom` tinyint(4) DEFAULT NULL,
`incident_status` tinyint(4) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `location_id` (`location_id`),
KEY `incident_active` (`incident_active`),
Expand Down
7 changes: 4 additions & 3 deletions themes/default/views/main/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,18 @@

<!-- filters -->
<div class="filters clearingfix">
<div class="media-filters">
<div class="filters">
<strong><?php echo Kohana::lang('ui_main.filters'); ?></strong>
<ul>
<li><a id="media_0" class="active" href="#"><span><?php echo Kohana::lang('ui_main.all'); ?></span></a></li>
<li><a id="media_4" href="#"><span><?php echo Kohana::lang('ui_main.news'); ?></span></a></li>
<li><a id="media_1" href="#"><span><?php echo Kohana::lang('ui_main.pictures'); ?></span></a></li>
<li><a id="media_2" href="#"><span><?php echo Kohana::lang('ui_main.video'); ?></span></a></li>
<li><a id="project_status_1" href="#"><span><?php echo Kohana::lang('ui_main.project_ended'); ?></span></a></li>
<li><a id="project_status_2" href="#"><span><?php echo Kohana::lang('ui_main.project_ongoing'); ?></span></a></li>
</ul>
</div>


</div>
<?php
// Action::main_filters - Add items to the main_filters
Event::run('ushahidi_action.map_main_filters');
Expand Down
18 changes: 17 additions & 1 deletion themes/default/views/main/main_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,26 @@ function refreshTimeline(options) {

//Execute the function when page loads
smartColumns();

// Project Status Filter Action
$('.filters a').click(function() {
var status = parseFloat(this.id.replace('project_status_', '')) || 0;

$('.filters a.active').removeClass('active');
$(this).addClass('active');

// Update the report filters
map.updateReportFilters({st: status});

return false;
});

//Execute the function when page loads
smartColumns();

});

$(window).resize(function () {
//Each time the viewport is adjusted/resized, execute the function
smartColumns();
});
});