-
Notifications
You must be signed in to change notification settings - Fork 0
/
organisation.class.php
170 lines (141 loc) · 5 KB
/
organisation.class.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Parser that uses data from a semantic wiki and outputs an
* XML file for import into plurio.net
*
* @author David Raison <[email protected]>
* @file organisation.class.php
* @ingroup plurioparser
*/
class Organisation extends Entity {
private $_name;
protected $_organisation; // internal xml object reference
private $_orgaToBuildings;
public function __construct( ){
parent::__construct();
}
/**
* Get the wiki's internal page id and use it as an extId
* Just a wrapper for _fetchPageId() that adds a prefix
*/
/*protected function _getEntityIdFor( $organization ) {
return 'org' . $this->_fetchPageId( $organization );
}*/
/**
* Only now do we create the xml node
*/
private function _addTo( $orgs ){
if( !($orgs instanceOf SimpleXMLElement) )
throw new Exception('No valid organisationsGuide element passed to ' . __METHOD__ );
$this->_organisation = $orgs->addChild('entityOrganisation');
}
/**
* This is an organisation factory
*/
public function addToGuide( $orgs, $organisation ){
try {
// MNHN workaround
//$this->_addTo( $orgs );
//$this->_create( $organisation );
// finally add this organisation to the guide
self::$_inGuide[] = get_class( $this ) . '_' . $organisation;
return $this->getIdFor( $organisation );
} catch (Exception $e) {
if( $e->getCode() == '001' ) {
print("Oops, no organisation info to be fetched.\n");
return false;
} else throw $e;
}
}
private function _create( $organisation ) {
try {
$info = $this->fetchOrganisationInfo( $organisation );
} catch (Exception $e) {
print($e->getMessage());
return false;
}
$this->setName( substr( $organisation,
strpos( $organisation, ':' ) + 1 )
);
// Add descriptions
$desc = new Descriptions( $this->_organisation );
if( !empty( $info->has_subtitle[0] ) )
$desc->setShortDescription( 'lu', $info->has_subtitle[0] );
$desc->setLongDescription( 'lu', $info->has_description[0] );
if( !empty($info->has_description[1] ) ) {
$desc->setLongDescription('fr', $info->has_description[1] );
}
// retrieve location information and add it as an address
$location = $this->fetchLocationInfo( $info->has_location[0] );
$this->setAddress( $location->label,
$location->has_number,
$location->has_address,
$location->has_zipcode,
$location->has_city );
// Add contact details
$this->setContact();
$relations = $this->_organisation->addChild('relationsOrganisation');
// Retrieve information for related location and tie it to this organisation
$building = new Building;
$this->tieToBuilding( $relations, $building->getIdFor( $info->has_location[0] ) );
// Add organisation logo
$this->addLogo( $relations, $info->has_picture[0] );
// FIXME: how to determine that for other organisations? FIXME FIXME
if ( $organisation == 'Organisation:Syn2cat' )
$this->_addCategories( $relations, array( 507, 510, 345, 616, 617 ) );
// get the ID for this wiki entry and set it as user-specific id
$orgId = $this->getIdFor( $organisation );
$this->setUserSpecific( $orgId, 'Organisation id ' . $orgId );
return $orgId;
}
public function setOrgaId( $id ){
if( !isset( $this->_organisation->id ) )
$this->_organisation->addAttribute( 'id', $id );
else throw new Exception('Trying to overwrite the organisation id.');
}
public function setName( $name ){
$this->_organisation->addChild( 'name', $name );
$this->_name = $name;
}
/**
* We need to fetch this from a wiki page!!
*/
public function setAddress( $venue, $number, $street, $zipcode, $city ){
$address = new Address;
$address->number = $number;
$address->street = $street;
$address->zipcode = $zipcode;
$address->city = $city;
$address->venue = $venue;
$address->addTo( $this->_organisation );
}
public function setContact(){
$contact = new Contact;
$contact->addTo( $this->_organisation, $this );
}
// organisations to Organisation (could add C3L here)
// organisation to building (Currently disabled, see issue #1188)
public function tieToBuilding( $relations, $extId ){
return true;
if(!isset($this->_orgaToBuildings) )
$this->_orgaToBuildings = $relations->addChild('organisationsToBuildings');
$otb = $this->_orgaToBuildings->addChild('organisationToBuilding');
$otb->addChild('extId', $extId );
$otb->addChild('organisationRelBuildingTypeId','ob10'); // FIXME HARDCODED!!
}
// organisation >> relations >> logo
public function addLogo( $relations, $filename ) {
$pictures = $relations->addChild('pictures'); // we don't need to store this, it's only one image
$picture = new Picture;
$picture->label = $this->_name . ' logo';
$picture->position = 'default';
$picture->name = $filename;
$picture->addTo( $pictures );
}
public function setUserSpecific( $extId, $info ){
// userspecific
$us = $this->_organisation->addChild('userspecific');
$us->addChild('entityId', $extId );
$us->addChild('entityInfo', $info);
}
}