• Resolved Etienne

    (@etienne01)


    What is the easiest way to link (or frequently upload/update) the connections of this Connections Business Directory plugin into the locations of the my calendar plugin?

    Note: see support request on my-calendar. Request of developer Joe Dolson: If you can ping the author of that plug-in, they’ll know better whether there are existing hooks in the plug-in that could be used.

    Is it possible you can hook up together?
    Thanks in advance for the support and teamwork!

    Related site: http://zwaluweleeft.nl (under construction)

Viewing 8 replies - 1 through 8 (of 8 total)
  • To be specific, I’d like to know if there are any actions or filters run when a new location is saved into your directory plug-in that could be hooked into to copy the location as an event location.

    If your locations are a custom post type, just let me know that.

    Thread Starter Etienne

    (@etienne01)

    Hi owner of Connections Business Directory, any possible feedback yet?

    Plugin Author shazahm1

    (@shazahm1)

    Yes, this can be done fairly easily. Another user created their own custom plugin to link data from Connections to WP Google Maps.

    You can hook into the cn_post_process_add-entry and cn_post_process_update-entry hooks. The action passes one value, an instance of the cnEntry object which contains the data that will be saved to the db.

    The hook can be found here:
    https://github.com/Connections-Business-Directory/Connections/blob/8.1.5/includes/entry/class.entry-actions.php#L816

    The methods available in the cnEntry object are in this file:
    https://github.com/Connections-Business-Directory/Connections/blob/8.1.5/includes/entry/class.entry-data.php

    Just use the getter methods.

    Hope that helps!

    Thread Starter Etienne

    (@etienne01)

    Thanks, good solution and got it working.

    Plugin Author Steven

    (@shazahm1hotmailcom)

    @ etienne01

    Fantastic! … do you have a gist or something you can share?

    Thread Starter Etienne

    (@etienne01)

    Kept id from connections and my calendar-location equal to use shortcodes for easier linking of calendar events to connections and vice versa.

    Every new connections is also made as a my calendar location, kept dbase-update on ‘low-level’:

    function add_calendar_location($entry) {
    // add new calendar location
      global $wpdb, $table_prefix;
      $wpdb->insert($table_prefix."my_calendar_locations", array("location_id" => $entry->getId(), "location_label" => $entry->getOrganization()), array("%d", "%s"));
    }
    
    add_action('cn_post_process_add-entry', 'add_calendar_location');
    
    function update_calendar_location($entry) {
      global $wpdb, $table_prefix;
      // check if record exists. If so: update. If not: create
      $id = $wpdb->get_results("SELECT location_id FROM ".$table_prefix."my_calendar_locations WHERE location_id = ".$entry->getId()." LIMIT 1");
      if ($id[0]->location_id == $entry->getId())
        $wpdb->update( $table_prefix."my_calendar_locations", array("location_label" => $entry->getOrganization()), array("location_id" => $entry->getId()), array("%s"), array("%d") );
      else add_calendar_location($entry);
    }
    
    add_action('cn_post_process_update-entry', 'update_calendar_location');

    Note: for now only company name is defined.
    Address info will need bit more playing around with PHP and $entry values due to possible multiple available addresses.

    Thread Starter Etienne

    (@etienne01)

    Oops, could not edit above version any more, made functionality for adding address information as well:

    function create_conn_to_location_array($entry){
    // define array to write data from connections dbase to my calendar locations dbase
      $array = array("location_label" => $entry->getOrganization(),
                     "location_street" => $entry->getAddresses()[0]->line_1,
                     "location_city" => $entry->getAddresses()[0]->city,
                     "location_postcode" => $entry->getAddresses()[0]->zipcode,
                     "location_longitude" => $entry->getAddresses()[0]->longitude,
                     "location_latitude" => $entry->getAddresses()[0]->latitude,
                     "location_zoom" => 16,
                     "location_access" => 'N;');
      return $array;
    }
    
    function add_calendar_location($entry) {
    // add new calendar location based on connection entry
      global $wpdb, $table_prefix;
      $value_array = array_merge ( create_conn_to_location_array($entry), array("location_id" => $entry->getId()) );
      $wpdb->insert($table_prefix."my_calendar_locations", $value_array);
    }
    
    add_action('cn_post_process_add-entry', 'add_calendar_location');
    
    function update_calendar_location($entry) {
    // update calendar location based on connection update
      global $wpdb, $table_prefix;
      $id = $wpdb->get_results("SELECT location_id FROM ".$table_prefix."my_calendar_locations WHERE location_id = ".$entry->getId()." LIMIT 1");
      if ($id[0]->location_id == $entry->getId())
        $wpdb->update( $table_prefix."my_calendar_locations", create_conn_to_location_array($entry), array("location_id" => $entry->getId()));
      else add_calendar_location($entry);
    }
    
    add_action('cn_post_process_update-entry', 'update_calendar_location');
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘link or import connections to my calendar locations’ is closed to new replies.