You are here

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

Same name and namespace in other branches
  1. 8.2 ldap_authorization/LdapAuthorizationConsumerConfAdmin.class.php \LdapAuthorizationConsumerConfAdmin::save()
  2. 7 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();
  $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->use_first_attr_as_groupid = (int) $this->useFirstAttrAsGroupId;
  $values->mappings = serialize($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;
      }
    }
    try {
      $values->export_type = NULL;
      $result = ctools_export_crud_save('ldap_authorization', $values);
    } catch (Exception $e) {
      $values->export_type = EXPORT_IN_DATABASE;
      $result = ctools_export_crud_save('ldap_authorization', $values);
    }

    // ctools_export_crud_save doesn't invalidate cache.
    ctools_export_load_object_reset('ldap_authorization');
  }
  else {
    if ($op == 'edit') {
      $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
    }
    else {
      $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.'));
    }
  }
}