Completed
Push — master ( 68b79b...383655 )
by Daniel
03:01
created

CommonViews::setViewModernDelete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 12
nc 3
nop 2
1
<?php
2
3
/**
4
 *
5
 * The MIT License (MIT)
6
 *
7
 * Copyright (c) 2015 Daniel Popiniuc
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
29
namespace danielgp\common_lib;
30
31
/**
32
 * usefull functions to get quick results
33
 *
34
 * @author Daniel Popiniuc
35
 */
36
trait CommonViews
37
{
38
39
    use MySQLiAdvancedOutput;
40
41
    protected function setTableLocaleFields($localizationStrings)
42
    {
43
        $this->advCache['tableStructureLocales'] = $localizationStrings;
44
    }
45
46
    private function setViewDeleteFeedbacks()
47
    {
48
        return [
49
            'Confirmation' => $this->lclMsgCmn('i18n_Action_Confirmation'),
50
            'Failed'       => $this->lclMsgCmn('i18n_ActionDelete_Failed'),
51
            'Impossible'   => $this->lclMsgCmn('i18n_ActionDelete_Impossible'),
52
            'Success'      => $this->lclMsgCmn('i18n_ActionDelete_Success'),
53
        ];
54
    }
55
56
    private function setViewDeletePackedFinal($sReturn)
57
    {
58
        $finalJavascript = $this->setJavascriptContent(implode('', [
59
            '$("#DeleteFeedback").fadeOut(4000, function() {',
60
            '$(this).remove();',
61
            '});',
62
        ]));
63
        return '<div id="DeleteFeedback">' . $sReturn . '</div>' . $finalJavascript;
64
    }
65
66
    /**
67
     * Automatic handler for Record deletion
68
     *
69
     * @param string $tbl
70
     * @param string $idn
71
     * @return string
72
     */
73
    protected function setViewModernDelete($tbl, $idn)
74
    {
75
        $tMsg = $this->setViewDeleteFeedbacks();
76
        if ($tbl == '') {
77
            $sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']);
78
        } else {
79
            $idFldVal = $this->tCmnRequest->request->get($idn);
80
            $this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $idFldVal]));
81
            $sReturn  = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed'])
82
                    . '(' . $this->mySQLconnection->error . ')';
83
            if ($this->mySQLconnection->affected_rows > 0) {
84
                $sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']);
85
            }
86
        }
87
        return $this->setViewDeletePackedFinal($sReturn);
88
    }
89
}
90