public function LdapQueryAdmin::save in Lightweight Directory Access Protocol (LDAP) 7
Same name and namespace in other branches
- 8.2 ldap_query/LdapQueryAdmin.class.php \LdapQueryAdmin::save()
- 7.2 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 73
Class
Code
public function save($op) {
$op = $this->inDatabase ? 'edit' : 'insert';
if (module_exists('ctools')) {
// add or edit with ctolls
ctools_include('export');
$ctools_values = clone $this;
foreach ($this
->fields() as $field_id => $field) {
$value = $this->{$field['property_name']};
if (isset($field['exportable']) && $field['exportable'] === FALSE) {
// field not exportable
unset($ctools_values->{$field['property_name']});
}
elseif (isset($field['schema']) && $field['property_name'] != $field_id) {
// field in property with different name
$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_load_object_reset('ldap_query');
// ctools_export_crud_save doesn't invalidate cache
}
else {
$values = array();
foreach ($this
->fields() as $field_id => $field) {
if (isset($field['schema'])) {
$values[$field_id] = $this->{$field['property_name']};
}
}
if ($op == 'edit') {
// edit w/o ctools
$result = drupal_write_record('ldap_query', $values, 'qid');
}
else {
// insert
$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.'));
}
}