diff options
| author | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
|---|---|---|
| committer | Philipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de> | 2024-09-24 10:53:31 +0200 |
| commit | 4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch) | |
| tree | 5c07151ae61276d334e88f6309c30d439a85c12e /lib/elearning/LonCapaConnectedCMS.php | |
| parent | da0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff) | |
| parent | 97a188592c679890a25c37ab78463add76a52ff7 (diff) | |
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/elearning/LonCapaConnectedCMS.php')
| -rw-r--r-- | lib/elearning/LonCapaConnectedCMS.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/elearning/LonCapaConnectedCMS.php b/lib/elearning/LonCapaConnectedCMS.php new file mode 100644 index 0000000..2f86aa8 --- /dev/null +++ b/lib/elearning/LonCapaConnectedCMS.php @@ -0,0 +1,67 @@ +<?php +/** + * main-class for connection to LonCapa + * + * This class contains the main methods of the elearning-interface to connect to + * LonCapa. Extends ConnectedCMS. + * + * @access public + * @modulegroup elearning_interface_modules + * @module LonCapaConnectedCMS + * @package ELearning-Interface + */ +class LonCapaConnectedCMS extends ConnectedCMS +{ + public $user; + protected $seminarId; + protected $lcRequest; + protected $cmsUrl; + + public function __construct($cms = '') + { + parent::__construct($cms); + + $this->seminarId = Context::getId(); + $this->user = User::findCurrent(); + $this->lcRequest = new LonCapaRequest(); + $this->cmsUrl = $this->ABSOLUTE_PATH_ELEARNINGMODULES; + } + + + /** + * search for content modules + * + * returns found content modules + * @throws AccessDeniedException + * @param string $key keyword + * @return array list of content modules + */ + public function searchContentModules($key) + { + + if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->seminarId)) { + throw new AccessDeniedException(); + } + + $url = $this->cmsUrl . '/courses?search=' . urlencode($key) . '&owner=' . urlencode($this->user->username); + $response = $this->lcRequest->request($url); + + if ($response) { + $courses = new SimpleXMLElement($response); + + $result = []; + foreach ($courses->course as $course) { + $temp = explode(':', (string)$course->owner); + + $result[] = [ + 'ref_id' => (string)$course->id, + 'title' => (string)$course->description, + 'authors' => $temp[0], + 'type' => $this->cms_type + ]; + } + } + + return $result; + } +} |
