Passed
Push — master ( 2cb546...9b3a22 )
by Thierry
08:13
created

JAlertLibrary   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 133
rs 10
c 0
b 0
f 0
wmc 16

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getScript() 0 3 1
A getCss() 0 3 1
A getVersion() 0 3 1
A alert() 0 12 3
A getSubdir() 0 3 1
A confirm() 0 10 2
A getReadyScript() 0 3 1
A getJs() 0 3 1
A error() 0 3 1
A getName() 0 3 1
A warning() 0 3 1
A info() 0 3 1
A success() 0 3 1
1
<?php
2
3
/**
4
 * DialogLibraryInterface.php - Adapter for the jAlert library.
5
 *
6
 * @package jaxon-dialogs
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2016 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-dialogs
11
 */
12
13
namespace Jaxon\Dialogs\JAlert;
14
15
use Jaxon\App\Dialog\Library\DialogLibraryTrait;
16
use Jaxon\App\Dialog\LibraryInterface;
17
use Jaxon\App\Dialog\MessageInterface;
18
use Jaxon\App\Dialog\QuestionInterface;
19
20
class JAlertLibrary implements LibraryInterface, MessageInterface, QuestionInterface
21
{
22
    use DialogLibraryTrait;
23
24
    /**
25
     * @const The library name
26
     */
27
    const NAME = 'jalert';
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function getName(): string
33
    {
34
        return self::NAME;
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getSubdir(): string
41
    {
42
        return 'jAlert';
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function getVersion(): string
49
    {
50
        return '4.5.1';
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function getJs(): string
57
    {
58
        return $this->helper()->getJsCode('jAlert.min.js');
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function getCss(): string
65
    {
66
        return $this->helper()->getCssCode('jAlert.css');
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function getScript(): string
73
    {
74
        return $this->helper()->render('jalert/alert.js');
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function getReadyScript(): string
81
    {
82
        return $this->helper()->render('jalert/ready.js.php');
83
    }
84
85
    /**
86
     * Print an alert message.
87
     *
88
     * @param string $sContent The text of the message
89
     * @param string $sTitle The title of the message
90
     * @param string $sTheme The type of the message
91
     *
92
     * @return string
93
     */
94
    protected function alert(string $sContent, string $sTitle, string $sTheme): string
95
    {
96
        if(!$sTitle)
97
        {
98
            $sTitle = '&nbsp;';
99
        }
100
        if($this->returnCode())
101
        {
102
            return "$.jAlert({content:" . $sContent . ", title:'" . $sTitle . "', theme:'" . $sTheme . "'})";
103
        }
104
        $this->addCommand(array('cmd' => 'jalert.alert'), array('content' => $sContent, 'title' => $sTitle, 'theme' => $sTheme));
105
        return '';
106
    }
107
108
    /**
109
     * @inheritDoc
110
     */
111
    public function success(string $sMessage, string $sTitle = ''): string
112
    {
113
        return $this->alert($sMessage, $sTitle, 'green');
114
    }
115
116
    /**
117
     * @inheritDoc
118
     */
119
    public function info(string $sMessage, string $sTitle = ''): string
120
    {
121
        return $this->alert($sMessage, $sTitle, 'blue');
122
    }
123
124
    /**
125
     * @inheritDoc
126
     */
127
    public function warning(string $sMessage, string $sTitle = ''): string
128
    {
129
        return $this->alert($sMessage, $sTitle, 'yellow');
130
    }
131
132
    /**
133
     * @inheritDoc
134
     */
135
    public function error(string $sMessage, string $sTitle = ''): string
136
    {
137
        return $this->alert($sMessage, $sTitle, 'red');
138
    }
139
140
    /**
141
     * @inheritDoc
142
     */
143
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
144
    {
145
        $sTitle = $this->helper()->getQuestionTitle();
146
        if(!$sNoScript)
147
        {
148
            return "jaxon.dialogs.jalert.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";})";
149
        }
150
        else
151
        {
152
            return "jaxon.dialogs.jalert.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";},function(){" . $sNoScript . ";})";
153
        }
154
    }
155
}
156