/**
  * Save the entry to the db.
  *
  * @access public
  * @since  unknown
  *
  * @return false|int
  */
 public function save()
 {
     /**
      * @var connectionsLoad $connections
      * @var wpdb            $wpdb
      */
     global $wpdb, $connections;
     $this->serializeOptions();
     $this->setPropertyDefaultsByEntryType();
     do_action('cn_save-entry', $this);
     $result = $wpdb->insert(CN_ENTRY_TABLE, array('ts' => current_time('mysql'), 'date_added' => current_time('timestamp'), 'ordo' => $this->getOrder(), 'entry_type' => $this->entryType, 'visibility' => $this->getVisibility(), 'slug' => $this->getSlug(), 'family_name' => $this->familyName, 'honorific_prefix' => $this->honorificPrefix, 'first_name' => $this->firstName, 'middle_name' => $this->middleName, 'last_name' => $this->lastName, 'honorific_suffix' => $this->honorificSuffix, 'title' => $this->title, 'organization' => $this->organization, 'department' => $this->department, 'contact_first_name' => $this->contactFirstName, 'contact_last_name' => $this->contactLastName, 'addresses' => $this->addresses, 'phone_numbers' => $this->phoneNumbers, 'email' => $this->emailAddresses, 'im' => $this->im, 'social' => $this->socialMedia, 'links' => $this->links, 'dates' => $this->dates, 'birthday' => $this->birthday, 'anniversary' => $this->anniversary, 'bio' => $this->bio, 'notes' => $this->notes, 'options' => $this->options, 'added_by' => $connections->currentUser->getID(), 'edited_by' => $connections->currentUser->getID(), 'owner' => $connections->currentUser->getID(), 'user' => $this->getUser(), 'status' => $this->status), array('%s', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s'));
     /**
      * @todo Are these really needed? If they are, this should be refactored to remove their usage.
      */
     $connections->lastQuery = $wpdb->last_query;
     $connections->lastQueryError = $wpdb->last_error;
     $connections->lastInsertID = $wpdb->insert_id;
     if (FALSE !== $result) {
         $this->setId($wpdb->insert_id);
         require_once CN_PATH . 'includes/entry/class.entry-db.php';
         $cnDb = new cnEntry_DB($this->getId());
         /*
          * NOTE: The format of the lat/lng values must be set as a string.
          *
          * WordPress sanitizes the float number, making it safe to write to the database,
          * the default precision for a float of 14 is used which basically “caps” the decimal place to 6 digits.
          * It is actually a bit more complicated than that and I would have to delve deeper myself
          * to better understand myself. But the jist is floating point numbers are approximate representations
          * of real numbers and they are not exact.
          *
          * There’s actually no way to change that precision when telling WordPress to sanitize a float.
          * So the only solution is to tell WordPress it is a string and let the database deal with the conversion.
          * Since the table that stores the the lat/lng are setup as decimal (a real number :) ) with a
          * precision of 15 and a scale of 12, the lat/lng will not get rounded until the 12th decimal place.
          */
         $cnDb->insert(CN_ENTRY_ADDRESS_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'line_1' => array('key' => 'line_1', 'format' => '%s'), 'line_2' => array('key' => 'line_2', 'format' => '%s'), 'line_3' => array('key' => 'line_3', 'format' => '%s'), 'line_4' => array('key' => 'line_4', 'format' => '%s'), 'district' => array('key' => 'district', 'format' => '%s'), 'county' => array('key' => 'county', 'format' => '%s'), 'city' => array('key' => 'city', 'format' => '%s'), 'state' => array('key' => 'state', 'format' => '%s'), 'zipcode' => array('key' => 'zipcode', 'format' => '%s'), 'country' => array('key' => 'country', 'format' => '%s'), 'latitude' => array('key' => 'latitude', 'format' => '%s'), 'longitude' => array('key' => 'longitude', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getAddresses(array(), TRUE, TRUE, 'db'));
         $cnDb->insert(CN_ENTRY_PHONE_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'number' => array('key' => 'number', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getPhoneNumbers(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_EMAIL_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'address' => array('key' => 'address', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getEmailAddresses(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_MESSENGER_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'uid' => array('key' => 'id', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getIm(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_SOCIAL_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'url' => array('key' => 'url', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getSocialMedia(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_LINK_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'title' => array('key' => 'title', 'format' => '%s'), 'url' => array('key' => 'url', 'format' => '%s'), 'target' => array('key' => 'target', 'format' => '%s'), 'follow' => array('key' => 'follow', 'format' => '%d'), 'image' => array('key' => 'image', 'format' => '%d'), 'logo' => array('key' => 'logo', 'format' => '%d'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getLinks(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_DATE_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'date' => array('key' => 'date', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getDates(array(), TRUE, TRUE));
     }
     do_action('cn_saved-entry', $this);
     return $result;
 }
 /**
  * Save the entry to the db.
  *
  * @access public
  * @since  unknown
  *
  * @return false|int
  */
 public function save()
 {
     /**
      * @var connectionsLoad $connections
      * @var wpdb            $wpdb
      */
     global $wpdb, $connections;
     $this->serializeOptions();
     $this->setPropertyDefaultsByEntryType();
     do_action('cn_save-entry', $this);
     $result = $wpdb->insert(CN_ENTRY_TABLE, array('ts' => current_time('mysql'), 'date_added' => current_time('timestamp'), 'entry_type' => $this->entryType, 'visibility' => $this->getVisibility(), 'slug' => $this->getSlug(), 'family_name' => $this->familyName, 'honorific_prefix' => $this->honorificPrefix, 'first_name' => $this->firstName, 'middle_name' => $this->middleName, 'last_name' => $this->lastName, 'honorific_suffix' => $this->honorificSuffix, 'title' => $this->title, 'organization' => $this->organization, 'department' => $this->department, 'contact_first_name' => $this->contactFirstName, 'contact_last_name' => $this->contactLastName, 'addresses' => $this->addresses, 'phone_numbers' => $this->phoneNumbers, 'email' => $this->emailAddresses, 'im' => $this->im, 'social' => $this->socialMedia, 'links' => $this->links, 'dates' => $this->dates, 'birthday' => $this->birthday, 'anniversary' => $this->anniversary, 'bio' => $this->bio, 'notes' => $this->notes, 'options' => $this->options, 'added_by' => $connections->currentUser->getID(), 'edited_by' => $connections->currentUser->getID(), 'owner' => $connections->currentUser->getID(), 'user' => $this->getUser(), 'status' => $this->status), array('%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s'));
     /**
      * @todo Are these really needed? If they are, this should be refactored to remove their usage.
      */
     $connections->lastQuery = $wpdb->last_query;
     $connections->lastQueryError = $wpdb->last_error;
     $connections->lastInsertID = $wpdb->insert_id;
     if (FALSE !== $result) {
         $this->setId($wpdb->insert_id);
         require_once CN_PATH . 'includes/entry/class.entry-db.php';
         $cnDb = new cnEntry_DB($this->getId());
         $cnDb->insert(CN_ENTRY_ADDRESS_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'line_1' => array('key' => 'line_1', 'format' => '%s'), 'line_2' => array('key' => 'line_2', 'format' => '%s'), 'line_3' => array('key' => 'line_3', 'format' => '%s'), 'city' => array('key' => 'city', 'format' => '%s'), 'state' => array('key' => 'state', 'format' => '%s'), 'zipcode' => array('key' => 'zipcode', 'format' => '%s'), 'country' => array('key' => 'country', 'format' => '%s'), 'latitude' => array('key' => 'latitude', 'format' => '%f'), 'longitude' => array('key' => 'longitude', 'format' => '%f'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getAddresses(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_PHONE_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'number' => array('key' => 'number', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getPhoneNumbers(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_EMAIL_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'address' => array('key' => 'address', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getEmailAddresses(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_MESSENGER_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'uid' => array('key' => 'id', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getIm(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_SOCIAL_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'url' => array('key' => 'url', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getSocialMedia(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_LINK_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'title' => array('key' => 'title', 'format' => '%s'), 'url' => array('key' => 'url', 'format' => '%s'), 'target' => array('key' => 'target', 'format' => '%s'), 'follow' => array('key' => 'follow', 'format' => '%d'), 'image' => array('key' => 'image', 'format' => '%d'), 'logo' => array('key' => 'logo', 'format' => '%d'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getLinks(array(), TRUE, TRUE));
         $cnDb->insert(CN_ENTRY_DATE_TABLE, array('order' => array('key' => 'order', 'format' => '%d'), 'preferred' => array('key' => 'preferred', 'format' => '%d'), 'type' => array('key' => 'type', 'format' => '%s'), 'date' => array('key' => 'date', 'format' => '%s'), 'visibility' => array('key' => 'visibility', 'format' => '%s')), $this->getDates(array(), TRUE, TRUE));
     }
     do_action('cn_saved-entry', $this);
     return $result;
 }