Browse Source

Minor - adding commented code, format code

Julio Montoya 11 years ago
parent
commit
6c5e3da9a9

+ 3 - 1
main/inc/Entity/Repository/UserRepository.php

@@ -32,6 +32,7 @@ class UserRepository extends EntityRepository implements UserProviderInterface
 
         try {
             $user = $q->getSingleResult();
+            // api_format_user_from_obj($user);
         } catch (NoResultException $e) {
             throw new UsernameNotFoundException(
                 sprintf('Unable to find an active admin User identified by "%s".', $username),
@@ -49,11 +50,12 @@ class UserRepository extends EntityRepository implements UserProviderInterface
      */
     public function refreshUser(UserInterface $user)
     {
+        return $user;
+
         $class = get_class($user);
         if (!$this->supportsClass($class)) {
             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
         }
-
         return $this->loadUserByUsername($user->getUsername());
     }
 

+ 23 - 11
main/inc/lib/api.lib.php

@@ -1195,6 +1195,12 @@ function api_get_user_courses($userid, $fetch_session = true) {
     return $courses;
 }
 
+function api_format_user_from_obj($user)
+{
+    $user = (array) $user;
+    //$user = api_format_user($user);
+    //Session::write($user);
+}
 /**
  * Formats user information into a standard array
  * This function should be only used inside api_get_user_info()
@@ -1269,18 +1275,24 @@ function api_format_user($user, $add_password = false) {
     $result['theme']            = $user['theme'];
     $result['language']         = $user['language'];
 
-    if (!isset($user['lastLogin']) && !isset($user['last_login'])) {
-        $timestamp = Tracking::get_last_connection_date($result['user_id'], false, true);
-        // Convert the timestamp back into a datetime
-        // NOTE: this timestamp has ALREADY been converted to the local timezone in the get_last_connection_date function
-        $last_login = date('Y-m-d H:i:s', $timestamp);
-    } else {
-        if (isset($user['lastLogin'])) {
-            $last_login = $user['lastLogin'];
+    if (!empty($result['user_id'])) {
+
+        if (!isset($user['lastLogin']) && !isset($user['last_login'])) {
+            $timestamp = Tracking::get_last_connection_date($result['user_id'], false, true);
+            // Convert the timestamp back into a datetime
+            // NOTE: this timestamp has ALREADY been converted to the local timezone in the get_last_connection_date function
+            $last_login = date('Y-m-d H:i:s', $timestamp);
         } else {
-            $last_login = $user['last_login'];
+            if (isset($user['lastLogin'])) {
+                $last_login = $user['lastLogin'];
+            } else {
+                $last_login = $user['last_login'];
+            }
         }
+    } else {
+        $last_login = api_get_utc_datetime();
     }
+
     $result['last_login'] = $last_login;
     // Kept for historical reasons
     $result['lastLogin'] = $last_login;
@@ -2246,7 +2258,8 @@ function api_get_self() {
  * @see usermanager::is_admin(user_id) for a user-id specific function
  */
 function api_is_platform_admin($allow_sessions_admins = false) {
-    if (isset($_SESSION['is_platformAdmin']) && $_SESSION['is_platformAdmin']) {
+    $isAdmin = Session::read('is_platformAdmin');
+    if ($isAdmin) {
         return true;
     }
     $_user = api_get_user_info();
@@ -3029,7 +3042,6 @@ function api_not_allowed($print_headers = false, $message = null) {
     $app['template']->assign('content', $msg);
     $app['allowed'] = true;
 
-
     if (($user_id!=0 && !api_is_anonymous()) && (!isset($course) || $course == -1) && empty($_GET['cidReq'])) {
         // if the access is not authorized and there is some login information
         // but the cidReq is not found, assume we are missing course data and send the user

+ 1 - 1
src/ChamiloLMS/Controller/LegacyController.php

@@ -75,6 +75,7 @@ class LegacyController extends CommonController
         }
 
         $mainPath = $app['paths']['sys_root'].'main/';
+
         if (is_file($mainPath.$file)) {
 
             // Default values
@@ -93,7 +94,6 @@ class LegacyController extends CommonController
             $out = ob_get_contents();
             ob_end_clean();
 
-            //var_dump($htmlHeadXtra);
             if (isset($htmlHeadXtra)) {
                 $app['template']->addJsFiles($htmlHeadXtra);
             }