diff --git a/src/RwthMoodleApiLib/Config.php b/src/RwthMoodleApiLib/Config.php index 27b12a11ac10f928eda9dab444786ccafd34f274..97d8d46eb2ed7302af9cd45d86e5f5eea0aabbfe 100644 --- a/src/RwthMoodleApiLib/Config.php +++ b/src/RwthMoodleApiLib/Config.php @@ -40,10 +40,9 @@ namespace RwthMoodleApiLib; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @link https://git.rwth-aachen.de/moodle/rwth_moodle_api **/ -namespace RwthMoodleApiLib; - class Config { + public static $debug_msgs = false; public static $moodle_url = "https://d-mo01.devlef.campus.rwth-aachen.de/moodlems/"; } ?> diff --git a/src/RwthMoodleApiLib/Controller/CourseRoom.php b/src/RwthMoodleApiLib/Controller/CourseRoom.php index 6381cfd1f03ceec879952377e1d616bad4db0cb9..2fa823746101061cdcf65daba22527a11d8776e0 100644 --- a/src/RwthMoodleApiLib/Controller/CourseRoom.php +++ b/src/RwthMoodleApiLib/Controller/CourseRoom.php @@ -79,7 +79,7 @@ class CourseRoom extends ApiController implements CourseRoomInterface $dataSet = array(); foreach ($courses as $course) { //TODO - $closed = !(((int)$course->enddate)===0 || ((int)$course->enddate)>time()); + /* $closed = !(((int)$course->enddate)===0 || ((int)$course->enddate)>time()); */ $uniqueid = $course->id; // "12ws-00000", $semester = "TODO"; // "ws12", diff --git a/src/RwthMoodleApiLib/Controller/WhatsNew.php b/src/RwthMoodleApiLib/Controller/WhatsNew.php index 4a890072f99bf23b6e3dc7fc14024d33987ced6c..e4570207606f69291e958f4f2a259403ec40eb58 100644 --- a/src/RwthMoodleApiLib/Controller/WhatsNew.php +++ b/src/RwthMoodleApiLib/Controller/WhatsNew.php @@ -93,7 +93,7 @@ class WhatsNew extends CourseRoom implements WhatsNewInterface $sharedDocuments = array(); $wikis = array(); foreach ($updates->instances as $update) { - print_r($update); + /* print_r($update); */ /* $params_mod = array("cmid"=>$update->id); */ /* print_r($params_mod); */ /* $module_raw = $this->getApi()->restCall('core_course_get_course_module', $params_mod); */ diff --git a/src/RwthMoodleApiLib/Exceptions/BadResponseException.php b/src/RwthMoodleApiLib/Exceptions/BadResponseException.php index 6064e31e88f350e9b6fa2c0bfca0e016b236cd54..5eadb8667d661b9a06845ca29d863bda20daa32a 100644 --- a/src/RwthMoodleApiLib/Exceptions/BadResponseException.php +++ b/src/RwthMoodleApiLib/Exceptions/BadResponseException.php @@ -50,12 +50,12 @@ class BadResponseException extends RequestException implements BadResponseExcept /** * Constructor * - * @param \GuzzleHttp\Exception\BadResponseException $gz Exception to wrap + * @param \GuzzleHttp\Exception\BadResponseException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\BadResponseException $gz) + public function __construct(\GuzzleHttp\Exception\BadResponseException $gzhttp) { - parent::__construct($gz); - $this->badResponseException = $gz; + parent::__construct($gzhttp); + $this->badResponseException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/ClientException.php b/src/RwthMoodleApiLib/Exceptions/ClientException.php index cbc14947da5de8b94d9ecd939e00a5f845398183..c49c4ef33cc63aa9aca9ce98f6f7225af86bf65a 100644 --- a/src/RwthMoodleApiLib/Exceptions/ClientException.php +++ b/src/RwthMoodleApiLib/Exceptions/ClientException.php @@ -50,12 +50,12 @@ class ClientException extends BadResponseException implements ClientExceptionInt /** * Constructor * - * @param \GuzzleHttp\Exception\ClientException $gz Exception to wrap + * @param \GuzzleHttp\Exception\ClientException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\ClientException $gz) + public function __construct(\GuzzleHttp\Exception\ClientException $gzhttp) { - parent::__construct($gz); - $this->clientException = $gz; + parent::__construct($gzhttp); + $this->clientException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/HttpException.php b/src/RwthMoodleApiLib/Exceptions/HttpException.php index 0ce0f87df9ff05379f334776a542e9d08232b313..24540779469d97f470c8996a8b2f38a6518eab0a 100644 --- a/src/RwthMoodleApiLib/Exceptions/HttpException.php +++ b/src/RwthMoodleApiLib/Exceptions/HttpException.php @@ -50,12 +50,12 @@ class HttpException extends RwthMoodleApiLibException implements HttpExceptionIn /** * Constructor * - * @param \GuzzleHttp\Exception\TransferException $gz exception to wrap + * @param \GuzzleHttp\Exception\TransferException $gzhttp exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\TransferException $gz) + public function __construct(\GuzzleHttp\Exception\TransferException $gzhttp) { - parent::__construct($gz); - $this->httpException = $gz; + parent::__construct($gzhttp); + $this->httpException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Exceptions/MoodleException.php b/src/RwthMoodleApiLib/Exceptions/MoodleException.php index e0f6fc444a30cfea6469c20e5e78bc554153b321..31e4a3ed50ff428eae3a3e2b3a227dd24d27fd9c 100644 --- a/src/RwthMoodleApiLib/Exceptions/MoodleException.php +++ b/src/RwthMoodleApiLib/Exceptions/MoodleException.php @@ -105,6 +105,11 @@ class MoodleException extends MoodleResponseException implements MoodleException return $this->moodleMessage; } + /** + * Returns the error message as a string + * + * @return string error message + **/ public function __toString() : string { diff --git a/src/RwthMoodleApiLib/Exceptions/RequestException.php b/src/RwthMoodleApiLib/Exceptions/RequestException.php index 7603b3e4c01f1dd7f98057f1ecc0854b6046b574..a8c50636c21c974b797c40e1d732c3806a0ea5c8 100644 --- a/src/RwthMoodleApiLib/Exceptions/RequestException.php +++ b/src/RwthMoodleApiLib/Exceptions/RequestException.php @@ -53,12 +53,12 @@ class RequestException extends HttpException implements RequestExceptionInterfac /** * Constructor * - * @param \GuzzleHttp\Exception\RequestInterface $gz RequestException to wrap + * @param \GuzzleHttp\Exception\RequestInterface $gzhttp RequestException to wrap **/ - public function __construct(\GuzzleHttp\Exception\RequestException $gz) + public function __construct(\GuzzleHttp\Exception\RequestException $gzhttp) { - parent::__construct($gz); - $this->requestException = $gz; + parent::__construct($gzhttp); + $this->requestException = $gzhttp; } /** diff --git a/src/RwthMoodleApiLib/Exceptions/ServerException.php b/src/RwthMoodleApiLib/Exceptions/ServerException.php index 4065b79ca5469dd906288fdfbd547c8b755e0ec4..c56474f664750b980db8049ac9bb19d2de4fd08e 100644 --- a/src/RwthMoodleApiLib/Exceptions/ServerException.php +++ b/src/RwthMoodleApiLib/Exceptions/ServerException.php @@ -50,12 +50,12 @@ class ServerException extends BadResponseException implements BadResponseExcepti /** * Constructor * - * @param \GuzzleHttp\Exception\ServerException $gz Exception to wrap + * @param \GuzzleHttp\Exception\ServerException $gzhttp Exception to wrap **/ - public function __construct(\GuzzleHttp\Exception\ServerException $gz) + public function __construct(\GuzzleHttp\Exception\ServerException $gzhttp) { - parent::__construct($gz); - $this->serverException = $gz; + parent::__construct($gzhttp); + $this->serverException = $gzhttp; } } diff --git a/src/RwthMoodleApiLib/Injector/Injector.php b/src/RwthMoodleApiLib/Injector/Injector.php index 0eb86542c582c755736d79ac9bfd9d5e2e44b1db..974b4402acf22811a1c467becf52099b2192c6b3 100644 --- a/src/RwthMoodleApiLib/Injector/Injector.php +++ b/src/RwthMoodleApiLib/Injector/Injector.php @@ -55,15 +55,17 @@ class Injector implements InjectorInterface /** * Constructor + * + * @param string $url The url to moodle **/ - public function __construct($url=Null) + public function __construct($url=null) { //observers - $informationalObserver = new Logging\ConsoleLogger(6); + $infoObserver = new Logging\ConsoleLogger(6); $warningObserver = new Logging\ConsoleLogger(4); $criticalObserver = new Logging\ConsoleLogger(2); $this->observers = array( - "informational" => $informationalObserver, + "informational" => $infoObserver, "warning" => $warningObserver, "critical" => $criticalObserver ); diff --git a/src/RwthMoodleApiLib/RwthMoodleApiLib.php b/src/RwthMoodleApiLib/RwthMoodleApiLib.php index 42daedbcc05a0b57eeac5b0be6a2732317b99cc1..3a326b1e8686f4a6b4b058c83c51a48532d041d3 100644 --- a/src/RwthMoodleApiLib/RwthMoodleApiLib.php +++ b/src/RwthMoodleApiLib/RwthMoodleApiLib.php @@ -99,10 +99,9 @@ class RwthMoodleApiLib implements RwthMoodleApiLibInterface throw new Exceptions\MoodleError($login->error, $login->errorcode, $response); } else if (empty($login->token) && empty($login->privatetoken)) { return false; - } else { - $this->moodleToken = $login->token??$login->privatetoken; - return true; } + $this->moodleToken = $login->token??$login->privatetoken; + return true; } /** @@ -128,13 +127,15 @@ class RwthMoodleApiLib implements RwthMoodleApiLibInterface } else if (!empty($login->exception)) { throw new Exceptions\MoodleException($login->exception, $login->errorcode, $login->message, $response); } else if (!empty($login->error)) { + if (Config::$debug_msgs) { + print_r($login); + } throw new Exceptions\MoodleError($login->error, $login->errorcode, $response); } else if (empty($login->token) && empty($login->privatetoken)) { return false; - } else { - $this->moodleToken = $login->token??$login->privatetoken; - return true; } + $this->moodleToken = $login->token??$login->privatetoken; + return true; } /** diff --git a/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php b/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php index fe3d0f52360aabca92aee1ce48da6b92fe12198e..a2330ba827e97db24533825ddd2899f469e8f33f 100644 --- a/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php +++ b/tests/RwthMoodleApiLib/Controller/AnnouncementTest.php @@ -70,15 +70,15 @@ final class AnnouncementTest extends TestCase } /** - * Test case for viewAllCourseInfo + * Test case for viewAllAnnouncements * - * @covers RwthMoodleApiLib\Controller\Announcement::viewAllCourseInfo() + * @covers RwthMoodleApiLib\Controller\Announcement::viewAllAnnouncements() * * @return none **/ - public function testViewAllCourseInfo() + public function testViewAllAnnouncements() { - $announcement = $this->announcement->viewAllAnnouncements(3); + $announcement = $this->announcement->viewAllAnnouncements(2); $this->assertTrue(true); } diff --git a/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php b/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php index 2b937a3dd74363c065b6823bae36ca5d6c7cf136..0e0ba1a99bef9d7a847f3bfbd91b58429222ce9a 100644 --- a/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php +++ b/tests/RwthMoodleApiLib/Controller/WhatsNewTest.php @@ -78,7 +78,7 @@ final class WhatsNewTest extends TestCase **/ public function testWhatsNewSince() { - $this->whatsNew->whatsNewSince(3, 99999); + $this->whatsNew->whatsNewSince(2, 99999); $this->assertTrue(true); }