Internal: Fix user image upload

pull/3451/head
Julio Montoya 4 years ago
parent dd6a342528
commit ba250d0fd9
  1. 90
      assets/vue/App.vue
  2. 1
      src/CoreBundle/Controller/AccountController.php
  3. 5
      src/CoreBundle/Entity/User.php
  4. 18
      src/CoreBundle/Repository/IllustrationRepository.php
  5. 3
      src/CoreBundle/Resources/views/Account/home.html.twig
  6. 5
      src/CoreBundle/Twig/Extension/ChamiloExtension.php

@ -1,10 +1,10 @@
<template> <template>
<v-app id="inspire"> <v-app id="inspire">
<snackbar></snackbar> <snackbar />
<v-navigation-drawer <v-navigation-drawer
v-model="drawer"
app app
dark dark
v-model="drawer"
:clipped="$vuetify.breakpoint.lgAndUp" :clipped="$vuetify.breakpoint.lgAndUp"
disable-resize-watcher disable-resize-watcher
color="primary" color="primary"
@ -53,34 +53,40 @@
</template> </template>
<v-list-item <v-list-item
:to="'/main/admin/user_list.php'"> :to="'/main/admin/user_list.php'"
>
<v-list-item-action> <v-list-item-action>
<v-icon>mdi-account</v-icon> <v-icon>mdi-account</v-icon>
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>User list <v-list-item-title>
User list
</v-list-item-title> </v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
<v-list-item <v-list-item
:to="'/main/admin/course_list.php'"> :to="'/main/admin/course_list.php'"
>
<v-list-item-action> <v-list-item-action>
<v-icon>mdi-book</v-icon> <v-icon>mdi-book</v-icon>
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>Courses <v-list-item-title>
Courses
</v-list-item-title> </v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
<v-list-item <v-list-item
:to="'/main/session/session_list.php'"> :to="'/main/session/session_list.php'"
>
<v-list-item-action> <v-list-item-action>
<v-icon>mdi-book-multiple</v-icon> <v-icon>mdi-book-multiple</v-icon>
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>Sessions <v-list-item-title>
Sessions
</v-list-item-title> </v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
@ -92,7 +98,8 @@
<v-icon>mdi-settings</v-icon> <v-icon>mdi-settings</v-icon>
</v-list-item-action> </v-list-item-action>
<v-list-item-content> <v-list-item-content>
<v-list-item-title>Settings <v-list-item-title>
Settings
</v-list-item-title> </v-list-item-title>
</v-list-item-content> </v-list-item-content>
</v-list-item> </v-list-item>
@ -136,7 +143,6 @@
<!-- </v-list-item-title>--> <!-- </v-list-item-title>-->
<!-- </v-list-item-content>--> <!-- </v-list-item-content>-->
<!-- </v-list-item>--> <!-- </v-list-item>-->
</v-list> </v-list>
<v-list v-if="!isAuthenticated"> <v-list v-if="!isAuthenticated">
@ -181,7 +187,7 @@
app app
color="white" color="white"
> >
<v-app-bar-nav-icon @click.stop="drawer = !drawer"></v-app-bar-nav-icon> <v-app-bar-nav-icon @click.stop="drawer = !drawer" />
<v-toolbar-title <v-toolbar-title
style="width: 160px" style="width: 160px"
@ -192,10 +198,9 @@
src="/build/css/themes/chamilo/images/header-logo.png" src="/build/css/themes/chamilo/images/header-logo.png"
max-height="50" max-height="50"
contain contain
></v-img> />
</v-toolbar-title> </v-toolbar-title>
<v-spacer></v-spacer> <v-spacer />
<v-menu <v-menu
v-if="isAuthenticated" v-if="isAuthenticated"
@ -203,9 +208,14 @@
:nudge-width="200" :nudge-width="200"
> >
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-btn icon v-on="on"> <v-btn
icon
v-on="on"
>
<v-avatar> <v-avatar>
<v-icon dark>mdi-bell</v-icon> <v-icon dark>
mdi-bell
</v-icon>
</v-avatar> </v-avatar>
</v-btn> </v-btn>
</template> </template>
@ -234,19 +244,26 @@
offset-y offset-y
> >
<template v-slot:activator="{ on }"> <template v-slot:activator="{ on }">
<v-btn icon v-on="on"> <v-btn
icon
v-on="on"
>
<v-avatar> <v-avatar>
<v-icon dark>mdi-account-circle</v-icon> <v-icon dark>
mdi-account-circle
</v-icon>
</v-avatar> </v-avatar>
</v-btn> </v-btn>
</template> </template>
<v-list> <v-list>
<v-list-item <v-list-item
:to="'/main/social/home.php'"> :to="'/account/home'"
>
<v-list-item-title>Profile</v-list-item-title> <v-list-item-title>Profile</v-list-item-title>
</v-list-item> </v-list-item>
<v-list-item <v-list-item
:to="'/main/messages/inbox.php'"> :to="'/main/messages/inbox.php'"
>
<v-list-item-title>Inbox</v-list-item-title> <v-list-item-title>Inbox</v-list-item-title>
</v-list-item> </v-list-item>
<v-list-item> <v-list-item>
@ -261,13 +278,25 @@
v-else v-else
offset-y offset-y
> >
<v-btn small color="primary" :to="'/login'"> <v-btn
<v-icon left>mdi-account</v-icon> small
color="primary"
:to="'/login'"
>
<v-icon left>
mdi-account
</v-icon>
Login Login
</v-btn> </v-btn>
<v-btn small color="primary" :to="'/register'"> <v-btn
<v-icon left>mdi-pencil</v-icon> small
color="primary"
:to="'/register'"
>
<v-icon left>
mdi-pencil
</v-icon>
Register Register
</v-btn> </v-btn>
</div> </div>
@ -275,12 +304,17 @@
<v-main> <v-main>
<Breadcrumb layout-class="pl-3 py-3" /> <Breadcrumb layout-class="pl-3 py-3" />
<router-view></router-view> <router-view />
<div id="legacy_content" v-html="legacy_content"> <div
</div> id="legacy_content"
v-html="legacy_content"
/>
</v-main> </v-main>
<v-footer color="indigo" app> <v-footer
color="indigo"
app
>
<span class="white--text">&copy; 2020</span> <span class="white--text">&copy; 2020</span>
</v-footer> </v-footer>
</v-app> </v-app>

@ -45,7 +45,6 @@ class AccountController extends BaseController
{ {
$user = $this->getUser(); $user = $this->getUser();
//UserManagerInterface $userManager,
if (!is_object($user) || !$user instanceof UserInterface) { if (!is_object($user) || !$user instanceof UserInterface) {
throw $this->createAccessDeniedException('This user does not have access to this section'); throw $this->createAccessDeniedException('This user does not have access to this section');
} }

@ -639,9 +639,6 @@ class User implements UserInterface, EquatableInterface
return $this->username; return $this->username;
} }
/**
* @return $this
*/
public function setResourceNode(ResourceNode $resourceNode): self public function setResourceNode(ResourceNode $resourceNode): self
{ {
$this->resourceNode = $resourceNode; $this->resourceNode = $resourceNode;
@ -2059,10 +2056,12 @@ class User implements UserInterface, EquatableInterface
public function getFirstname() public function getFirstname()
{ {
return $this->firstname;
} }
public function getLastname() public function getLastname()
{ {
return $this->lastname;
} }
public function eraseCredentials() public function eraseCredentials()

@ -14,7 +14,7 @@ use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Form\Resource\IllustrationType; use Chamilo\CoreBundle\Form\Resource\IllustrationType;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/ */
final class IllustrationRepository extends ResourceRepository implements GridInterface, UploadInterface final class IllustrationRepository extends ResourceRepository implements GridInterface, UploadInterface
{ {
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroup $group = null): QueryBuilder
{ {
$repo = $this->getRepository(); $repo = $this->getRepository();
$className = $repo->getClassName(); $className = $repo->getClassName();
@ -98,13 +98,12 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
if (null === $illustrationNode) { if (null === $illustrationNode) {
$illustration = new Illustration(); $illustration = new Illustration();
$illustration->setParentResourceNode($user->getResourceNode()->getId());
$em->persist($illustration); $em->persist($illustration);
$this->createNodeForResource($illustration, $user, $user->getResourceNode());
} else { } else {
$illustration = $this->repository->findOneBy(['resourceNode' => $illustrationNode]); $illustration = $this->repository->findOneBy(['resourceNode' => $illustrationNode]);
} }
//$this->addResourceToEveryone($illustrationNode);
$file = $this->addFile($illustration, $uploadFile); $file = $this->addFile($illustration, $uploadFile);
$em->flush(); $em->flush();
@ -116,17 +115,18 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
$nodeRepo = $this->getResourceNodeRepository(); $nodeRepo = $this->getResourceNodeRepository();
$name = $this->getResourceTypeName(); $name = $this->getResourceTypeName();
$qb = $nodeRepo->getEntityManager()->createQueryBuilder() $qb = $nodeRepo->createQueryBuilder('n')
->select('node') ->select('node')
->from(ResourceNode::class, 'node') ->from(ResourceNode::class, 'node')
->innerJoin('node.resourceType', 'type') ->innerJoin('node.resourceType', 'type')
->innerJoin('node.resourceFile', 'file') ->innerJoin('node.resourceFile', 'file')
->where('node.parent = :parent') ->where('node.parent = :parent')
->andWhere('type.name = :name') ->andWhere('type.name = :name')
->setParameters(['parent' => $resourceNode, 'name' => $name]) ->setParameters(['parent' => $resourceNode->getId(), 'name' => $name])
->setMaxResults(1)
; ;
return $qb->getQuery()->getFirstResult(); return $qb->getQuery()->getOneOrNullResult();
} }
public function deleteIllustration(AbstractResource $resource) public function deleteIllustration(AbstractResource $resource)
@ -147,9 +147,9 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
return $this->getIllustrationUrlFromNode($resource->getResourceNode(), $filter); return $this->getIllustrationUrlFromNode($resource->getResourceNode(), $filter);
} }
public function getIllustrationUrlFromNode(ResourceNode $resourceNode, string $filter = ''): string public function getIllustrationUrlFromNode(ResourceNode $node, string $filter = ''): string
{ {
$node = $this->getIllustrationNodeFromParent($resourceNode); $node = $this->getIllustrationNodeFromParent($node);
if (null !== $node) { if (null !== $node) {
$params = [ $params = [

@ -3,10 +3,9 @@
{% block content %} {% block content %}
{% autoescape false %} {% autoescape false %}
<h2>{{ 'Profile' | trans }}</h2> <h2>{{ 'Profile' | trans }}</h2>
<h3>{{ user.username }} {{ user.firstname }} {{ user.lastname }}</h3> <h3> {{ user.firstname }} {{ user.lastname }} ({{ user.username }})</h3>
<img src="{{ app.user.resourceNode | user_illustration }}?w=300&h=300&fit=crop"> <img src="{{ app.user.resourceNode | user_illustration }}?w=300&h=300&fit=crop">
<br /> <br />
<a href="{{ url('chamilo_core_account_edit') }}" class="btn btn-primary"> <a href="{{ url('chamilo_core_account_edit') }}" class="btn btn-primary">

@ -4,6 +4,7 @@
namespace Chamilo\CoreBundle\Twig\Extension; namespace Chamilo\CoreBundle\Twig\Extension;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Repository\IllustrationRepository; use Chamilo\CoreBundle\Repository\IllustrationRepository;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFilter; use Twig\TwigFilter;
@ -47,12 +48,12 @@ class ChamiloExtension extends AbstractExtension
return []; return [];
} }
public function getIllustration($node): string public function getIllustration(ResourceNode $node): string
{ {
return $this->illustrationRepository->getIllustrationUrlFromNode($node); return $this->illustrationRepository->getIllustrationUrlFromNode($node);
} }
public function getUserIllustration($node): string public function getUserIllustration(ResourceNode $node): string
{ {
$url = $this->getIllustration($node); $url = $this->getIllustration($node);

Loading…
Cancel
Save