Пример #1
0
 public static function prepare_buddypress_data($user_id, $config, $entry)
 {
     // required for user to display in the directory
     if (function_exists('bp_update_user_last_activity')) {
         bp_update_user_last_activity($user_id);
     } else {
         bp_update_user_meta($user_id, 'last_activity', true);
     }
     $buddypress_meta = rgars($config, 'meta/buddypress_meta');
     if (empty($buddypress_meta)) {
         return;
     }
     self::log_debug(__METHOD__ . '(): starting.');
     $form = RGFormsModel::get_form_meta($entry['form_id']);
     $buddypress_row = array();
     $i = 0;
     foreach ($buddypress_meta as $meta_item) {
         if (empty($meta_item['meta_name']) || empty($meta_item['meta_value'])) {
             continue;
         }
         $buddypress_row[$i]['field_id'] = $meta_item['meta_name'];
         $buddypress_row[$i]['user_id'] = $user_id;
         // get GF and BP fields
         $gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']);
         if (version_compare(BP_VERSION, '1.6', '<')) {
             $bp_field = new BP_XProfile_Field();
             $bp_field->bp_xprofile_field($meta_item['meta_name']);
         } else {
             require_once WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-classes.php';
             $bp_field = new BP_XProfile_Field($meta_item['meta_name']);
         }
         // if bp field is a checkbox AND gf field is a checkbox, get array of input values
         $input_type = RGFormsModel::get_input_type($gform_field);
         if (in_array($bp_field->type, array('checkbox', 'multiselectbox')) && in_array($input_type, array('checkbox', 'multiselect'))) {
             $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
             if (!is_array($meta_value)) {
                 $meta_value = explode(',', $meta_value);
             }
             $meta_value = self::maybe_get_category_name($gform_field, $meta_value);
             $meta_value = array_filter($meta_value, 'GFUser::not_empty');
         } else {
             if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') {
                 if (version_compare(BP_VERSION, '2.1.1', '<')) {
                     $meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry));
                 } else {
                     $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry) . ' 00:00:00';
                 }
             } else {
                 $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry);
             }
         }
         self::log_debug(__METHOD__ . "(): Meta item: {$meta_item['meta_name']}. Value: {$meta_value}");
         $buddypress_row[$i]['value'] = $meta_value;
         $buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s');
         $buddypress_row[$i]['field'] = $bp_field;
         $i++;
     }
     GFUserData::insert_buddypress_data($buddypress_row);
     self::log_debug(__METHOD__ . '(): finished.');
 }
Пример #2
0
 public static function prepare_buddypress_data($user_id, $config, $entry)
 {
     // required for user to display in the directory
     bp_update_user_meta($user_id, 'last_activity', true);
     $buddypress_meta = rgars($config, 'meta/buddypress_meta');
     if (empty($buddypress_meta)) {
         return;
     }
     $form = RGFormsModel::get_form_meta($entry['form_id']);
     $buddypress_row = array();
     $i = 0;
     foreach ($buddypress_meta as $meta_item) {
         $buddypress_row[$i]['field_id'] = $meta_item['meta_name'];
         $buddypress_row[$i]['user_id'] = $user_id;
         // get GF and BP fields
         $gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']);
         $bp_field = new BP_XProfile_Field();
         $bp_field->bp_xprofile_field($meta_item['meta_name']);
         // if bp field is a checkbox AND gf field is a checkbox, get array of input values
         if ($bp_field->type == 'checkbox' && $gform_field['type'] == 'checkbox') {
             $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
             $meta_value = array_filter($meta_value, 'GFUser::not_empty');
         } else {
             if ($bp_field->type == 'multiselectbox' && $gform_field['type'] == 'checkbox') {
                 $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field);
                 $meta_value = array_filter($meta_value, 'GFUser::not_empty');
             } else {
                 if ($bp_field->type == 'datebox' && $gform_field['type'] == 'date') {
                     $meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry));
                 } else {
                     $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry);
                 }
             }
         }
         $buddypress_row[$i]['value'] = xprofile_sanitize_data_value_before_save($meta_value, $meta_item['meta_name']);
         $buddypress_row[$i]['last_update'] = date('Y-m-d H:i:s');
         $i++;
     }
     GFUserData::insert_buddypress_data($buddypress_row);
 }