-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.class.php
65 lines (57 loc) · 1.82 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
<?php
abstract class Entity implements DrupalCommunicable
{
// Represents fields attached to this entity - is an array of things that extend Field
public $fields;
// A subclass of entity might have some more properties - for example, a bundle/type field, a machine name, ect.
//Constructor
public function __construct(){
$this->fields = array();
}
/**
* Add a field to the entity. This function is provided so that subclasses can override and add more functionality
* $field - A Field object to add
*/
public function addField(Field $field){
if (!isset($this->fields[$field->name])) {
$this->fields[$field->name] = $field;
return TRUE;
}
else {
return FALSE;
}
}
/**
* Remove a field from the entity. This function is provided so that subclasses can override and add more functionality
* $field - A Field object to remove
*/
public function removeField(Field $field){
if(isset($this->fields[$field->name])){
$this->fields[$field->name];
delete($this->fields[$field->name]);
return TRUE;
} else {
return FALSE;
}
}
public function getField($name){
return isset($this->fields[$name]) ? $this->fields[$name] : FALSE;
}
/**
* This function should save the entity type to the database
* It should call Field->saveToDatabase() for each of its fields.
*/
public function saveToDatabase() {
foreach($this->fields as $name => $field) {
$field->saveToDatabase();
}
// etc.
}
/**
* Compare this definition to the one in the database - should first ensure existance
* It should also compare the fields - both those currently attached by calling Field->diffToDatabase()
* and check that no additional fields have been added.
*/
public function diffToDatabase() {
}
}