Minor - remove display_individual_user() move code into a controller

- user.php file deleted using controller to render user information

public/user/usernameX
pull/2715/head
Julio Montoya 8 years ago
parent 2d4f240538
commit 520cffe0d8
  1. 4
      .htaccess
  2. 1
      config/packages/sonata_page.yaml
  3. 64
      main/inc/lib/social.lib.php
  4. 69
      src/CoreBundle/Controller/User/ProfileController.php
  5. 104
      src/CoreBundle/Controller/User/UserController.php
  6. 38
      src/CoreBundle/Controller/UserController.php
  7. 144
      src/CoreBundle/Resources/views/User/profile.html.twig
  8. 46
      user.php

@ -65,10 +65,6 @@ RewriteRule ^main/newscorm/(.*)$ main/lp/$1 [QSA,L]
# service Information
RewriteRule ^service/(\d{1,})$ plugin/buycourses/src/service_information.php?service_id=$1 [L]
# This rule is very generic and should always remain at the bottom of .htaccess
# http://my.chamilo.net/jdoe to http://my.chamilo.net/user.php?jdoe
RewriteRule ^([^/.]+)/?$ user.php?$1 [L]
# Deny access
RewriteRule ^(tests|.git|.env|.env.dist|config) - [F,L,NC]

@ -38,6 +38,7 @@ sonata_page:
- ^/faq/(.*)
- ^/faq
- ^/news
- ^/user/(.*)
- ^/news/(.*)
- ^/courses/(.*)
- ^/editor/(.*)

@ -1331,70 +1331,6 @@ class SocialManager extends UserManager
return $html;
}
/**
* Displays the information of an individual user.
*
* @param int $user_id
*
* @return string
*/
public static function display_individual_user($user_id)
{
global $interbreadcrumb;
$safe_user_id = intval($user_id);
$currentUserId = api_get_user_id();
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
$result = Database::query($sql);
$html = null;
if (Database::num_rows($result) == 1) {
$user_object = Database::fetch_object($result);
$userInfo = api_get_user_info($user_id);
$alt = $userInfo['complete_name'].($currentUserId == $user_id ? ' ('.get_lang('Me').')' : '');
$status = get_status_from_code($user_object->status);
$interbreadcrumb[] = ['url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')];
$html .= '<div class ="thumbnail">';
$fullurl = $userInfo['avatar'];
$html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
if (!empty($status)) {
$html .= '<div class="caption">'.$status.'</div>';
}
$html .= '</div>';
if (api_get_setting('show_email_addresses') == 'true') {
$html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
}
if ($user_object->competences) {
$html .= Display::page_subheader(get_lang('MyCompetences'));
$html .= '<p>'.$user_object->competences.'</p>';
}
if ($user_object->diplomas) {
$html .= Display::page_subheader(get_lang('MyDiplomas'));
$html .= '<p>'.$user_object->diplomas.'</p>';
}
if ($user_object->teach) {
$html .= Display::page_subheader(get_lang('MyTeach'));
$html .= '<p>'.$user_object->teach.'</p>';
}
self::display_productions($user_object->user_id);
if ($user_object->openarea) {
$html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
$html .= '<p>'.$user_object->openarea.'</p>';
}
} else {
$html .= '<div class="actions-title">';
$html .= get_lang('UsersOnLineList');
$html .= '</div>';
}
return $html;
}
/**
* Display productions in who is online.
*

@ -1,69 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller\User;
use Chamilo\CoreBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ProfileController.
*
* @package Chamilo\CoreBundle\Controller
*/
class ProfileController extends BaseController
{
/**
* My files.
*
* @Route("/{username}/files", methods={"GET"})
*/
public function fileAction($username)
{
if ($this->getUser()->getUsername() != $username) {
return $this->abort(401);
}
$userId = \UserManager::get_user_id_from_username($username);
$userInfo = api_get_user_info($userId);
$this->getTemplate()->assign(
'driver_list',
'PersonalDriver,DropBoxDriver'
);
$editor = $this->getTemplate()->renderTemplate(
$this->getHtmlEditor()->getEditorStandAloneTemplate()
);
$this->getTemplate()->assign('user', $userInfo);
$this->getTemplate()->assign('editor', $editor);
$response = $this->getTemplate()->renderTemplate(
$this->getTemplatePath().'files.tpl'
);
return new Response($response, 200, []);
}
/**
* Gets that rm.wav sound.
*
* @Route("/{username}/sounds/{file}", methods={"GET"})
*/
public function getSoundAction()
{
$file = api_get_path(LIBRARY_PATH).'elfinder/rm.wav';
return $this->app->sendFile($file);
}
/**
* {@inheritdoc}
*/
public function getTemplatePath()
{
return 'user/';
}
}

@ -1,104 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller\User;
use Chamilo\CoreBundle\Controller\BaseController;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class UserController.
*
* @package Chamilo\CoreBundle\Controller
* @Route("/user")
*
* @author Julio Montoya <gugli100@gmail.com>
*/
class UserController extends BaseController
{
/**
* @Route("/me", methods={"GET"})
*/
public function indexAction(Request $request)
{
$userInfo = api_get_user_info($this->getUser()->getUserId());
return $this->getTemplate()->render(
$this->getTemplatePath().'me.tpl',
['user', $userInfo]
);
$response = $this->getTemplate()->renderTemplate(
$this->getTemplatePath().'me.tpl'
);
return new Response($response, 200, ['user', $userInfo]);
}
/**
* @Route("/{username}", methods={"GET"})
*
* @Template("ChamiloCoreBundle:User:profile.html.twig")
*/
public function profileAction($username)
{
$userId = \UserManager::get_user_id_from_username($username);
$userInfo = api_get_user_info($userId);
return [
'user' => $userInfo,
'form_send_message' => \MessageManager::generate_message_form(
'send_message'
),
'form_send_invitation' => \MessageManager::generate_invitation_form(
'send_invitation'
),
];
}
/**
* @Route("/me/my_courses", methods={"GET"}, options={"expose"=true})
*/
public function myCoursesAction()
{
$user = $this->getUser();
$courses = $user->getCourses();
$output = [];
/** @var CourseRelUser $courseRelUser */
foreach ($courses as $courseRelUser) {
$course = $courseRelUser->getCourse();
if ($course) {
$output[] = [
'id' => $course->getId(),
'title' => $course->getTitle(),
];
}
}
return $response = new JsonResponse(['items' => $output]);
}
/**
* @Route("/online", methods={"GET"})
*/
public function onlineAction($app)
{
$response = $app['template']->renderLayout('layout_1_col.tpl');
return new Response($response, 200, []);
}
/**
* {@inheritdoc}
*/
public function getTemplatePath()
{
return 'user/';
}
}

@ -0,0 +1,38 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller;
use Chamilo\CoreBundle\Controller\BaseController;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class UserController.
*
* @Route("/user")
*
* @author Julio Montoya <gugli100@gmail.com>
*/
class UserController extends BaseController
{
/**
* @Route("/{username}", methods={"GET"})
*
* @param string $username
*
* @Template("ChamiloCoreBundle:User:profile.html.twig")
*
* @return Response
*/
public function profileAction($username): array
{
$user = $this->container->get('fos_user.user_manager')->findUserByUsername($username);
return ['user' => $user];
}
}

@ -1,138 +1,16 @@
{% block left_column %}
<script>
function checkLength(o, n, min, max) {
if (o.val().length > max || o.val().length < min) {
o.addClass("ui-state-error");
//updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
return false;
} else {
return true;
}
}
{% extends "@ChamiloTheme/Layout/layout_one_col.html.twig" %}
function send_message_to_user(user_id) {
var subject = $("#subject_id");
var content = $("#content_id");
$("#send_message_form").show();
$("#send_message_div").dialog({
modal: true,
height: 350,
buttons: {
"{{ 'Send' | trans }}": function () {
var bValid = true;
bValid = bValid && checkLength(subject, "subject", 1, 255);
bValid = bValid && checkLength(content, "content", 1, 255);
{% block content %}
{% autoescape false %}
<h3>{{ user.username }}</h3>
{{ user.firstname }}
{{ user.lastname }}
{{ user.competences }}
{{ user.openarea }}
{{ user.teach }}
if (bValid) {
var url = "{{ url('web.ajax') }}message.ajax.php?a=send_message&user_id=" + user_id;
var params = $("#send_message_form").serialize();
$.ajax({
url: url + "&" + params,
success: function (data) {
$("#message_ajax_reponse").html(data);
$("#message_ajax_reponse").show();
$("#send_message_div").dialog({buttons: {}});
$("#send_message_form").hide();
$("#send_message_div").dialog("close");
$("#subject_id").val("");
$("#content_id").val("");
}
});
}
}
},
close: function () {
}
});
$("#send_message_div").dialog("open");
//prevent the browser to follow the link
}
function send_invitation_to_user(user_id) {
var content = $("#content_invitation_id");
$("#send_invitation_form").show();
$("#send_invitation_div").dialog({
modal: true,
buttons: {
"{{ 'SendInvitation' | trans }}": function () {
var bValid = true;
bValid = bValid && checkLength(content, "content", 1, 255);
if (bValid) {
var url = "{{ url('web.ajax') }}message.ajax.php?a=send_invitation&user_id=" + user_id;
var params = $("#send_invitation_form").serialize();
$.ajax({
url: url + "&" + params,
success: function (data) {
$("#message_ajax_reponse").html(data);
$("#message_ajax_reponse").show();
$("#send_invitation_div").dialog({buttons: {}});
$("#send_invitation_form").hide();
$("#send_invitation_div").dialog("close");
$("#content_invitation_id").val("");
}
});
}
}
},
close: function () {
}
});
$("#send_invitation_div").dialog("open");
//prevent the browser to follow the link
}
{{ user.diplomas }}
$(document).ready(function () {
$("input#id_btn_send_invitation").bind("click", function () {
if (confirm("'.trans('SendMessageInvitation', '').'")) {
$("#form_register_friend").submit();
}
});
$("#send_message_div").dialog({
autoOpen: false,
modal: false,
width: 550,
height: 300
});
$("#send_invitation_div").dialog({
autoOpen: false,
modal: false,
width: 550,
height: 300
});
});
</script>
<div class="well social-background-content">
<img src="{{ user.avatar }}"/>
</div>
<div class="well sidebar-nav">
<ul class="nav nav-pills nav-stacked">
<li>
<a href="javascript:void(0);"
onclick="javascript:send_message_to_user('{{ user.id }}');">
{{ 'SendMessage' | trans }}
</a>
</li>
<li>
<a href="javascript:void(0);"
onclick="javascript:send_invitation_to_user('{{ user.id }}');">
{{ 'SendInvitation' | trans }}
</a>
</li>
</ul>
</div>
{% endblock %}
{% block right_column %}
<span id="message_ajax_reponse"></span>
<div class="well_border">
<h3>{{ user.complete_name }} @{{ user.username }} </h3>
</div>
{{ form_send_message }}
{{ form_send_invitation }}
{% endautoescape %}
{% endblock %}

@ -1,46 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Clean URls for the Social Network.
*
* The idea is to access to the user info more easily:
* http://campus.chamilo.org/admin instead of
* http://campus.chamilo.org/main/social/profile.php?1
* To use this you should rename the htaccess to .htaccess and check your
* virtualhost configuration
*
* More improvements will come in next versions of Chamilo maybe in the 1.8.8
*
* @package chamilo.main
*/
$cidReset = true;
require_once 'main/inc/global.inc.php';
/**
* Access permissions check.
*/
//api_block_anonymous_users();
/**
* Treat URL arguments.
*/
$array_keys = array_keys($_GET);
if (empty($array_keys)) {
// we cant find your friend
header('Location: whoisonline.php');
exit;
}
$username = substr($array_keys[0], 0, 20); // max len of an username
$friend_id = UserManager::get_user_id_from_username($username);
if (!$friend_id) {
// we cant find your friend
header('Location: whoisonline.php');
exit;
}
Display::display_header(get_lang('UserInfo'));
echo SocialManager::display_individual_user($friend_id);
Display::display_footer();
Loading…
Cancel
Save