broker team assignment cli update
Showing
5 changed files
with
90 additions
and
1 deletions
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
| ... | @@ -99,6 +99,13 @@ article { | ... | @@ -99,6 +99,13 @@ article { |
| 99 | } | 99 | } |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | // .page-template-marketing_masters-php { | ||
| 103 | |||
| 104 | // &.has-text-align-center { | ||
| 105 | // text-align: center !important; | ||
| 106 | // } | ||
| 107 | // } | ||
| 108 | |||
| 102 | #menu-hamburger-1 { | 109 | #menu-hamburger-1 { |
| 103 | white-space: nowrap; | 110 | white-space: nowrap; |
| 104 | } | 111 | } | ... | ... |
| ... | @@ -23,12 +23,14 @@ function syncBrokerListToPosts() { | ... | @@ -23,12 +23,14 @@ function syncBrokerListToPosts() { |
| 23 | 23 | ||
| 24 | global $wpdb; | 24 | global $wpdb; |
| 25 | 25 | ||
| 26 | $broker_posts = $wpdb->get_results('select post_author from wp_posts where post_author IN('.implode(',', $broker_ids).') and post_type = "broker"',OBJECT_K); | 26 | $broker_posts = $wpdb->get_results('select post_author,ID from wp_posts where post_author IN('.implode(',', $broker_ids).') and post_type = "broker"',OBJECT_K); |
| 27 | 27 | ||
| 28 | foreach($brokerList as $bl) { | 28 | foreach($brokerList as $bl) { |
| 29 | 29 | ||
| 30 | if(!empty($bl['broker_id']) && empty($broker_posts[$bl['broker_id']])) { | 30 | if(!empty($bl['broker_id']) && empty($broker_posts[$bl['broker_id']])) { |
| 31 | wp_insert_post(['post_type'=>'broker','post_author'=>$bl['broker_id'],'post_title'=>$bl['brokerage'],'post_status' => 'publish']); | 31 | wp_insert_post(['post_type'=>'broker','post_author'=>$bl['broker_id'],'post_title'=>$bl['brokerage'],'post_status' => 'publish']); |
| 32 | } else { | ||
| 33 | wp_update_post(['ID'=>$broker_posts[$bl['broker_id']]->ID,'post_author'=>$bl['broker_id'],'post_title'=>$bl['brokerage'],'post_status' => 'publish']); | ||
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | 36 | ... | ... |
| ... | @@ -3,7 +3,87 @@ | ... | @@ -3,7 +3,87 @@ |
| 3 | if ( class_exists( 'WP_CLI' ) ) { | 3 | if ( class_exists( 'WP_CLI' ) ) { |
| 4 | class TZ_BROKER_COMMANDS { | 4 | class TZ_BROKER_COMMANDS { |
| 5 | 5 | ||
| 6 | //collect rows of a csv file and store them in an associative array | ||
| 7 | function sync_broker_teams_assignment() { | ||
| 6 | 8 | ||
| 9 | $staff_members = []; | ||
| 10 | $row = 0; | ||
| 11 | if (($handle = fopen(wp_get_upload_dir()['basedir'] . "/" . "staff_assignment.csv", "r")) !== FALSE) { | ||
| 12 | while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | ||
| 13 | if($row == 0) { | ||
| 14 | ++$row; | ||
| 15 | continue; | ||
| 16 | } | ||
| 17 | $staff_members[] = ['full_name'=>trim($data[0]),'email'=>trim($data[1]), | ||
| 18 | 'phone'=>trim($data[2]).' #'.trim($data[3]),'category'=>strtolower(trim($data[4])),'sub_category'=>strtolower(trim($data[5])),'brokerages'=>trim($data[6])]; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | // if(count($staff_members) > 0) { | ||
| 23 | |||
| 24 | // $assignments = get_fields('options')['assignments']; | ||
| 25 | |||
| 26 | //Gather all the field keys from the ACF system | ||
| 27 | $field_keys = []; | ||
| 28 | $field_obj = get_field_objects('options')['assignments']; | ||
| 29 | foreach($field_obj['sub_fields'] as $fo) { | ||
| 30 | $field_keys[] = ['name'=>$fo['name'],'key'=>$fo['key']]; | ||
| 31 | } | ||
| 32 | |||
| 33 | global $wpdb; | ||
| 34 | $broker_posts = $wpdb->get_results('select post_author,ID from wp_posts where post_type = "broker"',OBJECT_K); | ||
| 35 | |||
| 36 | // $current_assignment_count = get_option('options_assignments'); | ||
| 37 | $iter_counter = 0; | ||
| 38 | foreach($staff_members as $assign) { | ||
| 39 | |||
| 40 | foreach($field_keys as $fk) { | ||
| 41 | |||
| 42 | $option_name = 'options_assignments_'.$iter_counter."_".$fk['name']; | ||
| 43 | $option_value = $assign[$fk['name']]; | ||
| 44 | if($option_value == 'all') { | ||
| 45 | $option_value = ''; | ||
| 46 | } | ||
| 47 | |||
| 48 | $option_name_key = '_options_assignments_'.$iter_counter."_".$fk['name']; | ||
| 49 | $option_value_key = $fk['key']; | ||
| 50 | |||
| 51 | // if($fk['name'] == 'brokerages') { | ||
| 52 | // var_dump($assign[$fk['name']]); | ||
| 53 | // } | ||
| 54 | |||
| 55 | if($fk['name'] == 'brokerages' && !empty($option_value)) { | ||
| 56 | $option_value = explode(',',$option_value); | ||
| 57 | |||
| 58 | $new_option_values = []; | ||
| 59 | |||
| 60 | foreach($option_value as $ov) { | ||
| 61 | foreach($broker_posts as $key => $val ) { | ||
| 62 | if($ov == $key) { | ||
| 63 | $ov = $val->ID; | ||
| 64 | $new_option_values[] = (int)$val->ID; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | var_dump($new_option_values);exit; | ||
| 70 | |||
| 71 | $option_value = serialize($new_option_values); | ||
| 72 | } | ||
| 73 | |||
| 74 | update_option($option_name, $option_value); | ||
| 75 | update_option($option_name_key, $option_value_key); | ||
| 76 | } | ||
| 77 | // var_dump( $assign); | ||
| 78 | ++$iter_counter; | ||
| 79 | |||
| 80 | } | ||
| 81 | |||
| 82 | // } | ||
| 83 | |||
| 84 | // syncBrokerListToPosts(); | ||
| 85 | |||
| 86 | } | ||
| 7 | 87 | ||
| 8 | function rebuild_brokers_assigment($args ) { | 88 | function rebuild_brokers_assigment($args ) { |
| 9 | 89 | ... | ... |
-
Please register or sign in to post a comment