PHP - Класс ImageButton
Войти

PHP - Класс ImageButton

PHP - Класс ImageButton
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
<?php 

class ImageButton extends Element {

    protected 
$attributes = array("class" => "asset-imageButton");
    protected 
$_image;
    protected 
$_link;
    protected 
$_label;
    protected 
$_showLabel;

    public function 
__construct($name$src$href '#'$onClick null,$width=''){
        
parent::__construct($name);

        
$this->_link = new Link($href);
        if (!empty(
$onClick)) {
            
$this->_link->addAttribute('onClick'$onClick);
        }
        
$this->_image = new Image($name);
        
$this->_image->setSrc($src);
        if(!empty(
$width)){
            
$this->_image->addAttribute('width'$width.'px;');
        }
        
$this->_link->addItem($this->_image);
        
$this->_label = new Label($name);

        
$this->_showLabel true;
    }

    public function 
getLabel() {
        return 
$this->_label;
    }

    public function 
hideLabel() {
        
$this->_showLabel false;
    }

    public function 
showLabel() {
        
$this->_showLabel true;
    }

    public function 
getLink() {
        return 
$this->_link;
    }

    public function 
setText($text) {
        
$this->_label->setText($text);
    }

    public function 
getImage() {
        return 
$this->_image;
    }

    public function 
draw() {

        echo 
$this->toString();
    }

    public function 
setImage($src) {
        
$this->attributes["src"] = $src;
    }

    public function 
toString() {
        
$imageButton ' <div ' $this->getAttributes() . ' > ';
        
$imageButton .= $this->_link->toString();
        if (
$this->_showLabel)
            
$imageButton .= $this->_label->toString();
        
$imageButton .= '</div>';

        return 
$imageButton;
    }

}

?>
Теги:
php