1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\base\constants\Size; |
7
|
|
|
use Ajax\common\html\HtmlDoubleElement; |
8
|
|
|
use Ajax\semantic\html\base\traits\TextAlignmentTrait; |
9
|
|
|
use Ajax\common\html\html5\HtmlImg; |
10
|
|
|
|
11
|
|
|
class HtmlHeader extends HtmlSemDoubleElement { |
12
|
|
|
use TextAlignmentTrait; |
13
|
|
|
protected $image; |
14
|
|
|
|
15
|
|
|
public function __construct($identifier, $niveau=1, $content=NULL, $type="page") { |
16
|
|
|
parent::__construct($identifier, "div", "ui header"); |
17
|
|
|
$this->_template="<%tagName% %properties%>%image%%content%</%tagName%>"; |
18
|
|
|
if (isset($type)) { |
19
|
|
|
if ($type=="page") { |
20
|
|
|
$this->asPageHeader($niveau); |
21
|
|
|
} else |
22
|
|
|
$this->asContentHeader($niveau); |
23
|
|
|
} |
24
|
|
|
$this->content=$content; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function asPageHeader($niveau) { |
28
|
|
|
$this->tagName="h".$niveau; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function asContentHeader($niveau) { |
32
|
|
|
$this->tagName="div"; |
33
|
|
|
if (\is_int($niveau)) { |
34
|
|
|
$niveau=Size::getConstantValues()[$niveau]; |
35
|
|
|
} |
36
|
|
|
$this->setSize($niveau); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function asIcon($icon, $title, $subHeader=NULL) { |
40
|
|
|
$this->addToProperty("class", "icon"); |
41
|
|
|
$this->image=new HtmlIcon("icon-".$this->identifier, $icon); |
42
|
|
|
return $this->asTitle($title, $subHeader); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function asImage($src, $title, $subHeader=NULL) { |
46
|
|
|
$this->image=new HtmlImg("img-".$this->identifier, $src, $title); |
47
|
|
|
$this->image->setClass("ui image"); |
48
|
|
|
return $this->asTitle($title, $subHeader); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function asTitle($title, $subHeader=NULL) { |
52
|
|
|
if (!\is_object($title)) { |
53
|
|
|
$this->content=new HtmlDoubleElement("content-".$this->identifier, "div"); |
54
|
|
|
$this->content->setContent($title); |
55
|
|
|
} else { |
56
|
|
|
$this->content=$title; |
57
|
|
|
} |
58
|
|
|
$this->content->setClass("content"); |
59
|
|
View Code Duplication |
if (isset($subHeader)) { |
|
|
|
|
60
|
|
|
$sub=new HtmlDoubleElement("subheader-".$this->identifier, "div"); |
61
|
|
|
$sub->setClass("sub header"); |
62
|
|
|
$sub->setContent($subHeader); |
63
|
|
|
$this->content->addContent($sub); |
64
|
|
|
} |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getImage() { |
69
|
|
|
return $this->image; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setDividing() { |
73
|
|
|
$this->addToProperty("class", "dividing"); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function image($identifier, $image, $niveau=1, $header=NULL, $subHeader=NULL) { |
77
|
|
|
$result=new HtmlHeader($identifier, $niveau, $header); |
78
|
|
|
$result->asImage($image, $header, $subHeader); |
79
|
|
|
$result->getImage()->addToProperty("class", "mini rounded"); |
80
|
|
|
return $result; |
81
|
|
|
} |
82
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.