1
|
<?php
|
2
|
require_once('objects/Entity.php');
|
3
|
|
4
|
class EntityList {
|
5
|
private $entities = array();
|
6
|
|
7
|
public function newEntity($name,$node = null) {
|
8
|
if($name == '') {
|
9
|
throw new Exception("Empty strings not allowed as entity names.");
|
10
|
}
|
11
|
|
12
|
if(array_key_exists($name,$this->entities)) {
|
13
|
if(!$this->entities[$name]->isInited()) {
|
14
|
// throw new Exception("Entity $name already exists!");
|
15
|
// } else {
|
16
|
$this->entities[$name]->init($name,$node);
|
17
|
return $this->entities[$name];
|
18
|
}
|
19
|
}
|
20
|
$e = new Entity($name,$node);
|
21
|
$this->entities[$name] = $e;
|
22
|
return $this->entities[$name];
|
23
|
}
|
24
|
|
25
|
public function getEntityForReference($name,$node = null) {
|
26
|
if($name == '') {
|
27
|
throw new Exception("Empty strings not allowed as entity names.");
|
28
|
}
|
29
|
|
30
|
if(array_key_exists($name,$this->entities)) {
|
31
|
return $this->entities[$name];
|
32
|
}
|
33
|
$e = new Entity($name,$node);
|
34
|
$this->entities[$name] = $e;
|
35
|
return $this->entities[$name];
|
36
|
}
|
37
|
|
38
|
public function printAll() {
|
39
|
|
40
|
// vegX has some classes that differ only by capitalzation:
|
41
|
// taxonNames/TaxonNames, taxonConcepts/TaxonConcepts,
|
42
|
// In order to help Django distinguish between them, we need
|
43
|
// to define them ahead of any classes that refrence them.
|
44
|
print $this->entities['taxonNames']->toString() . "\n\n";
|
45
|
print $this->entities['taxonConcepts']->toString() . "\n\n";
|
46
|
print $this->entities['TaxonNames']->toString() . "\n\n";
|
47
|
print $this->entities['TaxonConcepts']->toString() . "\n\n";
|
48
|
|
49
|
foreach(array_keys($this->entities) as $k) {
|
50
|
if($k == 'taxonNames' || $k == 'taxonConcepts' ||
|
51
|
$k == 'TaxonNames' || $k == 'TaxonConcepts')
|
52
|
{ continue; }
|
53
|
print $this->entities[$k]->toString() . "\n\n";
|
54
|
|
55
|
if($k == 'vegX') {
|
56
|
$deepDelete = " def deepDelete(self):\n";
|
57
|
foreach(array_keys($this->entities) as $k) {
|
58
|
$deepDelete .= " $k.objects.filter(entryInfo__id=self.entryInfo.id).delete()\n";
|
59
|
}
|
60
|
print $deepDelete . "\n\n";
|
61
|
}
|
62
|
}
|
63
|
}
|
64
|
|
65
|
public function getEntities() {
|
66
|
return $this->entities;
|
67
|
}
|
68
|
}
|
69
|
?>
|