Browse Source

Fix duration field in the DB

Julio 9 years ago
parent
commit
8b97be2b56

+ 2 - 10
app/Migrations/Schema/V110/Version20151101082300.php

@@ -312,7 +312,8 @@ class Version20151101082300 extends AbstractMigrationChamilo
         $sessionRelUser->addColumn('moved_to', Type::INTEGER)->setNotnull(false);
         $sessionRelUser->addColumn('moved_status', Type::INTEGER)->setNotnull(false);
         $sessionRelUser->addColumn('moved_at', Type::DATETIME)->setNotnull(false);
-        $sessionRelUser->dropColumn('duration');
+        $sessionRelUser->addColumn('duration', Type::INTEGER)->setNotnull(false);
+
         $sessionRelUser->addIndex(['session_id']);
         $sessionRelUser->addIndex(['user_id']);
         $sessionRelUser->addIndex(['user_id', 'moved_to']);
@@ -327,9 +328,7 @@ class Version20151101082300 extends AbstractMigrationChamilo
         $settingsCurrent->addUniqueIndex(['variable', 'value']);
 
         $schema->getTable('track_e_access')->addIndex(['c_id']);
-
         $schema->getTable('track_e_attempt')->addIndex(['c_id']);
-
         $schema->getTable('track_e_course_access')->addIndex(['c_id']);
 
         $trackEDefault = $schema->getTable('track_e_default');
@@ -337,19 +336,12 @@ class Version20151101082300 extends AbstractMigrationChamilo
         $trackEDefault->addIndex(['session_id']);
 
         $schema->getTable('track_e_downloads')->addIndex(['c_id']);
-
         $schema->getTable('track_e_exercises')->addIndex(['c_id']);
-
         $schema->getTable('track_e_hotpotatoes')->addIndex(['c_id']);
-
         $schema->getTable('track_e_lastaccess')->addIndex(['c_id']);
-
         $schema->getTable('track_e_links')->addIndex(['c_id']);
-
         $schema->getTable('track_e_online')->addIndex(['c_id']);
-
         $schema->getTable('track_e_uploads')->addIndex(['c_id']);
-
         $schema->getTable('user')->addUniqueIndex(['username_canonical']);
 
         $usergroupRelUSer = $schema->getTable('usergroup_rel_user');

+ 10 - 4
main/session/session_user_edit.php

@@ -12,12 +12,14 @@ $userId = isset($_GET['user_id']) ? $_GET['user_id'] : null;
 SessionManager::protectSession($sessionId);
 
 $sessionInfo = api_get_session_info($sessionId);
+
 if (empty($sessionInfo)) {
     api_not_allowed(true);
 }
 
 if (!isset($sessionInfo['duration']) ||
-    isset($sessionInfo['duration']) && empty($sessionInfo['duration'])) {
+    (isset($sessionInfo['duration']) && empty($sessionInfo['duration']))
+) {
     api_not_allowed(true);
 }
 
@@ -25,9 +27,12 @@ if (empty($sessionId) || empty($userId)) {
     api_not_allowed(true);
 }
 
-//$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+
 $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
-$interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$sessionId, "name" => get_lang('SessionOverview'));
+$interbreadcrumb[] = array(
+    'url' => "resume_session.php?id_session=".$sessionId,
+    "name" => get_lang('SessionOverview')
+);
 
 $form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId);
 $form->addHeader(get_lang('EditUserSessionDuration'));
@@ -39,6 +44,7 @@ $userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser(
     $sessionId,
     $userId
 );
+
 if (count($userAccess) == 0) {
     // User never accessed the session. End date is still open
     $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
@@ -54,7 +60,7 @@ if (count($userAccess) == 0) {
     if ($days > 0) {
         $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days);
     } else {
-        $endDateInSeconds = $firstAccess + $duration*24*60*60;
+        $endDateInSeconds = $firstAccess + $duration * 24*60*60;
         $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT);
         $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last);
     }

+ 26 - 0
src/Chamilo/CoreBundle/Entity/SessionRelUser.php

@@ -47,6 +47,13 @@ class SessionRelUser
      */
     private $relationType;
 
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="duration", type="integer", nullable=true)
+     */
+    private $duration;
+
     /**
      * @var integer
      *
@@ -267,4 +274,23 @@ class SessionRelUser
         return $this->registeredAt;
     }
 
+    /**
+     * @return int
+     */
+    public function getDuration()
+    {
+        return $this->duration;
+    }
+
+    /**
+     * @param int $duration
+     * @return SessionRelUser
+     */
+    public function setDuration($duration)
+    {
+        $this->duration = $duration;
+
+        return $this;
+    }
+
 }