Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 411b3f0

Browse files
committed
Updated the Peoplefinder Web Services package to the latest and added some customizations to make a PHP 5.2 compatible driver.
1 parent 2ae2105 commit 411b3f0

24 files changed

+630
-913
lines changed

lib/UNL/Peoplefinder/Department.php

+109-29
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class UNL_Peoplefinder_Department implements Countable, Iterator
2323
* @var number
2424
*/
2525
public $org_unit;
26+
27+
/**
28+
* Organization abbreviation
29+
*
30+
* @var string
31+
*/
32+
public $org_abbr;
2633

2734
/**
2835
* Building the department main office is in.
@@ -63,29 +70,73 @@ class UNL_Peoplefinder_Department implements Countable, Iterator
6370

6471
protected $_results;
6572

66-
protected $_xml;
73+
/**
74+
* SimpleXMLElement of the HR Tree file
75+
*
76+
* @var SimpleXMLElement
77+
*/
78+
protected static $_xml;
79+
80+
public $options = array();
6781

6882
/**
6983
* construct a department
7084
*
7185
* @param string $name Name of the department
7286
*/
73-
function __construct($name)
87+
function __construct($options = array())
7488
{
75-
$this->name = $name;
76-
$this->_xml = new SimpleXMLElement(file_get_contents(dirname(__FILE__).'/../../data/hr_tree.xml'));
77-
$results = $this->_xml->xpath('//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="name"][@value="'.$this->name.'"]/..');
78-
if (isset($results[0])) {
79-
foreach ($results[0] as $attribute) {
80-
if (isset($attribute['name'])) {
81-
$this->{$attribute['name']} = (string)$attribute['value'];
82-
}
89+
if (!(
90+
isset($options['d'])
91+
|| isset($options['org_unit'])
92+
|| isset($options['xml'])
93+
)
94+
) {
95+
throw new Exception('No department name or org_unit! Pass as the d or org_unit value.');
96+
}
97+
$this->options = $options + $this->options;
98+
99+
$xml = self::getXML();
100+
101+
$result = false;
102+
103+
if (isset($options['xml'])) {
104+
$result = $options['xml'];
105+
} elseif (isset($options['org_unit'])) {
106+
$result = self::getXMLById($options['org_unit']);
107+
} elseif (isset($options['d'])) {
108+
$result = self::getXMLByName($options['d']);
109+
}
110+
111+
if (!$result) {
112+
throw new Exception('Invalid department', 404);
113+
}
114+
115+
$this->setFromSimpleXMLElement($result);
116+
}
117+
118+
public function setFromSimpleXMLElement(SimpleXMLElement $result)
119+
{
120+
foreach ($result as $attribute) {
121+
if (isset($attribute['name'])) {
122+
$this->{$attribute['name']} = (string)$attribute['value'];
83123
}
84-
} else {
85-
throw new Exception('Invalid department name.');
86124
}
87125
}
88126

127+
/**
128+
* Get the XML for the HR Tree
129+
*
130+
* @return SimpleXMLElement
131+
*/
132+
protected static function getXML()
133+
{
134+
if (!isset(self::$_xml)) {
135+
self::$_xml = new SimpleXMLElement(file_get_contents(UNL_Peoplefinder::getDataDir().'/hr_tree.xml'));
136+
}
137+
return self::$_xml;
138+
}
139+
89140
/**
90141
* Retrieves people records from the LDAP directory
91142
*
@@ -94,17 +145,9 @@ function __construct($name)
94145
function getLDAPResults()
95146
{
96147
if (!isset($this->_results)) {
97-
$options = array(
98-
'bind_dn' => UNL_Peoplefinder_Driver_LDAP::$bindDN,
99-
'bind_password' => UNL_Peoplefinder_Driver_LDAP::$bindPW,
100-
);
101-
102-
$this->_ldap = UNL_LDAP::getConnection($options);
103-
$name = str_replace(array('(',')','*','\'','"'), '', $this->name);
104-
$this->_results = $this->_ldap->search('dc=unl,dc=edu',
105-
'(unlHRPrimaryDepartment='.$name.')');
106-
$this->_results->sort('cn');
107-
$this->_results->sort('sn');
148+
UNL_Peoplefinder::$resultLimit = 500;
149+
$pf = new UNL_Peoplefinder($this->options);
150+
$this->_results = $pf->getHROrgUnitNumberMatches($this->org_unit);
108151
}
109152
return $this->_results;
110153
}
@@ -131,7 +174,7 @@ function rewind()
131174
*/
132175
function current()
133176
{
134-
return UNL_Peoplefinder_Record::fromUNLLDAPEntry($this->getLDAPResults()->current());
177+
return $this->getLDAPResults()->current();
135178
}
136179

137180
function key()
@@ -151,24 +194,61 @@ function valid()
151194

152195
function hasChildren()
153196
{
154-
$results = $this->_xml->xpath('//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="name"][@value="'.$this->name.'"]/../branch');
197+
$results = self::getXML()->xpath('//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="org_unit"][@value="'.$this->org_unit.'"]/../branch');
155198
return count($results)?true:false;
156199
}
157200

158201
function getChildren()
159202
{
160203
$children = array();
161-
$results = $this->_xml->xpath('//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="name"][@value="'.$this->name.'"]/../branch');
204+
$results = self::getXML()->xpath('//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="org_unit"][@value="'.$this->org_unit.'"]/../branch');
162205
foreach ($results as $result) {
163206
foreach ($result[0] as $attribute) {
164207
if (isset($attribute['name'])
165-
&& $attribute['name']=='name') {
166-
$children[] = (string)$attribute['value'];
208+
&& $attribute['name']=='org_unit') {
209+
$children[] = self::getById((string)$attribute['value']);
167210
break;
168211
}
169212
}
170213
}
171-
asort($children);
214+
172215
return $children;
173216
}
217+
218+
/**
219+
* Retrieve an official SAP Org entry by ID
220+
*
221+
* @param int $id ID, such as 5000XXXX
222+
*/
223+
public static function getById($id, $options = array())
224+
{
225+
if ($result = self::getXMLById($id)) {
226+
$options['xml'] = $result;
227+
return new self($options);
228+
}
229+
return $result;
230+
}
231+
232+
public static function getXMLByName($name)
233+
{
234+
$xml = self::getXML();
235+
$quoted = preg_replace('/([\'\"\?])/', '\\$1', $name);
236+
$xpath = '//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="name"][@value="'.$quoted.'"]/..';
237+
$results = $xml->xpath($xpath);
238+
if (!$results) {
239+
return false;
240+
}
241+
return $results[0];
242+
}
243+
244+
public static function getXMLById($id)
245+
{
246+
$xml = self::getXML();
247+
$xpath = '//attribute[@name="org_unit"][@value="50000003"]/..//attribute[@name="org_unit"][@value='.$id.']/..';
248+
$results = $xml->xpath($xpath);
249+
if (!$results) {
250+
return false;
251+
}
252+
return $results[0];
253+
}
174254
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
class UNL_Peoplefinder_Department_Personnel extends ArrayIterator
3+
{
4+
public $options = array();
5+
6+
function __construct($mixed)
7+
{
8+
if (is_array($mixed)
9+
&& !empty($mixed['org_unit'])) {
10+
$this->options = $mixed;
11+
$peoplefinder = new UNL_Peoplefinder(array('driver'=>$this->options['driver']));
12+
$mixed = $peoplefinder->getHROrgUnitNumberMatches($this->options['org_unit']);
13+
}
14+
parent::__construct($mixed);
15+
}
16+
}

lib/UNL/Peoplefinder/Department/Search.php

-57
This file was deleted.

lib/UNL/Peoplefinder/Driver/LDAP/AdvancedFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function buildFilter(&$field_arr, $op='')
7272

7373
function __toString()
7474
{
75-
$this->_filter = '(&'.$this->_filter.'(!(eduPersonPrimaryAffiliation=guest)))';
75+
$this->_filter = UNL_Peoplefinder_Driver_LDAP_Util::wrapGlobalExclusions($this->_filter);
7676
return $this->_filter;
7777
}
7878

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
class UNL_Peoplefinder_Driver_LDAP_AffiliationFilter extends UNL_Peoplefinder_Driver_LDAP_StandardFilter
3+
{
4+
protected $affiliation = 'staff';
5+
6+
function __construct($query, $affiliation, $operator = '&', $wild = false)
7+
{
8+
switch($affiliation) {
9+
case 'student':
10+
case 'faculty':
11+
case 'staff':
12+
case 'guest':
13+
$this->affiliation = $affiliation;
14+
break;
15+
}
16+
parent::__construct($query, $operator, $wild);
17+
}
18+
19+
function __toString()
20+
{
21+
$this->addExcludedRecords();
22+
$this->_filter = '(&'.$this->_filter.'(eduPersonAffiliation='.$this->affiliation.'))';
23+
$this->_filter = UNL_Peoplefinder_Driver_LDAP_Util::wrapGlobalExclusions($this->_filter);
24+
return $this->_filter;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Builds a simple HR primary department filter for records.
4+
*
5+
* PHP version 5
6+
*
7+
* @category Default
8+
* @package UNL_Peoplefinder
9+
* @author Brett Bieber <[email protected]>
10+
* @copyright 2010 Regents of the University of Nebraska
11+
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
12+
* @link http://peoplefinder.unl.edu/
13+
*/
14+
class UNL_Peoplefinder_Driver_LDAP_HROrgUnitNumberFilter
15+
{
16+
private $_filter;
17+
18+
/**
19+
* Create a filter for HR primary department filtering.
20+
*
21+
* @param string $hrPrimaryDepartment HR primary department eg:College of Engineering
22+
*/
23+
function __construct($orgUnit)
24+
{
25+
if (empty($orgUnit)) {
26+
throw new Exception('Must set primary department.');
27+
}
28+
29+
$this->_filter = '(&(objectClass=person)(unlHROrgUnitNumber='.(int)$orgUnit.'))';
30+
}
31+
32+
function __toString()
33+
{
34+
$this->_filter = UNL_Peoplefinder_Driver_LDAP_Util::wrapGlobalExclusions($this->_filter);
35+
return $this->_filter;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Builds a simple HR primary department filter for records.
4+
*
5+
* PHP version 5
6+
*
7+
* @category Default
8+
* @package UNL_Peoplefinder
9+
* @author Brett Bieber <[email protected]>
10+
* @copyright 2010 Regents of the University of Nebraska
11+
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
12+
* @link http://peoplefinder.unl.edu/
13+
*/
14+
class UNL_Peoplefinder_Driver_LDAP_HRPrimaryDepartmentFilter
15+
{
16+
private $_filter;
17+
18+
/**
19+
* Create a filter for HR primary department filtering.
20+
*
21+
* @param string $hrPrimaryDepartment HR primary department eg:College of Engineering
22+
*/
23+
function __construct($hrPrimaryDepartment)
24+
{
25+
if (empty($hrPrimaryDepartment)) {
26+
throw new Exception('Must set primary department.');
27+
}
28+
29+
$this->_filter = '(unlHRPrimaryDepartment='.$hrPrimaryDepartment.')';
30+
}
31+
32+
function __toString()
33+
{
34+
$this->_filter = UNL_Peoplefinder_Driver_LDAP_Util::wrapGlobalExclusions($this->_filter);
35+
return $this->_filter;
36+
}
37+
}

lib/UNL/Peoplefinder/Driver/LDAP/OUFilter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function __construct($ou)
2929

3030
function __toString()
3131
{
32-
$this->_filter = '(&'.$this->_filter.'(!(eduPersonPrimaryAffiliation=guest)))';
32+
$this->_filter = UNL_Peoplefinder_Driver_LDAP_Util::wrapGlobalExclusions($this->_filter);
3333
return $this->_filter;
3434
}
3535
}

0 commit comments

Comments
 (0)