public static function send_saved_property_to_api($user_id, $saved_property, $api_user_id = false)
 {
     if (!empty($user_id) && !empty($saved_property)) {
         if (empty($api_user_id)) {
             $api_user_id = DispletRetsIdxLeadsModel::get_api_user_id($user_id);
         }
         if (!empty($api_user_id)) {
             return DispletRetsIdxUsersApiController::create_saved_property($api_user_id, $saved_property['sysid'], $saved_property['type'], $saved_property['rating'], $saved_property['message']);
         }
     }
 }
 private static function get_user_property_suggestions()
 {
     if (!empty(self::$_model['user_id'])) {
         $api_user_id = get_user_meta(self::$_model['user_id'], 'displet_api_user_id', true);
         if (!empty($api_user_id)) {
             $saved_searches = DispletRetsIdxUsersApiController::get_saved_searches($api_user_id);
             if (!empty($saved_searches)) {
                 foreach ($saved_searches as $saved_search) {
                     if (!empty($saved_search->suggested)) {
                         self::$_model['property_suggestions'] = $saved_search;
                     }
                 }
             }
         }
     }
 }
 public static function update_viewed_properties($property)
 {
     $user_id = get_current_user_id();
     if ($user_id != 0 && current_user_can('displet_save_properties') && !current_user_can('manage_options')) {
         $user_properties = get_user_meta($user_id, 'displet_user_properties', true);
         if (empty($user_properties)) {
             $user_properties = array();
         }
         $user_property = wp_parse_args($property, array('address' => '', 'baths' => '', 'beds' => '', 'id' => '', 'image_url' => '', 'price' => '', 'sq_ft' => '', 'url' => '', 'zip' => ''));
         $user_properties[] = $user_property;
         update_user_meta($user_id, 'displet_user_properties', $user_properties);
         $stats = DispletRetsIdxViewedPropertiesController::update_property_view_stats($user_id, $user_properties);
         if (!empty($property['id'])) {
             $api_user_id = get_user_meta($user_id, 'displet_api_user_id', true);
             if (!empty($api_user_id)) {
                 DispletRetsIdxUsersApiController::update_user_property_views($api_user_id, $property['id']);
             }
         }
         do_action('displetretsidx_post_lead_viewed_property', $user_id, array('all_properties' => $user_properties, 'last_property' => $user_property, 'properties_count' => count($user_properties), 'properties_stats' => $stats));
     }
 }
 public static function upgrade_users_to_role_2()
 {
     $leads = DispletRetsIdxLeadsModel::get_users();
     if (!empty($leads)) {
         foreach ($leads as $lead) {
             $name = get_user_meta($lead->ID, 'nickname', true);
             $names = DispletRetsIdxUsersModel::get_first_and_last_name($name);
             if (!empty($names)) {
                 wp_update_user(array('ID' => $lead->ID, 'display_name' => $names['first_name']));
                 update_user_meta($lead->ID, 'first_name', $names['first_name']);
                 update_user_meta($lead->ID, 'last_name', $names['last_name']);
             }
             $api_user_id = get_user_meta($lead->ID, 'displet_api_user_id', true);
             if (empty($api_user_id)) {
                 $api_user_id = DispletRetsIdxUsersApiController::create_user($lead->user_email, $names['first_name'], $names['last_name']);
                 update_user_meta($lead->ID, 'displet_api_user_id', $api_user_id);
             }
             DispletRetsIdxSavedSearchesController::send_users_saved_searches_to_api($lead->ID, $api_user_id);
         }
     }
 }
 public static function send_users_saved_searches_to_api($user_id, $api_user_id)
 {
     if (!empty($user_id) && !empty($api_user_id)) {
         $saved_searches = get_user_meta($user_id, 'displet_saved_searches', true);
         if (!empty($saved_searches)) {
             $new_saved_searches = array();
             foreach ($saved_searches as $saved_search) {
                 if (is_array($saved_search)) {
                     $hash = $saved_search['hash'];
                     $name = $saved_search['name'];
                 } else {
                     $hash = $saved_search;
                     $name = false;
                 }
                 if (empty($name)) {
                     $name = wp_generate_password(12, false);
                 }
                 $criteria = DispletRetsIdxResidentialsModel::get_search_criteria_from_hash($hash);
                 $saved_search_id = DispletRetsIdxUsersApiController::create_saved_search($api_user_id, $name, $criteria);
                 $new_saved_searches[] = array('hash' => $hash, 'name' => $name, 'api_id' => $saved_search_id);
             }
             update_user_meta($user_id, 'displet_saved_searches', $new_saved_searches);
         }
     }
 }
 public static function update_assigned_agent_id_at_api($lead_user_id, $agent_user_id)
 {
     if (!empty($lead_user_id) && !empty($agent_user_id)) {
         $api_user_id = get_user_meta($lead_user_id, self::$_meta_keys['api_user_id'], true);
         $api_agent_id = get_user_meta($agent_user_id, self::$_meta_keys['agent']['api_id'], true);
         if (!empty($api_user_id) && !empty($api_agent_id)) {
             DispletRetsIdxUsersApiController::update_user($api_user_id, array('agent_profile_id' => $api_agent_id));
         }
     }
 }