Update Usergroup as a resource + add usergroup tool.

pull/3768/head
Julio Montoya 5 years ago
parent 1b04900d66
commit 58d249b650
  1. 69
      public/main/inc/lib/usergroup.lib.php
  2. 4
      public/main/inc/lib/usermanager.lib.php
  3. 26
      src/CoreBundle/Entity/Usergroup.php
  4. 12
      src/CoreBundle/Resources/config/tools.yml
  5. 9
      src/CoreBundle/Tool/UserGroup.php

@ -3,6 +3,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Entity\Usergroup as UserGroupEntity;
/**
* Class UserGroup.
@ -1527,10 +1528,21 @@ class UserGroup extends Model
$groupExists = $this->usergroup_exists(trim($params['name']));
if (false == $groupExists) {
$group = new UserGroupEntity();
$repo = Container::getUsergroupRepository();
$group
->setName(trim($params['name']))
->setDescription($params['description'])
->setUrl($params['url'])
->setVisibility($params['visibility'])
;
if ($this->allowTeachers()) {
$params['author_id'] = api_get_user_id();
$group->setAuthorId(api_get_user_id());
}
$id = parent::save($params, $showQuery);
$repo->create($group);
$id = $group->getId();
if ($id) {
if ($this->getUseMultipleUrl()) {
$this->subscribeToUrl($id, api_get_current_access_url_id());
@ -1543,16 +1555,9 @@ class UserGroup extends Model
$params['group_type']
);
}
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
$picture = $this->manageFileUpload($id, $picture);
if ($picture) {
$params = [
'id' => $id,
'picture' => $picture,
'group_type' => $params['group_type'],
];
$this->update($params);
}
$request = Container::getRequest();
$file = $request->files->get('picture');
$this->manageFileUpload($group, $file);
}
return $id;
@ -1571,14 +1576,9 @@ class UserGroup extends Model
if (isset($params['id'])) {
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
if (!empty($picture)) {
$picture = $this->manageFileUpload($params['id'], $picture, $params['crop_image']);
if ($picture) {
$params['picture'] = $picture;
}
}
if (isset($params['delete_picture'])) {
$params['picture'] = null;
$request = Container::getRequest();
$file = $request->files->get('picture');
$this->manageFileUpload($params['id'], $file, $params['crop_image']);
}
}
@ -1592,21 +1592,18 @@ class UserGroup extends Model
}
/**
* @param int $groupId
* @param UserGroupEntity $groupId
* @param string $picture
* @param string $cropParameters
*
* @return bool|string
* @return bool
*/
public function manageFileUpload($groupId, $picture, $cropParameters = '')
public function manageFileUpload($userGroup, $picture, $cropParameters = '')
{
if (!empty($picture['name'])) {
return $this->update_group_picture(
$groupId,
$picture['name'],
$picture['tmp_name'],
$cropParameters
);
if ($userGroup) {
$illustrationRepo = Container::getIllustrationRepository();
$illustrationRepo->addIllustration($userGroup, api_get_user_entity(), $picture, $cropParameters);
return true;
}
return false;
@ -1619,7 +1616,12 @@ class UserGroup extends Model
*/
public function delete_group_picture($groupId)
{
return $this->update_group_picture($groupId);
$repo = Container::getUsergroupRepository();
$userGroup = $repo->find($groupId);
if ($userGroup) {
$illustrationRepo = Container::getIllustrationRepository();
$illustrationRepo->deleteIllustration($userGroup);
}
}
/**
@ -1654,7 +1656,10 @@ class UserGroup extends Model
WHERE usergroup_id = $id";
Database::query($sql);
parent::delete($id);
//parent::delete($id);
$repo = Container::getUsergroupRepository();
$userGroup = $repo->find($id);
$repo->delete($userGroup);
}
/**

@ -1990,6 +1990,8 @@ class UserManager
return false;
}
return false;
$production_dir = self::getUserPathById($user_id, 'web');
$del_image = Display::returnIconPath('delete.png');
$add_image = Display::returnIconPath('archive.png');
@ -2030,6 +2032,8 @@ class UserManager
*/
public static function get_user_productions($user_id)
{
return [];
$production_repository = self::getUserPathById($user_id, 'system');
$productions = [];

@ -19,7 +19,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(name="usergroup")
* @ORM\Entity
*/
class Usergroup extends AbstractResource implements ResourceInterface, ResourceIllustrationInterface
class Usergroup extends AbstractResource implements ResourceInterface, ResourceIllustrationInterface, ResourceToRootInterface
{
use TimestampableEntity;
@ -210,19 +210,11 @@ class Usergroup extends AbstractResource implements ResourceInterface, ResourceI
return $this;
}
/**
* @return string
*/
public function getVisibility(): string
{
return $this->visibility;
}
/**
* @param string $visibility
*
* @return Usergroup
*/
public function setVisibility(string $visibility): Usergroup
{
$this->visibility = $visibility;
@ -230,19 +222,11 @@ class Usergroup extends AbstractResource implements ResourceInterface, ResourceI
return $this;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* @param string|null $url
*
* @return Usergroup
*/
public function setUrl(?string $url): Usergroup
{
$this->url = $url;
@ -250,19 +234,11 @@ class Usergroup extends AbstractResource implements ResourceInterface, ResourceI
return $this;
}
/**
* @return string
*/
public function getAuthorId(): string
{
return $this->authorId;
}
/**
* @param string $authorId
*
* @return Usergroup
*/
public function setAuthorId(string $authorId): Usergroup
{
$this->authorId = $authorId;

@ -414,6 +414,18 @@ services:
tags:
- {name: chamilo_core.tool}
chamilo_core.tool.usergroup:
class: Chamilo\CoreBundle\Tool\UserGroup
arguments:
- 'usergroup'
- ''
- '/resources/usergroup/'
- ~
- usergroups:
repository: Chamilo\CoreBundle\Repository\Node\UsergroupRepository
tags:
- { name: chamilo_core.tool }
chamilo_core.tool.wiki:
class: Chamilo\CoreBundle\Tool\Wiki
arguments:

@ -0,0 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Tool;
class UserGroup extends AbstractTool
{
}
Loading…
Cancel
Save