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

SurveyExportTxtPlugin   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A uninstall() 0 2 1
A __construct() 0 8 1
A create() 0 5 2
A install() 0 2 1
A filterModify() 0 18 5
A removeLinkToCourseTools() 0 5 1
A createLinkToCourseTools() 0 8 2
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