Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/src/CoreBundle/Entity/Group.php

134 lines
2.4 KiB

<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity()
* @ORM\Table(name="fos_group")
*/
class Group
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected int $id;
/**
* @Assert\NotBlank()
* @ORM\Column(name="name", type="string", length=255, nullable=false, unique=true)
*/
protected string $name;
/**
* @Assert\NotBlank()
* @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
*/
protected string $code;
/**
* @var array
* @ORM\Column(name="roles", type="array")
*/
protected $roles;
/**
* @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\User", mappedBy="groups")
*/
protected $users;
public function __construct($name, $roles = [])
{
$this->name = $name;
$this->roles = $roles;
}
public function __toString(): string
{
return $this->getName() ?: '';
}
public function addRole($role)
{
if (!$this->hasRole($role)) {
$this->roles[] = strtoupper($role);
}
return $this;
}
public function hasRole($role)
{
return in_array(strtoupper($role), $this->roles, true);
}
public function getRoles()
{
return $this->roles;
}
public function removeRole($role)
{
if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Group
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
return $this;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function getUsers()
{
return $this->users;
}
public function getCode(): string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
}