PHP Client

Please download latest version of PHP client for Loorex API v1.5.

Access token can be created at API keys page of your profile.

Please refer to individual method pages to get explanation of all supported fields.

Exam example

	require_once 'loorex_api_base.php';
	require_once 'loorex_api_exam.php';

	$client = new LoorexApiExam($AccessToken);

	// Create new exam
	$params = [
		'title'		=> 'Using Loorex Software',
		'category'	=> 'Loorex',
		'code'		=> 'LR-001',
	];
	$ExamId = $client->examCreate($params);

	// Update exam
	$params['id']	= $ExamId;
	$params['title']= 'Using Loorex Software Updated';
	$bool = $client->examUpdate($params);

	// Create new question
	$params = [
		'question'	=> [
			'exam_id'		=> $ExamId,
			'question'		=> '<img src="/img/image-main.jpg"><br> Which files types are supported by import wizard? (Choose all that apply)',
			'type'			=> _LOOREX_QT_MULTISELECT,
		],
		'answers'	=> [
			[
				'answer'		=> 'DOCX',
				'is_correct'	=> false,
			],
			[
				'answer'		=> 'PDF',
				'is_correct'	=> true,
			],
			[
				'answer'		=> 'TXT',
				'is_correct'	=> true,
			],
			[
				'answer'		=> 'XPS',
				'is_correct'	=> true,
			],
			[
				'answer'		=> 'XLS',
				'is_correct'	=> false,
			],
			[
				'answer'		=> 'VCS',
				'is_correct'	=> false,
			]
		]
	];

	// Add /img/image-main.jpg image content to request $params['resources']['/img/image-main.jpg']
	if (!$client->loadMediaFile($params, '/img/image-main.jpg', 'https://loorex.com/img/og-image-main.jpg')) {
		// Resource was not loaded, do required action
	}
	$QuestionId = $client->questionCreate($params);

	// Get extended response
	$extResponse= $client->getExtendedResponse();

	// Print errors if any
	if ($client->getIsErrors()) {
		print_r($client->getErrors());
	}

	// Update question
	// It is not necessary to send resources in update request if new media resources was not introduced
	// However, please be aware that Loorex changes relative URLs of uploaded media files
	unset($params['resources']);
	$params['question']['id']		= $QuestionId;
	$params['question']['question']	= $extResponse['question']['question'] . '<br>UPDATED';
	$bool = $client->questionUpdate($params);
	if ($client->getIsErrors()) {
		print_r($client->getErrors());
	}

	// Get exam list
	$examIds = $client->examList();
	if (is_array($examIds)) {
		foreach ($examIds as $examValue) {
			$ExamId = $examValue['id'];

			// Get exam information
			$ExamInfo = $client->examGet($ExamId);

			// May have not full access to exam
			if ($ExamInfo && !$client->getIsErrors()) {
				print_r($ExamInfo);

				// Get question list
				$QuestionList = $client->questionList($ExamId);
				if (is_array($QuestionList)) {
					foreach ($QuestionList as $questionValue) {
						$QuestionId = $questionValue['id'];

						// Get question information
						$QuestionInfo = $client->questionGet($ExamId, $QuestionId);
						print_r($QuestionInfo);
					}
				}
			}
		}
	}

	// Delete exam
	$client->examDelete($ExamId);

Course example

	require_once 'loorex_api_base.php';
	require_once 'loorex_api_course.php';

	$client = new LoorexApiCourse($AccessToken);

	// Create new course
	$params = [
		'course'	=> [
			'title'			=> 'Using Loorex Software',
			'category'		=> 'Loorex',
			'code'			=> 'LRC-001',
			'description'	=> 'Using Loorex Software'
		],
	];
	$CourseId = $client->courseCreate($params);

	// Update course
	$params['course']['id']	= $CourseId;
	$params['course']['title']	= 'Using Loorex Software Updated';
	$bool = $client->courseUpdate($params);

	// Create new learning page (empty page is created first, then populated)
	$params = [
		'page'	=> [
			'course_id'		=> $CourseId,
			'name'			=> 'Intro',
			'description'	=> 'Welcome to the course.',
		],
	];
	$PageId = $client->pageCreate($params);

	// Update learning page
	$params = [
		'page'	=> [
			'id'			=> $PageId,
			'course_id'		=> $CourseId,
			'name'			=> 'Introduction',
			'description'	=> '<img src="/img/image-main.jpg"><br> Welcome to the course.',
		],
	];

	// Add /img/image-main.jpg image content to request $params['resources']['/img/image-main.jpg']
	if (!$client->loadMediaFile($params, '/img/image-main.jpg', 'https://loorex.com/img/og-image-main.jpg')) {
		// Resource was not loaded, do required action
	}
	$bool = $client->pageUpdate($params);

	// Print errors if any
	if ($client->getIsErrors()) {
		print_r($client->getErrors());
	}

	// Move the page to the first position (provide either "position" or "direction", not both)
	$NewOrder = $client->pageChangeOrder($CourseId, $PageId, null, 1);

	// Mark course as ready
	$client->courseUpdateStatus($CourseId, true);

	// Get course list
	$courseIds = $client->courseList();
	if (is_array($courseIds)) {
		foreach ($courseIds as $courseValue) {
			$CourseId = $courseValue['id'];

			// Get course information
			$CourseInfo = $client->courseGet($CourseId);

			// May have not full access to course
			if ($CourseInfo && !$client->getIsErrors()) {
				print_r($CourseInfo);

				// Get page list
				$PageList = $client->pageList($CourseId);
				if (is_array($PageList)) {
					foreach ($PageList as $pageValue) {
						$PageId = $pageValue['id'];

						// Get page information
						$PageInfo = $client->pageGet($CourseId, $PageId);
						print_r($PageInfo);
					}
				}
			}
		}
	}

	// Delete course
	$client->courseDelete($CourseId);