Passed
Push — master ( 0c5836...7e4fb9 )
by Thierry
02:39
created

JAlertLibrary::alert()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
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\Library\JAlert;
14
15
use Jaxon\Ui\Dialog\Library\AbstractDialogLibrary;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\Library\AbstractDialogLibrary was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Jaxon\Ui\Dialog\MessageInterface;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\MessageInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Jaxon\Ui\Dialog\QuestionInterface;
0 ignored issues
show
Bug introduced by
The type Jaxon\Ui\Dialog\QuestionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
class JAlertLibrary extends AbstractDialogLibrary implements MessageInterface, QuestionInterface
20
{
21
    /**
22
     * The constructor
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct('jAlert', '4.5.1');
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function getJs(): string
33
    {
34
        return $this->xHelper->getJsCode('jAlert.min.js');
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getCss(): string
41
    {
42
        return $this->xHelper->getCssCode('jAlert.css');
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function getScript(): string
49
    {
50
        return $this->xHelper->render('jalert/alert.js');
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function getReadyScript(): string
57
    {
58
        return $this->xHelper->render('jalert/ready.js.php');
59
    }
60
61
    /**
62
     * Print an alert message.
63
     *
64
     * @param string $sContent The text of the message
65
     * @param string $sTitle The title of the message
66
     * @param string $sTheme The type of the message
67
     *
68
     * @return string
69
     */
70
    protected function alert(string $sContent, string $sTitle, string $sTheme): string
71
    {
72
        if(!$sTitle)
73
        {
74
            $sTitle = '&nbsp;';
75
        }
76
        if($this->returnCode())
77
        {
78
            return "$.jAlert({content:" . $sContent . ", title:'" . $sTitle . "', theme:'" . $sTheme . "'})";
79
        }
80
        $this->addCommand(array('cmd' => 'jalert.alert'), array('content' => $sContent, 'title' => $sTitle, 'theme' => $sTheme));
81
        return '';
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87
    public function success(string $sMessage, string $sTitle = ''): string
88
    {
89
        return $this->alert($sMessage, $sTitle, 'green');
90
    }
91
92
    /**
93
     * @inheritDoc
94
     */
95
    public function info(string $sMessage, string $sTitle = ''): string
96
    {
97
        return $this->alert($sMessage, $sTitle, 'blue');
98
    }
99
100
    /**
101
     * @inheritDoc
102
     */
103
    public function warning(string $sMessage, string $sTitle = ''): string
104
    {
105
        return $this->alert($sMessage, $sTitle, 'yellow');
106
    }
107
108
    /**
109
     * @inheritDoc
110
     */
111
    public function error(string $sMessage, string $sTitle = ''): string
112
    {
113
        return $this->alert($sMessage, $sTitle, 'red');
114
    }
115
116
    /**
117
     * @inheritDoc
118
     */
119
    public function confirm(string $sQuestion, string $sYesScript, string $sNoScript): string
120
    {
121
        $sTitle = $this->xHelper->getQuestionTitle();
122
        if(!$sNoScript)
123
        {
124
            return "jaxon.dialogs.jalert.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";})";
125
        }
126
        else
127
        {
128
            return "jaxon.dialogs.jalert.confirm(" . $sQuestion . ",'" . $sTitle . "',function(){" . $sYesScript . ";},function(){" . $sNoScript . ";})";
129
        }
130
    }
131
}
132