Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is a patch for issue #1 #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions controllers/scheduler/s_endtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* EMAIL Scheduler Controller (IMAP/POP3)
*
* PHP version 5
* LICENSE: This source file is subject to LGPL license
* that is available through the world-wide-web at the following URI:
* http://www.gnu.org/copyleft/lesser.html
* @author Mr Evoltech <[email protected]>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
*/

class S_Endtime_Controller extends Controller {

public function __construct()
{
parent::__construct();
}

public function index()
{
// remain_on_map is not intended to be a boolean value, but instead allow a number of
// different values that will map to different actions to be taken when the incident
// reaches its endtime. Ie. change marker icon, send notification
$endtimes = ORM::factory('endtime')
->with('incident')
// Does the use of php date cause an issue with application timezone vs system timezone?
->where(array(
'incident_active' => '1',
'endtime_date <' => date("Y-m-d H:i:s"),
'remain_on_map' => '1'))
->find_all();

Kohana::log('debug', 'S_Endtime_Controller::index: '. print_r($endtimes, 1));

foreach($endtimes as $endtime){
Kohana::log('info', 'S_Endtime_Controller::index Setting '. $endtime->incident->incident_title .'('. $endtime->incident_id .') to inactive');
$incident = ORM::factory('incident')
->where('id', $endtime->incident->id)
->find();
$incident->incident_active = 0;
$incident->save();
}
}

}
20 changes: 12 additions & 8 deletions hooks/endtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function add()
// Hook into the report_edit (post_SAVE) event
Event::add('ushahidi_action.report_edit', array($this, '_report_form_submit'));


// Hook into the Report view (front end)
Event::add('ushahidi_action.report_meta_after_time', array($this, '_report_view'));
Event::add('ushahidi_action.report_meta_after_time', array($this, '_report_view'));

}

/**
Expand Down Expand Up @@ -70,6 +70,7 @@ public function _report_form()
->find();

$view->applicable = $endtime_item->applicable;
$view->remain_on_map = $endtime_item->remain_on_map;
$endtime_date = $endtime_item->endtime_date;

if($endtime_date == "")
Expand All @@ -92,6 +93,7 @@ public function _report_form()
else //initialize to now
{
$view->applicable = 0;
$view->remain_on_map= 0;
$form['end_incident_date'] = date("m/d/Y",time());
$form['end_incident_hour'] = date('h', time());
$form['end_incident_minute'] = date('i', time());
Expand Down Expand Up @@ -137,6 +139,7 @@ public function _report_form_submit()
->find();
$endtime->incident_id = $incident->id;
$endtime->applicable = isset($post['endtime_applicable']) ? "1" : "0";

//create the date
if(is_object($post))
{
Expand Down Expand Up @@ -180,13 +183,14 @@ public function _report_view()
$view = View::factory('endtime/endtime_view');
$view->end_date = $endtime->endtime_date;
$view->applicable = $endtime->applicable;
$view->remain_on_map = $endtime->remain_on_map;
$view->render(TRUE);
}



// Time functions
private function _hour_array()
protected function _hour_array()
{
for ($i=1; $i <= 12 ; $i++)
{
Expand All @@ -196,7 +200,7 @@ private function _hour_array()
}

// Time functions
private function _minute_array()
protected function _minute_array()
{
for ($i=0; $i <= 59 ; $i++)
{
Expand All @@ -206,12 +210,12 @@ private function _minute_array()
}


private function _ampm_array()
protected function _ampm_array()
{
return $ampm_array = array('pm'=>Kohana::lang('ui_admin.pm'),'am'=>Kohana::lang('ui_admin.am'));
}

private function _date_picker_js()
protected function _date_picker_js()
{
return "<script type=\"text/javascript\">
$(document).ready(function() {
Expand Down Expand Up @@ -245,4 +249,4 @@ private function _date_picker_js()

}//end method

new endtime;
new endtime;
49 changes: 44 additions & 5 deletions libraries/endtime_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,55 @@ public function run_install()
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`incident_id` int(11) NOT NULL,
`endtime_date` datetime DEFAULT NULL,
`applicable` tinyint(4) DEFAULT '1',
`applicable` tinyint(4) DEFAULT '1',
`remain_on_map` tinyint(4) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");


/**
* Updates made to the endtime schema from March-Hare Communications
* Collective on 2011-12-16:
* ALTER TABLE `endtime` ADD `remain_on_map` TINYINT( 4 ) NOT NULL
*/
$has_remain_on_map = false;
foreach($this->db->field_data(Kohana::config('database.default.table_prefix')."endtime") as $field) {
if ($field->Field == 'remain_on_map') {
$has_remain_on_map = true;
break;
}
}
if (!$has_remain_on_map) {
$this->db->query('ALTER TABLE '. Kohana::config('database.default.table_prefix') .'`endtime` ADD `remain_on_map` TINYINT( 4 ) NOT NULL');
}

$s_endtime = ORM::factory('scheduler')
->where(array('scheduler_name' => 'Endtime'))
->find();

if (!$s_endtime->count_last_query()) {
$this->db->query("INSERT INTO `".Kohana::config('database.default.table_prefix')."scheduler` (
`id`,
`scheduler_name`,
`scheduler_last`,
`scheduler_weekday`,
`scheduler_day`,
`scheduler_hour`,
`scheduler_minute`,
`scheduler_controller`,
`scheduler_active`)
VALUES (NULL, 'Endtime', '0', '-1', '-1', '-1', '-1', 's_endtime', '1')");
}
}

/**
* Deletes the database tables for the actionable module
*/
public function uninstall()
{
{

$this->db->query('DROP TABLE `'.Kohana::config('database.default.table_prefix').'endtime`');
}
}
$this->db->query('DELETE FROM `'.Kohana::config('database.default.table_prefix').'scheduler` WHERE `scheduler_name`="Endtime"');
}

}
8 changes: 7 additions & 1 deletion views/endtime/endtime_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<span><?php echo Kohana::lang('endtime.applicable_description');?></span></div>
</h4>
<!--<div style = "border: 1px solid black; margin-left:10px;">-->
<div id="endtime_form" style="margin-left:30px; <?php echo (($applicable == "1") ? "" : "display:none;"); ?>" >
<div id="endtime_form" style="margin-left:30px; <?php echo (($applicable == "1") ? "" : "display:none;"); ?>" >
<?php
print form::label('remain_on_map', Kohana::lang('endtime.remain_on_map'));
print form::radio('remain_on_map', 0, ($remain_on_map == 0)) ."<br />\n";
print form::label('remain_on_map', Kohana::lang('endtime.remove_from_map'));
print form::radio('remain_on_map', 1, ($remain_on_map == 1)) ."<br />\n";
?>
<?php print form::input('end_incident_date', $form['end_incident_date'], ' class="text"'); ?>
<?php print $date_picker_js; ?>
<br/>
Expand Down
10 changes: 7 additions & 3 deletions views/endtime/endtime_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

<br/>
<span class="r_date">
<?php echo Kohana::lang('endtime.endtime');?>:
<?php echo date('H:i M j Y', strtotime($end_date)); ?>
<?php
echo Kohana::lang('endtime.endtime') .": ".
date('H:i M j Y', strtotime($end_date)) .". ".
($remain_on_map ? Kohana::lang('endtime.will_remove_from_map') : Kohana::lang('endtime.will_remain_on_map'));

?>
</li>

<?php } ?>
<?php } ?>