1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
scorm.php
См. документацию.
1<?
2
3// 2012-04-20 Checked/modified for compatibility with new data model
5{
7 var $LAST_ERROR = "";
8 var $arManifest = Array();
9 var $arSITE_ID = Array();
10 var $COURSE_ID = 0;
12 var $arDraftFields = Array("detail_text", "preview_text", "description");
13 var $arUnsetFields = Array("id", "timestamp_x", "chapter_id", "course_id", "lesson_id", "question_id", "created_by");
14 var $arPicture = Array("detail_picture", "preview_picture", "file_id");
15 var $arDate = Array("active_from", "active_to", "date_create");
16 var $arWarnings = Array();
18
19
20 // 2012-04-19 Checked/modified for compatibility with new data model
21 public function __construct($PACKAGE_DIR, $arSITE_ID)
22 {
23 //Cut last slash
24 if (mb_substr($PACKAGE_DIR, -1, 1) == "/")
25 $PACKAGE_DIR = mb_substr($PACKAGE_DIR, 0, -1);
26
27 $this->package_dir = $_SERVER["DOCUMENT_ROOT"].$PACKAGE_DIR;
28
29 //Dir exists?
30 if (!is_dir($this->package_dir))
31 {
32 $this->LAST_ERROR = GetMessage("LEARNING_BAD_PACKAGE")."<br>";
33 return;
34 }
35
36 //Manifest exists?
37 if (!is_file($this->package_dir."/imsmanifest.xml"))
38 {
39 $this->LAST_ERROR = GetMessage("LEARNING_MANIFEST_NOT_FOUND")."<br>";
40 return;
41 }
42
43 //Sites check
44 if (!is_array($arSITE_ID) || empty($arSITE_ID))
45 {
46 $this->LAST_ERROR = GetMessage("LEARNING_BAD_SITE_ID")."<br>";
47 return;
48 }
49
50 $this->arSITE_ID = $arSITE_ID;
51
52 $this->objXML = new CDataXML();
53 if (!$this->objXML->Load($this->package_dir."/imsmanifest.xml"))
54 {
55 $this->LAST_ERROR = GetMessage("LEARNING_MANIFEST_NOT_FOUND")."<br>";
56 return;
57 }
58 }
59
60
61 // 2012-04-19 Checked/modified for compatibility with new data model
62 protected function CreateCourse()
63 {
64 global $APPLICATION;
65
66 if ($this->LAST_ERROR <> '')
67 return false;
68
69 if (!$title = $this->objXML->SelectNodes("/manifest/organizations/organization/title"))
70 {
71 $this->LAST_ERROR = GetMessage("LEARNING_BAD_NAME");
72 return false;
73 }
74
75 $arFields = Array(
76 "NAME" => $title->content,
77 "SITE_ID" => $this->arSITE_ID,
78 "SCORM" => "Y",
79 );
80
81 $course = new CCourse;
82 $this->COURSE_ID = $course->Add($arFields);
83
84 if ($this->COURSE_ID === false)
85 {
86 if($err = $APPLICATION->GetException())
87 $this->LAST_ERROR = $err->GetString();
88 return false;
89 }
90
91 return true;
92 }
93
94
95 // 2012-04-19 Checked/modified for compatibility with new data model
96 protected function CreateContent($arItems = array(), $PARENT_ID = 0)
97 {
98 if ($this->LAST_ERROR <> '')
99 return false;
100
101 if (empty($arItems))
102 {
103 if ($items = $this->objXML->SelectNodes("/manifest/organizations/organization/"))
104 {
105 $arItems = $items->__toArray();
106 $arItems = $arItems["#"]["item"];
107 }
108 }
109
110 foreach ($arItems as $ar)
111 {
112 $title = $ar["#"]["title"][0]["#"];
113 $type = (!is_set($ar["#"], "item") && is_set($ar["@"], "identifierref")) ? "LES" : "CHA";
114 $launch = "";
115 if ($type == "LES")
116 {
117 foreach($this->arResources as $res)
118 {
119 if ($res["@"]["identifier"] == $ar["@"]["identifierref"])
120 {
121 $launch = "/".(COption::GetOptionString("main", "upload_dir", "upload"))."/learning/scorm/".$this->COURSE_ID."/";
122 $launch .= $res["@"]["href"];
123 if(is_set($ar["@"]["parameters"]))
124 {
125 $launch .= $ar["@"]["parameters"];
126 }
127 }
128 }
129
130 }
131
132 $ID = $this->_MakeItems($title, $type, $launch, $PARENT_ID);
133
134 if (is_set($ar["#"], "item"))
135 $this->CreateContent($ar["#"]["item"], $ID);
136 }
137 }
138
139
140 // 2012-04-20 Checked/modified for compatibility with new data model
141 protected function _MakeItems($TITLE, $TYPE, $LAUNCH, $PARENT_ID)
142 {
143 global $APPLICATION;
144
145 if ($PARENT_ID === 0)
146 {
147 $linkToParentLessonId = CCourse::CourseGetLinkedLesson ($this->COURSE_ID);
148 }
149 else
150 {
151 $linkToParentLessonId = (int) $PARENT_ID;
152 }
153
154 if ($TYPE == "LES")
155 {
156 $arFields = Array(
157 'NAME' => $TITLE,
158 'LAUNCH' => $LAUNCH,
159 'DETAIL_TEXT_TYPE' => "file"
160 );
161 }
162 elseif ($TYPE == "CHA")
163 {
164 $arFields = Array(
165 'NAME' => $TITLE
166 );
167 }
168 else
169 {
170 return $PARENT_ID;
171 }
172
173 // properties (in context of parent) by default
174 $arProperties = array('SORT' => 500);
175
177 $arFields,
178 false, // is it course? - No, it isn't.
179 $linkToParentLessonId,
181
182 if ($ID > 0)
183 return $ID;
184 else
185 {
186 if($e = $APPLICATION->GetException())
187 $this->arWarnings[$TYPE][] = Array("TITLE" => $TITLE, "TEXT" =>$e->GetString());
188 }
189 }
190
191
192 // 2012-04-19 Checked/modified for compatibility with new data model
193 public function ImportPackage()
194 {
195 $resources = $this->objXML->SelectNodes("/manifest/resources/");
196 $this->arResources = $resources->__toArray();
197 $this->arResources = $this->arResources["#"]["resource"];
198
199 if (!$this->CreateCourse())
200 return false;
201
202 $this->CreateContent();
203
205 $this->package_dir,
206 $_SERVER["DOCUMENT_ROOT"]."/".(COption::GetOptionString("main", "upload_dir", "upload"))."/learning/scorm/".$this->COURSE_ID,
207 true,
208 true);
209
210 return true;
211 }
212}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
Определения course.php:4
static CourseGetLinkedLesson($courseId)
Определения course.php:55
Add($arFields)
Определения course.php:136
Определения scorm.php:5
CreateCourse()
Определения scorm.php:62
$objXML
Определения scorm.php:11
ImportPackage()
Определения scorm.php:193
$arManifest
Определения scorm.php:8
$arUnsetFields
Определения scorm.php:13
$arWarnings
Определения scorm.php:16
$arSITE_ID
Определения scorm.php:9
$LAST_ERROR
Определения scorm.php:7
$COURSE_ID
Определения scorm.php:10
$arDraftFields
Определения scorm.php:12
CreateContent($arItems=array(), $PARENT_ID=0)
Определения scorm.php:96
$package_dir
Определения scorm.php:6
__construct($PACKAGE_DIR, $arSITE_ID)
Определения scorm.php:21
$arResources
Определения scorm.php:17
$arDate
Определения scorm.php:15
$arPicture
Определения scorm.php:14
_MakeItems($TITLE, $TYPE, $LAUNCH, $PARENT_ID)
Определения scorm.php:141
Определения xml.php:396
static CopyDirFiles($path_from, $path_to, $ReWrite=True, $Recursive=False)
Определения clearnhelper.php:432
static Add($arFields, $isCourse=false, $parentLessonId=true, $arProperties=array('SORT'=> 500), $isCheckPermissions=true, $checkPermissionsForUserId=-1)
Определения clearnlesson.php:440
$arFields
Определения dblapprove.php:5
</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
if($ajaxMode) $ID
Определения get_user.php:27
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$TITLE
Определения menu_edit.php:223
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$TYPE
Определения rss.php:27
$items
Определения template.php:224
$title
Определения pdf.php:123
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644