Internal: Fix user image upload

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

@ -45,7 +45,6 @@ class AccountController extends BaseController
{
$user = $this->getUser();
//UserManagerInterface $userManager,
if (!is_object($user) || !$user instanceof UserInterface) {
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
*/
public function setResourceNode(ResourceNode $resourceNode): self
{
$this->resourceNode = $resourceNode;
@ -2059,10 +2056,12 @@ class User implements UserInterface, EquatableInterface
public function getFirstname()
{
return $this->firstname;
}
public function getLastname()
{
return $this->lastname;
}
public function eraseCredentials()

@ -14,7 +14,7 @@ use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Form\Resource\IllustrationType;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -24,7 +24,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
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();
$className = $repo->getClassName();
@ -98,13 +98,12 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
if (null === $illustrationNode) {
$illustration = new Illustration();
$illustration->setParentResourceNode($user->getResourceNode()->getId());
$em->persist($illustration);
$this->createNodeForResource($illustration, $user, $user->getResourceNode());
} else {
$illustration = $this->repository->findOneBy(['resourceNode' => $illustrationNode]);
}
//$this->addResourceToEveryone($illustrationNode);
$file = $this->addFile($illustration, $uploadFile);
$em->flush();
@ -116,17 +115,18 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
$nodeRepo = $this->getResourceNodeRepository();
$name = $this->getResourceTypeName();
$qb = $nodeRepo->getEntityManager()->createQueryBuilder()
$qb = $nodeRepo->createQueryBuilder('n')
->select('node')
->from(ResourceNode::class, 'node')
->innerJoin('node.resourceType', 'type')
->innerJoin('node.resourceFile', 'file')
->where('node.parent = :parent')
->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)
@ -147,9 +147,9 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
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) {
$params = [

@ -3,10 +3,9 @@
{% block content %}
{% autoescape false %}
<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">
<br />
<a href="{{ url('chamilo_core_account_edit') }}" class="btn btn-primary">

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

Loading…
Cancel
Save