Skip to content
Snippets Groups Projects
Commit 1d48e606 authored by Elmar Ludwig's avatar Elmar Ludwig Committed by David Siegfried
Browse files

count in SQL, not in PHP, fixes #1677

Closes #1677

Merge request studip/studip!1080
parent 8306d1a7
No related branches found
No related tags found
No related merge requests found
......@@ -138,7 +138,7 @@ class Admin_DomainController extends AuthenticatedController
CSRFProtection::verifyUnsafeRequest();
$domain = new UserDomain($id);
if (count($domain->users) == 0) {
if ($domain->countUsers() === 0) {
$domain->delete();
} else {
PageLayout::postError(_('Domänen, denen noch Personen zugewiesen sind, können nicht gelöscht werden.'));
......
......@@ -28,13 +28,13 @@
<tr>
<td><?= htmlReady($domain->name) ?></td>
<td><?= htmlReady($domain->id) ?></td>
<td><?= count($domain->users) ?></td>
<td><?= count($domain->courses) ?></td>
<td><?= $domain->countUsers() ?></td>
<td><?= $domain->countCourses() ?></td>
<td class="actions">
<a href="<?= $controller->link_for("admin/domain/edit/{$domain->id}") ?>" data-dialog="size=auto">
<?= Icon::create('edit')->asImg(tooltip2(_('bearbeiten'))) ?>
</a>
<? if (count($domain->users) === 0): ?>
<? if ($domain->countUsers() === 0): ?>
<?= Icon::create('trash')->asInput(tooltip2(_('löschen')) + [
'class' => 'text-top',
'formaction' => $controller->url_for("admin/domain/delete/{$domain->id}"),
......
......@@ -48,6 +48,30 @@ class UserDomain extends SimpleORMap
return self::findBySQL('1 ORDER BY name');
}
/**
* Count the number of courses associated with this user domain.
*
* @return int number of courses
*/
public function countCourses(): int
{
$query = 'SELECT COUNT(*) FROM seminar_userdomains WHERE userdomain_id = ?';
return (int) DBManager::get()->fetchColumn($query, [$this->id]);
}
/**
* Count the number of courses associated with this user domain.
*
* @return int number of users
*/
public function countUsers(): int
{
$query = 'SELECT COUNT(*) FROM user_userdomains WHERE userdomain_id = ?';
return (int) DBManager::get()->fetchColumn($query, [$this->id]);
}
/**
* Add a user to this user domain.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment