PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/backup/moodle2/backup_subplugin.class.php

https://bitbucket.org/moodle/moodle
PHP | 101 lines | 40 code | 17 blank | 44 comment | 3 complexity | 988e084888310bc70aade656312f3b6d MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Defines backup_subplugin class
  18. * @package core_backup
  19. * @subpackage moodle2
  20. * @category backup
  21. * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. /**
  26. * Class implementing the subplugins support for moodle2 backups
  27. *
  28. * TODO: Finish phpdocs
  29. * TODO: Make this subclass of backup_plugin
  30. */
  31. abstract class backup_subplugin {
  32. protected $subplugintype;
  33. protected $subpluginname;
  34. protected $connectionpoint;
  35. protected $optigroup; // Optigroup, parent of all optigroup elements
  36. protected $step;
  37. protected $task;
  38. public function __construct($subplugintype, $subpluginname, $optigroup, $step) {
  39. $this->subplugintype = $subplugintype;
  40. $this->subpluginname = $subpluginname;
  41. $this->optigroup = $optigroup;
  42. $this->connectionpoint = '';
  43. $this->step = $step;
  44. $this->task = $step->get_task();
  45. }
  46. public function define_subplugin_structure($connectionpoint) {
  47. $this->connectionpoint = $connectionpoint;
  48. $methodname = 'define_' . $connectionpoint . '_subplugin_structure';
  49. if (method_exists($this, $methodname)) {
  50. $this->$methodname();
  51. }
  52. }
  53. // Protected API starts here
  54. // backup_step/structure_step/task wrappers
  55. /**
  56. * Returns the value of one (task/plan) setting
  57. */
  58. protected function get_setting_value($name) {
  59. if (is_null($this->task)) {
  60. throw new backup_step_exception('not_specified_backup_task');
  61. }
  62. return $this->task->get_setting_value($name);
  63. }
  64. // end of backup_step/structure_step/task wrappers
  65. /**
  66. * Factory method that will return one backup_subplugin_element (backup_optigroup_element)
  67. * with its name automatically calculated, based one the subplugin being handled (type, name)
  68. */
  69. protected function get_subplugin_element($final_elements = null, $conditionparam = null, $conditionvalue = null) {
  70. // Something exclusive for this backup_subplugin_element (backup_optigroup_element)
  71. // because it hasn't XML representation
  72. $name = 'optigroup_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint;
  73. $optigroup_element = new backup_subplugin_element($name, $final_elements, $conditionparam, $conditionvalue);
  74. $this->optigroup->add_child($optigroup_element); // Add optigroup_element to stay connected since beginning
  75. return $optigroup_element;
  76. }
  77. /**
  78. * Simple helper function that suggests one name for the main nested element in subplugins
  79. * It's not mandatory to use it but recommended ;-)
  80. */
  81. protected function get_recommended_name() {
  82. return 'subplugin_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint;
  83. }
  84. }