Projet

Général

Profil

Paste
Télécharger (2,69 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_feeds / FeedsLdapEntryParser.inc @ 5136ce55

1
<?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
          else {
38
            unset($ldap_attributes[$source_lcase]['count']);
39
            $parsed_item[$source] = $ldap_attributes[$source_lcase];
40
          }
41
        }
42
        else {
43
          $parsed_item[$source] = '';
44
        }
45
      }
46
      $parsed_items[] = $parsed_item;
47
    }
48
    $result = new FeedsParserResult();
49
    $result->items = $parsed_items;
50
    return $result;
51
  }
52

    
53

    
54
  /**
55
   * Source form.
56
   */
57
  public function sourceForm($source_config) {
58
    $form = array();
59
    $mappings = feeds_importer($this->id)->processor->config['mappings'];
60
    if (empty($source_config)) {
61
      $source_config = $this->config;
62
    }
63
    return $form;
64
  }
65

    
66
  /**
67
   * Override parent::configFormValidate().
68
   */
69
  public function configFormValidate(&$values) {
70
    $this->setConfig(array('sources' => $values));
71
    $this->save();
72
  }
73

    
74

    
75
  /**
76
  * Override parent::getMappingSources().
77
  */
78
  public function getMappingSources() {
79
    return FALSE;
80
  }
81

    
82
  /**
83
   * Override parent::configDefaults().
84
   */
85
  public function configDefaults() {
86
    /** removed until design decisions on multivalued attributes are made
87
    return array(
88
      'multivalued' => LDAP_FEEDS_QUERY_FETCHER_MULTI_DEFAULT,
89
    );
90

    
91
  */
92
    return array();
93
  }
94

    
95
   /**
96
   * Override parent::configForm().
97
   */
98
  public function configForm(&$form_state) {
99
    $form = array();
100
    return $form;
101
  }
102

    
103
  public function sourceDefaults() {
104
    return array();
105
  }
106

    
107
}