parent
145553110e
commit
2ce394daa3
@ -0,0 +1,66 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; |
||||
|
||||
/** |
||||
* Class TrackCourseAccessLoader. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Loader |
||||
*/ |
||||
class TrackCourseAccessLoader implements LoaderInterface |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function load(array $incomingData) |
||||
{ |
||||
list($userId, $cId, $loginCourseDate, $ip, $sessionId) = array_values($incomingData); |
||||
|
||||
$sessionLifetime = api_get_configuration_value('session_lifetime'); |
||||
|
||||
/** @var \DateTime $time */ |
||||
$time = clone $loginCourseDate; |
||||
$time->modify("-$sessionLifetime seconds"); |
||||
|
||||
$time = $time->format('Y-m-d H:i:s'); |
||||
$loginCourseDate = $loginCourseDate->format('Y-m-d H:i:s'); |
||||
|
||||
$tableCourseAccess = \Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); |
||||
|
||||
$result = \Database::query( |
||||
"SELECT course_access_id |
||||
FROM $tableCourseAccess |
||||
WHERE user_id = $userId AND c_id = $cId AND session_id = $sessionId AND login_course_date > '$time' |
||||
ORDER BY login_course_date DESC |
||||
LIMIT 1" |
||||
); |
||||
|
||||
if (\Database::num_rows($result) > 0) { |
||||
$row = \Database::fetch_assoc($result); |
||||
|
||||
\Database::query( |
||||
"UPDATE $tableCourseAccess |
||||
SET logout_course_date = '$loginCourseDate', counter = counter + 1 |
||||
WHERE course_access_id = {$row['course_access_id']}" |
||||
); |
||||
|
||||
return $row['course_access_id']; |
||||
} |
||||
|
||||
return \Database::insert( |
||||
$tableCourseAccess, |
||||
[ |
||||
'c_id' => $cId, |
||||
'user_ip' => $ip, |
||||
'user_id' => $userId, |
||||
'login_course_date' => $loginCourseDate, |
||||
'logout_course_date' => $loginCourseDate, |
||||
'counter' => 1, |
||||
'session_id' => $sessionId, |
||||
] |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,86 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; |
||||
|
||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\LoadedUsersFilterExtractor; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\TrackCourseAccessLoader; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\DateTimeObject; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedUserLookup; |
||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedUserSessionLookup; |
||||
|
||||
/** |
||||
* Class TrackCourseAccessTask. |
||||
* |
||||
* @package Chamilo\PluginBundle\MigrationMoodle\Task |
||||
*/ |
||||
class TrackCourseAccessTask extends BaseTask |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getExtractConfiguration() |
||||
{ |
||||
$query = "SELECT id, userid, courseid, timecreated, ip |
||||
FROM mdl_logstore_standard_log |
||||
WHERE (userid IS NOT NULL AND userid != 0) AND (courseid IS NOT NULL AND courseid != 0) |
||||
ORDER BY timecreated"; |
||||
|
||||
$userFilter = $this->plugin->getUserFilterSetting(); |
||||
|
||||
if (!empty($userFilter)) { |
||||
$query = "SELECT lsl.id, lsl.userid, lsl.courseid, lsl.timecreated, lsl.ip |
||||
FROM mdl_logstore_standard_log lsl |
||||
INNER JOIN mdl_user u ON lsl.userid = u.id |
||||
WHERE (lsl.courseid IS NOT NULL AND lsl.courseid != 0) |
||||
AND u.username LIKE '$userFilter%' |
||||
ORDER BY lsl.timecreated"; |
||||
} |
||||
|
||||
return [ |
||||
'class' => LoadedUsersFilterExtractor::class, |
||||
'query' => $query, |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getTransformConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => BaseTransformer::class, |
||||
'map' => [ |
||||
'user_id' => [ |
||||
'class' => LoadedUserLookup::class, |
||||
'properties' => ['userid'], |
||||
], |
||||
'c_id' => [ |
||||
'class' => LoadedCourseLookup::class, |
||||
'properties' => ['courseid'], |
||||
], |
||||
'login_course_date' => [ |
||||
'class' => DateTimeObject::class, |
||||
'properties' => ['timecreated'], |
||||
], |
||||
'ip' => 'ip', |
||||
'session_id' => [ |
||||
'class' => LoadedUserSessionLookup::class, |
||||
'properties' => ['userid'], |
||||
], |
||||
], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getLoadConfiguration() |
||||
{ |
||||
return [ |
||||
'class' => TrackCourseAccessLoader::class, |
||||
]; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue