From 156cc42a343191b84c215e98b0db576fceee4f99 Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Sun, 4 Dec 2011 14:04:12 -0800 Subject: [PATCH 1/8] Changes to in-activate a incident if its endtime has passed via cron --- controllers/scheduler/s_endtime.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 controllers/scheduler/s_endtime.php diff --git a/controllers/scheduler/s_endtime.php b/controllers/scheduler/s_endtime.php new file mode 100644 index 0000000..d0cd42c --- /dev/null +++ b/controllers/scheduler/s_endtime.php @@ -0,0 +1,39 @@ + + * @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() + { + $endtimes = ORM::factory('endtime') + ->with('incident') + ->where(array('incident_active' => '1', 'endtime_date <' => 'NOW()')) + ->find_all(); + + //Kohana::log('info', 'S_Endtime_Controller::index: '. print_r($incidents, 3)); + + foreach($endtimes as $endtime){ + Kohana::log('info', 'S_Endtime_Controller::index: '. print_r($endtime->incident->incident_title, 1)); + $incident = ORM::factory('incident') + ->where('id', $endtime->incident->id) + ->find(); + $incident->incident_active = 0; + $incident->save(); + } + } + +} From 0e242bc92cd45a7172f364c09a550f0247df5a08 Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Tue, 13 Dec 2011 22:47:49 -0800 Subject: [PATCH 2/8] Add a row to scheduler on install and delete it on uninstall --- libraries/endtime_install.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libraries/endtime_install.php b/libraries/endtime_install.php index 466790a..f599458 100755 --- a/libraries/endtime_install.php +++ b/libraries/endtime_install.php @@ -36,7 +36,19 @@ public function run_install() `endtime_date` datetime DEFAULT NULL, `applicable` tinyint(4) DEFAULT '1', PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); + + $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', '', 's_endtime', '1')"); } /** @@ -45,5 +57,6 @@ public function run_install() 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"'); } -} \ No newline at end of file +} From 8001f3c2b0fe3b87156c85075fbf7750feb06374 Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Fri, 16 Dec 2011 12:00:13 -0800 Subject: [PATCH 3/8] - make sure decay is working - Even though the incident is active it does not show up on the map? Something is setting it to be inactive too quickly and inacurately? It seems the scheduler is called on frontpage refreshes. And it is incorrectly setting it inactive. The problem is that the where query for comparing the time to now() is getting compared to the string 'NOW()' I fixed this by getting the date from php ala date("Y-m-d H:i:s") instead of from mysql. I am not sure if this will cause an issue with the application time zone settings vs the system time zone settings. I am not even sure if there is such a thing in Ushahidi/Kohana. --- controllers/scheduler/s_endtime.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/scheduler/s_endtime.php b/controllers/scheduler/s_endtime.php index d0cd42c..fe88ee9 100644 --- a/controllers/scheduler/s_endtime.php +++ b/controllers/scheduler/s_endtime.php @@ -21,13 +21,14 @@ public function index() { $endtimes = ORM::factory('endtime') ->with('incident') - ->where(array('incident_active' => '1', 'endtime_date <' => 'NOW()')) + // 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"))) ->find_all(); - //Kohana::log('info', 'S_Endtime_Controller::index: '. print_r($incidents, 3)); + Kohana::log('debug', 'S_Endtime_Controller::index: '. print_r($endtimes, 1)); foreach($endtimes as $endtime){ - Kohana::log('info', 'S_Endtime_Controller::index: '. print_r($endtime->incident->incident_title, 1)); + 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(); From fd511b8187c4a5dba43fe136bba4d7de8722484e Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Fri, 16 Dec 2011 12:49:39 -0800 Subject: [PATCH 4/8] There was an issue where re-activating the endtime module would cause multiple rows to be added to the scheduler table. --- libraries/endtime_install.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/libraries/endtime_install.php b/libraries/endtime_install.php index f599458..77f6ecb 100755 --- a/libraries/endtime_install.php +++ b/libraries/endtime_install.php @@ -38,24 +38,32 @@ public function run_install() PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"); - $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', '', 's_endtime', '1')"); + + $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"'); } From dc69edd84613fc622ac436381fa94d136531f1a6 Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Fri, 16 Dec 2011 16:56:54 -0800 Subject: [PATCH 5/8] Add a new column to track what the user wants to do when the incident reaches endtime --- libraries/endtime_install.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/endtime_install.php b/libraries/endtime_install.php index 77f6ecb..94afb25 100755 --- a/libraries/endtime_install.php +++ b/libraries/endtime_install.php @@ -34,7 +34,8 @@ 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"); @@ -66,5 +67,12 @@ 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"'); - } + } + + /** + * There is a way to up date ushahidi core, but there does not seem to + * be a way to update modules. 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 + */ } From 953ddc0d42b90e9e3c6c03bd01fcc65495e2636a Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Fri, 16 Dec 2011 16:59:24 -0800 Subject: [PATCH 6/8] Support for optional actions to be performed on incident endtime The first implemented feature is removing an incident from the map by de-activating it. --- controllers/scheduler/s_endtime.php | 8 +++++++- hooks/endtime.php | 13 +++++++++---- i18n/en_US/endtime.php | 4 ++++ views/endtime/endtime_form.php | 8 +++++++- views/endtime/endtime_view.php | 10 +++++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/controllers/scheduler/s_endtime.php b/controllers/scheduler/s_endtime.php index fe88ee9..95037c0 100644 --- a/controllers/scheduler/s_endtime.php +++ b/controllers/scheduler/s_endtime.php @@ -19,10 +19,16 @@ public function __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"))) + ->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)); diff --git a/hooks/endtime.php b/hooks/endtime.php index 516ba11..3de14c1 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()); @@ -117,6 +119,7 @@ public function _report_validate() if(is_object($this->post_data)) { $this->post_data->add_rules('end_incident_date','date_mmddyyyy'); + $this->post_data->add_rules('remain_on_map','digit'); } } @@ -137,6 +140,7 @@ public function _report_form_submit() ->find(); $endtime->incident_id = $incident->id; $endtime->applicable = isset($post['endtime_applicable']) ? "1" : "0"; + $endtime->remain_on_map = isset($post['remain_on_map']) ? $post['remain_on_map'] : "0"; //create the date if(is_object($post)) { @@ -180,6 +184,7 @@ 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); } @@ -245,4 +250,4 @@ private function _date_picker_js() }//end method -new endtime; \ No newline at end of file +new endtime; diff --git a/i18n/en_US/endtime.php b/i18n/en_US/endtime.php index ebcc599..d34e1fc 100644 --- a/i18n/en_US/endtime.php +++ b/i18n/en_US/endtime.php @@ -15,4 +15,8 @@ 'endtime_description' => 'the time the event stopped', 'applicable' => 'Applicable?', 'applicable_description' => 'Is an end time applicable to this event?', +'remain_on_map' => 'Keep marker on map after endtime?', +'remove_from_map' => 'Remove marker from map after endtime?', +'will_remain_on_map' => 'Marker will remain on map after endtime', +'will_remove_from_map' => 'Marker will be removed from map after endtime', ); diff --git a/views/endtime/endtime_form.php b/views/endtime/endtime_form.php index 40d4004..67c412b 100755 --- a/views/endtime/endtime_form.php +++ b/views/endtime/endtime_form.php @@ -9,7 +9,13 @@ -
" > +
" > + \n"; + print form::label('remain_on_map', Kohana::lang('endtime.remove_from_map')); + print form::radio('remain_on_map', 1, ($remain_on_map == 1)) ."
\n"; + ?>
diff --git a/views/endtime/endtime_view.php b/views/endtime/endtime_view.php index c2e036b..e1051cd 100755 --- a/views/endtime/endtime_view.php +++ b/views/endtime/endtime_view.php @@ -4,8 +4,12 @@
- : - + - \ No newline at end of file + From 86c589b03512269a6592557fa02370820eeed85c Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Tue, 20 Dec 2011 20:12:43 -0800 Subject: [PATCH 7/8] Adds upgrade path for the endtime table --- libraries/endtime_install.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/endtime_install.php b/libraries/endtime_install.php index 94afb25..c93fb5d 100755 --- a/libraries/endtime_install.php +++ b/libraries/endtime_install.php @@ -40,6 +40,22 @@ public function run_install() ) 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(); @@ -69,10 +85,4 @@ public function uninstall() $this->db->query('DELETE FROM `'.Kohana::config('database.default.table_prefix').'scheduler` WHERE `scheduler_name`="Endtime"'); } - /** - * There is a way to up date ushahidi core, but there does not seem to - * be a way to update modules. 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 - */ } From e9ffaab4134963f8da7c1f39a7a30234d4f22241 Mon Sep 17 00:00:00 2001 From: "Mr. Evoltech" Date: Tue, 21 Feb 2012 11:42:28 -0800 Subject: [PATCH 8/8] We are moving away from a large commit to endtime These commits allow the decayimage to extend some of the functionality of the endtime module. Later down the line this will be cleaned up and all decayimage related code will be removed them we will submit another pull request to jetherton. --- hooks/endtime.php | 11 +++++------ i18n/en_US/endtime.php | 4 ---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/hooks/endtime.php b/hooks/endtime.php index 3de14c1..a0e5e85 100755 --- a/hooks/endtime.php +++ b/hooks/endtime.php @@ -119,7 +119,6 @@ public function _report_validate() if(is_object($this->post_data)) { $this->post_data->add_rules('end_incident_date','date_mmddyyyy'); - $this->post_data->add_rules('remain_on_map','digit'); } } @@ -140,7 +139,7 @@ public function _report_form_submit() ->find(); $endtime->incident_id = $incident->id; $endtime->applicable = isset($post['endtime_applicable']) ? "1" : "0"; - $endtime->remain_on_map = isset($post['remain_on_map']) ? $post['remain_on_map'] : "0"; + //create the date if(is_object($post)) { @@ -191,7 +190,7 @@ public function _report_view() // Time functions - private function _hour_array() + protected function _hour_array() { for ($i=1; $i <= 12 ; $i++) { @@ -201,7 +200,7 @@ private function _hour_array() } // Time functions - private function _minute_array() + protected function _minute_array() { for ($i=0; $i <= 59 ; $i++) { @@ -211,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 "