Added Group entity, and allow to show group name in user info.

This commit is contained in:
Jan Böhmer 2019-03-15 13:18:47 +01:00
parent c037a76651
commit e28eb3b84d
3 changed files with 102 additions and 9 deletions

72
src/Entity/Group.php Normal file
View file

@ -0,0 +1,72 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* This entity represents an user group
* @package App\Entity
*
* @ORM\Entity()
* @ORM\Table("groups")
*/
class Group extends StructuralDBElement
{
/**
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
*/
protected $children;
/**
* @ORM\ManyToOne(targetEntity="Group", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="User", mappedBy="group")
*/
protected $users;
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
* @return string The ID as a string;
*/
public function getIDString(): string
{
return 'G' . sprintf('%06d', $this->getID());
}
}

View file

@ -36,6 +36,9 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* This entity represents a user, which can log in and have permissions.
* Also this entity is able to save some informations about the user, like the names, email-address and other info.
*
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table("users")
*/
@ -68,44 +71,51 @@ class User extends NamedDBElement implements UserInterface
* @var string The first name of the User
* @ORM\Column(type="string", length=255)
*/
protected $first_name;
protected $first_name = "";
/**
* @var string The last name of the User
* @ORM\Column(type="string", length=255)
*/
protected $last_name;
protected $last_name = "";
/**
* @var string The department the user is working
* @ORM\Column(type="string", length=255)
*/
protected $department;
protected $department = "";
/**
* @var string The email address of the user
* @ORM\Column(type="string", length=255)
*/
protected $email;
protected $email = "";
/**
* @var string The language/locale the user prefers
* @ORM\Column(type="string", name="config_language")
*/
protected $language;
protected $language = "";
/**
* @var string The timezone the user prefers
* @ORM\Column(type="string", name="config_timezone")
*/
protected $timezone;
protected $timezone = "";
/**
* @var string The theme
* @ORM\Column(type="string", name="config_theme")
*/
protected $theme;
protected $theme = "";
/**
* @var Group|null The group this user belongs to.
* @ORM\ManyToOne(targetEntity="Group", inversedBy="users")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id")
*/
protected $group;
/**
@ -177,7 +187,7 @@ class User extends NamedDBElement implements UserInterface
*/
public function getIDString(): string
{
return "U" . $this->getID();
return 'U' . sprintf('%06d', $this->getID());
}
@ -311,4 +321,15 @@ class User extends NamedDBElement implements UserInterface
return $this;
}
public function getGroup(): ?Group
{
return $this->group;
}
public function setGroup(?Group $group): self
{
$this->group = $group;
return $this;
}
}

View file

@ -52,7 +52,7 @@
<div class="form-group row">
<label class="col-form-label col-md-4">{% trans %}group.label{% endtrans %}</label>
<div class="col-md-8">
<p class="form-control-plaintext">TODO</p>
<p class="form-control-plaintext">{{ user.group.fullPath }}</p>
</div>
</div>
</div>