Completed
Push — master ( e6cea0...5c122a )
by Marcin
01:53
created

Page::getXml()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 2
nop 0
crap 20
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
16
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model;
17
18
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface;
19
use mrcnpdlk\Grandstream\XMLApp\MyXML;
20
21
/**
22
 * Class Page
23
 *
24
 * @package mrcnpdlk\Grandstream\XMLApp\Application\Model
25
 */
26
class Page implements ModelInterface
27
{
28
29
    /**
30
     * @var Contents
31
     */
32
    private $oContents;
33
34
    /**
35
     * @var SoftKey[]
36
     */
37
    private $tSoftkeys = [];
38
39
    /**
40
     * @var boolean
41
     */
42
    private $isVisibleStatusLine;
43
44
    /**
45
     * @var boolean
46
     */
47
    private $ignoreCallUpdate;
48
49
    /**
50
     * Page constructor.
51
     *
52
     * @param Contents $oContents
53
     */
54
    public function __construct(Contents $oContents)
55
    {
56
        $this->setContents($oContents);
57
        $this->setVisibleStatusLine(true);
58
        $this->ignoreCallUpdate(false);
59
    }
60
61
    /**
62
     * @param Contents $oContents
63
     *
64
     * @return Page
65
     */
66
    public function setContents(Contents $oContents)
67
    {
68
        $this->oContents = $oContents;
69
70
        return $this;
71
    }
72
73
    /**
74
     * It could use "true" or "false" as its     text.
75
     * "true": the line label on the left side will be always displayed during XML application.
76
     * "false": the line label on the left side will not be displayed during XML application.
77
     * So the XML application information could be shown in a full screen manner.
78
     * Default is "true".
79
     *
80
     * @param bool $isVisible
81
     *
82
     * @return Page
83
     */
84
    public function setVisibleStatusLine(bool $isVisible = true)
85
    {
86
        $this->isVisibleStatusLine = $isVisible;
87
88
        return $this;
89
    }
90
91
    /**
92
     * When it’s set to true, phone will not  refresh the XML application screen to
93
     * call screen for call status update (except the one triggered by pressing
94
     * LINE key). Default value is false.
95
     *
96
     * @param bool $ignoreCallUpdate
97
     *
98
     * @return $this
99
     */
100
    public function ignoreCallUpdate(bool $ignoreCallUpdate = false)
101
    {
102
        $this->ignoreCallUpdate = $ignoreCallUpdate;
103
104
        return $this;
105
    }
106
107
    /**
108
     * Defines softkey display and action
109
     *
110
     * @param SoftKey $oSoftkey
111
     *
112
     * @return Page
113
     *
114
     */
115
    public function addSoftkey(SoftKey $oSoftkey)
116
    {
117
        $this->tSoftkeys[] = $oSoftkey;
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return MyXML
124
     */
125
    public function getXml(): MyXML
126
    {
127
        $oXml = new MyXML('Page');
128
        $oXml->asObject()->addAttribute('ignoreCallUpdate', $this->ignoreCallUpdate ? 'true' : 'false');
129
        $oXml->asObject()->addChild('ShowStatusLine', $this->isVisibleStatusLine ? 'true' : 'false');
130
131
        $oXml->insertChild($this->getContents()->getXml()->asObject());
132
133
        //Softkeys
134
        $oSoftkeys = new MyXML('SoftKeys');
135
        foreach ($this->tSoftkeys as $oSoftkey) {
136
            $oSoftkeys->insertChild($oSoftkey->getXml()->asObject());
137
        }
138
        $oXml->insertChild($oSoftkeys->asObject());
139
140
141
        return $oXml;
142
    }
143
144
    /**
145
     * @return Contents
146
     */
147
    public function getContents()
148
    {
149
        return $this->oContents;
150
    }
151
}
152