aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/user.php2
-rw-r--r--app/views/admin/user/_results.php2
-rw-r--r--app/views/admin/user/edit.php10
-rw-r--r--app/views/profile/index.php2
-rw-r--r--cli/Commands/Migrate/MigrateMatrikelnummer.php66
-rwxr-xr-xcli/studip1
-rw-r--r--db/migrations/5.5.6_add_matriculation_number.php28
-rw-r--r--lib/models/User.class.php1
8 files changed, 111 insertions, 1 deletions
diff --git a/app/controllers/admin/user.php b/app/controllers/admin/user.php
index 37b8b53..b6a4048 100644
--- a/app/controllers/admin/user.php
+++ b/app/controllers/admin/user.php
@@ -417,7 +417,7 @@ class Admin_UserController extends AuthenticatedController
if (count($editPerms)) {
$editUser['auth_user_md5.perms'] = $editPerms[0];
}
- foreach (words('Vorname Nachname auth_plugin visible') as $param) {
+ foreach (['Vorname', 'Nachname', 'matriculation_number', 'auth_plugin', 'visible'] as $param) {
if (Request::get($param)) $editUser['auth_user_md5.' . $param] = Request::get($param);
}
foreach (words('title_front title_rear geschlecht preferred_language') as $param) {
diff --git a/app/views/admin/user/_results.php b/app/views/admin/user/_results.php
index e41d995..8751436 100644
--- a/app/views/admin/user/_results.php
+++ b/app/views/admin/user/_results.php
@@ -22,6 +22,7 @@
</a>
</th>
<th>&nbsp;</th>
+ <th><?= _('Matrikelnummer') ?></th>
<th <?= $sortby === 'perms' ? 'class="sort' . $order . '"' : '' ?>>
<a href="<?= $controller->link_for('admin/user',['sortby' =>'perms', 'order'=> $order ,'toggle' => $sortby === 'perms']) ?>">
<?= _('Status') ?>
@@ -99,6 +100,7 @@
?>
<?= tooltipHtmlIcon(htmlReady($tooltxt, true, true)) ?>
</td>
+ <td><?= htmlReady($user->matriculation_number) ?></td>
<td><?= $user['perms'] ?></td>
<td><?= htmlReady($user->Vorname) ?></td>
<td><?= htmlReady($user->nachname) ?></td>
diff --git a/app/views/admin/user/edit.php b/app/views/admin/user/edit.php
index 9e1241e..8892d98 100644
--- a/app/views/admin/user/edit.php
+++ b/app/views/admin/user/edit.php
@@ -204,6 +204,16 @@ use Studip\Button, Studip\LinkButton;
</div>
</section>
+ <section>
+ <label>
+ <?= _('Matrikelnummer') ?>
+ <input class="user_form" type="text" id="matriculation_number"
+ value="<?= htmlReady($user->matriculation_number) ?>"
+ <?= StudipAuthAbstract::CheckField('auth_user_md5.matriculation_number', $user->auth_plugin)
+ || LockRules::check($user->user_id, 'matriculation_number') ? 'readonly' : 'name="matriculation_number"' ?>>
+ </label>
+ </section>
+
<? if (!empty($user_roles)) : ?>
<section>
diff --git a/app/views/profile/index.php b/app/views/profile/index.php
index 29f0119..82a001a 100644
--- a/app/views/profile/index.php
+++ b/app/views/profile/index.php
@@ -65,6 +65,8 @@
<? if ($current_user->user_id === $GLOBALS['user']->id) : ?>
<dt><?= _('Status') ?>:</dt>
<dd><?= htmlReady(ucfirst($current_user['perms'])) ?></dd>
+ <dt><?= _('Matrikelnummer') ?>:</dt>
+ <dd><?= htmlReady($current_user['matriculation_number']) ?></dd>
<? endif ?>
<? if (!empty($shortDatafields)) : ?>
diff --git a/cli/Commands/Migrate/MigrateMatrikelnummer.php b/cli/Commands/Migrate/MigrateMatrikelnummer.php
new file mode 100644
index 0000000..fbad2d8
--- /dev/null
+++ b/cli/Commands/Migrate/MigrateMatrikelnummer.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Studip\Cli\Commands\Migrate;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class MigrateMatrikelnummer extends Command
+{
+ protected static $defaultName = 'migrate:matrikelnummer';
+
+ protected function configure() : void
+ {
+ $this->setDescription('Migrates the "Matrikelnummer" datafield into the matriculation_number column of the auth_user_md5 table.');
+ $this->setHelp('This command migrates the "Matrikelnummer" datafield into the matriculation_number column of the auth_user_md5 table. The ID of the datafield must be provided. The datafield is not deleted in the migration process.');
+ $this->addOption('id', 'i', InputOption::VALUE_REQUIRED, 'The ID of the "Matrikelnummer" datafield.', null);
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) : int
+ {
+ $datafield_id = $input->getOption('id');
+ if (!$datafield_id) {
+ echo 'No ID for the "Matrikelnummer" datafield has been provided.' . "\n";
+ return Command::FAILURE;
+ }
+ $datafield = \DataField::find($datafield_id);
+ if (!$datafield) {
+ echo 'The datafield could not be found.' . "\n";
+ return Command::FAILURE;
+ }
+ //Get all entries of the datafield for users and set the
+ //matriculation_number field:
+
+ $verbose = $input->getOption('verbose');
+
+ $modifier = function ($entry) use ($verbose) {
+ if (!$entry->content) {
+ return;
+ }
+ $user = \User::find($entry->range_id);
+ if (!$user) {
+ return;
+ }
+ $user->matriculation_number = $entry->content;
+ if ($user->isDirty()) {
+ $success = $user->store();
+ if ($verbose) {
+ if ($success === false) {
+ printf('Error updating matriculation number for user %s.', $user->username) . "\n";
+ } elseif ($success > 0) {
+ printf('Matriculation number updated for user %s.', $user->username) . "\n";
+ }
+ }
+ }
+ };
+
+ \DatafieldEntryModel::findEachByDatafield_id(
+ $modifier,
+ $datafield->id
+ );
+
+ return Command::SUCCESS;
+ }
+}
diff --git a/cli/studip b/cli/studip
index bef389c..c4addb9 100755
--- a/cli/studip
+++ b/cli/studip
@@ -38,6 +38,7 @@ $commands = [
Commands\Fix\EndTimeWeeklyRecurredEvents::class,
Commands\Fix\IconDimensions::class,
Commands\HelpContent\Migrate::class,
+ Commands\Migrate\MigrateMatrikelnummer::class,
Commands\Migrate\MigrateList::class,
Commands\Migrate\MigrateStatus::class,
Commands\Migrate\Migrate::class,
diff --git a/db/migrations/5.5.6_add_matriculation_number.php b/db/migrations/5.5.6_add_matriculation_number.php
new file mode 100644
index 0000000..4fa0784
--- /dev/null
+++ b/db/migrations/5.5.6_add_matriculation_number.php
@@ -0,0 +1,28 @@
+<?php
+
+
+class AddMatriculationNumber extends Migration
+{
+ public function description()
+ {
+ return 'Add auth_user_md5.matriculation_number';
+ }
+
+ protected function up()
+ {
+ $db = DBManager::get();
+ $db->exec(
+ "ALTER TABLE `auth_user_md5`
+ ADD COLUMN matriculation_number VARCHAR(255) NULL DEFAULT NULL"
+ );
+ }
+
+ protected function down()
+ {
+ $db = DBManager::get();
+ $db->exec(
+ "ALTER TABLE `auth_user_md5`
+ DROP COLUMN matriculation_number"
+ );
+ }
+}
diff --git a/lib/models/User.class.php b/lib/models/User.class.php
index 627673d..21f8f87 100644
--- a/lib/models/User.class.php
+++ b/lib/models/User.class.php
@@ -30,6 +30,7 @@
* @property string $vorname database column
* @property string $nachname database column
* @property string $email database column
+ * @property string $matriculation_number database column
* @property string $validation_key database column
* @property string|null $auth_plugin database column
* @property int $locked database column