Exemplo n.º 1
0
 /**
  * Sync the BullhornCategory from Bullhorn's API
  */
 public function sync()
 {
     // Import the required api classes
     require_once sprintf("%s/rest/entity.php", dirname(__FILE__));
     require_once sprintf("%s/rest/connection.php", dirname(__FILE__));
     // Create a connection to bullhorn
     $bh_connection = new BullhornRestConnection(get_option('bh_client_id'), get_option('bh_client_secret'), get_option('bh_username'), get_option('bh_password'));
     $bh_entity = new BullhornEntity($bh_connection, "Category");
     // Query for all job order JobOrderIDs
     $entities = $bh_entity->query("id,name,description", get_option("bh_category_sync_where"));
     foreach ($entities as $category) {
         if (!get_term_by("name", $category->name, self::SLUG, ARRAY_A)) {
             // Create the new term
             $t = wp_insert_term($category->name, self::SLUG, array("description" => $category->description));
         }
         // END if(!get_term_by("name", $category->name, self::SLUG, ARRAY_A))
     }
     // END foreach($entities as $category)
 }
Exemplo n.º 2
0
 /**
  * Sync the JobOrders from Bullhorn's API
  */
 public function sync()
 {
     $this->init();
     global $wpdb;
     // Import the required api classes
     require_once sprintf("%s/rest/entity.php", dirname(__FILE__));
     require_once sprintf("%s/rest/connection.php", dirname(__FILE__));
     // Create a connection to bullhorn
     $bh_connection = new BullhornRestConnection(get_option('bh_client_id'), get_option('bh_client_secret'), get_option('bh_username'), get_option('bh_password'));
     $bh_entity = new BullhornEntity($bh_connection, "JobOrder");
     $bh_country = new BullhornEntity($bh_connection, "Country");
     // Query for all job order JobOrderIDs
     $this->_query_parts = array();
     foreach ($this->_acf_config['fields'] as $field) {
         if ($field['type'] == 'tab') {
             /* Do nothing this isn't an API content part */
         } elseif ($field['type'] == 'repeater') {
             if ("address" == $field['name']) {
                 $this->_query_parts[] = $field['name'];
             }
             if (in_array($field['name'], array("responseUser", "owner"))) {
                 $sub_query_parts = array();
                 foreach ($field['sub_fields'] as $sub_field) {
                     $sub_query_parts[] = $sub_field['name'];
                 }
                 $this->_query_parts[] = sprintf("%s(%s)", $field['name'], implode($sub_query_parts, ","));
             }
         } else {
             $this->_query_parts[] = $field['name'];
         }
     }
     $this->_query_parts[] = "categories(name,description)";
     $entities = $bh_entity->query(implode($this->_query_parts, ","), get_option("bh_joborder_sync_where"));
     if (is_array($entities)) {
         // Unpublish all job-order posts
         $wpdb->query(sprintf("\n                        UPDATE {$wpdb->posts} \n                        SET post_status = 'draft' \n                        WHERE post_type = '%s'", self::POST_TYPE));
         // Get all of the job-order that are active currently
         foreach ($entities as $job) {
             // Set up the post
             $post = array('post_status' => 'publish', 'post_type' => self::POST_TYPE, 'post_title' => (string) $job->title, 'post_content' => (string) $job->publicDescription, 'post_author' => 1, 'filter' => true);
             // Try to get a post with this JobOrderID
             $post_id = $wpdb->get_var(sprintf("\n                            SELECT post_id\n                            FROM {$wpdb->postmeta}\n                            WHERE meta_key = 'id'\n                            AND meta_value = %s\n                            LIMIT 1", $job->id));
             // Insert or update a post depending on whther the
             // JobOrderID exists in the system already
             if ($post_id != 0) {
                 $post['ID'] = $post_id;
                 $post_id = wp_update_post($post);
             } else {
                 $post_id = wp_insert_post($post);
             }
             // If post_id
             if (!empty($post_id) && $post_id > 0) {
                 // then update all of the metadata
                 foreach ($job as $field_name => $field_value) {
                     if (is_object($field_value)) {
                         // Handle the main Job Address
                         if ("address" == $field_name) {
                             $address = array((array) $field_value);
                             try {
                                 $country = $bh_country->get($address[0]['countryID'], "name");
                                 $address[0]['country_name'] = $country->data->name;
                             } catch (Exception $e) {
                                 $address[0]['country_name'] = "";
                             }
                             update_field("field_53bfeccc29e78", $address, $post_id);
                         }
                         // END if("address" == $field_name)
                         // Handle the ResponseUser
                         if ("responseUser" == $field_name) {
                             // Get the CorporateUser Fields
                             $u = array((array) $field_value);
                             // Pull the Address Out
                             $a = array((array) $u[0]['address']);
                             // Pull the CountryName by countryID
                             try {
                                 $country = $bh_country->get($a[0]['countryID'], "name");
                                 $a[0]['country_name'] = $country->data->name;
                             } catch (Exception $e) {
                                 $a[0]['country_name'] = "";
                             }
                             $u[0]['address'] = $a;
                             // Save the CorporateUser Fields
                             update_field("field_53c04224c7cf3", $u, $post_id);
                         }
                         // END if("responseUser" == $field_name)
                         // Handle the owner
                         if ("owner" == $field_name) {
                             // Get the CorporateUser Fields
                             $u = array((array) $field_value);
                             // Pull the Address Out
                             $a = array((array) $u[0]['address']);
                             // Pull the CountryName by countryID
                             try {
                                 $country = $bh_country->get($a[0]['countryID'], "name");
                                 $a[0]['country_name'] = $country->data->name;
                             } catch (Exception $e) {
                                 $a[0]['country_name'] = "";
                             }
                             $u[0]['address'] = $a;
                             // Save the CorporateUser Fields
                             update_field("field_53c054d0c6231", $u, $post_id);
                         }
                         // END if("owner" == $field_name)
                     } else {
                         @update_post_meta($post_id, $field_name, (string) $field_value);
                     }
                 }
                 // END foreach($job as $field_name => $field_value)
                 // Then update the attached terms
                 $terms = array();
                 foreach ($job->categories->data as $category) {
                     $t = get_term_by("name", $category->name, BullhornCategory::SLUG, ARRAY_A);
                     if (!$t) {
                         // Create the new term
                         $t = wp_insert_term($category->name, BullhornCategory::SLUG, array("description" => $category->description));
                         if (is_wp_error($t)) {
                             $terms[] = $t->error_data["term_exists"];
                         } else {
                             $terms[] = $t["term_id"];
                         }
                     } else {
                         $terms[] = $t["term_id"];
                     }
                 }
                 // END for($job->categories->data as $category)
                 // Set Object Terms
                 wp_set_post_terms($post_id, $terms, BullhornCategory::SLUG, FALSE);
             }
             // END if(!empty($post_id) && $post_id > 0)
         }
         // END foreach($jobs as $job)
     }
     // END if(($arr_ids = $bh_job_order->query($bh_connection)) != False)
 }