diff --git a/controllers/scheduler/s_endtime.php b/controllers/scheduler/s_endtime.php new file mode 100644 index 0000000..95037c0 --- /dev/null +++ b/controllers/scheduler/s_endtime.php @@ -0,0 +1,46 @@ + + * @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(); + } + } + +} diff --git a/hooks/endtime.php b/hooks/endtime.php index 516ba11..a0e5e85 100755 --- a/hooks/endtime.php +++ b/hooks/endtime.php @@ -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')); + } /** @@ -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 == "") @@ -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()); @@ -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)) { @@ -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++) { @@ -196,7 +200,7 @@ private function _hour_array() } // Time functions - private function _minute_array() + protected function _minute_array() { for ($i=0; $i <= 59 ; $i++) { @@ -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 "