@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use Symfony\Component\Dotenv\Dotenv; |
| 6 | 6 | use Symfony\Component\HttpFoundation\Request; |
| 7 | 7 | |
| 8 | -require __DIR__.'/../vendor/autoload.php'; |
|
| 8 | +require __DIR__ . '/../vendor/autoload.php'; |
|
| 9 | 9 | |
| 10 | 10 | session_start(); |
| 11 | 11 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | if (!class_exists(Dotenv::class)) { |
| 15 | 15 | throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.'); |
| 16 | 16 | } |
| 17 | - (new Dotenv())->load(__DIR__.'/../.env'); |
|
| 17 | + (new Dotenv())->load(__DIR__ . '/../.env'); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) { |
@@ -16,17 +16,17 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function getCacheDir() |
| 18 | 18 | { |
| 19 | - return $this->getProjectDir().'/var/cache/'.$this->environment; |
|
| 19 | + return $this->getProjectDir() . '/var/cache/' . $this->environment; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function getLogDir() |
| 23 | 23 | { |
| 24 | - return $this->getProjectDir().'/var/log'; |
|
| 24 | + return $this->getProjectDir() . '/var/log'; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function registerBundles() |
| 28 | 28 | { |
| 29 | - $contents = require $this->getProjectDir().'/config/bundles.php'; |
|
| 29 | + $contents = require $this->getProjectDir() . '/config/bundles.php'; |
|
| 30 | 30 | foreach ($contents as $class => $envs) { |
| 31 | 31 | if (isset($envs['all']) || isset($envs[$this->environment])) { |
| 32 | 32 | yield new $class(); |
@@ -38,24 +38,24 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $container->setParameter('container.autowiring.strict_mode', true); |
| 40 | 40 | $container->setParameter('container.dumper.inline_class_loader', true); |
| 41 | - $confDir = $this->getProjectDir().'/config'; |
|
| 42 | - $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); |
|
| 43 | - if (is_dir($confDir.'/packages/'.$this->environment)) { |
|
| 44 | - $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
|
| 41 | + $confDir = $this->getProjectDir() . '/config'; |
|
| 42 | + $loader->load($confDir . '/packages/*' . self::CONFIG_EXTS, 'glob'); |
|
| 43 | + if (is_dir($confDir . '/packages/' . $this->environment)) { |
|
| 44 | + $loader->load($confDir . '/packages/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); |
|
| 45 | 45 | } |
| 46 | - $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); |
|
| 47 | - $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
|
| 46 | + $loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob'); |
|
| 47 | + $loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | protected function configureRoutes(RouteCollectionBuilder $routes) |
| 51 | 51 | { |
| 52 | - $confDir = $this->getProjectDir().'/config'; |
|
| 53 | - if (is_dir($confDir.'/routes/')) { |
|
| 54 | - $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob'); |
|
| 52 | + $confDir = $this->getProjectDir() . '/config'; |
|
| 53 | + if (is_dir($confDir . '/routes/')) { |
|
| 54 | + $routes->import($confDir . '/routes/*' . self::CONFIG_EXTS, '/', 'glob'); |
|
| 55 | 55 | } |
| 56 | - if (is_dir($confDir.'/routes/'.$this->environment)) { |
|
| 57 | - $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
|
| 56 | + if (is_dir($confDir . '/routes/' . $this->environment)) { |
|
| 57 | + $routes->import($confDir . '/routes/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); |
|
| 58 | 58 | } |
| 59 | - $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); |
|
| 59 | + $routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob'); |
|
| 60 | 60 | } |
| 61 | 61 | } |
@@ -83,10 +83,10 @@ |
||
| 83 | 83 | */ |
| 84 | 84 | public function languagesAvailable() |
| 85 | 85 | { |
| 86 | - $languages = []; |
|
| 87 | - foreach ($this->container->getParameter('dictionaries') as $languageId => $dictionary) { |
|
| 88 | - $languages += [ $dictionary['self_name'] => $languageId ]; |
|
| 89 | - } |
|
| 86 | + $languages = []; |
|
| 87 | + foreach ($this->container->getParameter('dictionaries') as $languageId => $dictionary) { |
|
| 88 | + $languages += [ $dictionary['self_name'] => $languageId ]; |
|
| 89 | + } |
|
| 90 | 90 | return $languages; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | { |
| 86 | 86 | $languages = []; |
| 87 | 87 | foreach ($this->container->getParameter('dictionaries') as $languageId => $dictionary) { |
| 88 | - $languages += [ $dictionary['self_name'] => $languageId ]; |
|
| 88 | + $languages += [$dictionary['self_name'] => $languageId]; |
|
| 89 | 89 | } |
| 90 | 90 | return $languages; |
| 91 | 91 | } |
@@ -43,6 +43,6 @@ |
||
| 43 | 43 | |
| 44 | 44 | public static function getSubscribedEvents() |
| 45 | 45 | { |
| 46 | - return [ KernelEvents::CONTROLLER => 'onKernelController' ]; |
|
| 46 | + return [KernelEvents::CONTROLLER => 'onKernelController']; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -36,17 +36,21 @@ |
||
| 36 | 36 | if ($controller[0] instanceof AdminAuthenticatedInterface) { |
| 37 | 37 | $isAdmin = false; |
| 38 | 38 | if (isset($_SESSION['phpCAS']['user'])) { |
| 39 | - if (in_array($_SESSION['phpCAS']['user'], $this->administrators)) |
|
| 40 | - $isAdmin = true; |
|
| 39 | + if (in_array($_SESSION['phpCAS']['user'], $this->administrators)) { |
|
| 40 | + $isAdmin = true; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + if (!$isAdmin) { |
|
| 44 | + throw new AccessDeniedHttpException('Access forbidden.'); |
|
| 41 | 45 | } |
| 42 | - if (!$isAdmin) throw new AccessDeniedHttpException('Access forbidden.'); |
|
| 43 | 46 | } |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | public function onKernelRequest(GetResponseEvent $event) |
| 47 | 50 | { |
| 48 | - if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) |
|
| 49 | - return; |
|
| 51 | + if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | |
@@ -58,6 +58,6 @@ |
||
| 58 | 58 | |
| 59 | 59 | public static function getSubscribedEvents() |
| 60 | 60 | { |
| 61 | - return [ KernelEvents::REQUEST => [['onKernelRequest', 200]] ]; |
|
| 61 | + return [KernelEvents::REQUEST => [['onKernelRequest', 200]]]; |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | \ No newline at end of file |
@@ -33,8 +33,9 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | public function onKernelRequest(GetResponseEvent $event) |
| 35 | 35 | { |
| 36 | - if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) |
|
| 37 | - return; |
|
| 36 | + if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | $this->registerLDAP(); |
| 40 | 41 | $this->registerCapsule(); |
@@ -41,8 +41,8 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public static function generateJwt() |
| 43 | 43 | { |
| 44 | - $_SESSION['JWT'] = json_decode( self::$http->request('POST', 'api/auth/login', [ |
|
| 45 | - 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' ], |
|
| 44 | + $_SESSION['JWT'] = json_decode(self::$http->request('POST', 'api/auth/login', [ |
|
| 45 | + 'headers' => ['X-Requested-With' => 'XMLHttpRequest'], |
|
| 46 | 46 | 'json' => [ |
| 47 | 47 | 'username' => env('API_USERNAME'), |
| 48 | 48 | 'password' => env('API_PASSWORD') |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 14 | 14 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 15 | 15 | |
| 16 | - abstract class AbstractController extends Controller |
|
| 16 | + abstract class AbstractController extends Controller |
|
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | $container->set('http', self::$http); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Creates and return a JSON Web Token through the OpenLRW API by using credentials filled in .env |
|
| 38 | - * |
|
| 39 | - * @return mixed|\Psr\Http\Message\ResponseInterface |
|
| 40 | - * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 41 | - */ |
|
| 36 | + /** |
|
| 37 | + * Creates and return a JSON Web Token through the OpenLRW API by using credentials filled in .env |
|
| 38 | + * |
|
| 39 | + * @return mixed|\Psr\Http\Message\ResponseInterface |
|
| 40 | + * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 41 | + */ |
|
| 42 | 42 | public static function generateJwt() |
| 43 | 43 | { |
| 44 | 44 | $_SESSION['JWT'] = json_decode( self::$http->request('POST', 'api/auth/login', [ |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | 'password' => env('API_PASSWORD') |
| 49 | 49 | ] |
| 50 | 50 | ])->getBody() |
| 51 | - ->getContents())->token; |
|
| 51 | + ->getContents())->token; |
|
| 52 | 52 | |
| 53 | 53 | return $_SESSION['JWT']; |
| 54 | 54 | |
@@ -124,26 +124,26 @@ discard block |
||
| 124 | 124 | return ldap_get_entries($this->__get('ldap'), $this->searchLDAP($filter, $arg))[0]; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Function to check if OpenLRW is up |
|
| 129 | - * |
|
| 130 | - * @return boolean |
|
| 131 | - * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 132 | - */ |
|
| 133 | - public static function isUp() |
|
| 134 | - { |
|
| 135 | - return self::$http->request('GET', '/info.json')->getStatusCode() == 200; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Get the logged username |
|
| 140 | - * |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public static function loggedUser() |
|
| 144 | - { |
|
| 145 | - return $_SESSION['phpCAS']['user']; |
|
| 146 | - } |
|
| 127 | + /** |
|
| 128 | + * Function to check if OpenLRW is up |
|
| 129 | + * |
|
| 130 | + * @return boolean |
|
| 131 | + * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 132 | + */ |
|
| 133 | + public static function isUp() |
|
| 134 | + { |
|
| 135 | + return self::$http->request('GET', '/info.json')->getStatusCode() == 200; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Get the logged username |
|
| 140 | + * |
|
| 141 | + * @return mixed |
|
| 142 | + */ |
|
| 143 | + public static function loggedUser() |
|
| 144 | + { |
|
| 145 | + return $_SESSION['phpCAS']['user']; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | \ No newline at end of file |
@@ -60,8 +60,8 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function post(String $route, array $args) // ToDo : add JWT |
| 62 | 62 | { |
| 63 | - return json_decode( self::$http->request('POST', $route, [ |
|
| 64 | - 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' ], |
|
| 63 | + return json_decode(self::$http->request('POST', $route, [ |
|
| 64 | + 'headers' => ['X-Requested-With' => 'XMLHttpRequest'], |
|
| 65 | 65 | 'json' => $args |
| 66 | 66 | ])->getBody()->getContents()); |
| 67 | 67 | } |
@@ -68,10 +68,10 @@ |
||
| 68 | 68 | */ |
| 69 | 69 | public function post(String $route, array $args) // ToDo : add JWT |
| 70 | 70 | { |
| 71 | - return json_decode( self::$http->request('POST', $route, [ |
|
| 72 | - 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' ], |
|
| 73 | - 'json' => $args |
|
| 74 | - ])->getBody()->getContents()); |
|
| 71 | + return json_decode( self::$http->request('POST', $route, [ |
|
| 72 | + 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' ], |
|
| 73 | + 'json' => $args |
|
| 74 | + ])->getBody()->getContents()); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
@@ -43,6 +43,6 @@ |
||
| 43 | 43 | |
| 44 | 44 | public static function getSubscribedEvents() |
| 45 | 45 | { |
| 46 | - return [ KernelEvents::CONTROLLER => 'onKernelController' ]; |
|
| 46 | + return [KernelEvents::CONTROLLER => 'onKernelController']; |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -42,8 +42,9 @@ |
||
| 42 | 42 | |
| 43 | 43 | public function onKernelRequest(GetResponseEvent $event) |
| 44 | 44 | { |
| 45 | - if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) |
|
| 46 | - return; |
|
| 45 | + if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $events['moodle'] = null; |
| 44 | 44 | |
| 45 | 45 | if ($events['all'] != null) { |
| 46 | - usort($events['all'], function ($a, $b) { |
|
| 46 | + usort($events['all'], function($a, $b) { |
|
| 47 | 47 | return $a->eventTime < $b->eventTime; |
| 48 | 48 | }); |
| 49 | 49 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $events = Klass::eventsForUser($id, self::loggedUser()); |
| 131 | 131 | |
| 132 | 132 | if ($events != null) |
| 133 | - usort($events, function($a, $b) {return $a->eventTime < $b->eventTime;}); |
|
| 133 | + usort($events, function($a, $b) {return $a->eventTime < $b->eventTime; }); |
|
| 134 | 134 | |
| 135 | 135 | return $this->render('User/class.twig', [ |
| 136 | 136 | 'class' => $class, |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | return $this->json($res); |
| 166 | - }catch (Exception $e) { |
|
| 166 | + } catch (Exception $e) { |
|
| 167 | 167 | return new Response($e->getMessage(), 404); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -55,11 +55,13 @@ discard block |
||
| 55 | 55 | foreach ($events['all'] as $event) { |
| 56 | 56 | $date = date('Y-m-d', strtotime($event->eventTime)); |
| 57 | 57 | if ($event->object->{'@type'} == 'SoftwareApplication') { |
| 58 | - if (array_key_exists($date, $cas_events)) |
|
| 59 | - array_push($cas_events[$date], $event); |
|
| 58 | + if (array_key_exists($date, $cas_events)) { |
|
| 59 | + array_push($cas_events[$date], $event); |
|
| 60 | + } |
|
| 60 | 61 | } else { |
| 61 | - if (array_key_exists($date, $moodle_events)) |
|
| 62 | - array_push($moodle_events[$date], $event); |
|
| 62 | + if (array_key_exists($date, $moodle_events)) { |
|
| 63 | + array_push($moodle_events[$date], $event); |
|
| 64 | + } |
|
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | 67 | |
@@ -129,8 +131,10 @@ discard block |
||
| 129 | 131 | |
| 130 | 132 | $events = Klass::eventsForUser($id, self::loggedUser()); |
| 131 | 133 | |
| 132 | - if ($events != null) |
|
| 133 | - usort($events, function($a, $b) {return $a->eventTime < $b->eventTime;}); |
|
| 134 | + if ($events != null) { |
|
| 135 | + usort($events, function($a, $b) {return $a->eventTime < $b->eventTime; |
|
| 136 | + } |
|
| 137 | + }); |
|
| 134 | 138 | |
| 135 | 139 | return $this->render('User/class.twig', [ |
| 136 | 140 | 'class' => $class, |
@@ -157,13 +161,14 @@ discard block |
||
| 157 | 161 | $res[$i]['date'] = $result->date; |
| 158 | 162 | $res[$i]['score'] = $result->score; |
| 159 | 163 | foreach ($lineItems as $lineItem) { |
| 160 | - if ($lineItem->sourcedId == $result->lineitem->sourcedId) |
|
| 161 | - $res[$i]['title'] = $lineItem->title; |
|
| 164 | + if ($lineItem->sourcedId == $result->lineitem->sourcedId) { |
|
| 165 | + $res[$i]['title'] = $lineItem->title; |
|
| 166 | + } |
|
| 162 | 167 | } $i++; |
| 163 | 168 | } |
| 164 | 169 | |
| 165 | 170 | return $this->json($res); |
| 166 | - }catch (Exception $e) { |
|
| 171 | + } catch (Exception $e) { |
|
| 167 | 172 | return new Response($e->getMessage(), 404); |
| 168 | 173 | } |
| 169 | 174 | |