Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ldap / ldap_feeds / FeedsLdapEntryParser.inc @ 7547bb19

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
        // dn is already parsed
26
        if ($source_lcase == 'dn') {
27
          continue;
28
        }
29
        $source = $map['source'];
30
        if (isset($ldap_entry['attr'])) {
31
          // exception need because of unconvential format of ldap data returned from $ldap_server->userUserNameToExistingLdapEntry
32
          $ldap_attributes = $ldap_entry['attr'];
33
        }
34
        else {
35
          $ldap_attributes = $ldap_entry;
36
        }
37
        if (isset($ldap_attributes[$source_lcase][0])) {
38
          if ($ldap_attributes[$source_lcase]['count'] == 1 && is_scalar($ldap_attributes[$source_lcase][0])) {
39
            $parsed_item[$source] = (string)$ldap_attributes[$source_lcase][0];
40
          }
41
          else {
42
            unset($ldap_attributes[$source_lcase]['count']);
43
            $parsed_item[$source] = $ldap_attributes[$source_lcase];
44
          }
45
        }
46
        else {
47
          $parsed_item[$source] = ' ';
48
        }
49
      }
50
      $parsed_items[] = $parsed_item;
51
    }
52
    $result = new FeedsParserResult();
53
    $result->items = $parsed_items;
54
    return $result;
55
  }
56

    
57

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

    
70
  /**
71
   * Override parent::configFormValidate().
72
   */
73
  public function configFormValidate(&$values) {
74
    $this->setConfig(array('sources' => $values));
75
    $this->save();
76
  }
77

    
78

    
79
  /**
80
  * Override parent::getMappingSources().
81
  */
82
  public function getMappingSources() {
83
    return FALSE;
84
  }
85

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

    
95
  */
96
    return array();
97
  }
98

    
99
   /**
100
   * Override parent::configForm().
101
   */
102
  public function configForm(&$form_state) {
103
    $form = array();
104
    return $form;
105
  }
106

    
107
  public function sourceDefaults() {
108
    return array();
109
  }
110

    
111
}