/** * @param array $params * @return int|string */ function WSDeleteLp($params) { global $debug; if (!WSHelperVerifyKey($params)) { return return_error(WS_ERROR_SECRET_KEY); } require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathItem.class.php'; $courseIdName = $params['course_id_name']; $courseIdValue = $params['course_id_value']; $lpId = $params['lp_id']; $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null; $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null; $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName); if (empty($courseInfo)) { if ($debug) { error_log("Course not found: {$courseIdName} : {$courseIdValue}"); } return 'Course not found'; } $courseId = $courseInfo['real_id']; $courseCode = $courseInfo['code']; $sessionId = 0; /* if (!empty($sessionIdName) && !empty($sessionIdValue)) { $sessionId = SessionManager::get_session_id_from_original_id( $sessionIdValue, $sessionIdName ); if (empty($sessionId)) { if ($debug) error_log('Session not found'); return 'Session not found'; } } */ $lp = new learnpath($courseCode, $lpId, null); if ($lp) { if ($debug) { error_log("LP deleted {$lpId}"); } $course_dir = $courseInfo['directory'] . '/document'; $sys_course_path = api_get_path(SYS_COURSE_PATH); $base_work_dir = $sys_course_path . $course_dir; $items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId); if (!empty($items)) { /** @var $item learnpathItem */ foreach ($items as $itemId) { $item = new learnpathItem($itemId, null, $courseId); if ($item) { $documentId = $item->get_path(); if ($debug) { error_log("lp item id found #{$itemId}"); } $documentInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId); if (!empty($documentInfo)) { if ($debug) { error_log("Document id deleted #{$documentId}"); } DocumentManager::delete_document($courseInfo, null, $base_work_dir, $sessionId, $documentId); } else { if ($debug) { error_log("No document found for id #{$documentId}"); } } } else { if ($debug) { error_log("Document not found #{$itemId}"); } } } } $lp->delete($courseInfo, $lpId, 'remove'); return 1; } return 0; }