Skip to content

Commit a7ccea2

Browse files
committed
Updates from 1.9.x
1 parent 0457b64 commit a7ccea2

File tree

5 files changed

+115
-31
lines changed

5 files changed

+115
-31
lines changed

main/newscorm/learnpath.class.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ public function delete($courseInfo = null, $id = null, $delete = 'keep')
11041104
*/
11051105
public function delete_children_items($id)
11061106
{
1107-
$course_id = api_get_course_int_id();
1107+
$course_id = $this->course_info['real_id'];
11081108
if ($this->debug > 0) {
11091109
error_log('New LP - In learnpath::delete_children_items(' . $id . ')', 0);
11101110
}
@@ -4534,7 +4534,7 @@ public function set_name($name = null)
45344534
$this->name = $name;
45354535
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
45364536
$lp_id = $this->get_id();
4537-
$course_id = api_get_course_int_id();
4537+
$course_id = $this->course_info['real_id'];
45384538
$sql = "UPDATE $lp_table SET
45394539
name = '" . Database::escape_string($this->name). "'
45404540
WHERE c_id = ".$course_id." AND id = '$lp_id'";
@@ -5983,18 +5983,39 @@ public function create_document($courseInfo, $content = '', $title = '', $extens
59835983
$tmp_filename = $filename . '_' . ++ $i;
59845984

59855985
$filename = $tmp_filename . '.'.$extension;
5986-
$content = stripslashes($content);
5987-
5988-
$content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content);
5986+
if ($extension == 'html') {
5987+
$content = stripslashes($content);
5988+
$content = str_replace(
5989+
api_get_path(WEB_COURSE_PATH),
5990+
api_get_path(REL_PATH).'courses/',
5991+
$content
5992+
);
59895993

5990-
// Change the path of mp3 to absolute.
5994+
// Change the path of mp3 to absolute.
59915995

5992-
// The first regexp deals with :// urls.
5993-
$content = preg_replace("|(flashvars=\"file=)([^:/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['path'] . '/document/', $content);
5994-
// The second regexp deals with audio/ urls.
5995-
$content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['path'] . '/document/$2/', $content);
5996-
// For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
5997-
$content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
5996+
// The first regexp deals with :// urls.
5997+
$content = preg_replace(
5998+
"|(flashvars=\"file=)([^:/]+)/|",
5999+
"$1".api_get_path(
6000+
REL_COURSE_PATH
6001+
).$courseInfo['path'].'/document/',
6002+
$content
6003+
);
6004+
// The second regexp deals with audio/ urls.
6005+
$content = preg_replace(
6006+
"|(flashvars=\"file=)([^/]+)/|",
6007+
"$1".api_get_path(
6008+
REL_COURSE_PATH
6009+
).$courseInfo['path'].'/document/$2/',
6010+
$content
6011+
);
6012+
// For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
6013+
$content = str_replace(
6014+
'</body>',
6015+
'<style type="text/css">body{}</style></body>',
6016+
$content
6017+
);
6018+
}
59986019

59996020
if (!file_exists($filepath . $filename)) {
60006021
if ($fp = @ fopen($filepath . $filename, 'w')) {

main/newscorm/scorm.class.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public function __construct($course_code = null, $resource_id = null, $user_id =
4141
if ($this->debug > 0) {
4242
error_log('New LP - scorm::scorm('.$course_code.','.$resource_id.','.$user_id.') - In scorm constructor', 0);
4343
}
44-
if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
45-
parent::__construct($course_code, $resource_id, $user_id);
46-
}
44+
45+
parent::__construct($course_code, $resource_id, $user_id);
4746
}
4847

4948
/**

main/webservices/client_soap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
// third party user id
7070
'original_user_id_value' => $random_user_id,
7171
'secret_key' => $secret_key,
72-
//Extra fields
72+
// Extra fields
7373
'extra' => array(
7474
array('field_name' => 'ruc', 'field_value' => '123'),
7575
array('field_name' => 'DNI', 'field_value' => '4200000')

main/webservices/lp.php

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function WSHelperVerifyKey($params)
110110
),
111111
'file_data' => array('name' => 'file', 'type' => 'xsd:string'),
112112
'filename' => array('name' => 'filename', 'type' => 'xsd:string'),
113+
'lp_name' => array('name' => 'lp_name', 'type' => 'xsd:string'),
113114
'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string'),
114115
)
115116
);
@@ -142,6 +143,8 @@ function WSImportLP($params)
142143
$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
143144
$sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
144145

146+
$lpName = $params['lp_name'];
147+
145148
$courseCode = CourseManager::get_course_id_from_original_id(
146149
$courseIdValue,
147150
$courseIdName
@@ -173,7 +176,7 @@ function WSImportLP($params)
173176
$maker = 'Scorm';
174177
$maxScore = ''; //$_REQUEST['use_max_score']
175178

176-
$oScorm = new scorm();
179+
$oScorm = new scorm($courseCode);
177180
$fileData = base64_decode($params['file_data']);
178181

179182
$uniqueFile = uniqid();
@@ -184,7 +187,7 @@ function WSImportLP($params)
184187

185188
$fileInfo = array(
186189
'tmp_name' => $filePath,
187-
'name' => $fileName
190+
'name' => $fileName,
188191
);
189192

190193
$manifest = $oScorm->import_package($fileInfo, '', $courseInfo);
@@ -203,7 +206,7 @@ function WSImportLP($params)
203206
$maxScore,
204207
$sessionId
205208
);
206-
209+
$oScorm->set_name($lpName);
207210
$oScorm->set_proximity($proximity, $courseId);
208211
$oScorm->set_maker($maker, $courseId);
209212
//$oScorm->set_jslib('scorm_api.php');
@@ -329,7 +332,7 @@ function WSGetLpList($params)
329332
foreach ($flatList as $id => $lp) {
330333
$result[] = array(
331334
'id' => $id,
332-
'name' => $lp['lp_name']
335+
'name' => $lp['lp_name'],
333336
);
334337
}
335338

@@ -399,14 +402,16 @@ function WSDeleteLp($params)
399402
);
400403

401404
$courseInfo = api_get_course_info($courseCode);
402-
//$courseId = $courseInfo['real_id'];
405+
$courseId = $courseInfo['real_id'];
403406

404407
if (empty($courseInfo)) {
405408
if ($debug) error_log("Course not found: $courseIdName : $courseIdValue");
406409
return 'Course not found';
407410
}
408411

409-
/*$sessionId = 0;
412+
$sessionId = 0;
413+
414+
/*
410415
if (!empty($sessionIdName) && !empty($sessionIdValue)) {
411416
$sessionId = SessionManager::get_session_id_from_original_id(
412417
$sessionIdValue,
@@ -424,7 +429,54 @@ function WSDeleteLp($params)
424429
$lp = new learnpath($courseInfo['code'], $lpId, null);
425430
if ($lp) {
426431
if ($debug) error_log("LP deleted $lpId");
432+
433+
$course_dir = $courseInfo['directory'] . '/document';
434+
$sys_course_path = api_get_path(SYS_COURSE_PATH);
435+
$base_work_dir = $sys_course_path . $course_dir;
436+
437+
$items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId);
438+
439+
if (!empty($items)) {
440+
/** @var $item learnpathItem */
441+
foreach ($items as $itemId) {
442+
$item = new learnpathItem($itemId, null, $courseId);
443+
444+
if ($item) {
445+
$documentId = $item->get_path();
446+
447+
if ($debug) error_log("lp item id found #$itemId");
448+
449+
$documentInfo = DocumentManager::get_document_data_by_id(
450+
$documentId,
451+
$courseInfo['code'],
452+
false,
453+
$sessionId
454+
);
455+
456+
if (!empty($documentInfo)) {
457+
if ($debug) {
458+
error_log("Document id deleted #$documentId");
459+
}
460+
DocumentManager::delete_document(
461+
$courseInfo,
462+
null,
463+
$base_work_dir,
464+
$sessionId,
465+
$documentId
466+
);
467+
} else {
468+
if ($debug) {
469+
error_log("No document found for id #$documentId");
470+
}
471+
}
472+
} else {
473+
if ($debug) error_log("Document not found #$itemId");
474+
}
475+
}
476+
}
477+
427478
$lp->delete($courseInfo, $lpId, 'remove');
479+
428480
return 1;
429481
}
430482

@@ -453,7 +505,7 @@ function WSDeleteLp($params)
453505
'SOAP-ENC:Array',
454506
array(),
455507
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:lpItem[]')),
456-
'tns:lpItemList'
508+
'tns:lpItem'
457509
);
458510

459511
$server->wsdl->addComplexType(

main/webservices/registration.soap.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,20 +2682,23 @@ function WSCreateCourse($params)
26822682
$title = $course_param['title'];
26832683
$category_code = isset($course_param['category_code']) ? $course_param['category_code'] : '';
26842684
$wanted_code = $course_param['wanted_code'];
2685-
$tutor_name = $course_param['tutor_name'];
2685+
$tutor_name = isset($course_param['tutor_name']) ? $course_param['tutor_name'] : '';
26862686
$course_language = 'english'; // TODO: A hard-coded value.
26872687
$original_course_id_name = $course_param['original_course_id_name'];
26882688
$original_course_id_value = $course_param['original_course_id_value'];
26892689
$orig_course_id_value[] = $course_param['original_course_id_value'];
26902690
$visibility = null;
26912691

2692-
if ($course_param['visibility'] &&
2693-
$course_param['visibility'] >= 0 &&
2694-
$course_param['visibility'] <= 3
2695-
) {
2696-
$visibility = $course_param['visibility'];
2692+
if (isset($course_param['visibility'])) {
2693+
if ($course_param['visibility'] &&
2694+
$course_param['visibility'] >= 0 &&
2695+
$course_param['visibility'] <= 3
2696+
) {
2697+
$visibility = $course_param['visibility'];
2698+
}
26972699
}
2698-
$extra_list = $course_param['extra'];
2700+
$extra_list = isset($course_param['extra']) ? $course_param['extra'] : '';
2701+
26992702

27002703
// Check whether exits $x_course_code into user_field_values table.
27012704
$courseInfo = CourseManager::getCourseInfoFromOriginalId(
@@ -2747,12 +2750,21 @@ function WSCreateCourse($params)
27472750
$values['course_language'] = api_get_setting('platformLanguage');
27482751
}
27492752

2750-
$values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastName'], null, null, $values['course_language']);
2753+
if (isset($_user['firstName'])) {
2754+
$values['tutor_name'] = api_get_person_name(
2755+
$_user['firstName'],
2756+
$_user['lastName'],
2757+
null,
2758+
null,
2759+
$values['course_language']
2760+
);
2761+
}
27512762

27522763
$params = array();
27532764
$params['title'] = $title;
27542765
$params['wanted_code'] = $wanted_code;
27552766
$params['category_code'] = $category_code;
2767+
$params['course_category'] = $category_code;
27562768
$params['tutor_name'] = $tutor_name;
27572769
$params['course_language'] = $course_language;
27582770
$params['user_id'] = api_get_user_id();

0 commit comments

Comments
 (0)