| Total Complexity | 102 |
| Total Lines | 726 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AppPlugin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AppPlugin, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class AppPlugin |
||
| 10 | { |
||
| 11 | public $plugin_regions = [ |
||
| 12 | 'main_top', |
||
| 13 | 'main_bottom', |
||
| 14 | 'login_top', |
||
| 15 | 'login_bottom', |
||
| 16 | 'menu_top', |
||
| 17 | 'menu_bottom', |
||
| 18 | 'content_top', |
||
| 19 | 'content_bottom', |
||
| 20 | 'header_main', |
||
| 21 | 'header_center', |
||
| 22 | 'header_left', |
||
| 23 | 'header_right', |
||
| 24 | 'pre_footer', |
||
| 25 | 'footer_left', |
||
| 26 | 'footer_center', |
||
| 27 | 'footer_right', |
||
| 28 | 'menu_administrator', |
||
| 29 | 'course_tool_plugin', |
||
| 30 | ]; |
||
| 31 | |||
| 32 | public $installedPluginListName = []; |
||
| 33 | public $installedPluginListObject = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Constructor. |
||
| 37 | */ |
||
| 38 | public function __construct() |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Read plugin from path. |
||
| 44 | * |
||
| 45 | * @return array |
||
| 46 | */ |
||
| 47 | public function read_plugins_from_path() |
||
| 48 | { |
||
| 49 | /* We scan the plugin directory. Each folder is a potential plugin. */ |
||
| 50 | $pluginPath = api_get_path(SYS_PLUGIN_PATH); |
||
| 51 | $plugins = []; |
||
| 52 | $handle = @opendir($pluginPath); |
||
| 53 | while (false !== ($file = readdir($handle))) { |
||
|
|
|||
| 54 | if ($file != '.' && $file != '..' && is_dir(api_get_path(SYS_PLUGIN_PATH).$file)) { |
||
| 55 | $plugins[] = $file; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | @closedir($handle); |
||
| 59 | sort($plugins); |
||
| 60 | |||
| 61 | return $plugins; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function get_installed_plugins_by_region() |
||
| 68 | { |
||
| 69 | $plugins = []; |
||
| 70 | /* We retrieve all the active plugins. */ |
||
| 71 | $result = api_get_settings('Plugins'); |
||
| 72 | if (!empty($result)) { |
||
| 73 | foreach ($result as $row) { |
||
| 74 | $plugins[$row['variable']][] = $row['selected_value']; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $plugins; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | public function getInstalledPluginListName() |
||
| 85 | { |
||
| 86 | if (empty($this->installedPluginListName)) { |
||
| 87 | $this->installedPluginListName = $this->get_installed_plugins(); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $this->installedPluginListName; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @return array List of Plugin |
||
| 95 | */ |
||
| 96 | public function getInstalledPluginListObject() |
||
| 97 | { |
||
| 98 | if (empty($this->installedPluginListObject)) { |
||
| 99 | $this->setInstalledPluginListObject(); |
||
| 100 | } |
||
| 101 | |||
| 102 | return $this->installedPluginListObject; |
||
| 103 | } |
||
| 104 | |||
| 105 | public function setInstalledPluginListObject() |
||
| 106 | { |
||
| 107 | $pluginListName = $this->getInstalledPluginListName(); |
||
| 108 | $pluginList = []; |
||
| 109 | if (!empty($pluginListName)) { |
||
| 110 | foreach ($pluginListName as $pluginName) { |
||
| 111 | $pluginInfo = $this->getPluginInfo($pluginName, true); |
||
| 112 | if (isset($pluginInfo['plugin_class'])) { |
||
| 113 | $pluginList[] = $pluginInfo['plugin_class']::create(); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | $this->installedPluginListObject = $pluginList; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return array |
||
| 122 | */ |
||
| 123 | public function get_installed_plugins() |
||
| 124 | { |
||
| 125 | $installedPlugins = []; |
||
| 126 | $plugins = api_get_settings_params( |
||
| 127 | [ |
||
| 128 | 'variable = ? AND selected_value = ? AND category = ? ' => ['status', 'installed', 'Plugins'], |
||
| 129 | ] |
||
| 130 | ); |
||
| 131 | |||
| 132 | if (!empty($plugins)) { |
||
| 133 | foreach ($plugins as $row) { |
||
| 134 | $installedPlugins[$row['subkey']] = true; |
||
| 135 | } |
||
| 136 | $installedPlugins = array_keys($installedPlugins); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $installedPlugins; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param string $pluginName |
||
| 144 | * @param int $urlId |
||
| 145 | */ |
||
| 146 | public function install($pluginName, $urlId = null) |
||
| 147 | { |
||
| 148 | if (empty($urlId)) { |
||
| 149 | $urlId = api_get_current_access_url_id(); |
||
| 150 | } else { |
||
| 151 | $urlId = intval($urlId); |
||
| 152 | } |
||
| 153 | |||
| 154 | api_add_setting( |
||
| 155 | 'installed', |
||
| 156 | 'status', |
||
| 157 | $pluginName, |
||
| 158 | 'setting', |
||
| 159 | 'Plugins', |
||
| 160 | $pluginName, |
||
| 161 | '', |
||
| 162 | '', |
||
| 163 | '', |
||
| 164 | $urlId, |
||
| 165 | 1 |
||
| 166 | ); |
||
| 167 | |||
| 168 | $pluginPath = api_get_path(SYS_PLUGIN_PATH).$pluginName.'/install.php'; |
||
| 169 | |||
| 170 | if (is_file($pluginPath) && is_readable($pluginPath)) { |
||
| 171 | // Execute the install procedure. |
||
| 172 | |||
| 173 | require $pluginPath; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $pluginName |
||
| 179 | * @param int $urlId |
||
| 180 | */ |
||
| 181 | public function uninstall($pluginName, $urlId = null) |
||
| 182 | { |
||
| 183 | if (empty($urlId)) { |
||
| 184 | $urlId = api_get_current_access_url_id(); |
||
| 185 | } else { |
||
| 186 | $urlId = intval($urlId); |
||
| 187 | } |
||
| 188 | |||
| 189 | // First call the custom uninstall to allow full access to global settings |
||
| 190 | $pluginPath = api_get_path(SYS_PLUGIN_PATH).$pluginName.'/uninstall.php'; |
||
| 191 | if (is_file($pluginPath) && is_readable($pluginPath)) { |
||
| 192 | // Execute the uninstall procedure. |
||
| 193 | |||
| 194 | require $pluginPath; |
||
| 195 | } |
||
| 196 | // Second remove all remaining global settings |
||
| 197 | api_delete_settings_params( |
||
| 198 | ['category = ? AND access_url = ? AND subkey = ? ' => ['Plugins', $urlId, $pluginName]] |
||
| 199 | ); |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $pluginName |
||
| 204 | * |
||
| 205 | * @return array |
||
| 206 | */ |
||
| 207 | public function get_areas_by_plugin($pluginName) |
||
| 208 | { |
||
| 209 | $result = api_get_settings('Plugins'); |
||
| 210 | $areas = []; |
||
| 211 | foreach ($result as $row) { |
||
| 212 | if ($pluginName == $row['selected_value']) { |
||
| 213 | $areas[] = $row['variable']; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | return $areas; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param string $location |
||
| 222 | * |
||
| 223 | * @return bool |
||
| 224 | */ |
||
| 225 | public function is_valid_plugin_location($location) |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param string $pluginName |
||
| 232 | * |
||
| 233 | * @return bool |
||
| 234 | */ |
||
| 235 | public function is_valid_plugin($pluginName) |
||
| 236 | { |
||
| 237 | if (is_dir(api_get_path(SYS_PLUGIN_PATH).$pluginName)) { |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return array |
||
| 248 | */ |
||
| 249 | public function getPluginRegions() |
||
| 250 | { |
||
| 251 | sort($this->plugin_regions); |
||
| 252 | |||
| 253 | return $this->plugin_regions; |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param array $pluginRegionList |
||
| 258 | * @param string $region |
||
| 259 | * @param Twig_Environment $template |
||
| 260 | * @param bool $forced |
||
| 261 | * |
||
| 262 | * @return null|string |
||
| 263 | */ |
||
| 264 | public function loadRegion($pluginName, $region, $template, $forced = false) |
||
| 265 | { |
||
| 266 | ob_start(); |
||
| 267 | $this->getAllPluginContentsByRegion($pluginName, $region, $template, $forced); |
||
| 268 | $content = ob_get_contents(); |
||
| 269 | ob_end_clean(); |
||
| 270 | |||
| 271 | return $content; |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Loads the translation files inside a plugin if exists. |
||
| 276 | * It loads by default english see the hello world plugin. |
||
| 277 | * |
||
| 278 | * @param string $plugin_name |
||
| 279 | * |
||
| 280 | * @todo add caching |
||
| 281 | */ |
||
| 282 | public function load_plugin_lang_variables($plugin_name) |
||
| 283 | { |
||
| 284 | $language_interface = api_get_interface_language(); |
||
| 285 | $root = api_get_path(SYS_PLUGIN_PATH); |
||
| 286 | $strings = null; |
||
| 287 | |||
| 288 | // 1. Loading english if exists |
||
| 289 | $english_path = $root.$plugin_name.'/lang/english.php'; |
||
| 290 | if (is_readable($english_path)) { |
||
| 291 | include $english_path; |
||
| 292 | |||
| 293 | foreach ($strings as $key => $string) { |
||
| 294 | $GLOBALS[$key] = $string; |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | // 2. Loading the system language |
||
| 299 | if ($language_interface != 'english') { |
||
| 300 | $path = $root.$plugin_name."/lang/$language_interface.php"; |
||
| 301 | if (is_readable($path)) { |
||
| 302 | include $path; |
||
| 303 | if (!empty($strings)) { |
||
| 304 | foreach ($strings as $key => $string) { |
||
| 305 | $GLOBALS[$key] = $string; |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } else { |
||
| 309 | /*$interfaceLanguageId = api_get_language_id($language_interface); |
||
| 310 | $interfaceLanguageInfo = api_get_language_info($interfaceLanguageId); |
||
| 311 | $languageParentId = intval($interfaceLanguageInfo['parent_id']); |
||
| 312 | |||
| 313 | if ($languageParentId > 0) { |
||
| 314 | $languageParentInfo = api_get_language_info($languageParentId); |
||
| 315 | $languageParentFolder = $languageParentInfo['dokeos_folder']; |
||
| 316 | |||
| 317 | $parentPath = "{$root}{$plugin_name}/lang/{$languageParentFolder}.php"; |
||
| 318 | if (is_readable($parentPath)) { |
||
| 319 | include $parentPath; |
||
| 320 | if (!empty($strings)) { |
||
| 321 | foreach ($strings as $key => $string) { |
||
| 322 | $this->strings[$key] = $string; |
||
| 323 | } |
||
| 324 | } |
||
| 325 | } |
||
| 326 | }*/ |
||
| 327 | } |
||
| 328 | } |
||
| 329 | } |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param array $_plugins |
||
| 333 | * @param string $region |
||
| 334 | * @param Twig_Environment $template |
||
| 335 | * @param bool $forced |
||
| 336 | * |
||
| 337 | * @return bool |
||
| 338 | * |
||
| 339 | * @todo improve this function |
||
| 340 | */ |
||
| 341 | public function getAllPluginContentsByRegion($plugin_name, $region, $template, $forced = false) |
||
| 342 | { |
||
| 343 | // The plugin_info variable is available inside the plugin index |
||
| 344 | $plugin_info = $this->getPluginInfo($plugin_name, $forced); |
||
| 345 | |||
| 346 | // We also know where the plugin is |
||
| 347 | $plugin_info['current_region'] = $region; |
||
| 348 | |||
| 349 | // Loading the plugin/XXX/index.php file |
||
| 350 | $plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php"; |
||
| 351 | |||
| 352 | if (file_exists($plugin_file)) { |
||
| 353 | //Loading the lang variables of the plugin if exists |
||
| 354 | self::load_plugin_lang_variables($plugin_name); |
||
| 355 | |||
| 356 | // Printing the plugin index.php file |
||
| 357 | require $plugin_file; |
||
| 358 | |||
| 359 | // If the variable $_template is set we assign those values to be accessible in Twig |
||
| 360 | if (isset($_template)) { |
||
| 361 | $_template['plugin_info'] = $plugin_info; |
||
| 362 | } else { |
||
| 363 | $_template = []; |
||
| 364 | $_template['plugin_info'] = $plugin_info; |
||
| 365 | } |
||
| 366 | |||
| 367 | // Setting the plugin info available in the template if exists. |
||
| 368 | //$template->addGlobal($plugin_name, $_template); |
||
| 369 | |||
| 370 | // Loading the Twig template plugin files if exists |
||
| 371 | $templateList = []; |
||
| 372 | if (isset($plugin_info) && isset($plugin_info['templates'])) { |
||
| 373 | $templateList = $plugin_info['templates']; |
||
| 374 | } |
||
| 375 | |||
| 376 | if (!empty($templateList)) { |
||
| 377 | foreach ($templateList as $pluginTemplate) { |
||
| 378 | if (!empty($pluginTemplate)) { |
||
| 379 | $templatePluginFile = "$plugin_name/$pluginTemplate"; // for twig |
||
| 380 | //$template->render($templatePluginFile, []); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | } |
||
| 384 | } |
||
| 385 | |||
| 386 | return true; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Loads plugin info. |
||
| 391 | * |
||
| 392 | * @staticvar array $plugin_data |
||
| 393 | * |
||
| 394 | * @param string $pluginName |
||
| 395 | * @param bool $forced load from DB or from the static array |
||
| 396 | * |
||
| 397 | * @return array |
||
| 398 | * |
||
| 399 | * @todo filter setting_form |
||
| 400 | */ |
||
| 401 | public function getPluginInfo($pluginName, $forced = false) |
||
| 402 | { |
||
| 403 | //$pluginData = Session::read('plugin_data'); |
||
| 404 | if (0) { |
||
| 405 | //if (isset($pluginData[$pluginName]) && $forced == false) { |
||
| 406 | return $pluginData[$pluginName]; |
||
| 407 | } else { |
||
| 408 | $plugin_file = api_get_path(SYS_PLUGIN_PATH)."$pluginName/plugin.php"; |
||
| 409 | |||
| 410 | $plugin_info = []; |
||
| 411 | if (file_exists($plugin_file)) { |
||
| 412 | require $plugin_file; |
||
| 413 | } |
||
| 414 | |||
| 415 | // @todo check if settings are already added |
||
| 416 | // Extra options |
||
| 417 | $plugin_settings = api_get_settings_params( |
||
| 418 | [ |
||
| 419 | 'subkey = ? AND category = ? AND type = ? AND access_url = ?' => [ |
||
| 420 | $pluginName, |
||
| 421 | 'Plugins', |
||
| 422 | 'setting', |
||
| 423 | api_get_current_access_url_id(), |
||
| 424 | ], |
||
| 425 | ] |
||
| 426 | ); |
||
| 427 | |||
| 428 | $settings_filtered = []; |
||
| 429 | foreach ($plugin_settings as $item) { |
||
| 430 | if (!empty($item['selected_value'])) { |
||
| 431 | //if (unserialize($item['selected_value']) !== false) { |
||
| 432 | //$item['selected_value'] = unserialize($item['selected_value']); |
||
| 433 | //} |
||
| 434 | } |
||
| 435 | $settings_filtered[$item['variable']] = $item['selected_value']; |
||
| 436 | } |
||
| 437 | |||
| 438 | $plugin_info['settings'] = $settings_filtered; |
||
| 439 | $pluginData[$pluginName] = $plugin_info; |
||
| 440 | //Session::write('plugin_data', $pluginData); |
||
| 441 | |||
| 442 | return $plugin_info; |
||
| 443 | } |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Get the template list. |
||
| 448 | * |
||
| 449 | * @param string $pluginName |
||
| 450 | * |
||
| 451 | * @return bool |
||
| 452 | */ |
||
| 453 | public function get_templates_list($pluginName) |
||
| 454 | { |
||
| 455 | $plugin_info = $this->getPluginInfo($pluginName); |
||
| 456 | if (isset($plugin_info) && isset($plugin_info['templates'])) { |
||
| 457 | return $plugin_info['templates']; |
||
| 458 | } else { |
||
| 459 | return false; |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Remove all regions of an specific plugin. |
||
| 465 | * |
||
| 466 | * @param string $plugin |
||
| 467 | */ |
||
| 468 | public function removeAllRegions($plugin) |
||
| 478 | ], |
||
| 479 | ] |
||
| 480 | ); |
||
| 481 | } |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Add a plugin to a region. |
||
| 486 | * |
||
| 487 | * @param string $plugin |
||
| 488 | * @param string $region |
||
| 489 | */ |
||
| 490 | public function add_to_region($plugin, $region) |
||
| 504 | ); |
||
| 505 | } |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @param int $courseId |
||
| 509 | */ |
||
| 510 | public function install_course_plugins($courseId) |
||
| 524 | } |
||
| 525 | } |
||
| 526 | } |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Trigger for Plugin::doWhenDeleting[Item] functions. |
||
| 532 | * |
||
| 533 | * @param string $itemType |
||
| 534 | * @param int $itemId |
||
| 535 | */ |
||
| 536 | public function performActionsWhenDeletingItem($itemType, $itemId) |
||
| 556 | } |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Add the course settings to the course settings form. |
||
| 562 | * |
||
| 563 | * @param FormValidator $form |
||
| 564 | */ |
||
| 565 | public function add_course_settings_form($form) |
||
| 566 | { |
||
| 567 | $pluginList = $this->getInstalledPluginListObject(); |
||
| 568 | /** @var Plugin $obj */ |
||
| 569 | foreach ($pluginList as $obj) { |
||
| 570 | $pluginName = $obj->get_name(); |
||
| 571 | $pluginTitle = $obj->get_title(); |
||
| 572 | if (!empty($obj->course_settings)) { |
||
| 573 | if (is_file(api_get_path(SYS_CODE_PATH).'img/icons/'.ICON_SIZE_SMALL.'/'.$pluginName.'.png')) { |
||
| 574 | $icon = Display::return_icon( |
||
| 575 | $pluginName.'.png', |
||
| 576 | Security::remove_XSS($pluginTitle), |
||
| 577 | '', |
||
| 578 | ICON_SIZE_SMALL |
||
| 579 | ); |
||
| 580 | } else { |
||
| 581 | $icon = Display::return_icon( |
||
| 582 | 'plugins.png', |
||
| 583 | Security::remove_XSS($pluginTitle), |
||
| 584 | '', |
||
| 585 | ICON_SIZE_SMALL |
||
| 586 | ); |
||
| 587 | } |
||
| 588 | |||
| 589 | $form->addHtml('<div class="panel panel-default">'); |
||
| 590 | $form->addHtml(' |
||
| 591 | <div class="panel-heading" role="tab" id="heading-'.$pluginName.'-settings"> |
||
| 592 | <h4 class="panel-title"> |
||
| 593 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-'.$pluginName.'-settings" aria-expanded="false" aria-controls="collapse-'.$pluginName.'-settings"> |
||
| 594 | '); |
||
| 595 | $form->addHtml($icon.' '.$pluginTitle); |
||
| 596 | $form->addHtml(' |
||
| 597 | </a> |
||
| 598 | </h4> |
||
| 599 | </div> |
||
| 600 | '); |
||
| 601 | $form->addHtml(' |
||
| 602 | <div id="collapse-'.$pluginName.'-settings" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-'.$pluginName.'-settings"> |
||
| 603 | <div class="panel-body"> |
||
| 604 | '); |
||
| 605 | |||
| 606 | $groups = []; |
||
| 607 | foreach ($obj->course_settings as $setting) { |
||
| 608 | if ($obj->validateCourseSetting($setting['name']) === false) { |
||
| 609 | continue; |
||
| 610 | } |
||
| 611 | if ($setting['type'] != 'checkbox') { |
||
| 612 | $form->addElement($setting['type'], $setting['name'], $obj->get_lang($setting['name'])); |
||
| 613 | } else { |
||
| 614 | $element = &$form->createElement( |
||
| 615 | $setting['type'], |
||
| 616 | $setting['name'], |
||
| 617 | '', |
||
| 618 | $obj->get_lang($setting['name']) |
||
| 619 | ); |
||
| 620 | if (isset($setting['init_value']) && $setting['init_value'] == 1) { |
||
| 621 | $element->setChecked(true); |
||
| 622 | } |
||
| 623 | $form->addElement($element); |
||
| 624 | |||
| 625 | if (isset($setting['group'])) { |
||
| 626 | $groups[$setting['group']][] = $element; |
||
| 627 | } |
||
| 628 | } |
||
| 629 | } |
||
| 630 | foreach ($groups as $k => $v) { |
||
| 631 | $form->addGroup($groups[$k], $k, [$obj->get_lang($k)]); |
||
| 632 | } |
||
| 633 | $form->addButtonSave(get_lang('SaveSettings')); |
||
| 634 | $form->addHtml(' |
||
| 635 | </div> |
||
| 636 | </div> |
||
| 637 | '); |
||
| 638 | $form->addHtml('</div>'); |
||
| 639 | } |
||
| 640 | } |
||
| 641 | } |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Get all course settings from all installed plugins. |
||
| 645 | * |
||
| 646 | * @return array |
||
| 647 | */ |
||
| 648 | public function getAllPluginCourseSettings() |
||
| 649 | { |
||
| 650 | $pluginList = $this->getInstalledPluginListObject(); |
||
| 651 | /** @var Plugin $obj */ |
||
| 652 | $courseSettings = []; |
||
| 653 | if (!empty($pluginList)) { |
||
| 654 | foreach ($pluginList as $obj) { |
||
| 655 | $pluginCourseSetting = $obj->getCourseSettings(); |
||
| 656 | $courseSettings = array_merge($courseSettings, $pluginCourseSetting); |
||
| 657 | } |
||
| 658 | } |
||
| 659 | |||
| 660 | return $courseSettings; |
||
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * When saving the plugin values in the course settings, check whether |
||
| 665 | * a callback method should be called and send it the updated settings. |
||
| 666 | * |
||
| 667 | * @param array $values The new settings the user just saved |
||
| 668 | */ |
||
| 669 | public function saveCourseSettingsHook($values) |
||
| 670 | { |
||
| 671 | $pluginList = $this->getInstalledPluginListObject(); |
||
| 672 | |||
| 673 | /** @var Plugin $obj */ |
||
| 674 | foreach ($pluginList as $obj) { |
||
| 675 | $settings = $obj->getCourseSettings(); |
||
| 676 | $subValues = []; |
||
| 677 | if (!empty($settings)) { |
||
| 678 | foreach ($settings as $v) { |
||
| 679 | if (isset($values[$v])) { |
||
| 680 | $subValues[$v] = $values[$v]; |
||
| 681 | } |
||
| 682 | } |
||
| 683 | } |
||
| 684 | |||
| 685 | if (!empty($subValues)) { |
||
| 686 | $obj->course_settings_updated($subValues); |
||
| 687 | } |
||
| 688 | } |
||
| 689 | } |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Get first SMS plugin name. |
||
| 693 | * |
||
| 694 | * @return string|bool |
||
| 695 | */ |
||
| 696 | public function getSMSPluginName() |
||
| 697 | { |
||
| 698 | $installedPluginsList = $this->getInstalledPluginListObject(); |
||
| 699 | foreach ($installedPluginsList as $installedPlugin) { |
||
| 700 | if ($installedPlugin->isMailPlugin) { |
||
| 701 | return get_class($installedPlugin); |
||
| 702 | } |
||
| 703 | } |
||
| 704 | |||
| 705 | return false; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * @return SmsPluginLibraryInterface |
||
| 710 | */ |
||
| 711 | public function getSMSPluginLibrary() |
||
| 712 | { |
||
| 713 | $className = $this->getSMSPluginName(); |
||
| 714 | $className = str_replace('Plugin', '', $className); |
||
| 715 | |||
| 716 | if (class_exists($className)) { |
||
| 717 | return new $className(); |
||
| 718 | } |
||
| 719 | |||
| 720 | return false; |
||
| 721 | } |
||
| 722 | |||
| 723 | /** |
||
| 724 | * @param array $pluginRegionList |
||
| 725 | * @param string $pluginRegion |
||
| 726 | * @param Twig_Environment $twig |
||
| 727 | */ |
||
| 728 | public function setPluginRegion($pluginRegionList, $pluginRegion, $twig) |
||
| 735 | ); |
||
| 736 | |||
| 737 | //$twig->addGlobal('plugin_'.$pluginRegion, $regionContent); |
||
| 738 | } |
||
| 739 | } |
||
| 740 |