1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * Class MindmapPlugin |
||
6 | * This class defines the course plugin "MindMap", storing its data in the plugin_mindmap table. |
||
7 | */ |
||
8 | class MindmapPlugin extends Plugin |
||
9 | { |
||
10 | public $isCoursePlugin = true; |
||
11 | public $course_settings = []; |
||
12 | public $table = 'plugin_mindmap'; |
||
13 | |||
14 | /** |
||
15 | * MindmapPlugin constructor. |
||
16 | */ |
||
17 | protected function __construct() |
||
18 | { |
||
19 | parent::__construct( |
||
20 | '1.1', 'Damien Renou - Batisseurs Numériques', |
||
21 | [ |
||
22 | 'tool_enable' => 'boolean', |
||
23 | ] |
||
24 | ); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Create instance of a Mindmap plugin object. |
||
29 | * |
||
30 | * @return MindmapPlugin|null |
||
31 | */ |
||
32 | public static function create() |
||
33 | { |
||
34 | static $result = null; |
||
35 | |||
36 | return $result ? $result : $result = new self(); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Install the table structure. |
||
41 | */ |
||
42 | public function install() |
||
43 | { |
||
44 | $sql = "CREATE TABLE IF NOT EXISTS ".$this->table."( |
||
45 | id INT NOT NULL AUTO_INCREMENT, |
||
46 | title VARCHAR(255) NOT NULL, |
||
47 | description VARCHAR(512), |
||
48 | mindmap_type VARCHAR(155), |
||
49 | mindmap_data TEXT, |
||
50 | user_id INT, |
||
51 | is_public INT, |
||
52 | is_shared INT, |
||
53 | c_id INT, |
||
54 | session_id INT, |
||
55 | url_id INT, |
||
56 | PRIMARY KEY (id));"; |
||
57 | Database::query($sql); |
||
58 | |||
59 | // Copy icons into the main/img/icons folder |
||
60 | $iconName = 'mindmap'; |
||
61 | $iconsList = [ |
||
62 | '64/'.$iconName.'.png', |
||
63 | '64/'.$iconName.'_na.png', |
||
64 | '32/'.$iconName.'.png', |
||
65 | '32/'.$iconName.'_na.png', |
||
66 | '22/'.$iconName.'.png', |
||
67 | '22/'.$iconName.'_na.png', |
||
68 | ]; |
||
69 | $sourceDir = api_get_path(SYS_PLUGIN_PATH).'mindmap/img/'; |
||
70 | $destinationDir = api_get_path(SYS_CODE_PATH).'img/icons/'; |
||
71 | foreach ($iconsList as $icon) { |
||
72 | $src = $sourceDir.$icon; |
||
73 | $dest = $destinationDir.$icon; |
||
74 | copy($src, $dest); |
||
75 | } |
||
76 | |||
77 | // Installing course settings |
||
78 | $this->install_course_fields_in_all_courses(true, 'mindmap.png'); |
||
79 | } |
||
80 | |||
81 | public function uninstall() |
||
82 | { |
||
83 | // Remove table |
||
84 | $em = Database::getManager(); |
||
85 | $sm = $em->getConnection()->getSchemaManager(); |
||
86 | if ($sm->tablesExist('plugin_mindmap')) { |
||
87 | Database::query('DROP TABLE IF EXISTS plugin_mindmap'); |
||
88 | } |
||
89 | |||
90 | // Remove icons from the main/img/icons folder |
||
91 | $iconName = 'mindmap'; |
||
92 | $iconsList = [ |
||
93 | '64/'.$iconName.'.png', |
||
94 | '64/'.$iconName.'_na.png', |
||
95 | '32/'.$iconName.'.png', |
||
96 | '32/'.$iconName.'_na.png', |
||
97 | '22/'.$iconName.'.png', |
||
98 | '22/'.$iconName.'_na.png', |
||
99 | ]; |
||
100 | $destinationDir = api_get_path(SYS_CODE_PATH).'img/icons/'; |
||
101 | foreach ($iconsList as $icon) { |
||
102 | $dest = $destinationDir.$icon; |
||
103 | if (is_file($dest)) { |
||
104 | @unlink($dest); |
||
0 ignored issues
–
show
|
|||
105 | } |
||
106 | } |
||
107 | |||
108 | // Deleting course settings and course home icons |
||
109 | $this->uninstall_course_fields_in_all_courses(); |
||
110 | } |
||
111 | } |
||
112 |
If you suppress an error, we recommend checking for the error condition explicitly: