JAlertLibrary::getSubdir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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