You are here

public function LdapAuthorizationConsumerConfAdmin::save in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php \LdapAuthorizationConsumerConfAdmin::save()
  2. 7.2 ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php \LdapAuthorizationConsumerConfAdmin::save()
1 call to LdapAuthorizationConsumerConfAdmin::save()
LdapAuthorizationConsumerConfAdmin::drupalFormSubmit in ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php

File

ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php, line 17

Class

LdapAuthorizationConsumerConfAdmin
LDAP Authorization Consumer Configration Admin Class

Code

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

  // $this;
  $values->sid = $this->sid;
  $values->numeric_consumer_conf_id = $this->numericConsumerConfId;
  $values->consumer_type = $this->consumerType;
  $values->consumer_module = $this->consumer->consumerModule;
  $values->status = $this->status ? 1 : 0;
  $values->only_ldap_authenticated = (int) $this->onlyApplyToLdapAuthenticated;
  $values->derive_from_dn = (int) $this->deriveFromDn;
  $values->derive_from_dn_attr = $this->deriveFromDnAttr;
  $values->derive_from_attr = (int) $this->deriveFromAttr;
  $values->derive_from_attr_attr = $this
    ->arrayToLines($this->deriveFromAttrAttr);
  $values->derive_from_attr_use_first_attr = (int) $this->deriveFromAttrUseFirstAttr;
  $values->derive_from_attr_nested = (int) $this->deriveFromAttrNested;
  $values->derive_from_entry = (int) $this->deriveFromEntry;
  $values->derive_from_entry_search_all = (int) $this->deriveFromEntrySearchAll;
  $values->derive_from_entry_entries = $this
    ->arrayToLines($this->deriveFromEntryEntries);
  $values->derive_from_entry_entries_attr = $this->deriveFromEntryEntriesAttr;
  $values->derive_from_entry_attr = $this->deriveFromEntryMembershipAttr;
  $values->derive_from_entry_user_ldap_attr = $this->deriveFromEntryAttrMatchingUserAttr;
  $values->derive_from_entry_use_first_attr = (int) $this->deriveFromEntryUseFirstAttr;
  $values->derive_from_entry_nested = (int) $this->deriveFromEntryNested;
  $values->mappings = $this
    ->arrayToPipeList($this->mappings);
  $values->use_filter = (int) $this->useMappingsAsFilter;
  $values->synch_to_ldap = (int) $this->synchToLdap;
  $values->synch_on_logon = (int) $this->synchOnLogon;
  $values->revoke_ldap_provisioned = (int) $this->revokeLdapProvisioned;
  $values->create_consumers = (int) $this->createConsumers;
  $values->regrant_ldap_provisioned = (int) $this->regrantLdapProvisioned;
  if (module_exists('ctools')) {
    ctools_include('export');

    // Populate our object with ctool's properties
    $object = ctools_export_crud_new('ldap_authorization');
    foreach ($object as $property => $value) {
      if (!isset($values->{$property})) {
        $values->{$property} = $value;
      }
    }
    $values->export_type = $this->numericConsumerConfId ? EXPORT_IN_DATABASE : NULL;
    $result = ctools_export_crud_save('ldap_authorization', $values);
    ctools_export_load_object_reset('ldap_authorization');

    // ctools_export_crud_save doesn't invalidate cache
  }
  else {
    if ($op == 'edit') {
      $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
    }
    else {

      // insert
      $result = drupal_write_record('ldap_authorization', $values);
    }
    if ($result) {
      $this->inDatabase = TRUE;
    }
    else {
      drupal_set_message(t('Failed to write LDAP Authorization to the database.'));
    }
  }

  // revert mappings to array and remove temporary properties from ctools export
  $this->mappings = $this
    ->pipeListToArray($values->mappings, FALSE);
  foreach (array(
    'consumer_type',
    'consumer_module',
    'only_ldap_authenticated',
    'derive_from_dn',
    'derive_from_dn_attr',
    'derive_from_attr',
    'derive_from_attr_attr',
    'derive_from_attr_use_first_attr',
    'derive_from_attr_nested',
    'derive_from_entry',
    'derive_from_entry_search_all',
    'derive_from_entry_entries',
    'derive_from_entry_entries_attr',
    'derive_from_entry_attr',
    'derive_from_entry_user_ldap_attr',
    'derive_from_entry_use_first_attr',
    'derive_from_entry_nested',
    'use_filter',
    'synch_to_ldap',
    'synch_on_logon',
    'revoke_ldap_provisioned',
    'create_consumers',
    'regrant_ldap_provisioned',
  ) as $prop_name) {
    unset($this->{$prop_name});
  }
}