/**
  * save event relation for the applies to promotion
  *
  * @since   1.0.0
  *
  * @param EE_Promotion $promotion
  * @param array  	    $data the incoming form data
  * @return void
  */
 public function handle_promotion_update(EE_Promotion $promotion, $data)
 {
     //first do we have any selected items?
     $selected_items = !empty($data['ee_promotions_applied_selected_items_Event']) ? explode(',', $data['ee_promotions_applied_selected_items_Event']) : array();
     $evt_ids = array();
     //existing pro_objects
     $pro_objects = $promotion->promotion_objects();
     //loop through existing and remove any that aren't present in the selected_items.
     foreach ($pro_objects as $pro_obj) {
         if (!in_array($pro_obj->OBJ_ID(), $selected_items)) {
             $promotion->delete_related('Promotion_Object', array(array('POB_ID' => $pro_obj->ID())));
         }
         $evt_ids[] = $pro_obj->OBJ_ID();
     }
     //k now let's make sure any that should be added are added.
     foreach ($selected_items as $EVT_ID) {
         if (in_array($EVT_ID, $evt_ids)) {
             continue;
         }
         $promotion_obj = EE_Promotion_Object::new_instance(array('PRO_ID' => $promotion->ID(), 'OBJ_ID' => $EVT_ID, 'POB_type' => $this->slug, 'POB_used' => 0));
         $promotion_obj->save();
     }
     //any filters to save?
     $set_filters = array('EVT_CAT_ID' => !empty($data['EVT_CAT_ID']) ? $data['EVT_CAT_ID'] : null, 'EVT_start_date_filter' => !empty($data['EVT_start_date_filter']) ? $data['EVT_start_date_filter'] : null, 'EVT_end_date_filter' => !empty($data['EVT_end_date_filter']) ? $data['EVT_end_date_filter'] : null, 'EVT_title_filter' => !empty($data['EVT_title_filter']) ? $data['EVT_title_filter'] : null, 'include_expired_events_filter' => !empty($data['include_expired_events_filter']) ? $data['include_expired_events_filter'] : null);
     $promotion->update_extra_meta('promo_saved_filters', $set_filters);
 }
 /**
  * get_promotion_objects
  * returns an array of EE_Promotion_Object's for the current scope type,
  * and adds any new ones required for the passed array of objects
  *
  * @since   1.0.4
  *
  * @param \EE_Promotion   $promotion
  * @param \EE_Base_Class[] $objects
  * @return \EE_Promotion_Object[]
  */
 protected function get_promotion_objects(EE_Promotion $promotion, $objects = array())
 {
     // retrieve promotion objects for this promotion type scope
     $promotion_objects = $promotion->promotion_objects(array(array('POB_type' => $this->slug)));
     // check that global promotions cover all events
     return $this->add_promotion_objects_for_global_promotions($promotion_objects, $promotion, $objects);
 }