/
addMOProperty.php
99 lines (77 loc) · 2.58 KB
/
addMOProperty.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
require_once('vendor/autoload.php');
require_once('databaseConfig.php');
require_once('URLParser.php');
use Everyman\Neo4j\Cypher\Query;
function findIfProfessor($title_str, $keywords=array("Professor", "Prof")){
//@Debug
echo "\nThe title is: $title_str\n";
foreach($keywords as $k){
if(($found = stripos($title_str, $k, 0)) !== false){
return 1;
}
}
return 0;
}
function addMOProperty($unifiedName, $client){
$mysqli = new mysqli(HOSTNAME, USERNAME, PASSWD, DATABASE);
if($mysqli->connect_errno){
die("error: ". $mysqli->connect_error);
}
$localTable = "MOSpacePeople";
$parser = new HumanNameParser_Parser($unifiedName);
$last = $parser->getLast();
$first = $parser->getFirst();
//@Debug
//echo "Checking ".$last.", ".$first.".....";
$q = "SELECT * from ".$localTable." where firstname='".$mysqli->real_escape_string($first)."' and lastname='".$mysqli->real_escape_string($last)."'";
$fromMU = 0;
$isProfessor = 0;
if($result = $mysqli->query($q)){
if($result->num_rows == 1){
//@Debug
//echo "found in local database.....";
$fromMU = 1;
if($resAssocArray = $result->fetch_assoc()){
if(isset($resAssocArray['Title'])){
$isProfessor = findIfProfessor($resAssocArray['Title']) == 1 ? 1 : 0;
//@Debug
//if($isProfessor == 1) echo "is a prof\n"; else echo "NOT a prof\n";
}
else{
$isProfessor = 0;
//@Debu
//echo "NOT a prof\n";
}
}
else{
die("fetch result from MOSpacePeople failed");
}
}
else{
$peopleFinderURL = "https://webservices.doit.missouri.edu/peoplefinderWS/peoplefinderws.asmx/PeopleFinderXml?firstName=".urlencode($first)."&lastname=".urlencode($last)."&department=&phoneno=&email=";
$url_parser = new URLParser($peopleFinderURL);
$retArr = $url_parser->XMLToArray();
if(intval($retArr['@attributes']['found']) == 1){
//@Debug
//echo "found in Peoplefinder...";
$fromMU = 1;
$title = (array_key_exists("Title", $retArr['Person']) && !empty($retArr['Person']['Title'])) ? $retArr['Person']['Title'] : "";
$isProfessor = findIfProfessor($title) == 1 ? 1 : 0;
//@Debug
//if($isProfessor == 1) echo "is a prof\n"; else echo "NOT a prof\n";
}
else{
$isProfessor = 0;
//@Debug
//echo "NOT a prof\n";
}
}
}
else{
die("query: ". $q."\nFailed");
}
$q_str = "match (u:Person {name: \"". $unifiedName."\"}) set u.fromMU = ".$fromMU.", u.isProfessor = ".$isProfessor;
$query = new Query($client, $q_str);
$client->executeCypherQuery($query);
}