From 210907aead9bd350cb6edbbd899ef83b9dcd0ef2 Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Thu, 10 Nov 2022 21:05:12 +0100 Subject: [PATCH] code cleanup --- TeachUOS.class.php | 62 +++-------------------------------- composer.json | 13 -------- composer.lock | 18 ---------- controllers/admin.php | 27 --------------- controllers/index.php | 13 +++----- controllers/pages.php | 3 ++ migrations/001_add_tables.php | 4 +-- plugin.manifest | 2 +- templates/widget.php | 17 ---------- views/admin/index.php | 11 ------- 10 files changed, 15 insertions(+), 155 deletions(-) delete mode 100644 composer.json delete mode 100644 composer.lock delete mode 100644 controllers/admin.php delete mode 100644 templates/widget.php delete mode 100644 views/admin/index.php diff --git a/TeachUOS.class.php b/TeachUOS.class.php index 4a40d55..87b6d0b 100644 --- a/TeachUOS.class.php +++ b/TeachUOS.class.php @@ -2,15 +2,12 @@ use Courseware\StructuralElement; -require_once __DIR__ . '/vendor/autoload.php'; - /** * [Description TeachUOS] */ class TeachUOS extends StudipPlugin implements StandardPlugin, - SystemPlugin, - PortalPlugin + SystemPlugin { /** */ @@ -33,16 +30,6 @@ class TeachUOS extends StudipPlugin implements ); $navigation->addSubNavigation("teachUOS", $teachUOS); } - - // more setup if this plugin is active in this course - $contextId = \Context::getId(); - if (\Context::getType() === \Context::COURSE && $this->isActivated($contextId)) { - if (!$GLOBALS['perm']->have_studip_perm('tutor', $contextId)) { - if (Navigation::hasItem('/course/courseware')) { - Navigation::removeItem('/course/courseware'); - } - } - } } /** @@ -63,44 +50,9 @@ class TeachUOS extends StudipPlugin implements */ public function isTeachUOSMember() { - $teachUOS_course_id = $this->getTeachUOSCourse(); - $teachUOSCourse = Course::find($teachUOS_course_id); - if (!$teachUOSCourse) { - return false; - } - $member_ids = $teachUOSCourse->members->pluck("user_id"); - $user_id = $GLOBALS["user"]->id; - return in_array($user_id, $member_ids); - } - - /** - * @return [type] - */ - public function getPluginName() - { - return "teachUOS"; - } - - /** - * Returns the portal widget template. - */ - function getPortalTemplate() - { - $template_path = $this->getPluginPath() . "/templates"; - $template_factory = new Flexi_TemplateFactory($template_path); - $template = $template_factory->open("widget"); - //set $teachUOS_course_id variable for widget template - $template->set_attribute( - "teachUOS_course_id", - $this->getTeachUOSCourse() - ); - //set $isMember variable if student is already member of teachuos course - $template->set_attribute("isMember", $this->isTeachUOSMember()); - - //TODO: set title of widget - $template->title = _("teachUOS"); + $course_id = $this->getTeachUOSCourse(); - return $template; + return $course_id && CourseMember::exists([$course_id, $GLOBALS['user']->id]); } /** @@ -173,13 +125,7 @@ class TeachUOS extends StudipPlugin implements */ public function getTabNavigation($course_id) { - //Link to overview page in the course - $tab = new Navigation( - $this->getPluginName(), - PluginEngine::getURL($this, [], "admin") - ); - - return [$this->getPluginName() => $tab]; + return []; } /** diff --git a/composer.json b/composer.json deleted file mode 100644 index 488ce30..0000000 --- a/composer.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "elan-ev/teachuos-plugin", - "type": "project", - "license": "GPL-2.0+", - "autoload": { - "psr-4": { - "TeachUOSPlugin\\": "lib/" - } - }, - "scripts": { - "zip": "zip -r studip-plugin-teachuos.zip assets controllers migrations README.md templates dist plugin.manifest vendor lib TeachUOS.class.php views" - } -} diff --git a/composer.lock b/composer.lock deleted file mode 100644 index aad2332..0000000 --- a/composer.lock +++ /dev/null @@ -1,18 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "ee7bd932978c1e52ebc34cfa946d1fae", - "packages": [], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.3.0" -} diff --git a/controllers/admin.php b/controllers/admin.php deleted file mode 100644 index 52ac9c5..0000000 --- a/controllers/admin.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -class AdminController extends StudipController -{ - // TODO: delete if unneccessary - public function __construct($dispatcher) - { - parent::__construct($dispatcher); - $this->plugin = $GLOBALS["plugin"]; - } - - //TODO: delete if unneccessary - public function before_filter(&$action, &$args) - { - parent::before_filter($action, $args); - Navigation::activateItem("/course/" . $this->plugin->getPluginName()); - } - - public function index_action() - { - $this->course_id = Context::getId(); - $this->teachUOS_course_id = $this->plugin->getTeachUOSCourse(); - $this->teachUOS_course_name = Course::find( - $this->teachUOS_course_id - )->name; - } -} diff --git a/controllers/index.php b/controllers/index.php index 59d09fb..298e761 100644 --- a/controllers/index.php +++ b/controllers/index.php @@ -8,11 +8,14 @@ class IndexController extends StudipController $this->plugin = $GLOBALS["plugin"]; } - public function before_filter(&$action, &$args) + public function index_action() { - parent::before_filter($action, $args); // Set title of browser tab PageLayout::setTitle(_("teachUOS")); + + // Activate icon in main navigation + subnavigation + Navigation::activateItem("teachUOS/teachUOS"); + // Add stylesheets for index page PageLayout::addStylesheet( $this->plugin->getPluginURL() . "/assets/index.css" @@ -20,12 +23,6 @@ class IndexController extends StudipController PageLayout::addStylesheet( $this->plugin->getPluginURL() . "/assets/teachUOS.css" ); - // Activate icon in main navigation + subnavigation - Navigation::activateItem("teachUOS/teachUOS"); - } - - public function index_action() - { //define js file for layout PageLayout::addScript( $this->plugin->getPluginURL() . "/assets/index.js" diff --git a/controllers/pages.php b/controllers/pages.php index c9e7d5a..7f41a95 100644 --- a/controllers/pages.php +++ b/controllers/pages.php @@ -1,5 +1,8 @@ <?php +require_once dirname(__DIR__) . '/lib/IncludesVite.php'; +require_once dirname(__DIR__) . '/lib/ViteManifest.php'; + use Courseware\StructuralElement; use TeachUOSPlugin\IncludesVite; diff --git a/migrations/001_add_tables.php b/migrations/001_add_tables.php index f5ef170..e0cf02f 100644 --- a/migrations/001_add_tables.php +++ b/migrations/001_add_tables.php @@ -11,8 +11,8 @@ class AddTables extends Migration { $db = DBManager::get(); $db->exec("CREATE TABLE IF NOT EXISTS `teachUOS_favourites` ( - `user_id` VARCHAR(32) NOT NULL, - `course_id` VARCHAR(32) NOT NULL, + `user_id` VARCHAR(32) COLLATE latin1_bin NOT NULL, + `course_id` VARCHAR(32) COLLATE latin1_bin NOT NULL, `block_id` INT(11) NOT NULL, `parent_id` INT(11) DEFAULT NULL, `title` VARCHAR(255) DEFAULT NULL, diff --git a/plugin.manifest b/plugin.manifest index a00430e..5752087 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,6 +1,6 @@ pluginname=teachUOS pluginclassname=TeachUOS origin=virtUOS -version=1.1 +version=1.2 studipMinVersion=4.1 studipMaxVersion=5.1.99 diff --git a/templates/widget.php b/templates/widget.php deleted file mode 100644 index ca67790..0000000 --- a/templates/widget.php +++ /dev/null @@ -1,17 +0,0 @@ -<article class="studip"> - <section> - <p><?= _("Info-Text zu teachUOS.") ?></p> - <? if (!$isMember) : ?> - <?= \Studip\LinkButton::create( - _("teachUOS für mich aktivieren"), - URLHelper::getLink( - "dispatch.php/course/enrolment/apply/" . $teachUOS_course_id - ), - [] - ) ?> - <? else : ?> - <p>teachUOS ist für dich bereits aktiviert !</p> - <? endif ?> - - </section> -</article> diff --git a/views/admin/index.php b/views/admin/index.php deleted file mode 100644 index 751f722..0000000 --- a/views/admin/index.php +++ /dev/null @@ -1,11 +0,0 @@ -<!-- Show text inside of a MessageBox to indicate whether the plugin is activated in the current context or not --> -<? if (!strcmp($course_id, $teachUOS_course_id)) : ?> - <?= MessageBox::success( - "Das teachUOS-Plugin ist aktuell in dieser Veranstaltung aktiviert." - ) ?> -<? else : ?> - <?= MessageBox::info( - "Aktuell ist das teachUOS-Plugin in einer anderen Veranstaltung aktiviert: ", - [$teachUOS_course_name] - ) ?> -<? endif ?> -- GitLab