/**
  * Displays al lthe person relationships for this user.
  *
  * @since 1.0.0
  * @todo   Add paging.
  * @todo   Add filters.
  *
  * @param WP_Post $post
  *
  * @return string
  */
 public function person_to_cpt_details($post)
 {
     //get all relationships for the given person
     $person_relationships = EEM_Person_Post::instance()->get_all(array(array('PER_ID' => $post->ID)));
     //let's setup the row data for the rows.
     $row_data = array();
     foreach ($person_relationships as $person_relationship) {
         $cpt_obj = EE_Registry::instance()->load_model($person_relationship->get('OBJ_type'))->get_one_by_ID($person_relationship->get('OBJ_ID'));
         if ($cpt_obj instanceof EE_Base_Class) {
             if (!isset($row_data[$cpt_obj->ID()])) {
                 switch (get_class($cpt_obj)) {
                     case 'EE_Event':
                         $css_class = 'dashicons dashicons-calendar-alt';
                         $edit_link = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $cpt_obj->ID()), admin_url('admin.php'));
                         break;
                     case 'EE_Venue':
                         $css_class = 'ee-icon ee-icon-venue';
                         $edit_link = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $cpt_obj->ID()), admin_url('admin.php'));
                         break;
                     case 'EE_Attendee':
                         $css_class = 'dashicons dashicons-admin-users';
                         $edit_link = add_query_arg(array('page' => 'espresso_registrations', 'action' => 'edit_attendee', 'post' => $cpt_obj->ID()), admin_url('admin.php'));
                         break;
                     default:
                         $css_class = '';
                         break;
                 }
                 $row_data[$cpt_obj->ID()] = array('css_class' => $css_class, 'cpt_type' => strtolower($person_relationship->get('OBJ_type')), 'cpt_obj' => $cpt_obj, 'edit_link' => $edit_link, 'ct_obj' => array(EEM_Term_Taxonomy::instance()->get_one_by_ID($person_relationship->get('PT_ID'))));
             } else {
                 //add other person types.
                 $row_data[$cpt_obj->ID()]['ct_obj'][] = EEM_Term_Taxonomy::instance()->get_one_by_ID($person_relationship->get('PT_ID'));
             }
         }
     }
     //now we have row data so we can send that to the template
     $template_args = array('row_data' => $row_data);
     $template = EEA_PEOPLE_ADDON_ADMIN_TEMPLATE_PATH . 'person_to_cpt_details_metabox_content.template.php';
     EEH_Template::display_template($template, $template_args);
 }
 public function column_PER_event_types($item)
 {
     EE_Registry::instance()->load_helper('URL');
     //first do a query to get all the types for this user for where they are assigned to an event.
     $event_type_IDs = EEM_Person_Post::instance()->get_col(array(array('PER_ID' => $item->ID(), 'OBJ_type' => 'Event')), 'PT_ID');
     $event_types = EEM_Term_Taxonomy::instance()->get_all(array(array('term_taxonomy_id' => array('IN', $event_type_IDs))));
     //loop through the types and setup the pills and the links
     $content = '<ul class="person-to-cpt-people-type-list">';
     foreach ($event_types as $type) {
         $name = $type->get_first_related('Term')->get('name');
         $count = EEM_Person_Post::instance()->count(array(array('PER_ID' => $item->ID(), 'OBJ_type' => 'Event', 'PT_ID' => $type->ID())));
         $event_filter_link = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_events', 'action' => 'default', 'PER_ID' => $item->ID(), 'PT_ID' => $type->ID()), admin_url('admin.php'));
         $content .= '<li><a href="' . $event_filter_link . '">' . $name . '<span class="person-type-count">' . $count . '</span></a></li>';
     }
     $content .= '</ul>';
     echo $content;
 }
 /**
  * resets the model and returns it
  * @return EEM_Person_Post
  */
 public static function reset($timezone = NULL)
 {
     self::$_instance = NULL;
     return self::instance($timezone);
 }
 /**
  * Utility function used to get various items from the Person_Post model depending on the given params.
  * When no obj_id is provided, we use what is set as the $post id if present.
  *
  * @param int         $obj_id              What the obj_id is for comparing against.
  * @param string    $primary_obj_type What it is being retrieved.
  *
  * @return EE_Base_Class[]  (what is returned depends on what the primary_obj_type is)
  */
 protected static function _get_rel_objects($obj_id = 0, $primary_obj_type = 'Person')
 {
     $objects = array();
     if (empty($obj_id)) {
         global $post;
         $obj_id = $post instanceof WP_Post ? $post->ID : $obj_id;
     }
     //still empty? return empty array
     if (empty($obj_id)) {
         return array();
     }
     if ($primary_obj_type != 'Person') {
         $where = array('PER_ID' => $obj_id, 'OBJ_type' => $primary_obj_type);
         $query = array($where);
     } else {
         $where = array('OBJ_ID' => $obj_id);
         $query = array($where, 'order_by' => array('PER_OBJ_order' => 'ASC'));
     }
     $object_items = EEM_Person_Post::instance()->get_all($query);
     $term_name_cache = array();
     if (method_exists(EEM_Event::instance(), 'public_event_stati')) {
         $public_event_stati = EEM_Event::instance()->public_event_stati();
     } else {
         $public_event_stati = get_post_stati(array('public' => TRUE));
         foreach (EEM_Event::instance()->get_custom_post_statuses() as $custom_post_status) {
             $public_event_stati[] = strtolower(str_replace(' ', '_', $custom_post_status));
         }
     }
     foreach ($object_items as $object_item) {
         if (!isset($term_name_cache[$object_item->get('PT_ID')]) || !isset($objects[$term_name][$object_item->ID()])) {
             $term_name = EEM_Term_Taxonomy::instance()->get_one_by_ID($object_item->get('PT_ID'))->get_first_related('Term')->get('name');
             $related_object = $object_item->get_first_related($primary_obj_type, array(array('status' => array('IN', apply_filters('FHEE__EEH_People_View__get_rel_objects__public_event_stati', $public_event_stati)))));
             if ($related_object instanceof EE_Base_Class) {
                 $objects[$term_name][$object_item->ID()] = $related_object;
                 $term_name_cache[$object_item->get('PT_ID')] = $term_name;
             }
         }
     }
     return $objects;
 }
 /**
  * Callback for AHEE__EE_Base_Class__delete_before hook so we can ensure any person relationships for an item being deleted
  * are also handled.
  *
  * @param EE_Base_Class $model_object
  */
 public function delete_people_relations_on_related_delete(EE_Base_Class $model_object)
 {
     if ($model_object instanceof EE_Event) {
         $remove_where = array('OBJ_ID' => $model_object->ID(), 'OBJ_type' => 'Event');
         EEM_Person_Post::instance()->delete(array($remove_where));
     }
 }