You are here

public function LdapQueryAdmin::save in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_query/LdapQueryAdmin.class.php \LdapQueryAdmin::save()
  2. 7 ldap_query/LdapQueryAdmin.class.php \LdapQueryAdmin::save()
1 call to LdapQueryAdmin::save()
LdapQueryAdmin::drupalFormSubmit in ldap_query/LdapQueryAdmin.class.php

File

ldap_query/LdapQueryAdmin.class.php, line 81

Class

LdapQueryAdmin

Code

public function save($op) {
  $op = $this->inDatabase ? 'edit' : 'insert';

  // Add or edit with ctolls.
  if (module_exists('ctools')) {
    ctools_include('export');
    $ctools_values = clone $this;
    foreach ($this
      ->fields() as $field_id => $field) {
      $value = $this->{$field['property_name']};

      // Field not exportable.
      if (isset($field['exportable']) && $field['exportable'] === FALSE) {
        unset($ctools_values->{$field['property_name']});
      }
      elseif (isset($field['schema']) && $field['property_name'] != $field_id) {
        $ctools_values->{$field_id} = $value;
        unset($ctools_values->{$field['property_name']});
      }
      else {

        // Do nothing.  property is already in cloned objecat.
      }
    }

    // Populate our object with ctool's properties.  copying all properties for backward compatibility.
    $object = ctools_export_crud_new('ldap_query');
    foreach ($object as $property_name => $value) {
      if (!isset($ctools_values->{$property_name})) {
        $ctools_values->{$property_name} = $value;
      }
    }
    $result = ctools_export_crud_save('ldap_query', $ctools_values);

    // ctools_export_crud_save doesn't invalidate cache.
    ctools_export_load_object_reset('ldap_query');
  }
  else {
    $values = [];
    foreach ($this
      ->fields() as $field_id => $field) {
      if (isset($field['schema'])) {
        $values[$field_id] = $this->{$field['property_name']};
      }
    }

    // Edit w/o ctools.
    if ($op == 'edit') {
      $result = drupal_write_record('ldap_query', $values, 'qid');
    }
    else {
      $result = drupal_write_record('ldap_query', $values);
    }
  }
  if ($result) {
    $this->inDatabase = TRUE;
  }
  else {
    drupal_set_message(t('Failed to write LDAP Query to the database.'));
  }
}