Automatically generated installer lang files
[moodle.git] / backup / cc / cc_lib / cc_converters.php
blob2584bbb542479f7f966cdf70f63bf5ae3b71eb85
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.
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 * @package backup-convert
18 * @subpackage cc-library
19 * @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 require_once('cc_interfaces.php');
25 abstract class cc_converter {
26 /**
28 * Enter description here ...
29 * @var cc_item
31 protected $item = null;
32 /**
34 * Enter description here ...
35 * @var cc_manifest
37 protected $manifest = null;
38 /**
40 * Enter description here ...
41 * @var string
43 protected $rootpath = null;
44 /**
46 * Enter description here ...
47 * @var string
49 protected $path = null;
50 /**
52 * Enter description here ...
53 * @var string
55 protected $defaultfile = null;
56 /**
58 * Enter description here ...
59 * @var string
61 protected $defaultname = null;
62 /**
64 * Enter description here ...
65 * @var string
67 protected $cc_type = null;
68 /**
70 * Document
71 * @var XMLGenericDocument
73 protected $doc = null;
75 /**
77 * ctor
78 * @param cc_i_item $item
79 * @param cc_i_manifest $manifest
80 * @param string $rootpath
81 * @param string $path
82 * @throws InvalidArgumentException
84 public function __construct(cc_i_item &$item, cc_i_manifest &$manifest, $rootpath, $path) {
85 $rpath = realpath($rootpath);
86 if (empty($rpath)) {
87 throw new InvalidArgumentException('Invalid path!');
89 $rpath2 = realpath($path);
90 if (empty($rpath)) {
91 throw new InvalidArgumentException('Invalid path!');
93 $doc = new XMLGenericDocument();
94 if (!$doc->load($path . DIRECTORY_SEPARATOR . $this->defaultfile)) {
95 throw new RuntimeException('File does not exist!');
98 $this->doc = $doc;
99 $this->item = $item;
100 $this->manifest = $manifest;
101 $this->rootpath = $rpath;
102 $this->path = $rpath2;
107 * performs conversion
108 * @param string $outdir - root directory of common cartridge
109 * @return boolean
111 abstract public function convert($outdir);
115 * Is the element visible in the course?
116 * @throws RuntimeException
117 * @return bool
119 protected function is_visible() {
120 $tdoc = new XMLGenericDocument();
121 if (!$tdoc->load($this->path . DIRECTORY_SEPARATOR . 'module.xml')) {
122 throw new RuntimeException('File does not exist!');
124 $visible = (int)$tdoc->nodeValue('/module/visible');
125 return ($visible > 0);
130 * Stores any files that need to be stored
132 protected function store(general_cc_file $doc, $outdir, $title, $deps = null) {
133 $rdir = new cc_resource_location($outdir);
134 $rtp = $rdir->fullpath(true).$this->defaultname;
135 if ( $doc->saveTo($rtp) ) {
136 $resource = new cc_resource($rdir->rootdir(), $this->defaultname, $rdir->dirname(true));
137 $resource->dependency = empty($deps) ? array() : $deps;
138 $resource->instructoronly = !$this->is_visible();
139 $res = $this->manifest->add_resource($resource, null, $this->cc_type);
140 $resitem = new cc_item();
141 $resitem->attach_resource($res[0]);
142 $resitem->title = $title;
143 $this->item->add_child_item($resitem);
144 } else {
145 throw new RuntimeException("Unable to save file {$rtp}!");