1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
export.php
См. документацию.
1<?
2// 2012-04-18 Checked/modified for compatibility with new data model
4{
5
6 var $ID;
8 var $LAST_ERROR = "";
9 var $arCourse = Array();
10 var $arSite = Array();
11 var $arItems = Array();
12 var $arResources = Array();
13 var $RefID = 1;
14 var $strItems = "";
15 var $strResourses = "";
16 var $arDraftFields = Array("detail_text", "preview_text", "description");
17 var $arPicture = Array("detail_picture", "preview_picture", "file_id");
18 var $arDate = Array("active_from", "active_to", "timestamp_x", "date_create");
19 private $replacingResId;
20
21 // 2012-04-18 Checked/modified for compatibility with new data model
22 public function __construct($COURSE_ID)
23 {
24 global $DB;
25 $this->ID = intval($COURSE_ID);
26
27 //Course exists?
28 $res = CCourse::GetByID($this->ID);
29 if (!$this->arCourse = $res->Fetch())
30 {
31 $this->LAST_ERROR = GetMessage("LEARNING_BAD_COURSE_ID_EX");
32 return false;
33 }
34
35 $res = CCourse::GetSite($this->ID);
36 if ($arSite = $res->GetNext())
37 {
38 $charset = $arSite["CHARSET"];
39 }
40 else
41 {
42 $this->LAST_ERROR = GetMessage("LEARNING_BAD_SITE_ID_EX");
43 return false;
44 }
45
46 //Define charset
47 if ($charset == '')
48 {
49 if (defined("SITE_CHARSET") && SITE_CHARSET <> '')
51 else
52 $charset = "windows-1251";
53 }
54 $this->charset = $charset;
55
56 //Get chapters, lessons, questions
57 $this->_GetCourseContent($this->arCourse['LESSON_ID']);
58
59 //Get tests
60 $strSql =
61 "SELECT T.*, ".
62 $DB->DateToCharFunction("T.TIMESTAMP_X")." as TIMESTAMP_X ".
63 "FROM b_learn_test T ".
64 "WHERE T.COURSE_ID = ".intval($this->ID)." ".
65 "ORDER BY SORT ASC ";
66
67 $res = $DB->Query($strSql);
68 while ($arRes= $res->Fetch())
69 {
70 $r = ++$this->RefID;
71 $this->arItems[$r] = $this->_CreateContent("TES", $arRes, $r);
72 $this->strItems .= '<item identifier="TES'.$r.'" identifierref="RES'.$r.'"><title>'.htmlspecialcharsbx($arRes["NAME"]).'</title>';
73
74 $marksRes = $DB->Query(
75 "SELECT * FROM b_learn_test_mark WHERE TEST_ID = '" . (string) ((int) $arRes['ID']) . "'"
76 );
77 while ($arMarksRes= $marksRes->Fetch())
78 {
79 $r = ++$this->RefID;
80 $this->arItems[$r] = $this->CreateTMK($arMarksRes, $r);
81 $this->strItems .= '<item identifier="TMK'.$r.'" identifierref="RES'.$r.'">'
82 . '<title>' . htmlspecialcharsbx($arMarksRes['MARK'] . ' (' . $arMarksRes['DESCRIPTION'] . ')') . '</title>'
83 . '</item>';
84 }
85
86 $this->strItems .= '</item>';
87 $this->strResourses .= '<resource identifier="RES'.$r.'" type="webcontent" href="res'.$r.'.xml">'.$this->_GetResourceFiles($r).'</resource>';
88 }
89 }
90
91
92 // 2012-04-18 Checked/modified for compatibility with new data model
93 function CreatePackage($PACKAGE_DIR)
94 {
95 if ($this->LAST_ERROR <> '')
96 return false;
97
98 //Add last slash
99 if (mb_substr($PACKAGE_DIR, -1, 1) != "/")
100 $PACKAGE_DIR .= "/";
101
102 $path = $_SERVER["DOCUMENT_ROOT"].$PACKAGE_DIR;
103
105
106 if (!is_dir($path) || !is_writable($path))
107 {
108 $this->LAST_ERROR = GetMessage("LEARNING_BAD_PACKAGE");
109 return false;
110 }
111
112 RewriteFile($path."/res1.xml", $this->_CreateCourseToc());
113 RewriteFile($path."/imsmanifest.xml", $this->CreateManifest());
114
115 //XML Resource Data
116 foreach ($this->arItems as $res_id => $content)
117 {
118 RewriteFile($path."/res".$res_id.".xml", $content);
119 }
120
121 //Resource
122 $dbres_path = $path."/dbresources/";
123 CheckDirPath($dbres_path);
124
125 foreach ($this->arResources as $res_id => $arFiles)
126 {
127 $res_path = $path."/resources/res".$res_id."/";
128
129 CheckDirPath($res_path);
130 foreach ($arFiles as $arFile)
131 {
132 if (array_key_exists("DB", $arFile))
133 {
134 $arTempFile = CFile::MakeFileArray($arFile["DB"]);
135 if($arTempFile && isset($arTempFile["tmp_name"]))
136 @copy($arTempFile["tmp_name"], $dbres_path.$arFile["ID"]);
137 }
138 else
139 {
140 @copy($_SERVER["DOCUMENT_ROOT"].$arFile["SRC"], $res_path.$arFile["ID"]);
141 }
142 }
143 }
144
145 return true;
146 }
147
148
149 // 2012-04-18 Checked/modified for compatibility with new data model
150 function CreateManifest()
151 {
152 global $DB;
153
154 if ($this->LAST_ERROR <> '')
155 return false;
156
157 $this->createQuestionItems($this->arCourse["LESSON_ID"]);
158
159 $strManifest = "<"."?xml version=\"1.0\" encoding=\"".$this->charset."\"?".">\n";
160 $strManifest .= '<manifest xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2" identifier="toc1">';
161 //<Organization>
162 $strManifest .= '<organizations default="man1"><organization identifier="man1" structure="hierarchical">';
163 $strManifest .= '<item identifier="COR1" identifierref="RES1" parameters=""><title>'.htmlspecialcharsbx($this->arCourse["NAME"]).'</title>';
164 $strManifest .= $this->strItems;
165 $strManifest .= '</item>';
166 $strManifest .= '</organization></organizations>';
167 //<Resource>
168 $strManifest .= '<resources><resource identifier="RES1" type="webcontent" href="res1.xml">'.$this->_GetResourceFiles(1).'</resource>';
169 $strManifest .= $this->strResourses;
170 $strManifest .= '</resources>';
171 $strManifest .= '</manifest>';
172
173 return $strManifest;
174 }
175
176 // 2012-04-18 Checked/modified for compatibility with new data model
177 function _GetCourseContent($parentLessonId, $DEPTH_LEVEL = 1)
178 {
179 global $DB;
180
182 $parentLessonId,
183 array( // order
184 'EDGE_SORT' => 'asc'
185 )
186 );
187
188 while ($arRes= $res->Fetch())
189 {
190 $arRes['ID'] = $arRes['LESSON_ID']; // for compatibility
191
192 if ($arRes['IS_CHILDS'] == '1')
193 $itemType = 'CHA';
194 else
195 $itemType = 'LES';
196
197 if (CLearnLesson::IsPublishProhibited($arRes['LESSON_ID'], $parentLessonId))
198 $arRes['META_PUBLISH_PROHIBITED'] = 'Y';
199 else
200 $arRes['META_PUBLISH_PROHIBITED'] = 'N';
201
202 $r = ++$this->RefID;
203 $this->arItems[$r] = $this->_CreateContent($itemType, $arRes, $r);
204 $this->strItems .= '<item identifier="' . $itemType . $r . '" identifierref="RES'.$r.'"><title>'.htmlspecialcharsbx($arRes["NAME"]).'</title>';
205 $this->strResourses .= '<resource identifier="RES'.$r.'" type="webcontent" href="res'.$r.'.xml">'.$this->_GetResourceFiles($r).'</resource>';
206
207 $this->createQuestionItems($arRes["ID"]);
208
209 // Load content recursively for chapters
210 if ($arRes['IS_CHILDS'] == '1')
211 $this->_GetCourseContent($arRes["ID"], $DEPTH_LEVEL+1);
212
213 $this->strItems .= "</item>";
214 }
215 }
216
217
218 // 2012-04-18 Checked/modified for compatibility with new data model
220 {
221 $str = "<"."?xml version=\"1.0\" encoding=\"".$this->charset."\"?".">\n";
222 $str .= "<coursetoc>";
223
224 foreach ($this->arCourse as $key => $val)
225 {
226 $strDelayed = '';
227 $key = mb_strtolower($key);
228
229 if ($key === 'site_id')
230 continue;
231
232 $str .= "<".$key.">";
233 if (in_array($key, $this->arDraftFields) && $val <> '')
234 {
235 $str .= "<![CDATA[".$this->_ReplaceImages($val, 1)."]]>";
236 }
237 elseif (in_array($key, $this->arDate) && $val <> '')
238 {
240 }
241 elseif (in_array($key, $this->arPicture) && $val <> '')
242 {
243 $src = CFile::GetPath($val);
244 $ext = GetFileExtension($src);
245 $this->arResources[1][] = Array("DB" => $val, "SRC"=>$src, "ID"=>$val.".".$ext);
246 $str .= $val.".".$ext;
247
248 $rs = CFile::GetByID($val);
249 if ($arFileData = $rs->Fetch())
250 {
251 $strDelayed = '<' . $key . '_description' . '>'
252 . htmlspecialcharsbx($arFileData['DESCRIPTION'])
253 . '</' . $key . '_description' . '>';
254 }
255 }
256 else
257 {
259 }
260 $str .= "</".$key.">\n";
261 $str .= $strDelayed;
262 }
263
264 $str .= "</coursetoc>";
265
266 return $str;
267 }
268
269 // 2012-04-18 Checked/modified for compatibility with new data model
270 function _GetResourceFiles($res_id)
271 {
272 $str = "";
273
274 if (is_set($this->arResources,$res_id))
275 foreach ($this->arResources[$res_id] as $arFile)
276 if (is_set($arFile,"DB"))
277 $str .= '<file href="dbresources/'.$arFile["ID"].'" />';
278 else
279 $str .= '<file href="resources/res'.$res_id.'/'.$arFile["ID"].'" />';
280 return $str;
281 }
282
283 // 2012-04-18 Checked/modified for compatibility with new data model
284 function _CreateContent($TYPE, $arParams, $res_id)
285 {
286 $str = "<"."?xml version=\"1.0\" encoding=\"".$this->charset."\"?".">\n";
287 $str .= '<content type="'.$TYPE.'">';
288
289 foreach ($arParams as $key => $val)
290 {
291 $strDelayed = '';
292
293 $key = mb_strtolower($key);
294
295 if ($key === 'site_id')
296 continue;
297
298 $str .= "<".$key.">";
299 if (in_array($key, $this->arDraftFields) && $val <> '')
300 {
301 $str .= "<![CDATA[".$this->_ReplaceImages($val, $res_id)."]]>";
302 }
303 elseif (in_array($key, $this->arPicture) && $val <> '')
304 {
305 $src = CFile::GetPath($val);
306 $ext = GetFileExtension($src);
307 $this->arResources[$res_id][] = Array("DB" => $val, "SRC"=>$src, "ID"=>$val.".".$ext);
308 $str .= $val.".".$ext;
309
310 $rs = CFile::GetByID($val);
311 if ($arFileData = $rs->Fetch())
312 {
313 $strDelayed = '<' . $key . '_description' . '>'
314 . htmlspecialcharsbx($arFileData['DESCRIPTION'])
315 . '</' . $key . '_description' . '>';
316 }
317 }
318 elseif (in_array($key, $this->arDate) && $val <> '')
319 {
321 }
322 else
323 {
325 }
326 $str .= "</".$key.">\n";
327
328 $str .= $strDelayed;
329 }
330
331 $str .= "</content>";
332 return $str;
333 }
334
335 // 2012-04-18 Checked/modified for compatibility with new data model
337 {
338 $src = $matches[3];
339 if($src <> "" && is_file($_SERVER["DOCUMENT_ROOT"].$src))
340 {
341 $dest = basename($src);
342 $uid = RandString(5);
343
344 $res_id = 1;
345 $this->arResources[$this->replacingResId][] = array("SRC"=>$src, "ID"=> $uid.".".$dest);
346 return stripslashes($matches[1].$matches[2]."cid:resources/res".$this->replacingResId."/".$uid.".".$dest.$matches[4].$matches[5]);
347 }
348 return stripslashes($matches[0]);
349 }
350
351 // 2012-04-18 Checked/modified for compatibility with new data model
352 function _ReplaceImages($text, $res_id)
353 {
354 $this->replacingResId = $res_id;
355 return preg_replace_callback("/(<.+?src\\s*=\\s*)([\"']?)(.*?)(\\2)(.*?>)/is", array($this, "_replace_img"), $text);
356 }
357
358 private function createQuestionItems($lessonId)
359 {
360 global $DB;
361
362 $strSql = "SELECT * FROM b_learn_question WHERE LESSON_ID=".$lessonId." ORDER BY SORT ASC ";
363 $q = $DB->Query($strSql);
364 while ($arQRes = $q->Fetch())
365 {
366 $r = ++$this->RefID;
367 $this->arItems[$r] = $this->CreateQTI($arQRes, $r);
368 $this->strItems .= '<item identifier="QUE'.$r.'" identifierref="RES'.$r.'"><title>'.htmlspecialcharsbx($arQRes["NAME"]).'</title></item>';
369 $this->strResourses .= '<resource identifier="RES'.$r.'" type="imsqti_xmlv1p1" href="res'.$r.'.xml">'.$this->_GetResourceFiles($r).'</resource>';
370 }
371 }
372
373 // 2012-04-18 Checked/modified for compatibility with new data model
374 function CreateQTI($arParams, $res_id = 1)
375 {
376 global $DB;
377
378 if ($this->LAST_ERROR <> '')
379 return false;
380
381 $str = "<"."?xml version=\"1.0\" encoding=\"".$this->charset."\"?".">\n";
382 $str .= "<questestinterop>";
383
384 $str .= '<item ident="QUE'.$res_id.'">';
385 $str .= '<presentation><material><mattext>'.htmlspecialcharsbx($arParams["NAME"]).'</mattext>';
386
387 if (intval($arParams["FILE_ID"]) > 0)
388 {
389 $arFile = CFile::GetFileArray($arParams["FILE_ID"]);
390 if ($arFile)
391 {
392 $name = $arFile["ID"].'.'.GetFileExtension($arFile["FILE_NAME"]);
393 $this->arResources[$res_id][] = Array("DB" => $arFile["ID"], "SRC"=>$arFile["SRC"], "ID"=>$name);
394
395 $str .= '<matimage imagtype="'.$arFile["CONTENT_TYPE"].'" width="'.$arFile["WIDTH"].'" height="'.$arFile["HEIGHT"].'" uri="dbresources/'.$name.'"></matimage>';
396 $str .= '<image_description>' . htmlspecialcharsbx($arFile['DESCRIPTION']) . '</image_description>';
397 }
398 }
399
400 $str .= "</material>";
401 switch ($arParams["QUESTION_TYPE"])
402 {
403 case "M":
404 $qType = 'Multiple';
405 break;
406 case "T":
407 $qType = 'Text';
408 break;
409 case "R":
410 $qType = 'Sort';
411 break;
412 default:
413 $qType = 'Single';
414 break;
415 }
416 $str .= '<response_lid ident="LID'.$res_id.'" rcardinality="'.$qType.'"><render_choice>';
417
418 $strSql =
419 "SELECT * FROM b_learn_answer WHERE QUESTION_ID = '".intval($arParams["ID"])."' ORDER BY SORT ASC ";
420 $res = $DB->Query($strSql);
421
422
423 $cond = "";
424 while ($arAnwer = $res->Fetch())
425 {
426 if ($arAnwer["CORRECT"] == "Y")
427 $cond .= '<varequal respident="LID'.$res_id.'">ANS'.$arAnwer["ID"].'</varequal>';
428 $str .= '<response_label ident="ANS'.$arAnwer["ID"].'"><material><mattext>'.htmlspecialcharsbx($arAnwer["ANSWER"]).'</mattext></material></response_label>';
429 }
430
431
432 $str .= "</render_choice></response_lid></presentation>";
433
434 $str .= "<resprocessing>";
435 $str .= "<respcondition><conditionvar>".$cond."</conditionvar><setvar>".$arParams["POINT"]."</setvar></respcondition>";
436 $str .= "</resprocessing>";
437
438 $str .= "<bitrix>";
439 $str .= "<description>";
440 if ($arParams["DESCRIPTION"] <> '')
441 {
442 $str .= "<![CDATA[".$this->_ReplaceImages($arParams["DESCRIPTION"], $res_id)."]]>";
443 }
444 $str .= "</description>";
445
446 $str .= "<description_type>".$arParams["DESCRIPTION_TYPE"]."</description_type>";
447 $str .= "<incorrect_message>" . htmlspecialcharsbx($arParams["INCORRECT_MESSAGE"]) . "</incorrect_message>";
448 $str .= "<self>".$arParams["SELF"]."</self>";
449 $str .= "<sort>".$arParams["SORT"]."</sort>";
450 $str .= "<active>".$arParams["ACTIVE"]."</active>";
451 $str .= "</bitrix>";
452
453 $str .= "</item></questestinterop>";
454
455 return $str;
456 }
457
458 function CreateTMK($arParams, $res_id = 1)
459 {
460 $str = "<"."?xml version=\"1.0\" encoding=\"".$this->charset."\"?".">\n"
461 . '<content type="TMK">'
462 . '<score>' . (int) $arParams['SCORE'] . '</score>'
463 . '<mark>' . htmlspecialcharsbx($arParams['MARK']) . '</mark>'
464 . '<description>' . htmlspecialcharsbx($arParams['DESCRIPTION']) . '</description>'
465 . '</content>';
466 return $str;
467 }
468}
$arParams
Определения access_dialog.php:21
$path
Определения access_edit.php:21
static GetByID($ID)
Определения course.php:307
static GetSite($COURSE_ID)
Определения course.php:323
Определения export.php:4
$strItems
Определения export.php:14
_ReplaceImages($text, $res_id)
Определения export.php:352
CreateTMK($arParams, $res_id=1)
Определения export.php:458
_CreateCourseToc()
Определения export.php:219
_replace_img($matches)
Определения export.php:336
$arSite
Определения export.php:10
_GetResourceFiles($res_id)
Определения export.php:270
$ID
Определения export.php:6
$LAST_ERROR
Определения export.php:8
$arDraftFields
Определения export.php:16
_GetCourseContent($parentLessonId, $DEPTH_LEVEL=1)
Определения export.php:177
$arCourse
Определения export.php:9
$arResources
Определения export.php:12
$RefID
Определения export.php:13
$arItems
Определения export.php:11
$arDate
Определения export.php:18
CreateQTI($arParams, $res_id=1)
Определения export.php:374
_CreateContent($TYPE, $arParams, $res_id)
Определения export.php:284
$strResourses
Определения export.php:15
CreateManifest()
Определения export.php:150
CreatePackage($PACKAGE_DIR)
Определения export.php:93
$arPicture
Определения export.php:17
$charset
Определения export.php:7
__construct($COURSE_ID)
Определения export.php:22
static IsPublishProhibited($in_lessonId, $in_contextCourseLessonId)
Определения clearnlesson.php:2218
static GetListOfImmediateChilds($lessonId, $arOrder=array(), $arFilter=array(), $arSelectFields=array(), $arNavParams=array())
Определения clearnlesson.php:1855
$str
Определения commerceml2.php:63
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$uid
Определения hot_keys_act.php:8
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
const SITE_CHARSET
Определения include.php:62
GetFileExtension($path)
Определения tools.php:2972
CheckDirPath($path)
Определения tools.php:2707
RewriteFile($abs_path, $strContent)
Определения tools.php:2895
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$name
Определения menu_edit.php:35
$arFiles
Определения options.php:60
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
$TYPE
Определения rss.php:27
if(!empty($sellerData)) $dest
Определения pdf.php:818
$val
Определения options.php:1793
$matches
Определения index.php:22
$arRes
Определения options.php:104
$rs
Определения action.php:82