1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
*
|
6 |
|
|
* Provides the Parser for an ldap entry array.
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
class FeedsLdapEntryParser extends FeedsParser {
|
10 |
|
|
public $ldap_result;
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Implements FeedsParser::parse().
|
14 |
|
|
*/
|
15 |
|
|
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
|
16 |
|
|
|
17 |
|
|
$mappings = feeds_importer($this->id)->processor->config['mappings'];
|
18 |
|
|
$ldap_entries = $fetcher_result->ldap_result;
|
19 |
|
|
$parsed_items = array();
|
20 |
|
|
for ($i = 0; $i < $ldap_entries['count']; $i++) {
|
21 |
|
|
$ldap_entry = $ldap_entries[$i];
|
22 |
|
|
$parsed_item = array('dn' => (string)$ldap_entry['dn']);
|
23 |
|
|
foreach ($mappings as $j => $map) {
|
24 |
|
|
$source_lcase = drupal_strtolower($map['source']);
|
25 |
|
|
$source = $map['source'];
|
26 |
|
|
if (isset($ldap_entry['attr'])) {
|
27 |
|
|
// exception need because of unconvential format of ldap data returned from $ldap_server->userUserNameToExistingLdapEntry
|
28 |
|
|
$ldap_attributes = $ldap_entry['attr'];
|
29 |
|
|
}
|
30 |
|
|
else {
|
31 |
|
|
$ldap_attributes = $ldap_entry;
|
32 |
|
|
}
|
33 |
|
|
if ($source_lcase != 'dn' && isset($ldap_attributes[$source_lcase][0])) {
|
34 |
|
|
if ($ldap_attributes[$source_lcase]['count'] == 1 && is_scalar($ldap_attributes[$source_lcase][0])) {
|
35 |
|
|
$parsed_item[$source] = (string)$ldap_attributes[$source_lcase][0];
|
36 |
|
|
}
|
37 |
|
|
}
|
38 |
|
|
else {
|
39 |
|
|
$parsed_item[$source] = '';
|
40 |
|
|
}
|
41 |
|
|
}
|
42 |
|
|
$parsed_items[] = $parsed_item;
|
43 |
|
|
}
|
44 |
|
|
$result = new FeedsParserResult();
|
45 |
|
|
$result->items = $parsed_items;
|
46 |
|
|
return $result;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/**
|
51 |
|
|
* Source form.
|
52 |
|
|
*/
|
53 |
|
|
public function sourceForm($source_config) {
|
54 |
|
|
$form = array();
|
55 |
|
|
$mappings = feeds_importer($this->id)->processor->config['mappings'];
|
56 |
|
|
if (empty($source_config)) {
|
57 |
|
|
$source_config = $this->config;
|
58 |
|
|
}
|
59 |
|
|
return $form;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/**
|
63 |
|
|
* Override parent::configFormValidate().
|
64 |
|
|
*/
|
65 |
|
|
public function configFormValidate(&$values) {
|
66 |
|
|
$this->setConfig(array('sources' => $values));
|
67 |
|
|
$this->save();
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* Override parent::getMappingSources().
|
73 |
|
|
*/
|
74 |
|
|
public function getMappingSources() {
|
75 |
|
|
return FALSE;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Override parent::configDefaults().
|
80 |
|
|
*/
|
81 |
|
|
public function configDefaults() {
|
82 |
|
|
/** removed until design decisions on multivalued attributes are made
|
83 |
|
|
return array(
|
84 |
|
|
'multivalued' => LDAP_FEEDS_QUERY_FETCHER_MULTI_DEFAULT,
|
85 |
|
|
);
|
86 |
|
|
|
87 |
|
|
*/
|
88 |
|
|
return array();
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* Override parent::configForm().
|
93 |
|
|
*/
|
94 |
|
|
public function configForm(&$form_state) {
|
95 |
|
|
$form = array();
|
96 |
|
|
return $form;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
public function sourceDefaults() {
|
100 |
|
|
return array();
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
} |