1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package userforms |
5
|
|
|
* @subpackage relatives |
6
|
|
|
*/ |
7
|
|
|
class AncestryField extends FormField |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var nameField |
12
|
|
|
*/ |
13
|
|
|
//level 1 |
14
|
|
|
protected static $array_of_ancestors = array( |
15
|
|
|
"mField" => "Mother", |
16
|
|
|
"fField" => "Father", |
17
|
|
|
//level 2 |
18
|
|
|
"mmField" => "Mother's Mother", |
19
|
|
|
"mfField" => "Mother's Father", |
20
|
|
|
"fmField" => "Father's Mother", |
21
|
|
|
"ffField" => "Father's Father", |
22
|
|
|
//level 3 |
23
|
|
|
"mmmField" => "Mother's Mother's Mother", |
24
|
|
|
"mmfField" => "Mother's Mother's Father", |
25
|
|
|
"mfmField" => "Mother's Father's Mother", |
26
|
|
|
"mffField" => "Mother's Father's Father", |
27
|
|
|
"fmmField" => "Father's Mother's Mother", |
28
|
|
|
"fmfField" => "Father's Mother's Father", |
29
|
|
|
"ffmField" => "Father's Father's Mother", |
30
|
|
|
"fffField" => "Father's Father's Father", |
31
|
|
|
//level 4 |
32
|
|
|
"mmmmField" => "Mother's Mother's Mother's Mother", |
33
|
|
|
"mmmfField" => "Mother's Mother's Mother's Father", |
34
|
|
|
"mmfmField" => "Mother's Mother's Father's Mother", |
35
|
|
|
"mmffField" => "Mother's Mother's Father's Father", |
36
|
|
|
"mfmmField" => "Mother's Father's Mother's Mother", |
37
|
|
|
"mfmfField" => "Mother's Father's Mother's Father", |
38
|
|
|
"mffmField" => "Mother's Father's Father's Mother", |
39
|
|
|
"mfffField" => "Mother's Father's Father's Father", |
40
|
|
|
"fmmmField" => "Father's Mother's Mother's Mother", |
41
|
|
|
"fmmfField" => "Father's Mother's Mother's Father", |
42
|
|
|
"fmfmField" => "Father's Mother's Father's Mother", |
43
|
|
|
"fmffField" => "Father's Mother's Father's Father", |
44
|
|
|
"ffmmField" => "Father's Father's Mother's Mother", |
45
|
|
|
"ffmfField" => "Father's Father's Mother's Father", |
46
|
|
|
"fffmField" => "Father's Father's Father's Mother", |
47
|
|
|
"ffffField" => "Father's Father's Father's Father" |
48
|
|
|
); |
49
|
|
|
public static function get_array_of_ancestors() |
50
|
|
|
{ |
51
|
|
|
return self::$array_of_ancestors; |
52
|
|
|
} |
53
|
|
|
public static function set_array_of_ancestors($a) |
54
|
|
|
{ |
55
|
|
|
self::$array_of_ancestors = $a; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected $fieldHolder = array(); |
59
|
|
|
|
60
|
|
|
public function __construct($name, $title = null, $value = "") |
61
|
|
|
{ |
62
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
63
|
|
|
$this->fieldHolder[$key] = new TextField($name . '['.$key.']', $fieldTitle); |
64
|
|
|
} |
65
|
|
|
parent::__construct($name, $title, $value); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setForm($form) |
69
|
|
|
{ |
70
|
|
|
parent::setForm($form); |
71
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
72
|
|
|
$this->fieldHolder[$key]->setForm($form); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function Field() |
77
|
|
|
{ |
78
|
|
|
Requirements::themedCSS("AncestryField"); |
79
|
|
|
Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
80
|
|
|
Requirements::javascript("userforms_relatives/javascript/AncestryField.js"); |
81
|
|
|
$html = ""; |
82
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
83
|
|
|
$levelClass = "level".(strlen($key)-5); |
84
|
|
|
$nextLevels = ".".str_replace("Field", "mField", $key).", .".str_replace("Field", "fField", $key); |
85
|
|
|
$html .= "<div class=\"$key $levelClass ancestorNode \" rel=\"$nextLevels\">".$this->fieldHolder[$key]->SmallFieldHolder()."</div>"; |
86
|
|
|
} |
87
|
|
|
return $html; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
*/ |
92
|
|
|
public function setValue($val) |
93
|
|
|
{ |
94
|
|
|
if (empty($val)) { |
95
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
96
|
|
|
$this->fieldHolder[$key]->setValue(null); |
97
|
|
|
} |
98
|
|
|
} else { |
99
|
|
|
// String setting is only possible from the database, so we don't allow anything but ISO format |
100
|
|
|
if (is_string($val)) { |
|
|
|
|
101
|
|
|
//TO DO |
102
|
|
|
} |
103
|
|
|
// Setting from form submission |
104
|
|
|
elseif (is_array($val)) { |
105
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
106
|
|
|
$myValue = isset($val[$key]) ? $val[$key] : ""; |
107
|
|
|
$this->fieldHolder[$key]->setValue($myValue); |
108
|
|
|
} |
109
|
|
|
} else { |
110
|
|
|
$this->nameField->setValue($val); |
|
|
|
|
111
|
|
|
$this->dobField->setValue($val); |
|
|
|
|
112
|
|
|
$this->sexField->setValue($val); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function dataValue() |
118
|
|
|
{ |
119
|
|
|
$array = array(); |
120
|
|
|
foreach (self::get_array_of_ancestors() as $key => $fieldTitle) { |
121
|
|
|
$array[$key] = $this->fieldHolder[$key]->dataValue(); |
122
|
|
|
} |
123
|
|
|
return $array; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function Icon() |
127
|
|
|
{ |
128
|
|
|
return 'userforms/images/' . strtolower($this->class) . '.png'; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.