Skip to content

Commit

Permalink
Merge pull request #1028 from ngodfraind/master
Browse files Browse the repository at this point in the history
user profile editable
  • Loading branch information
ngodfraind committed Feb 13, 2015
2 parents f77394d + 9bacc5d commit e86cba4
Show file tree
Hide file tree
Showing 30 changed files with 1,279 additions and 163 deletions.
91 changes: 75 additions & 16 deletions Controller/Administration/FacetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
use Claroline\CoreBundle\Manager\ToolManager;
use Claroline\CoreBundle\Manager\RoleManager;
use Claroline\CoreBundle\Manager\FacetManager;
use Claroline\CoreBundle\Manager\ProfilePropertyManager;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Form\FormFactoryInterface;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Entity\ProfileProperty;
use Claroline\CoreBundle\Entity\Facet\Facet;
use Claroline\CoreBundle\Entity\Facet\FieldFacet;
use Claroline\CoreBundle\Entity\Facet\PanelFacet;
Expand All @@ -38,16 +41,18 @@ class FacetController extends Controller
private $roleManager;
private $userAdminTool;
private $facetManager;
private $profilePropertyManager;

/**
* @DI\InjectParams({
* "router" = @DI\Inject("router"),
* "sc" = @DI\Inject("security.context"),
* "toolManager" = @DI\Inject("claroline.manager.tool_manager"),
* "roleManager" = @DI\Inject("claroline.manager.role_manager"),
* "facetManager" = @DI\Inject("claroline.manager.facet_manager"),
* "formFactory" = @DI\Inject("form.factory"),
* "request" = @DI\Inject("request")
* "router" = @DI\Inject("router"),
* "sc" = @DI\Inject("security.context"),
* "toolManager" = @DI\Inject("claroline.manager.tool_manager"),
* "roleManager" = @DI\Inject("claroline.manager.role_manager"),
* "facetManager" = @DI\Inject("claroline.manager.facet_manager"),
* "formFactory" = @DI\Inject("form.factory"),
* "request" = @DI\Inject("request"),
* "profilePropertyManager" = @DI\Inject("claroline.manager.profile_property_manager")
* })
*/
public function __construct(
Expand All @@ -57,17 +62,19 @@ public function __construct(
FacetManager $facetManager,
RoleManager $roleManager,
FormFactoryInterface $formFactory,
Request $request
Request $request,
ProfilePropertyManager $profilePropertyManager
)
{
$this->sc = $sc;
$this->toolManager = $toolManager;
$this->userAdminTool = $this->toolManager->getAdminToolByName('user_management');
$this->facetManager = $facetManager;
$this->formFactory = $formFactory;
$this->request = $request;
$this->roleManager = $roleManager;
$this->router = $router;
$this->sc = $sc;
$this->toolManager = $toolManager;
$this->userAdminTool = $this->toolManager->getAdminToolByName('user_management');
$this->facetManager = $facetManager;
$this->formFactory = $formFactory;
$this->request = $request;
$this->roleManager = $roleManager;
$this->router = $router;
$this->profilePropertyManager = $profilePropertyManager;
}

/**
Expand All @@ -79,6 +86,21 @@ public function __construct(
* @return Response
*/
public function indexAction()
{
$this->checkOpen();

return array();
}

/**
* Returns the facet list.
*
* @EXT\Route("/facet", name="claro_admin_facet")
* @EXT\Template
*
* @return Response
*/
public function facetsAction()
{
$this->checkOpen();
$facets = $this->facetManager->getFacets();
Expand All @@ -92,6 +114,43 @@ public function indexAction()
);
}

/**
* Returns the facet list.
*
* @EXT\Route("/properties", name="claro_admin_profile_properties")
* @EXT\Template
*
* @return Response
*/
public function profilePropertiesAction()
{
$this->checkOpen();
$platformRoles = $this->roleManager->getPlatformNonAdminRoles(false);
$labels = User::getEditableProperties();
$properties = $this->profilePropertyManager->getAllProperties();

return array(
'platformRoles' => $platformRoles,
'labels' => $labels,
'properties' => $properties
);
}

/**
* @EXT\Route("/property/{property}/invert",
* name="claro_admin_invert_user_properties_edition",
* options = {"expose"=true}
* )
*
*/
public function invertPropertiesEditableAction(ProfileProperty $property)
{
$this->checkOpen();
$this->profilePropertyManager->invertProperty($property);

return new JsonResponse(array(), 200);
}

/**
* Returns the facet creation form in a modal
*
Expand Down
21 changes: 19 additions & 2 deletions Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Claroline\CoreBundle\Manager\RoleManager;
use Claroline\CoreBundle\Manager\ToolManager;
use Claroline\CoreBundle\Manager\UserManager;
use Claroline\CoreBundle\Manager\ProfilePropertyManager;
use Doctrine\ORM\NoResultException;
use JMS\DiExtraBundle\Annotation as DI;
use JMS\SecurityExtraBundle\Annotation as SEC;
Expand Down Expand Up @@ -55,6 +56,7 @@ class ProfileController extends Controller
private $facetManager;
private $ch;
private $authenticationManager;
private $profilePropertyManager;

/**
* @DI\InjectParams({
Expand All @@ -68,7 +70,8 @@ class ProfileController extends Controller
* "toolManager" = @DI\Inject("claroline.manager.tool_manager"),
* "facetManager" = @DI\Inject("claroline.manager.facet_manager"),
* "ch" = @DI\Inject("claroline.config.platform_config_handler"),
* "authenticationManager" = @DI\Inject("claroline.common.authentication_manager")
* "authenticationManager" = @DI\Inject("claroline.common.authentication_manager"),
* "profilePropertyManager" = @DI\Inject("claroline.manager.profile_property_manager")
* })
*/
public function __construct(
Expand All @@ -82,7 +85,8 @@ public function __construct(
ToolManager $toolManager,
FacetManager $facetManager,
PlatformConfigurationHandler $ch,
AuthenticationManager $authenticationManager
AuthenticationManager $authenticationManager,
ProfilePropertyManager $profilePropertyManager
)
{
$this->userManager = $userManager;
Expand All @@ -96,6 +100,7 @@ public function __construct(
$this->facetManager = $facetManager;
$this->ch = $ch;
$this->authenticationManager = $authenticationManager;
$this->profilePropertyManager = $profilePropertyManager;
}

private function isInRoles($role, $roles)
Expand Down Expand Up @@ -206,13 +211,15 @@ public function editProfileAction(User $loggedUser, User $user = null)
}
$userRole = $this->roleManager->getUserRoleByUser($user);
$roles = $this->roleManager->getPlatformRoles($user);
$accesses = $this->profilePropertyManager->getAccessesForCurrentUser();

$form = $this->createForm(
new ProfileType(
$roles,
$isAdmin,
$isGrantedUserAdmin,
$this->localeManager->getAvailableLocales(),
$accesses,
$this->authenticationManager->getDrivers()
),
$user
Expand Down Expand Up @@ -475,6 +482,16 @@ public function editFacet(User $user, Facet $facet)
return new JsonResponse($data);
}

public function propertiesFormAction()
{

}

public function editPropertiesAction()
{

}

private function encodePassword(User $user)
{
return $this->encoderFactory
Expand Down
29 changes: 29 additions & 0 deletions DataFixtures/Required/Data/LoadProfilePropertiesData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\CoreBundle\DataFixtures\Required\Data;

use Claroline\CoreBundle\Persistence\ObjectManager;
use Claroline\CoreBundle\DataFixtures\Required\RequiredFixture;

class LoadProfilePropertiesData implements RequiredFixture
{
public function load(ObjectManager $manager)
{
$this->container->get('claroline.manager.profile_property_manager')
->addDefaultProperties();
}

public function setContainer($container)
{
$this->container = $container;
}
}
88 changes: 88 additions & 0 deletions Entity/ProfileProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Claroline Connect package.
*
* (c) Claroline Consortium <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Claroline\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="Claroline\CoreBundle\Repository\ProfilePropertyRepository")
* @ORM\Table(name="claro_profile_property")
*/
class ProfileProperty
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(name="is_editable", type="boolean")
*/
protected $isEditable;

/**
* @ORM\ManyToOne(
* targetEntity="Claroline\CoreBundle\Entity\Role",
* inversedBy="profileProperties",
* cascade={"persist"}
* )
* @ORM\JoinColumn(onDelete="CASCADE")
*/
protected $role;

/**
* @ORM\Column(name="property", length=256)
*/
protected $property;

public function getId()
{
return $this->id;
}

public function setIsEditable($bool)
{
$this->isEditable = $bool;
}

public function isEditable()
{
return $this->isEditable;
}

public function getIsEditable()
{
return $this->isEditable;
}

public function setRole(Role $role)
{
$this->role = $role;
}

public function getRole()
{
return $this->role;
}

public function setProperty($property)
{
$this->property = $property;
}

public function getProperty()
{
return $this->property;
}
}
33 changes: 26 additions & 7 deletions Entity/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,24 @@ class Role implements RoleInterface
*/
protected $personalWorkspaceCreationEnabled = false;

/**
* @ORM\OneToMany(
* targetEntity="Claroline\CoreBundle\Entity\ProfileProperty",
* mappedBy="role"
* )
*/
protected $profileProperties;

public function __construct()
{
$this->users = new ArrayCollection();
$this->resourceContext = new ArrayCollection();
$this->groups = new ArrayCollection();
$this->facets = new ArrayCollection();
$this->fieldFacetsRoles = new ArrayCollection();
$this->toolRights = new ArrayCollection();
$this->pwsToolConfig = new ArrayCollection();
$this->users = new ArrayCollection();
$this->resourceContext = new ArrayCollection();
$this->groups = new ArrayCollection();
$this->facets = new ArrayCollection();
$this->fieldFacetsRoles = new ArrayCollection();
$this->toolRights = new ArrayCollection();
$this->pwsToolConfig = new ArrayCollection();
$this->profileProperties = new ArrayCollection();
}

public function getId()
Expand Down Expand Up @@ -347,4 +356,14 @@ public function setPersonalWorkspaceCreationEnabled($boolean)
{
$this->personalWorkspaceCreationEnabled = $boolean;
}

public function getProfileProperties()
{
return $this->profileProperties;
}

public function addProfileProperty(ProfileProperty $property)
{
$this->profileProperties->add($property);
}
}
14 changes: 14 additions & 0 deletions Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,4 +1074,18 @@ public function getAuthentication()
{
return $this->authentication;
}

public static function getEditableProperties()
{
return array(
'username' => false,
'firstName' => false,
'lastName' => false,
'administrativeCode' => false,
'email' => false,
'phone' => true,
'picture' => true,
'description' => true
);
}
}
Loading

0 comments on commit e86cba4

Please sign in to comment.