-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.class.php
79 lines (67 loc) · 1.97 KB
/
entity.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
<?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 entity.class.php
* @ingroup plurioparser
*/
class Entity {
protected static $_inGuide; // one-dimensional list of entities already in the guide
protected static $_locIds; // associative array of location ids and their labels
protected $_source; // points to source object
// Create two static arrays if they don't yet exist
public function __construct(){
global $config;
if( !isset( self::$_inGuide ) )
self::$_inGuide = array();
if( !isset( self::$_locIds ) )
self::$_locIds = array();
$this->_source = $this->_sourceFactory( $config['data.format'] );
}
/**
* Factory for source objects allowing us to retrieve additional information
* from the respective source as needed
*/
private function _sourceFactory( $source ) {
switch( $source ) {
case 'smw':
return new WikiApiClient;
break;
case 'pdo':
return new PDOMapper;
break;
default:
throw new Exception( sprintf( 'No adapter for source format "%s"', $source ), 404 );
break;
}
}
/**
* Pass any queries on to the respective source
*/
public function __call( $method, $args ) {
$args[] = $this;
return call_user_func_array( array( $this->_source, $method), $args );
}
/**
* Called from event.class
* Returns true if an entity is already in the guide and false if not
* @var $entity label of an entity, key to $_inGuide array
* @return bool
*/
protected function _inGuide( $entity ) {
return in_array( get_class( $this ) . '_' . $entity, self::$_inGuide );
}
/**
* Adds categories to ???
* @var $parent the parent object
* @var $cats an array of categories to be added
* @return void
*/
protected function _addCategories( &$parent, array $cats ) {
$categories = $parent->addChild('guideCategories');
foreach( $cats as $cat )
$categories->addChild('guideCategoryId', $cat );
}
}