/**
  * update function
  *
  * Called when a user submits the widget configuration form. The data should
  * be validated and returned.
  *
  * @param array $new_instance The new data that was submitted.
  * @param array $old_instance The widget's old data.
  * @return array The new data to save for this widget instance.
  */
 function update($new_instance, $old_instance)
 {
     // Save existing data as a base to modify with new data
     $instance = $old_instance;
     $instance['title'] = strip_tags($new_instance['title']);
     $instance['events_per_page'] = Ai1ec_Number_Utility::index($new_instance['events_per_page'], 1, 1);
     $instance['days_per_page'] = Ai1ec_Number_Utility::index($new_instance['days_per_page'], 1, 1);
     $instance['events_seek_type'] = $this->_valid_seek_type($new_instance['events_seek_type']);
     $instance['show_subscribe_buttons'] = $new_instance['show_subscribe_buttons'] ? true : false;
     $instance['show_calendar_button'] = $new_instance['show_calendar_button'] ? true : false;
     $instance['hide_on_calendar_page'] = $new_instance['hide_on_calendar_page'] ? true : false;
     // For limits, set the limit to False if no IDs were selected, or set the respective IDs to empty if "limit by" was unchecked
     $instance['limit_by_cat'] = false;
     $instance['event_cat_ids'] = array();
     if (isset($new_instance['event_cat_ids']) && $new_instance['event_cat_ids'] != false) {
         $instance['limit_by_cat'] = true;
     }
     if (isset($new_instance['limit_by_cat']) && $new_instance['limit_by_cat'] != false) {
         $instance['limit_by_cat'] = true;
     }
     if (isset($new_instance['event_cat_ids']) && $instance['limit_by_cat'] === true) {
         $instance['event_cat_ids'] = $new_instance['event_cat_ids'];
     }
     $instance['limit_by_tag'] = false;
     $instance['event_tag_ids'] = array();
     if (isset($new_instance['event_tag_ids']) && $new_instance['event_tag_ids'] != false) {
         $instance['limit_by_tag'] = true;
     }
     if (isset($new_instance['limit_by_tag']) && $new_instance['limit_by_tag'] != false) {
         $instance['limit_by_tag'] = true;
     }
     if (isset($new_instance['event_tag_ids']) && $instance['limit_by_tag'] === true) {
         $instance['event_tag_ids'] = $new_instance['event_tag_ids'];
     }
     $instance['limit_by_post'] = false;
     $instance['event_post_ids'] = array();
     if (isset($new_instance['event_post_ids']) && $new_instance['event_post_ids'] != false) {
         $instance['limit_by_post'] = true;
     }
     if (isset($new_instance['limit_by_post']) && $new_instance['limit_by_post'] != false) {
         $instance['limit_by_post'] = true;
     }
     if (isset($new_instance['event_post_ids']) && $instance['limit_by_post'] === true) {
         $instance['event_post_ids'] = $new_instance['event_post_ids'];
     }
     return $instance;
 }
 /**
  * get_pending_regeneration method
  *
  * Get events, that needs to be regenerated.
  *
  * @param int $limit Number of events to fetch [optional=100]
  *
  * @return array List of `Ai1ec_Event` objects, that need to be regenerated
  */
 public function get_pending_regeneration($limit = 100)
 {
     global $wpdb;
     $limit = Ai1ec_Number_Utility::index($limit, 1, 50);
     $table = $wpdb->prefix . 'ai1ec_events';
     $sql_query = 'SELECT post_id FROM ' . $table . ' WHERE force_regenerate = 1 LIMIT ' . $limit;
     $event_ids = $wpdb->get_col($sql_query);
     $events = array();
     foreach ($event_ids as $id) {
         try {
             $events[$id] = new Ai1ec_Event($id);
         } catch (Ai1ec_Event_Not_Found $excpt) {
             $this->toggle_regenerate_status($id, 0);
         }
     }
     return $events;
 }