Passed
Push — master ( 621302...15a517 )
by Angel Fernando Quiroz
16:26 queued 07:49
created

SurveyExportTxtPlugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Enums\ActionIcon;
6
7
/**
8
 * Class SurveyExportTxtPlugin.
9
 */
10
class SurveyExportTxtPlugin extends Plugin
11
{
12
    /**
13
     * SurveyExportTxtPlugin constructor.
14
     */
15
    protected function __construct()
16
    {
17
        $settings = [
18
            'enabled' => 'boolean',
19
            'export_incomplete' => 'boolean',
20
        ];
21
22
        parent::__construct('0.1', 'Angel Fernando Quiroz Campos', $settings);
23
    }
24
25
    /**
26
     * @return SurveyExportTxtPlugin|null
27
     */
28
    public static function create()
29
    {
30
        static $result = null;
31
32
        return $result ?: $result = new self();
33
    }
34
35
    /**
36
     * Installation process.
37
     */
38
    public function install()
39
    {
40
    }
41
42
    /**
43
     * Uninstallation process.
44
     */
45
    public function uninstall()
46
    {
47
    }
48
49
    /**
50
     * @param array $params
51
     *
52
     * @return string
53
     */
54
    public static function filterModify($params)
55
    {
56
        $enabled = api_get_plugin_setting('surveyexporttxt', 'enabled');
57
58
        if ('true' !== $enabled) {
59
            return '';
60
        }
61
62
        $surveyId = isset($params['survey_id']) ? (int) $params['survey_id'] : 0;
63
        $iconSize = isset($params['icon_size']) ? $params['icon_size'] : ICON_SIZE_SMALL;
64
65
        if (empty($surveyId)) {
66
            return '';
67
        }
68
69
        return Display::url(
70
            Display::getMdiIcon(ActionIcon::EXPORT_ARCHIVE, 'ch-tool-icon', null, $iconSize, get_lang('Export')),
71
            api_get_path(WEB_PLUGIN_PATH).'SurveyExportTxt/export.php?survey='.$surveyId.'&'.api_get_cidreq()
72
        );
73
    }
74
75
    /**
76
     * Create tools for all courses.
77
     */
78
    private function createLinkToCourseTools()
0 ignored issues
show
Unused Code introduced by
The method createLinkToCourseTools() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
79
    {
80
        $result = Database::getManager()
81
            ->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c')
82
            ->getResult();
83
84
        foreach ($result as $item) {
85
            $this->createLinkToCourseTool($this->get_name().':teacher', $item['id']);
86
        }
87
    }
88
89
    /**
90
     * Remove all course tools created by plugin.
91
     */
92
    private function removeLinkToCourseTools()
0 ignored issues
show
Unused Code introduced by
The method removeLinkToCourseTools() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
93
    {
94
        Database::getManager()
95
            ->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.link LIKE :link AND t.category = :category')
96
            ->execute(['link' => 'SurveyExportTxt/start.php%', 'category' => 'plugin']);
97
    }
98
}
99