parent
							
								
									cb303ddc8e
								
							
						
					
					
						commit
						23f82bc5b8
					
				@ -0,0 +1,58 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\PluginBundle\MigrationMoodle\Loader; | 
				
			||||
 | 
				
			||||
use Chamilo\CourseBundle\Entity\CLpItemView; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Class UserLearnPathsSectionsLoader. | 
				
			||||
 * | 
				
			||||
 * @package Chamilo\PluginBundle\MigrationMoodle\Loader | 
				
			||||
 */ | 
				
			||||
class UserLearnPathsSectionsLoader implements LoaderInterface | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @inheritDoc | 
				
			||||
     */ | 
				
			||||
    public function load(array $incomingData) | 
				
			||||
    { | 
				
			||||
        $em = \Database::getManager(); | 
				
			||||
 | 
				
			||||
        $lpViewRepo = $em->getRepository('ChamiloCourseBundle:CLpView'); | 
				
			||||
        $lpItemViewRepo = $em->getRepository('ChamiloCourseBundle:CLpItemView'); | 
				
			||||
 | 
				
			||||
        $lpView = $lpViewRepo->findOneBy(['userId' => $incomingData['user_id'], 'lpId' => $incomingData['lp_id']]); | 
				
			||||
 | 
				
			||||
        if (empty($lpView)) { | 
				
			||||
            throw new \Exception( | 
				
			||||
                "LP view not found for user ({$incomingData['user_id']}) and LP ({$incomingData['lp_id']})" | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        /** @var CLpItemView $lpItemView */ | 
				
			||||
        $lpItemView = $lpItemViewRepo->findOneBy( | 
				
			||||
            [ | 
				
			||||
                'lpViewId' => $lpView->getId(), | 
				
			||||
                'lpItemId' => $incomingData['item_id'] | 
				
			||||
            ] | 
				
			||||
        ); | 
				
			||||
 | 
				
			||||
        if (empty($lpItemView)) { | 
				
			||||
            throw new \Exception( | 
				
			||||
                "LP item view not found for view ({$lpView->getId()}) and item ({$incomingData['item_id']})" | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        $lpItemView | 
				
			||||
            ->setMaxScore('100') | 
				
			||||
            ->setStartTime($incomingData['start_time']) | 
				
			||||
            ->setTotalTime($incomingData['total_time']); | 
				
			||||
 | 
				
			||||
        $em->persist($lpItemView); | 
				
			||||
        $em->flush(); | 
				
			||||
 | 
				
			||||
        return $lpItemView->getId(); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,69 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Chamilo\PluginBundle\MigrationMoodle\Task; | 
				
			||||
 | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Extractor\UserExtractor; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Loader\UserLearnPathsSectionsLoader; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\BaseTransformer; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseModuleLessonLookup; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedCourseSectionFromLessonLookup; | 
				
			||||
use Chamilo\PluginBundle\MigrationMoodle\Transformer\Property\LoadedUserLookup; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Class UsersLearnPathsSectionsTask. | 
				
			||||
 * | 
				
			||||
 * Update lp item (dirs) view. | 
				
			||||
 * | 
				
			||||
 * @package Chamilo\PluginBundle\MigrationMoodle\Task | 
				
			||||
 */ | 
				
			||||
class UsersLearnPathsSectionsTask extends BaseTask | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @inheritDoc | 
				
			||||
     */ | 
				
			||||
    public function getExtractConfiguration() | 
				
			||||
    { | 
				
			||||
        return [ | 
				
			||||
            'class' => UserExtractor::class, | 
				
			||||
            'query' => "SELECT id, lessonid, userid, starttime, lessontime - starttime AS total_time | 
				
			||||
                FROM mdl_lesson_timer", | 
				
			||||
        ]; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @inheritDoc | 
				
			||||
     */ | 
				
			||||
    public function getTransformConfiguration() | 
				
			||||
    { | 
				
			||||
        return [ | 
				
			||||
            'class' => BaseTransformer::class, | 
				
			||||
            'map' => [ | 
				
			||||
                'user_id' => [ | 
				
			||||
                    'class' => LoadedUserLookup::class, | 
				
			||||
                    'properties' => ['userid'], | 
				
			||||
                ], | 
				
			||||
                'item_id' => [ | 
				
			||||
                    'class' => LoadedCourseModuleLessonLookup::class, | 
				
			||||
                    'properties' => ['lessonid'] | 
				
			||||
                ], | 
				
			||||
                'start_time' => 'starttime', | 
				
			||||
                'total_time' => 'total_time', | 
				
			||||
                'lp_id' => [ | 
				
			||||
                    'class' => LoadedCourseSectionFromLessonLookup::class, | 
				
			||||
                    'properties' => ['lessonid'], | 
				
			||||
                ], | 
				
			||||
            ], | 
				
			||||
        ]; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @inheritDoc | 
				
			||||
     */ | 
				
			||||
    public function getLoadConfiguration() | 
				
			||||
    { | 
				
			||||
        return [ | 
				
			||||
            'class' => UserLearnPathsSectionsLoader::class, | 
				
			||||
        ]; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue