/
Control.class.php
87 lines (73 loc) · 1.98 KB
/
Control.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
<?php
Library::import('recess.framework.helpers.blocks.PartBlock');
Library::import('recess.framework.ui.HtmlAttributes');
Library::import('recess.framework.ui.HtmlClasses');
Library::import('recess.framework.ui.Container');
class Control extends PartBlock {
public static $defaultSkin = 'skins/default';
protected $parent;
protected $skin;
public function __construct($part, $name, $value = '', $label = false) {
$part = 'controls/' . $part;
if($label === false) {
$label = Inflector::toEnglish($name);
}
if($value === true) {
$value = '__true__';
} else if($value === false) {
$value = '__false__';
}
parent::__construct($part, $this, $name, $value, $label);
}
public static function make($part, $name, $value = '', $label = false) {
return new Control($part, $name, $value, $label);
}
// Special draw clones the part, uses the computed name property
public function draw() {
$args = func_get_args();
$clone = clone $this;
$clone->set('name', $this->getFormName());
$clone->set('id', $this->getId());
$clone->curry($args);
try {
Part::drawArray($clone->partPath, $clone->args);
return true;
} catch(MissingRequiredInputException $e) {
throw new MissingRequiredDrawArgumentsException($e->getMessage(), 1);
}
}
public function setParent(Container $parent) {
$this->parent = $parent;
}
public function getParent() {
return $this->parent();
}
public function getFormName() {
if(isset($this->parent)) {
return $this->parent->getFormNameFor($this);
} else {
return $this->get('name');
}
}
public function getId() {
if(isset($this->parent)) {
return $this->parent->getIdFor($this);
} else {
return $this->get('name');
}
}
public function setSkin($skin) {
$this->skin = $skin;
return $this;
}
public function getSkin() {
if($this->skin != '') {
return $this->skin;
} else if(isset($this->parent)) {
return $this->parent->get('defaultSkin');
} else {
return self::$defaultSkin;
}
}
}
?>