Completed
Push — master ( 067f55...e1cb48 )
by Julito
09:39
created

SurveyExportTxtPlugin   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 87
rs 10
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 removeLinkToCourseTools() 0 5 1
A install() 0 2 1
A createLinkToCourseTools() 0 8 2
A filterModify() 0 18 5
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class SurveyExportTxtPlugin.
6
 */
7
class SurveyExportTxtPlugin extends Plugin
8
{
9
    /**
10
     * SurveyExportTxtPlugin constructor.
11
     */
12
    protected function __construct()
13
    {
14
        $settings = [
15
            'enabled' => 'boolean',
16
            'export_incomplete' => 'boolean',
17
        ];
18
19
        parent::__construct('0.1', 'Angel Fernando Quiroz Campos', $settings);
20
    }
21
22
    /**
23
     * @return SurveyExportTxtPlugin|null
24
     */
25
    public static function create()
26
    {
27
        static $result = null;
28
29
        return $result ? $result : $result = new self();
30
    }
31
32
    /**
33
     * Installation process.
34
     */
35
    public function install()
36
    {
37
    }
38
39
    /**
40
     * Uninstallation process.
41
     */
42
    public function uninstall()
43
    {
44
    }
45
46
    /**
47
     * @param array $params
48
     *
49
     * @return string
50
     */
51
    public static function filterModify($params)
52
    {
53
        $enabled = api_get_plugin_setting('surveyexporttxt', 'enabled');
54
55
        if ($enabled !== 'true') {
56
            return '';
57
        }
58
59
        $surveyId = isset($params['survey_id']) ? (int) $params['survey_id'] : 0;
60
        $iconSize = isset($params['icon_size']) ? $params['icon_size'] : ICON_SIZE_SMALL;
61
62
        if (empty($surveyId)) {
63
            return '';
64
        }
65
66
        return Display::url(
67
            Display::return_icon('export_evaluation.png', get_lang('Export'), [], $iconSize),
68
            api_get_path(WEB_PLUGIN_PATH).'surveyexporttxt/export.php?survey='.$surveyId.'&'.api_get_cidreq()
69
        );
70
    }
71
72
    /**
73
     * Create tools for all courses.
74
     */
75
    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...
76
    {
77
        $result = Database::getManager()
78
            ->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c')
79
            ->getResult();
80
81
        foreach ($result as $item) {
82
            $this->createLinkToCourseTool($this->get_name().':teacher', $item['id'], 'survey.png');
83
        }
84
    }
85
86
    /**
87
     * Remove all course tools created by plugin.
88
     */
89
    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...
90
    {
91
        Database::getManager()
92
            ->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.link LIKE :link AND t.category = :category')
93
            ->execute(['link' => 'surveyexporttxt/start.php%', 'category' => 'plugin']);
94
    }
95
}
96