idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
53,300
|
public function serialize ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ logo = $ this -> fileUtilities -> getOneBy ( [ 'url' => $ this -> config -> getParameter ( 'logo' ) , ] ) ; return [ 'maintenance' => MaintenanceHandler :: isMaintenanceEnabled ( ) , 'logo' => $ logo ? [ 'url' => $ logo -> getUrl ( ) , 'colorized' => 'image/svg+xml' === $ logo -> getMimeType ( ) , ] : null , 'logo_redirect_home' => $ this -> config -> getParameter ( 'logo_redirect_home' ) , 'name' => $ this -> config -> getParameter ( 'name' ) , 'secondaryName' => $ this -> config -> getParameter ( 'secondary_name' ) , 'description' => null , 'version' => $ this -> versionManager -> getDistributionVersion ( ) , 'environment' => $ this -> env , 'links' => $ this -> serializeLinks ( ) , 'asset' => $ this -> assets -> getUrl ( '' ) , 'server' => [ 'protocol' => $ request -> isSecure ( ) || $ this -> config -> getParameter ( 'ssl_enabled' ) ? 'https' : 'http' , 'host' => $ this -> config -> getParameter ( 'domain_name' ) ? $ this -> config -> getParameter ( 'domain_name' ) : $ request -> getHost ( ) , 'path' => $ request -> getBasePath ( ) , ] , 'theme' => $ this -> serializeTheme ( ) , 'locale' => $ this -> serializeLocale ( ) , 'openGraph' => [ 'enabled' => $ this -> config -> getParameter ( 'enable_opengraph' ) , ] , 'resources' => [ 'types' => array_map ( function ( ResourceType $ resourceType ) { return $ this -> resourceTypeSerializer -> serialize ( $ resourceType ) ; } , $ this -> om -> getRepository ( 'ClarolineCoreBundle:Resource\ResourceType' ) -> findAll ( ) ) , 'softDelete' => $ this -> config -> getParameter ( 'resource.soft_delete' ) , ] , 'plugins' => $ this -> pluginManager -> getEnabled ( true ) , 'javascripts' => $ this -> config -> getParameter ( 'javascripts' ) , ] ; }
|
Serializes required information for FrontEnd rendering .
|
53,301
|
public function getHTMLFiles ( $ directory ) { try { $ dir = new RecursiveDirectoryIterator ( $ directory , RecursiveDirectoryIterator :: SKIP_DOTS | RecursiveDirectoryIterator :: NEW_CURRENT_AND_KEY ) ; $ files = new \ RecursiveIteratorIterator ( $ dir ) ; $ allowedExtensions = [ 'htm' , 'html' ] ; $ list = [ ] ; foreach ( $ files as $ file ) { if ( in_array ( $ file -> getExtension ( ) , $ allowedExtensions ) ) { $ relativePath = str_replace ( $ directory , '' , $ file -> getPathname ( ) ) ; $ list [ ] = ltrim ( $ relativePath , '\\/' ) ; } } return $ list ; } catch ( \ Exception $ e ) { return [ ] ; } }
|
Get all HTML files from a zip archive .
|
53,302
|
public function guessRootFile ( UploadedFile $ file , Workspace $ workspace ) { $ zipPath = $ this -> container -> getParameter ( 'claroline.param.uploads_directory' ) . DIRECTORY_SEPARATOR . 'webresource' . DIRECTORY_SEPARATOR . $ workspace -> getUuid ( ) . DIRECTORY_SEPARATOR ; if ( ! $ this -> getZip ( ) -> open ( $ file ) ) { throw new \ Exception ( 'Can not open archive file.' ) ; } foreach ( $ this -> defaultIndexFiles as $ html ) { if ( is_numeric ( $ this -> getZip ( ) -> locateName ( $ html ) ) ) { return $ html ; } } $ tmpDir = $ zipPath . 'tmp/' ; if ( ! $ tmpDir ) { mkdir ( $ zipPath . 'tmp/' , 0777 , true ) ; } $ this -> getZip ( ) -> extractTo ( $ tmpDir ) ; $ this -> getZip ( ) -> close ( ) ; $ htmlFiles = $ this -> getHTMLFiles ( $ tmpDir ) ; $ this -> unzipDelete ( $ tmpDir ) ; if ( 1 === count ( $ htmlFiles ) ) { return array_shift ( $ htmlFiles ) ; } return ; }
|
Try to retrieve root file of the WebResource from the zip archive .
|
53,303
|
public function guessRootFileFromUnzipped ( $ hash ) { $ htmlFiles = $ this -> getHTMLFiles ( $ hash ) ; if ( 1 === count ( $ htmlFiles ) ) { return array_shift ( $ htmlFiles ) ; } foreach ( $ this -> defaultIndexFiles as $ file ) { if ( in_array ( $ file , $ htmlFiles ) ) { return $ file ; } } return ; }
|
Try to retrieve root file of the WebResource from the unzipped directory .
|
53,304
|
public function isZip ( UploadedFile $ file , $ workspace ) { $ isZip = false ; if ( 'application/zip' === $ file -> getClientMimeType ( ) || true === $ this -> getZip ( ) -> open ( $ file ) ) { $ rootFile = $ this -> guessRootFile ( $ file , $ workspace ) ; if ( ! empty ( $ rootFile ) ) { $ isZip = true ; } } return $ isZip ; }
|
Checks if a UploadedFile is a zip and contains index . html file .
|
53,305
|
public function unzip ( $ hash , Workspace $ workspace ) { $ filesPath = $ this -> container -> getParameter ( 'claroline.param.files_directory' ) . DIRECTORY_SEPARATOR . 'webresource' . DIRECTORY_SEPARATOR . $ workspace -> getUuid ( ) . DIRECTORY_SEPARATOR ; $ zipPath = $ this -> container -> getParameter ( 'claroline.param.uploads_directory' ) . DIRECTORY_SEPARATOR . 'webresource' . DIRECTORY_SEPARATOR . $ workspace -> getUuid ( ) . DIRECTORY_SEPARATOR ; if ( ! file_exists ( $ zipPath . $ hash ) ) { mkdir ( $ zipPath . $ hash , 0777 , true ) ; } $ this -> getZip ( ) -> open ( $ filesPath . $ hash ) ; $ this -> getZip ( ) -> extractTo ( $ zipPath . $ hash ) ; $ this -> getZip ( ) -> close ( ) ; }
|
Unzips files in web directory .
|
53,306
|
public function findByUserAndCompetencyIds ( User $ user , array $ competencyIds ) { if ( 0 === count ( $ competencyIds ) ) { return [ ] ; } return $ this -> createQueryBuilder ( 'p' ) -> select ( 'p' , 'c' ) -> join ( 'p.competency' , 'c' ) -> where ( 'p.user = :user' ) -> andWhere ( ( new Expr ( ) ) -> in ( 'p.competency' , $ competencyIds ) ) -> setParameter ( ':user' , $ user ) -> getQuery ( ) -> getResult ( ) ; }
|
Returns every competency progress entity related to a given user and whose id is in a given set .
|
53,307
|
public function removeUsedHint ( $ hintId ) { $ pos = array_search ( $ hintId , $ this -> usedHints ) ; if ( false !== $ pos ) { array_splice ( $ this -> usedHints , $ pos , 1 ) ; } }
|
Removes an Hint .
|
53,308
|
public function onLoad ( LoadResourceEvent $ event ) { $ lesson = $ event -> getResource ( ) ; $ firstChapter = $ this -> chapterRepository -> getFirstChapter ( $ lesson ) ; $ root = $ this -> chapterRepository -> findOneBy ( [ 'lesson' => $ lesson , 'level' => 0 , 'parent' => null ] ) ; $ event -> setData ( [ 'exportPdfEnabled' => $ this -> config -> getParameter ( 'is_pdf_export_active' ) , 'lesson' => $ this -> serializer -> serialize ( $ lesson ) , 'tree' => $ this -> chapterManager -> serializeChapterTree ( $ lesson ) , 'chapter' => $ firstChapter ? $ this -> serializer -> serialize ( $ firstChapter ) : null , 'root' => $ root ? $ this -> serializer -> serialize ( $ root ) : null , ] ) ; $ event -> stopPropagation ( ) ; }
|
Loads a lesson .
|
53,309
|
public function indexAction ( ) { $ this -> checkAccess ( ) ; $ allowWorkspace = $ this -> configHandler -> getParameter ( 'allow_workspace_at_registration' ) ; $ data = [ 'facets' => $ this -> profileSerializer -> serialize ( [ Options :: REGISTRATION ] ) , 'termOfService' => $ this -> configHandler -> getParameter ( 'terms_of_service' ) ? $ this -> tosManager -> getTermsOfService ( ) : null , 'options' => [ 'autoLog' => $ this -> configHandler -> getParameter ( 'auto_logging' ) , 'localeLanguage' => $ this -> configHandler -> getParameter ( 'locale_language' ) , 'defaultRole' => $ this -> configHandler -> getParameter ( 'default_role' ) , 'redirectAfterLoginOption' => $ this -> configHandler -> getParameter ( 'redirect_after_login_option' ) , 'redirectAfterLoginUrl' => $ this -> configHandler -> getParameter ( 'redirect_after_login_url' ) , 'userNameRegex' => $ this -> configHandler -> getParameter ( 'username_regex' ) , 'forceOrganizationCreation' => $ this -> configHandler -> getParameter ( 'force_organization_creation' ) , 'allowWorkspace' => $ allowWorkspace , ] , ] ; return $ data ; }
|
Displays the user self - registration form .
|
53,310
|
public function writeMigrationClass ( Bundle $ bundle , $ driverName , $ version , array $ queries ) { if ( ! $ this -> hasSqlExtension ) { $ this -> twigEnvironment -> addExtension ( new SqlFormatterExtension ( ) ) ; $ this -> hasSqlExtension = true ; } $ targetDir = "{$bundle->getPath()}/Migrations/{$driverName}" ; $ class = "Version{$version}" ; $ namespace = "{$bundle->getNamespace()}\\Migrations\\{$driverName}" ; $ classFile = "{$targetDir}/{$class}.php" ; if ( ! $ this -> fileSystem -> exists ( $ targetDir ) ) { $ this -> fileSystem -> mkdir ( $ targetDir ) ; } $ content = $ this -> twigEngine -> render ( 'ClarolineMigrationBundle::migration_class.html.twig' , array ( 'namespace' => $ namespace , 'class' => $ class , 'upQueries' => $ queries [ Generator :: QUERIES_UP ] , 'downQueries' => $ queries [ Generator :: QUERIES_DOWN ] , ) ) ; $ this -> fileSystem -> touch ( $ classFile ) ; file_put_contents ( $ classFile , $ content ) ; }
|
Writes a bundle migration class for a given driver .
|
53,311
|
public function deleteUpperMigrationClasses ( Bundle $ bundle , $ driverName , $ referenceVersion ) { $ migrations = new \ DirectoryIterator ( "{$bundle->getPath()}/Migrations/{$driverName}" ) ; $ deletedVersions = array ( ) ; foreach ( $ migrations as $ migration ) { if ( preg_match ( '#Version(\d+)\.php#' , $ migration -> getFilename ( ) , $ matches ) ) { if ( $ matches [ 1 ] > $ referenceVersion ) { $ this -> fileSystem -> remove ( array ( $ migration -> getPathname ( ) ) ) ; $ deletedVersions [ ] = $ migration -> getFilename ( ) ; } } } return $ deletedVersions ; }
|
Deletes bundle migration classes for a given driver which are above a reference version .
|
53,312
|
public function addUsersToGroup ( Group $ group , array $ users ) { $ addedUsers = [ ] ; if ( ! $ this -> validateAddUsersToGroup ( $ users , $ group ) ) { throw new Exception \ AddRoleException ( ) ; } foreach ( $ users as $ user ) { if ( ! $ group -> containsUser ( $ user ) ) { $ addedUsers [ ] = $ user ; $ group -> addUser ( $ user ) ; $ this -> eventDispatcher -> dispatch ( 'log' , 'Log\LogGroupAddUser' , [ $ group , $ user ] ) ; } } $ this -> om -> persist ( $ group ) ; $ this -> om -> flush ( ) ; return $ addedUsers ; }
|
Adds an array of user to a group .
|
53,313
|
public function setPlatformRoles ( Group $ group , $ roles ) { foreach ( $ group -> getPlatformRoles ( ) as $ role ) { $ group -> removeRole ( $ role ) ; } $ this -> om -> persist ( $ group ) ; $ this -> roleManager -> associateRoles ( $ group , $ roles ) ; $ this -> om -> flush ( ) ; }
|
Sets an array of platform role to a group .
|
53,314
|
public function getCsvAnswers ( AbstractItem $ item , Answer $ answer ) { $ data = json_decode ( $ answer -> getData ( ) , true ) ; $ answers = [ ] ; foreach ( $ item -> getChoices ( ) as $ choice ) { if ( is_array ( $ data ) && in_array ( $ choice -> getUuid ( ) , $ data ) ) { $ answers [ ] = $ choice -> getData ( ) ; } } $ compressor = new ArrayCompressor ( ) ; return [ $ compressor -> compress ( $ answers ) ] ; }
|
Exports choice answers .
|
53,315
|
public function update ( Theme $ theme , array $ data ) { $ errors = $ this -> validate ( $ data ) ; if ( count ( $ errors ) > 0 ) { throw new InvalidDataException ( 'Theme is not valid' , $ errors ) ; } $ this -> serializer -> deserialize ( $ data , $ theme ) ; $ this -> om -> persist ( $ theme ) ; $ this -> om -> flush ( ) ; return $ theme ; }
|
Updates an existing theme .
|
53,316
|
public function deleteBulk ( array $ themes , User $ user ) { $ toDelete = $ this -> repository -> findByUuids ( $ themes ) ; $ this -> om -> startFlushSuite ( ) ; foreach ( $ toDelete as $ theme ) { $ this -> delete ( $ theme , $ user , true ) ; } $ this -> om -> endFlushSuite ( ) ; }
|
Deletes a Theme . It s only possible if the User owns it .
|
53,317
|
public function all ( $ onlyEnabled = false ) { $ themes = $ this -> repository -> findAll ( ) ; if ( $ onlyEnabled ) { $ themes = array_filter ( $ themes , function ( $ theme ) { return $ theme -> isEnabled ( ) ; } ) ; $ pm = $ this -> pm ; $ themes = array_filter ( $ themes , function ( $ theme ) use ( $ pm ) { return $ pm -> isLoaded ( $ theme -> getPlugin ( ) ) ; } ) ; } return $ themes ; }
|
Lists all themes installed in the current platform .
|
53,318
|
public function addDefinition ( ItemDefinitionInterface $ definition ) { if ( ! is_string ( $ definition -> getMimeType ( ) ) ) { throw UnregisterableDefinitionException :: notAStringMimeType ( $ definition ) ; } if ( ! in_array ( $ definition -> getMimeType ( ) , ItemType :: getList ( ) ) ) { throw UnregisterableDefinitionException :: unsupportedMimeType ( $ definition ) ; } if ( $ this -> has ( $ definition -> getMimeType ( ) ) ) { throw UnregisterableDefinitionException :: duplicateMimeType ( $ definition ) ; } $ this -> definitions [ $ definition -> getMimeType ( ) ] = $ definition ; }
|
Adds a item definition to the collection .
|
53,319
|
public function addContentItemDefinition ( ContentItemDefinition $ definition ) { if ( ! is_string ( $ definition -> getMimeType ( ) ) ) { throw UnregisterableDefinitionException :: notAStringMimeType ( $ definition ) ; } if ( ! in_array ( $ definition -> getMimeType ( ) , ItemType :: getList ( ) ) ) { throw UnregisterableDefinitionException :: unsupportedMimeType ( $ definition ) ; } if ( $ this -> has ( $ definition -> getMimeType ( ) ) ) { throw UnregisterableDefinitionException :: duplicateMimeType ( $ definition ) ; } $ this -> definitions [ $ definition -> getMimeType ( ) ] = $ definition ; }
|
Adds a content item definition to the collection .
|
53,320
|
public function get ( $ type ) { if ( isset ( $ this -> definitions [ $ type ] ) ) { return $ this -> definitions [ $ type ] ; } throw new UnregisteredDefinitionException ( $ type , UnregisteredDefinitionException :: TARGET_MIME_TYPE ) ; }
|
Returns the definition for a specific MIME type if any .
|
53,321
|
public function getConvertedType ( $ mimeType ) { $ type = $ mimeType ; if ( 1 !== preg_match ( '#^application\/x\.[^/]+\+json$#' , $ mimeType ) && 1 === preg_match ( '#^[^/]+\/[^/]+$#' , $ mimeType ) ) { $ type = 'content' ; } return $ type ; }
|
Converts mime - type to a supported format .
|
53,322
|
public function openResourceAction ( $ node ) { $ resourceNode = $ this -> container -> get ( 'claroline.persistence.object_manager' ) -> find ( ResourceNode :: class , $ node ) ; return $ this -> redirectToRoute ( 'claro_resource_show' , [ 'id' => $ resourceNode -> getUuid ( ) , 'type' => $ resourceNode -> getResourceType ( ) -> getId ( ) , ] ) ; }
|
Renders a resource application . Used for old links compatibility .
|
53,323
|
public function listAction ( Exercise $ exercise , User $ user , Request $ request ) { $ this -> assertHasPermission ( 'OPEN' , $ exercise ) ; $ params = $ request -> query -> all ( ) ; $ params [ 'hiddenFilters' ] = [ ] ; $ params [ 'hiddenFilters' ] [ 'exercise' ] = $ exercise -> getId ( ) ; $ serializationOptions = [ ] ; $ collection = new ResourceCollection ( [ $ exercise -> getResourceNode ( ) ] ) ; if ( ! $ this -> authorization -> isGranted ( 'ADMINISTRATE' , $ collection ) && ! $ this -> authorization -> isGranted ( 'MANAGE_PAPERS' , $ collection ) ) { $ params [ 'hiddenFilters' ] [ 'user' ] = $ user -> getId ( ) ; } elseif ( ShowScoreAt :: NEVER !== $ exercise -> getMarkMode ( ) ) { $ serializationOptions [ ] = Transfer :: INCLUDE_USER_SCORE ; } return new JsonResponse ( $ this -> finder -> search ( Paper :: class , $ params , $ serializationOptions ) ) ; }
|
Returns all the papers associated with an exercise . Administrators get the papers of all users others get only theirs .
|
53,324
|
public function getAction ( Exercise $ exercise , Paper $ paper , User $ user ) { $ this -> assertHasPermission ( 'OPEN' , $ exercise ) ; if ( ! $ this -> isAdmin ( $ paper -> getExercise ( ) ) && $ paper -> getUser ( ) !== $ user ) { throw new AccessDeniedException ( ) ; } return new JsonResponse ( $ this -> paperManager -> serialize ( $ paper ) ) ; }
|
Returns one paper . Also includes the complete definition and solution of each question associated with the exercise .
|
53,325
|
public function deleteAction ( Paper $ paper ) { $ this -> assertHasPermission ( 'MANAGE_PAPERS' , $ paper -> getExercise ( ) ) ; try { $ this -> paperManager -> delete ( $ paper ) ; } catch ( InvalidDataException $ e ) { return new JsonResponse ( $ e -> getErrors ( ) , 422 ) ; } return new JsonResponse ( null , 204 ) ; }
|
Deletes a paper from an exercise .
|
53,326
|
public function exportCsvAction ( Exercise $ exercise ) { $ this -> assertHasPermission ( 'MANAGE_PAPERS' , $ exercise ) ; return new StreamedResponse ( function ( ) use ( $ exercise ) { $ this -> exerciseManager -> exportPapersToCsv ( $ exercise ) ; } , 200 , [ 'Content-Type' => 'application/force-download' , 'Content-Disposition' => 'attachment; filename="export.csv"' , ] ) ; }
|
Exports papers into a CSV file .
|
53,327
|
public function exportJsonAction ( Exercise $ exercise ) { if ( ! $ this -> isAdmin ( $ exercise ) ) { throw new AccessDeniedException ( ) ; } $ response = new StreamedResponse ( function ( ) use ( $ exercise ) { $ data = $ this -> paperManager -> serializeExercisePapers ( $ exercise ) ; $ handle = fopen ( 'php://output' , 'w+' ) ; fwrite ( $ handle , json_encode ( $ data , JSON_PRETTY_PRINT ) ) ; fclose ( $ handle ) ; } ) ; $ response -> headers -> set ( 'Content-Type' , 'application/force-download' ) ; $ response -> headers -> set ( 'Content-Disposition' , 'attachment; filename="statistics.json"' ) ; return $ response ; }
|
Exports papers into a json file .
|
53,328
|
public function exportCsvAnswersAction ( Exercise $ exercise ) { if ( ! $ this -> isAdmin ( $ exercise ) ) { throw new AccessDeniedException ( ) ; } return new StreamedResponse ( function ( ) use ( $ exercise ) { $ this -> exerciseManager -> exportResultsToCsv ( $ exercise ) ; } , 200 , [ 'Content-Type' => 'application/force-download' , 'Content-Disposition' => 'attachment; filename="' . preg_replace ( '/[^A-Za-z0-9_\-]/' , '_' , $ exercise -> getResourceNode ( ) -> getName ( ) ) . '.csv"' , ] ) ; }
|
Exports papers into a csv file .
|
53,329
|
private function updateSteps ( ) { $ this -> log ( 'Initializing resource node of steps...' ) ; $ om = $ this -> container -> get ( 'claroline.persistence.object_manager' ) ; $ steps = $ om -> getRepository ( 'Innova\PathBundle\Entity\Step' ) -> findAll ( ) ; $ om -> startFlushSuite ( ) ; $ i = 0 ; foreach ( $ steps as $ step ) { $ activity = $ step -> getActivity ( ) ; if ( ! empty ( $ activity ) ) { if ( ! empty ( $ activity -> getPrimaryResource ( ) ) ) { $ step -> setResource ( $ activity -> getPrimaryResource ( ) ) ; } $ step -> setTitle ( $ activity -> getResourceNode ( ) -> getName ( ) ) ; $ step -> setDescription ( $ activity -> getDescription ( ) ) ; $ parameters = $ activity -> getParameters ( ) ; if ( ! empty ( $ parameters ) ) { $ order = 0 ; foreach ( $ parameters -> getSecondaryResources ( ) as $ resource ) { $ secondaryResource = new SecondaryResource ( ) ; $ secondaryResource -> setResource ( $ resource ) ; $ secondaryResource -> setOrder ( $ order ) ; $ step -> addSecondaryResource ( $ secondaryResource ) ; $ om -> persist ( $ secondaryResource ) ; ++ $ order ; } } $ om -> persist ( $ step ) ; } ++ $ i ; if ( $ i % 250 === 0 ) { $ om -> forceFlush ( ) ; } } $ om -> endFlushSuite ( ) ; }
|
Initializes Steps resource node from activity resource .
|
53,330
|
protected function refreshUser ( TokenInterface $ token ) { $ user = $ token -> getUser ( ) ; if ( ! $ user instanceof UserInterface ) { return ; } $ refreshedUser = $ this -> userProvider -> refreshUser ( $ user ) ; $ token -> setUser ( $ refreshedUser ) ; return $ token ; }
|
Refreshes the user by reloading it from the user provider . This method was copied from Symfony \ Component \ Security \ Http \ Firewall \ ContextListener .
|
53,331
|
public function addNotation ( \ Innova \ CollecticielBundle \ Entity \ Notation $ notation ) { $ this -> notations [ ] = $ notation ; return $ this ; }
|
Add notation .
|
53,332
|
public function removeNotation ( \ Innova \ CollecticielBundle \ Entity \ Notation $ notation ) { $ this -> notations -> removeElement ( $ notation ) ; }
|
Remove notation .
|
53,333
|
public function deserialize ( $ data , MatchQuestion $ matchQuestion = null , array $ options = [ ] ) { if ( empty ( $ matchQuestion ) ) { $ matchQuestion = new MatchQuestion ( ) ; } if ( isset ( $ data [ 'penaty' ] ) ) { if ( ! empty ( $ data [ 'penalty' ] ) || 0 === $ data [ 'penalty' ] ) { $ matchQuestion -> setPenalty ( $ data [ 'penalty' ] ) ; } } $ this -> sipe ( 'random' , 'setShuffle' , $ data , $ matchQuestion ) ; $ this -> deserializeLabels ( $ matchQuestion , $ data [ 'secondSet' ] , $ options ) ; $ this -> deserializeProposals ( $ matchQuestion , $ data [ 'firstSet' ] , $ options ) ; $ this -> deserializeSolutions ( $ matchQuestion , $ data [ 'solutions' ] ) ; return $ matchQuestion ; }
|
Converts raw data into a Match question entity .
|
53,334
|
public function serialize ( ScheduledTask $ scheduledTask ) { return [ 'id' => $ scheduledTask -> getId ( ) , 'type' => $ scheduledTask -> getType ( ) , 'name' => $ scheduledTask -> getName ( ) , 'scheduledDate' => $ scheduledTask -> getScheduledDate ( ) -> format ( 'Y-m-d\TH:i:s' ) , 'data' => $ scheduledTask -> getData ( ) , 'meta' => [ 'lastExecution' => $ scheduledTask -> getExecutionDate ( ) ? $ scheduledTask -> getExecutionDate ( ) -> format ( 'Y-m-d\TH:i:s' ) : null , ] , 'users' => array_map ( function ( User $ user ) { return $ this -> userSerializer -> serialize ( $ user ) ; } , $ scheduledTask -> getUsers ( ) ) , 'workspace' => $ scheduledTask -> getWorkspace ( ) ? $ this -> workspaceSerializer -> serialize ( $ scheduledTask -> getWorkspace ( ) , [ 'minimal' ] ) : null , 'group' => $ scheduledTask -> getGroup ( ) ? [ 'id' => $ scheduledTask -> getGroup ( ) -> getId ( ) , 'name' => $ scheduledTask -> getGroup ( ) -> getName ( ) , ] : null , ] ; }
|
Serializes a ScheduledTask entity for the JSON api .
|
53,335
|
public function deserialize ( array $ data , ScheduledTask $ scheduledTask = null ) { $ scheduledTask = $ scheduledTask ? : new ScheduledTask ( ) ; $ scheduledTask -> setName ( $ data [ 'name' ] ) ; $ scheduledTask -> setType ( $ data [ 'type' ] ) ; $ scheduledDate = \ DateTime :: createFromFormat ( 'Y-m-d\TH:i:s' , $ data [ 'scheduledDate' ] ) ; $ scheduledTask -> setScheduledDate ( $ scheduledDate ) ; if ( isset ( $ data [ 'data' ] ) ) { $ scheduledTask -> setData ( $ data [ 'data' ] ) ; } if ( isset ( $ data [ 'workspace' ] ) ) { if ( empty ( $ scheduledTask -> getWorkspace ( ) ) || $ data [ 'workspace' ] [ 'id' ] !== $ scheduledTask -> getWorkspace ( ) -> getId ( ) ) { $ workspace = $ this -> om -> getRepository ( 'ClarolineCoreBundle:Workspace\Workspace' ) -> find ( $ data [ 'workspace' ] [ 'id' ] ) ; if ( $ workspace ) { $ scheduledTask -> setWorkspace ( $ workspace ) ; } } } else { $ scheduledTask -> setWorkspace ( null ) ; } $ scheduledTask -> emptyUsers ( ) ; if ( isset ( $ data [ 'users' ] ) ) { foreach ( $ data [ 'users' ] as $ dataUser ) { $ user = $ this -> om -> getRepository ( 'ClarolineCoreBundle:User' ) -> find ( $ dataUser [ 'id' ] ) ; if ( $ user ) { $ scheduledTask -> addUser ( $ user ) ; } } } if ( isset ( $ data [ 'group' ] ) ) { if ( empty ( $ scheduledTask -> getGroup ( ) ) || $ data [ 'group' ] [ 'id' ] !== $ scheduledTask -> getGroup ( ) -> getId ( ) ) { $ group = $ this -> om -> getRepository ( 'ClarolineCoreBundle:Group' ) -> find ( $ data [ 'group' ] [ 'id' ] ) ; if ( $ group ) { $ scheduledTask -> setGroup ( $ group ) ; } } } else { $ scheduledTask -> setGroup ( null ) ; } return $ scheduledTask ; }
|
Deserializes JSON api data into a ScheduledTask entity .
|
53,336
|
public function generate ( ) { $ tempName = Uuid :: uuid4 ( ) -> toString ( ) ; $ tempFile = $ this -> getDirectory ( ) . DIRECTORY_SEPARATOR . $ tempName ; $ this -> files [ ] = $ tempFile ; return $ tempFile ; }
|
Generates a new temporary file .
|
53,337
|
public function clear ( ) { if ( ! empty ( $ this -> files ) ) { $ fs = new FileSystem ( ) ; foreach ( $ this -> files as $ file ) { $ fs -> remove ( $ file ) ; } } }
|
Removes current temp files .
|
53,338
|
public function validate ( PluginBundleInterface $ plugin ) { $ validationErrors = [ ] ; foreach ( $ this -> checkers as $ checker ) { if ( null !== $ errors = $ checker -> check ( $ plugin , $ this -> isInUpdateMode ( ) ) ) { $ validationErrors = array_merge ( $ validationErrors , $ errors ) ; continue ; } if ( $ checker instanceof ConfigurationChecker ) { $ this -> pluginConfiguration = $ checker -> getProcessedConfiguration ( ) ; } } return $ validationErrors ; }
|
Validates a plugin .
|
53,339
|
public function onDisplayWorkspace ( DisplayToolEvent $ event ) { $ workspace = $ event -> getWorkspace ( ) ; $ content = $ this -> templating -> render ( 'ClarolineCoreBundle:workspace:users.html.twig' , [ 'workspace' => $ workspace , 'restrictions' => [ 'hasUserManagementAccess' => $ this -> authorization -> isGranted ( 'OPEN' , $ this -> om -> getRepository ( 'ClarolineCoreBundle:Tool\AdminTool' ) -> findOneBy ( [ 'name' => 'user_management' ] ) ) , ] , ] ) ; $ event -> setContent ( $ content ) ; $ event -> stopPropagation ( ) ; }
|
Displays users on Workspace .
|
53,340
|
public function updateAction ( Exercise $ exercise , Request $ request ) { $ this -> assertHasPermission ( 'EDIT' , $ exercise ) ; $ errors = [ ] ; $ data = $ this -> decodeRequestData ( $ request ) ; if ( null === $ data ) { $ errors [ ] = [ 'path' => '' , 'message' => 'Invalid JSON data' , ] ; } else { try { $ this -> exerciseManager -> update ( $ exercise , $ data ) ; } catch ( InvalidDataException $ e ) { $ errors = $ e -> getErrors ( ) ; } } if ( ! empty ( $ errors ) ) { return new JsonResponse ( $ errors , 422 ) ; } return new JsonResponse ( $ this -> exerciseManager -> serialize ( $ exercise , [ Transfer :: INCLUDE_SOLUTIONS ] ) ) ; }
|
Updates an Exercise .
|
53,341
|
public function exportAction ( Exercise $ exercise ) { $ this -> assertHasPermission ( 'ADMINISTRATE' , $ exercise ) ; $ file = $ this -> exerciseManager -> export ( $ exercise ) ; $ response = new StreamedResponse ( ) ; $ response -> setCallBack ( function ( ) use ( $ file ) { readfile ( $ file ) ; } ) ; $ name = $ exercise -> getResourceNode ( ) -> getName ( ) . '.json' ; $ response -> headers -> set ( 'Content-Transfer-Encoding' , 'octet-stream' ) ; $ response -> headers -> set ( 'Content-Type' , 'application/force-download' ) ; $ response -> headers -> set ( 'Content-Disposition' , 'attachment; filename=' . urlencode ( $ name ) ) ; $ response -> headers -> set ( 'Content-Type' , 'application/json' ) ; $ response -> headers -> set ( 'Connection' , 'close' ) ; $ response -> send ( ) ; return new Response ( ) ; }
|
download json quiz .
|
53,342
|
public function docimologyOpenAction ( Exercise $ exercise ) { return [ '_resource' => $ exercise , 'resourceNode' => $ exercise -> getResourceNode ( ) , 'exercise' => $ this -> exerciseManager -> serialize ( $ exercise , [ Transfer :: MINIMAL ] ) , 'statistics' => $ this -> docimologyManager -> getStatistics ( $ exercise , 100 ) , ] ; }
|
Opens the docimology of a quiz .
|
53,343
|
public function statisticsAction ( Exercise $ exercise ) { if ( ! $ exercise -> hasStatistics ( ) ) { $ this -> assertHasPermission ( 'EDIT' , $ exercise ) ; } $ statistics = [ ] ; $ finishedOnly = ! $ exercise -> isAllPapersStatistics ( ) ; foreach ( $ exercise -> getSteps ( ) as $ step ) { foreach ( $ step -> getQuestions ( ) as $ question ) { $ itemStats = $ this -> itemManager -> getStatistics ( $ question , $ exercise , $ finishedOnly ) ; $ statistics [ $ question -> getUuid ( ) ] = ! empty ( $ itemStats [ 'solutions' ] ) ? $ itemStats [ 'solutions' ] : new \ stdClass ( ) ; } } return new JsonResponse ( $ statistics ) ; }
|
Gets statistics of an Exercise .
|
53,344
|
public function findByCompetency ( Competency $ competency ) { return $ this -> createQueryBuilder ( 'a' ) -> select ( 'a.id' , 'a.name' , 'a.resourceCount' , 'a.minResourceCount' , 'c.id AS competencyId' , 'l.name AS levelName' , 'l.value AS levelValue' ) -> join ( 'a.competencyAbilities' , 'ca' ) -> join ( 'ca.competency' , 'c' ) -> join ( 'ca.level' , 'l' ) -> where ( 'c.root = :root' ) -> andWhere ( 'c.lft >= :lft' ) -> andWhere ( 'c.rgt <= :rgt' ) -> orderBy ( 'l.value, a.id' ) -> setParameters ( [ ':root' => $ competency -> getRoot ( ) , ':lft' => $ competency -> getLeft ( ) , ':rgt' => $ competency -> getRight ( ) , ] ) -> getQuery ( ) -> getArrayResult ( ) ; }
|
Returns an array representation of all the abilities linked to a given competency tree . Result includes information about ability level as well .
|
53,345
|
public function findOthersByCompetencyAndLevel ( Competency $ competency , Level $ level , Ability $ abilityToExclude ) { return $ this -> createQueryBuilder ( 'a' ) -> select ( 'a' ) -> join ( 'a.competencyAbilities' , 'ca' ) -> join ( 'ca.competency' , 'c' ) -> join ( 'ca.level' , 'l' ) -> where ( 'c = :competency' ) -> andWhere ( 'l = :level' ) -> andWhere ( 'a <> :excluded' ) -> orderBy ( 'l.value, a.id' ) -> setParameters ( [ ':competency' => $ competency , ':level' => $ level , ':excluded' => $ abilityToExclude , ] ) -> getQuery ( ) -> getResult ( ) ; }
|
Returns the abilities directly linked to a given competency and a particular level excluding a given ability .
|
53,346
|
public function findByCompetencyAndLevel ( Competency $ competency , Level $ level ) { return $ this -> createQueryBuilder ( 'a' ) -> select ( 'a' ) -> join ( 'a.competencyAbilities' , 'ca' ) -> join ( 'ca.competency' , 'c' ) -> join ( 'ca.level' , 'l' ) -> where ( 'c = :competency' ) -> andWhere ( 'l = :level' ) -> orderBy ( 'l.value, a.id' ) -> setParameters ( [ ':competency' => $ competency , ':level' => $ level , ] ) -> getQuery ( ) -> getResult ( ) ; }
|
Returns the abilities directly linked to a given competency and a particular level .
|
53,347
|
public function deleteOrphans ( ) { $ linkedAbilityIds = $ this -> _em -> createQueryBuilder ( ) -> select ( 'a.id' ) -> distinct ( ) -> from ( 'HeVinci\CompetencyBundle\Entity\CompetencyAbility' , 'ca' ) -> join ( 'ca.ability' , 'a' ) -> getQuery ( ) -> getScalarResult ( ) ; $ qb = $ this -> createQueryBuilder ( 'a' ) -> delete ( ) ; if ( count ( $ linkedAbilityIds ) > 0 ) { $ linkedAbilityIds = array_map ( function ( $ element ) { return $ element [ 'id' ] ; } , $ linkedAbilityIds ) ; $ qb -> where ( $ qb -> expr ( ) -> notIn ( 'a.id' , $ linkedAbilityIds ) ) ; } $ qb -> getQuery ( ) -> execute ( ) ; }
|
Deletes abilities which are no longer associated with a competency .
|
53,348
|
public function findFirstByName ( $ name , Competency $ excludedParent ) { $ qb = $ this -> createQueryBuilder ( 'a' ) ; $ qb2 = $ this -> _em -> createQueryBuilder ( ) ; $ qb2 -> select ( 'a2' ) -> from ( 'HeVinci\CompetencyBundle\Entity\CompetencyAbility' , 'ca' ) -> join ( 'ca.ability' , 'a2' ) -> where ( $ qb2 -> expr ( ) -> eq ( 'ca.competency' , ':parent' ) ) ; return $ qb -> select ( 'a' ) -> where ( $ qb -> expr ( ) -> like ( 'a.name' , ':name' ) ) -> andWhere ( $ qb -> expr ( ) -> notIn ( 'a' , $ qb2 -> getDQL ( ) ) ) -> orderBy ( 'a.name' ) -> setMaxResults ( 5 ) -> setParameter ( ':name' , $ name . '%' ) -> setParameter ( ':parent' , $ excludedParent ) -> getQuery ( ) -> getResult ( ) ; }
|
Returns the first five abilities whose name begins by a given string excluding abilities linked to a particular competency .
|
53,349
|
public function findEvaluationsByCompetency ( Competency $ competency , User $ user ) { if ( $ competency -> getRight ( ) - $ competency -> getLeft ( ) > 1 ) { throw new \ Exception ( 'Expected leaf competency' ) ; } $ resourceQb = $ this -> createQueryBuilder ( 'a1' ) -> select ( 'node.id' ) -> join ( 'a1.resources' , 'node' ) -> join ( 'a1.competencyAbilities' , 'ca' ) -> where ( 'ca.competency = :competency' ) ; return $ this -> _em -> createQueryBuilder ( ) -> select ( 'e.id AS evaluationId' , 'e.status' , 'e.date' , 'n.id AS resourceId' , 'n.name AS resourceName' , 'a.id AS abilityId' , 'a.name AS abilityName' , 'l.name AS levelName' ) -> from ( 'Claroline\CoreBundle\Entity\Resource\ResourceEvaluation' , 'e' ) -> join ( 'e.resourceUserEvaluation' , 'eru' ) -> join ( 'eru.user' , 'u' ) -> join ( 'eru.resourceNode' , 'n' ) -> join ( 'HeVinci\CompetencyBundle\Entity\Ability' , 'a' , 'WITH' , 'n IN (SELECT node2 FROM HeVinci\CompetencyBundle\Entity\Ability a2 JOIN a2.resources node2 WHERE a2 = a)' ) -> join ( 'a.competencyAbilities' , 'ca2' ) -> join ( 'ca2.level' , 'l' ) -> join ( 'ca2.competency' , 'c2' ) -> where ( 'c2 = :competency' ) -> where ( $ resourceQb -> expr ( ) -> in ( 'n' , $ resourceQb -> getQuery ( ) -> getDQL ( ) ) ) -> andWhere ( 'u = :user' ) -> orderBy ( 'e.date, e.id, a.id' , 'ASC' ) -> setParameters ( [ ':competency' => $ competency , ':user' => $ user , ] ) -> getQuery ( ) -> getArrayResult ( ) ; }
|
Returns an array representation of resource evaluation data for a given user and a given competency including information about the resource and the related abilities .
|
53,350
|
public function getQuestion ( $ uuid ) { $ found = null ; foreach ( $ this -> stepQuestions as $ stepQuestion ) { if ( $ stepQuestion -> getQuestion ( ) -> getUuid ( ) === $ uuid ) { $ found = $ stepQuestion -> getQuestion ( ) ; break ; } } return $ found ; }
|
Gets a question by its uuid .
|
53,351
|
public function addQuestion ( Item $ question ) { $ stepQuestions = $ this -> stepQuestions -> toArray ( ) ; foreach ( $ stepQuestions as $ stepQuestion ) { if ( $ stepQuestion -> getQuestion ( ) === $ question ) { return ; } } $ stepQuestion = new StepItem ( ) ; $ stepQuestion -> setOrder ( $ this -> stepQuestions -> count ( ) ) ; $ stepQuestion -> setStep ( $ this ) ; $ stepQuestion -> setQuestion ( $ question ) ; return $ stepQuestion ; }
|
Shortcut to add Items to Step . Avoids the need to manually initialize a StepItem object to hold the relation .
|
53,352
|
public function listQuestionsToCorrectAction ( Exercise $ exercise ) { $ toCorrect = $ this -> isAdmin ( $ exercise ) ? $ this -> correctionManager -> getToCorrect ( $ exercise ) : [ ] ; return new JsonResponse ( $ toCorrect ) ; }
|
Lists all questions with manual score rule that have answers to correct .
|
53,353
|
public function saveAction ( Exercise $ exercise , Request $ request ) { if ( $ this -> isAdmin ( $ exercise ) ) { $ data = $ this -> decodeRequestData ( $ request ) ; if ( null === $ data ) { $ errors [ ] = [ 'path' => '' , 'message' => 'Invalid JSON data' , ] ; } else { try { $ this -> correctionManager -> save ( $ data ) ; } catch ( InvalidDataException $ e ) { $ errors = $ e -> getErrors ( ) ; } } if ( empty ( $ errors ) ) { return new JsonResponse ( null , 204 ) ; } else { return new JsonResponse ( $ errors , 422 ) ; } } }
|
Saves score & feedback for a bulk of answers .
|
53,354
|
public function getConfigurableRights ( ResourceNode $ node ) { $ existing = $ this -> rightsRepo -> findConfigurableRights ( $ node ) ; $ roles = $ node -> getWorkspace ( ) -> getRoles ( ) ; $ missings = [ ] ; foreach ( $ roles as $ role ) { $ found = false ; foreach ( $ existing as $ right ) { if ( $ right -> getRole ( ) -> getId ( ) === $ role -> getId ( ) ) { $ found = true ; } } if ( ! $ found ) { $ missings [ ] = $ role ; } } if ( 0 === count ( $ missings ) ) { return $ existing ; } foreach ( $ missings as $ missing ) { $ this -> create ( [ ] , $ missing , $ node , true , [ ] ) ; } return $ this -> rightsRepo -> findConfigurableRights ( $ node ) ; }
|
Returns every ResourceRights of a resource on 1 level if the role linked is not ROLE_ADMIN .
|
53,355
|
public function getCustomRoleRights ( ResourceNode $ node ) { $ perms = [ ] ; foreach ( $ node -> getRights ( ) as $ right ) { if ( 'ROLE_ANONYMOUS' !== $ right -> getRole ( ) -> getName ( ) && 'ROLE_USER' !== $ right -> getRole ( ) -> getName ( ) ) { $ rolePerms = $ this -> maskManager -> decodeMask ( $ right -> getMask ( ) , $ node -> getResourceType ( ) ) ; $ perms [ $ right -> getRole ( ) -> getName ( ) ] = $ rolePerms ; $ perms [ $ right -> getRole ( ) -> getName ( ) ] [ 'role' ] = $ right -> getRole ( ) ; $ perms [ $ right -> getRole ( ) -> getName ( ) ] [ 'create' ] = [ ] ; } } return $ perms ; }
|
Return the resource rights as a readable array . This array can be used for the resource creation .
|
53,356
|
public function initializePermissions ( array $ nodes , array $ roles ) { $ this -> om -> startFlushSuite ( ) ; foreach ( $ nodes as $ node ) { foreach ( $ roles as $ role ) { $ type = $ node -> getResourceType ( ) ; $ this -> editPerms ( $ type -> getDefaultMask ( ) , $ role , $ node , false ) ; } } $ this -> om -> endFlushSuite ( ) ; }
|
Initialize the default permissions for a role list . Directories are excluded .
|
53,357
|
public function isManager ( ResourceNode $ resourceNode ) { $ token = $ this -> tokenStorage -> getToken ( ) ; if ( 'anon.' === $ token ) { return false ; } $ roleNames = array_map ( function ( RoleInterface $ role ) { return $ role -> getRole ( ) ; } , $ token -> getRoles ( ) ) ; $ isWorkspaceUsurp = in_array ( 'ROLE_USURPATE_WORKSPACE_ROLE' , $ roleNames ) ; $ workspace = $ resourceNode -> getWorkspace ( ) ; if ( $ workspace && $ this -> container -> get ( 'claroline.manager.workspace_manager' ) -> isManager ( $ workspace , $ token ) ) { return true ; } if ( ! $ isWorkspaceUsurp && $ token -> getUser ( ) === $ resourceNode -> getCreator ( ) ) { return true ; } if ( in_array ( 'ROLE_ADMIN' , $ roleNames ) ) { return true ; } return false ; }
|
Checks if the current user is a manager of a resource .
|
53,358
|
public function getCurrentPermissionArray ( ResourceNode $ resourceNode ) { $ currentRoles = $ this -> tokenStorage -> getToken ( ) -> getRoles ( ) ; $ roleNames = array_map ( function ( RoleInterface $ roleName ) { return $ roleName -> getRole ( ) ; } , $ currentRoles ) ; $ creatable = [ ] ; if ( $ this -> isManager ( $ resourceNode ) ) { $ resourceTypes = $ this -> om -> getRepository ( 'ClarolineCoreBundle:Resource\ResourceType' ) -> findAll ( ) ; foreach ( $ resourceTypes as $ resourceType ) { $ creatable [ ] = $ resourceType -> getName ( ) ; } $ perms = array_fill_keys ( array_values ( $ this -> maskManager -> getPermissionMap ( $ resourceNode -> getResourceType ( ) ) ) , true ) ; } else { $ creatable = $ this -> getCreatableTypes ( $ roleNames , $ resourceNode ) ; $ perms = $ this -> maskManager -> decodeMask ( $ this -> rightsRepo -> findMaximumRights ( $ roleNames , $ resourceNode ) , $ resourceNode -> getResourceType ( ) ) ; } return array_merge ( $ perms , [ 'create' => $ creatable ] ) ; }
|
maybe use that one in the voter later because it s going to be usefull
|
53,359
|
public function refreshIdentifiers ( AbstractItem $ item ) { foreach ( $ item -> getColors ( ) as $ color ) { $ color -> refreshUuid ( ) ; } foreach ( $ item -> getSelections ( ) as $ selection ) { $ selection -> refreshUuid ( ) ; } }
|
Refreshes selections and colors UUIDs .
|
53,360
|
public function getUpdatedResourceUserEvaluation ( Path $ path ) { $ resourceUserEvaluation = null ; $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; if ( $ user instanceof User ) { $ resourceUserEvaluation = $ this -> resourceEvalManager -> getResourceUserEvaluation ( $ path -> getResourceNode ( ) , $ user ) ; $ data = $ this -> computeResourceUserEvaluation ( $ path , $ user ) ; if ( $ data [ 'score' ] !== $ resourceUserEvaluation -> getScore ( ) || $ data [ 'scoreMax' ] !== $ resourceUserEvaluation -> getScoreMax ( ) || $ data [ 'status' ] !== $ resourceUserEvaluation -> getStatus ( ) ) { $ resourceUserEvaluation -> setScore ( $ data [ 'score' ] ) ; $ resourceUserEvaluation -> setScoreMax ( $ data [ 'scoreMax' ] ) ; $ resourceUserEvaluation -> setStatus ( $ data [ 'status' ] ) ; $ resourceUserEvaluation -> setDate ( new \ DateTime ( ) ) ; $ this -> om -> persist ( $ resourceUserEvaluation ) ; $ this -> om -> flush ( ) ; } } return $ resourceUserEvaluation ; }
|
Fetch resource user evaluation with up - to - date status .
|
53,361
|
public function getResourceUserEvaluation ( Path $ path , User $ user ) { return $ this -> resourceEvalManager -> getResourceUserEvaluation ( $ path -> getResourceNode ( ) , $ user ) ; }
|
Fetch or create resource user evaluation .
|
53,362
|
public function generateResourceEvaluation ( Step $ step , User $ user , $ status ) { $ statusData = $ this -> computeResourceUserEvaluation ( $ step -> getPath ( ) , $ user ) ; $ stepIndex = array_search ( $ step -> getUuid ( ) , $ statusData [ 'stepsToDo' ] ) ; if ( false !== $ stepIndex && false !== array_search ( $ status , [ 'seen' , 'done' ] ) ) { ++ $ statusData [ 'score' ] ; array_splice ( $ statusData [ 'stepsToDo' ] , $ stepIndex , 1 ) ; } $ evaluationData = [ 'step' => $ step -> getUuid ( ) , 'status' => $ status , 'toDo' => $ statusData [ 'stepsToDo' ] , ] ; $ progression = ! is_null ( $ statusData [ 'score' ] ) && $ statusData [ 'scoreMax' ] > 0 ? floor ( ( $ statusData [ 'score' ] / $ statusData [ 'scoreMax' ] ) * 100 ) : null ; return $ this -> resourceEvalManager -> createResourceEvaluation ( $ step -> getPath ( ) -> getResourceNode ( ) , $ user , null , [ 'status' => $ statusData [ 'status' ] , 'score' => $ statusData [ 'score' ] , 'scoreMax' => $ statusData [ 'scoreMax' ] , 'progression' => $ progression , 'data' => $ evaluationData , ] , [ 'status' => true , 'score' => true , 'progression' => true , ] ) ; }
|
Create a ResourceEvaluation for a step .
|
53,363
|
public function computeResourceUserEvaluation ( Path $ path , User $ user ) { $ steps = $ path -> getSteps ( ) -> toArray ( ) ; $ stepsUuids = array_map ( function ( Step $ step ) { return $ step -> getUuid ( ) ; } , $ steps ) ; $ resourceUserEval = $ this -> resourceEvalManager -> getResourceUserEvaluation ( $ path -> getResourceNode ( ) , $ user ) ; $ evaluations = $ resourceUserEval -> getEvaluations ( ) ; $ score = 0 ; $ scoreMax = count ( $ steps ) ; foreach ( $ evaluations as $ evaluation ) { $ data = $ evaluation -> getData ( ) ; if ( isset ( $ data [ 'step' ] ) && isset ( $ data [ 'status' ] ) ) { $ statusIndex = array_search ( $ data [ 'status' ] , [ 'seen' , 'done' ] ) ; $ uuidIndex = array_search ( $ data [ 'step' ] , $ stepsUuids ) ; if ( false !== $ statusIndex && false !== $ uuidIndex ) { ++ $ score ; array_splice ( $ stepsUuids , $ uuidIndex , 1 ) ; } } } $ status = $ score >= $ scoreMax ? AbstractResourceEvaluation :: STATUS_COMPLETED : AbstractResourceEvaluation :: STATUS_INCOMPLETE ; return [ 'score' => $ score , 'scoreMax' => $ scoreMax , 'status' => $ status , 'stepsToDo' => $ stepsUuids , ] ; }
|
Compute current resource evaluation status .
|
53,364
|
public function getStepsProgressionForUser ( Path $ path , User $ user ) { $ stepsProgression = [ ] ; foreach ( $ path -> getSteps ( ) as $ step ) { $ userProgression = $ this -> repository -> findOneBy ( [ 'step' => $ step , 'user' => $ user ] ) ; if ( $ userProgression ) { $ stepsProgression [ $ step -> getUuid ( ) ] = $ userProgression -> getStatus ( ) ; } } return $ stepsProgression ; }
|
Get all steps progression for an user .
|
53,365
|
public function serialize ( Keyword $ keyword , array $ options = [ ] ) { $ serialized = [ 'id' => $ keyword -> getUuid ( ) , 'name' => $ keyword -> getName ( ) , ] ; return $ serialized ; }
|
Serializes a Keyword entity for the JSON api .
|
53,366
|
public function serialize ( Role $ role , array $ options = [ ] ) { $ serialized = [ 'id' => $ role -> getUuid ( ) , 'name' => $ role -> getName ( ) , 'type' => $ role -> getType ( ) , 'translationKey' => $ role -> getTranslationKey ( ) , ] ; if ( ! in_array ( Options :: SERIALIZE_MINIMAL , $ options ) ) { $ serialized [ 'meta' ] = $ this -> serializeMeta ( $ role , $ options ) ; $ serialized [ 'restrictions' ] = $ this -> serializeRestrictions ( $ role ) ; if ( $ workspace = $ role -> getWorkspace ( ) ) { $ serialized [ 'workspace' ] = $ this -> workspaceSerializer -> serialize ( $ workspace , [ Options :: SERIALIZE_MINIMAL ] ) ; } if ( Role :: USER_ROLE === $ role -> getType ( ) ) { $ serialized [ 'user' ] = $ this -> userSerializer -> serialize ( $ role -> getUsers ( ) -> toArray ( ) [ 0 ] , [ Options :: SERIALIZE_MINIMAL ] ) ; } $ adminTools = [ ] ; foreach ( $ this -> om -> getRepository ( 'ClarolineCoreBundle:Tool\AdminTool' ) -> findAll ( ) as $ adminTool ) { $ adminTools [ $ adminTool -> getName ( ) ] = $ role -> getAdminTools ( ) -> contains ( $ adminTool ) ; } $ serialized [ 'adminTools' ] = $ adminTools ; if ( in_array ( Options :: SERIALIZE_ROLE_TOOLS_RIGHTS , $ options ) ) { $ workspaceId = null ; foreach ( $ options as $ option ) { if ( 'workspace_id_' === substr ( $ option , 0 , 13 ) ) { $ workspaceId = substr ( $ option , 13 ) ; break ; } } if ( $ workspaceId ) { $ serialized [ 'tools' ] = $ this -> serializeTools ( $ role , $ workspaceId ) ; } } if ( Role :: PLATFORM_ROLE === $ role -> getType ( ) && in_array ( Options :: SERIALIZE_ROLE_DESKTOP_TOOLS , $ options ) ) { $ serialized [ 'desktopTools' ] = $ this -> serializeDesktopToolsConfig ( $ role ) ; } } return $ serialized ; }
|
Serializes a Role entity .
|
53,367
|
public function serializeMeta ( Role $ role , array $ options ) { $ meta = [ 'readOnly' => $ role -> isReadOnly ( ) , 'personalWorkspaceCreationEnabled' => $ role -> getPersonalWorkspaceCreationEnabled ( ) , ] ; if ( in_array ( Options :: SERIALIZE_COUNT_USER , $ options ) ) { if ( Role :: USER_ROLE !== $ role -> getType ( ) ) { $ meta [ 'users' ] = $ this -> userRepo -> countUsersByRoleIncludingGroup ( $ role ) ; } else { $ meta [ 'users' ] = 1 ; } } return $ meta ; }
|
Serialize role metadata .
|
53,368
|
private function serializeTools ( Role $ role , $ workspaceId ) { $ tools = [ ] ; $ workspace = $ this -> om -> getRepository ( Workspace :: class ) -> findBy ( [ 'uuid' => $ workspaceId ] ) ; $ orderedTools = $ this -> orderedToolRepo -> findBy ( [ 'workspace' => $ workspace ] ) ; foreach ( $ orderedTools as $ orderedTool ) { $ toolRights = $ this -> toolRightsRepo -> findBy ( [ 'role' => $ role , 'orderedTool' => $ orderedTool ] , [ 'id' => 'ASC' ] ) ; $ mask = 0 < count ( $ toolRights ) ? $ toolRights [ 0 ] -> getMask ( ) : 0 ; $ toolName = $ orderedTool -> getTool ( ) -> getName ( ) ; $ tools [ $ toolName ] = [ ] ; foreach ( ToolMaskDecoder :: $ defaultActions as $ action ) { $ actionValue = ToolMaskDecoder :: $ defaultValues [ $ action ] ; $ tools [ $ toolName ] [ $ action ] = $ mask & $ actionValue ? true : false ; } } return count ( $ tools ) > 0 ? $ tools : new \ stdClass ( ) ; }
|
Serialize role tools rights .
|
53,369
|
private function serializeDesktopToolsConfig ( Role $ role ) { $ configs = [ ] ; $ desktopTools = $ this -> om -> getRepository ( Tool :: class ) -> findBy ( [ 'isDisplayableInDesktop' => true ] ) ; $ toolsRole = $ this -> om -> getRepository ( ToolRole :: class ) -> findBy ( [ 'role' => $ role ] ) ; foreach ( $ toolsRole as $ toolRole ) { $ toolName = $ toolRole -> getTool ( ) -> getName ( ) ; if ( ! in_array ( $ toolName , ToolsOptions :: EXCLUDED_TOOLS ) ) { $ configs [ $ toolName ] = $ toolRole -> getDisplay ( ) ; } } foreach ( $ desktopTools as $ desktopTool ) { $ toolName = $ desktopTool -> getName ( ) ; if ( ! in_array ( $ toolName , ToolsOptions :: EXCLUDED_TOOLS ) && ! isset ( $ configs [ $ toolName ] ) ) { $ configs [ $ toolName ] = null ; } } return 0 < count ( $ configs ) ? $ configs : new \ stdClass ( ) ; }
|
Serialize role configuration for desktop tools .
|
53,370
|
public function expectAnswer ( AbstractItem $ question ) { $ expected = [ ] ; switch ( $ question -> getSumMode ( ) ) { case GridQuestion :: SUM_CELL : foreach ( $ question -> getCells ( ) -> toArray ( ) as $ cell ) { if ( 0 < count ( $ cell -> getChoices ( ) ) ) { $ expected [ ] = $ this -> findCellExpectedAnswer ( $ cell ) ; } } break ; case GridQuestion :: SUM_COLUMN : for ( $ i = 0 ; $ i < $ question -> getColumns ( ) ; ++ $ i ) { foreach ( $ question -> getCells ( ) as $ cell ) { if ( $ cell -> getCoordsX ( ) === $ i && 0 < count ( $ cell -> getChoices ( ) ) ) { $ scoreToApply = $ cell -> getChoices ( ) [ 0 ] -> getScore ( ) ; $ expected [ ] = new GenericScore ( $ scoreToApply ) ; break ; } } } break ; case GridQuestion :: SUM_ROW : for ( $ i = 0 ; $ i < $ question -> getRows ( ) ; ++ $ i ) { foreach ( $ question -> getCells ( ) as $ cell ) { if ( $ cell -> getCoordsY ( ) === $ i && 0 < count ( $ cell -> getChoices ( ) ) ) { $ scoreToApply = $ cell -> getChoices ( ) [ 0 ] -> getScore ( ) ; $ expected [ ] = new GenericScore ( $ scoreToApply ) ; break ; } } } break ; } return $ expected ; }
|
Used to compute the question total score . Only for sum score type .
|
53,371
|
public function serialize ( Chapter $ chapter , array $ options = [ ] ) { $ previousChapter = $ this -> chapterRepository -> getPreviousChapter ( $ chapter ) ; $ nextChapter = $ this -> chapterRepository -> getNextChapter ( $ chapter ) ; $ serialized = [ 'id' => $ chapter -> getUuid ( ) , 'slug' => $ chapter -> getSlug ( ) , 'title' => $ chapter -> getTitle ( ) , 'text' => $ chapter -> getText ( ) , 'parentSlug' => $ chapter -> getParent ( ) ? $ chapter -> getParent ( ) -> getSlug ( ) : null , 'previousSlug' => $ previousChapter ? $ previousChapter -> getSlug ( ) : null , 'nextSlug' => $ nextChapter ? $ nextChapter -> getSlug ( ) : null , ] ; return $ serialized ; }
|
Serializes a Chapter entity for the JSON api .
|
53,372
|
public function connect ( $ server , $ user = null , $ password = null , $ isAuthentication = false ) { if ( $ server && isset ( $ server [ 'host' ] ) ) { if ( isset ( $ server [ 'port' ] ) && is_numeric ( $ server [ 'port' ] ) ) { $ this -> connect = ldap_connect ( $ server [ 'host' ] , $ server [ 'port' ] ) ; } else { $ this -> connect = ldap_connect ( $ server [ 'host' ] ) ; } ldap_set_option ( $ this -> connect , LDAP_OPT_PROTOCOL_VERSION , $ server [ 'protocol_version' ] ) ; try { if ( $ isAuthentication && $ this -> connect && $ user && $ password ) { $ user = $ this -> findDnFromUserName ( $ server , $ user ) ; return ( false === $ user ) ? $ user : ldap_bind ( $ this -> connect , $ user , $ password ) ; } elseif ( $ this -> connect ) { return ldap_bind ( $ this -> connect ) ; } } catch ( \ Exception $ e ) { throw new InvalidLdapCredentialsException ( ) ; } } }
|
This method create the LDAP link identifier on success and test the connection .
|
53,373
|
public function search ( $ server , $ filter , $ attributes = [ ] ) { return ldap_search ( $ this -> connect , $ server [ 'dn' ] , $ filter , $ attributes ) ; }
|
This method search something in LDAP directory using a filter .
|
53,374
|
public function getEntries ( $ search ) { $ entries = ldap_get_entries ( $ this -> connect , $ search ) ; array_walk_recursive ( $ entries , function ( & $ item ) { if ( ! mb_detect_encoding ( $ item , 'utf-8' , true ) ) { $ item = utf8_encode ( $ item ) ; } } ) ; return $ entries ; }
|
This method reads the entries of a LDAP search .
|
53,375
|
public function exists ( $ name , $ data ) { $ servers = isset ( $ this -> config [ 'servers' ] ) ? $ this -> config [ 'servers' ] : null ; if ( ( ! $ name || ( $ name && $ name !== $ data [ 'name' ] ) ) && isset ( $ data [ 'name' ] ) && isset ( $ servers [ $ data [ 'name' ] ] ) ) { return true ; } }
|
Test if a given server name exist in LDAP configuration .
|
53,376
|
public function deleteIfReplace ( $ name , $ data ) { if ( $ name && isset ( $ data [ 'name' ] ) && $ name !== $ data [ 'name' ] ) { $ this -> ldapUserRepo -> updateUsersByServerName ( $ name , $ data [ 'name' ] ) ; $ this -> deleteServer ( $ name ) ; } }
|
Delete a server configuration if the newest one replace it .
|
53,377
|
public function deleteServer ( $ name ) { if ( isset ( $ this -> config [ 'servers' ] ) && isset ( $ this -> config [ 'servers' ] [ $ name ] ) ) { unset ( $ this -> config [ 'servers' ] [ $ name ] ) ; $ this -> ldapUserRepo -> deleteUsersByServerName ( $ name ) ; return $ this -> saveConfig ( ) ; } }
|
Delete a server configuration .
|
53,378
|
public function saveSettings ( $ settings ) { if ( isset ( $ settings [ 'name' ] ) && isset ( $ this -> config [ 'servers' ] [ $ settings [ 'name' ] ] ) ) { return $ this -> saveConfig ( array_merge ( $ this -> config [ 'servers' ] [ $ settings [ 'name' ] ] , $ settings ) ) ; } }
|
Save the LDAP mapping settings .
|
53,379
|
public function saveConfig ( $ server = null ) { if ( is_array ( $ server ) && isset ( $ server [ 'name' ] ) ) { if ( ! isset ( $ server [ 'objectClass' ] ) ) { $ server = $ this -> setDefaultServerUserObject ( $ server ) ; } $ this -> config [ 'servers' ] [ $ server [ 'name' ] ] = $ server ; } return file_put_contents ( $ this -> path , $ this -> dumper -> dump ( $ this -> config , 3 ) ) ; }
|
Save the LDAP configuration in a . yml file .
|
53,380
|
public function getClasses ( $ server ) { $ classes = [ ] ; if ( $ search = $ this -> search ( $ server , '(&(objectClass=*))' , [ 'objectclass' ] ) ) { $ entries = $ this -> getEntries ( $ search ) ; foreach ( $ entries as $ objectClass ) { if ( isset ( $ objectClass [ 'objectclass' ] ) ) { unset ( $ objectClass [ 'objectclass' ] [ 'count' ] ) ; $ classes = array_merge ( $ classes , $ objectClass [ 'objectclass' ] ) ; } } } return array_unique ( $ classes ) ; }
|
Get LDAP opbject classes .
|
53,381
|
public function getServers ( ) { $ servers = [ ] ; if ( isset ( $ this -> config [ 'servers' ] ) && is_array ( $ this -> config [ 'servers' ] ) ) { foreach ( $ this -> config [ 'servers' ] as $ server ) { $ servers [ ] = $ server [ 'name' ] ; } } return $ servers ; }
|
Return a list of available servers .
|
53,382
|
public function getActiveServers ( ) { $ activeServers = [ ] ; if ( isset ( $ this -> config [ 'servers' ] ) && is_array ( $ this -> config [ 'servers' ] ) ) { foreach ( $ this -> config [ 'servers' ] as $ server ) { if ( isset ( $ server [ 'active' ] ) && isset ( $ server [ 'objectClass' ] ) && $ server [ 'active' ] ) { $ activeServers [ ] = $ server [ 'name' ] ; } } } return $ activeServers ; }
|
Return a list of active servers .
|
53,383
|
private function parseYml ( ) { if ( ! file_exists ( $ this -> path ) ) { touch ( $ this -> path ) ; } return $ this -> yml -> parse ( file_get_contents ( $ this -> path ) ) ; }
|
Parse . yml file into LDAP configuration array .
|
53,384
|
public function authenticate ( Request $ request , $ serverName ) { $ server = $ this -> get ( $ serverName ) ; $ username = $ request -> get ( '_username' ) ; $ password = $ request -> get ( '_password' ) ; if ( ! empty ( $ username ) && ! empty ( $ password ) && $ this -> connect ( $ server , $ this -> prepareUsername ( $ server , $ username ) , $ password , true ) ) { $ ldapUser = $ this -> ldapUserRepo -> findOneBy ( [ 'serverName' => $ server , 'ldapId' => $ username ] ) ; if ( null !== $ ldapUser ) { return $ this -> registrationManager -> loginUser ( $ ldapUser -> getUser ( ) , $ request ) ; } if ( $ this -> platformConfigHandler -> getParameter ( 'direct_third_party_authentication' ) ) { $ user = $ this -> userManager -> getUserByUsername ( $ username ) ; if ( null === $ user ) { throw $ this -> getUsernameNotFoundException ( $ username ) ; } $ this -> createLdapUser ( $ serverName , $ username , $ user ) ; return $ this -> registrationManager -> loginUser ( $ user ) ; } throw $ this -> getUsernameNotFoundException ( $ username ) ; } throw new InvalidLdapCredentialsException ( ) ; }
|
Authenticate ldap user .
|
53,385
|
public function check ( string $ type , string $ context ) : bool { $ dataSource = $ this -> dataSourceRepository -> findOneBy ( [ 'name' => $ type ] ) ; if ( ! $ dataSource ) { return false ; } if ( ! in_array ( $ context , $ dataSource -> getContext ( ) ) ) { return false ; } return true ; }
|
Checks if a data source exists and is available for the given context .
|
53,386
|
public function load ( string $ type , string $ context , $ contextId = null , array $ options = null ) { $ user = null ; if ( $ this -> tokenStorage -> getToken ( ) -> getUser ( ) instanceof User ) { $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; } $ workspace = null ; if ( DataSource :: CONTEXT_WORKSPACE === $ context ) { $ workspace = $ this -> om -> getRepository ( Workspace :: class ) -> findOneBy ( [ 'uuid' => $ contextId ] ) ; } $ event = $ this -> eventDispatcher -> dispatch ( 'data_source.' . $ type . '.load' , GetDataEvent :: class , [ $ context , $ options , $ user , $ workspace ] ) ; return $ event -> getData ( ) ; }
|
Loads data from a data source .
|
53,387
|
public function addChild ( self $ resourceNode ) { if ( ! $ this -> children -> contains ( $ resourceNode ) ) { $ this -> children -> add ( $ resourceNode ) ; } }
|
Add a child resource node .
|
53,388
|
public static function getList ( ) { return [ static :: CHOICE , static :: CLOZE , static :: GRAPHIC , static :: MATCH , static :: PAIR , static :: SET , static :: WORDS , static :: OPEN , static :: SELECTION , static :: GRID , static :: CONTENT , static :: ORDERING , static :: BOOLEAN , ] ; }
|
Get the list of managed item types .
|
53,389
|
public function serialize ( Lesson $ lesson , array $ options = [ ] ) { $ firstChapter = $ this -> chapterRepository -> getFirstChapter ( $ lesson ) ; $ serialized = [ 'id' => $ lesson -> getUuid ( ) , 'title' => $ lesson -> getResourceNode ( ) -> getName ( ) , 'firstChapterId' => $ firstChapter ? $ firstChapter -> getUuid ( ) : null , 'firstChapterSlug' => $ firstChapter ? $ firstChapter -> getSlug ( ) : null , ] ; return $ serialized ; }
|
Serializes a Lesson entity for the JSON api .
|
53,390
|
public function search ( $ class , array $ finderParams = [ ] , array $ serializerOptions = [ ] ) { $ queryParams = self :: parseQueryParams ( $ finderParams ) ; $ page = $ queryParams [ 'page' ] ; $ limit = $ queryParams [ 'limit' ] ; $ filters = $ queryParams [ 'filters' ] ; $ allFilters = $ queryParams [ 'allFilters' ] ; $ sortBy = $ queryParams [ 'sortBy' ] ; $ count = $ this -> fetch ( $ class , $ allFilters , $ sortBy , $ page , $ limit , true ) ; $ data = $ this -> fetch ( $ class , $ allFilters , $ sortBy , $ page , $ limit ) ; if ( 0 < $ count && empty ( $ data ) ) { $ page = ceil ( $ count / $ limit ) - 1 ; $ data = $ this -> fetch ( $ class , $ allFilters , $ sortBy , $ page , $ limit ) ; } return self :: formatPaginatedData ( array_map ( function ( $ result ) use ( $ serializerOptions ) { return $ this -> serializer -> serialize ( $ result , $ serializerOptions ) ; } , $ data ) , $ count , $ page , $ limit , $ filters , $ sortBy ) ; }
|
Builds and fires the query for a given class . The result will be serialized afterwards .
|
53,391
|
public function fetch ( $ class , array $ filters = [ ] , array $ sortBy = null , $ page = 0 , $ limit = - 1 , $ count = false ) { try { return $ this -> get ( $ class ) -> find ( $ filters , $ sortBy , $ page , $ limit , $ count ) ; } catch ( FinderException $ e ) { $ data = $ this -> om -> getRepository ( $ class ) -> findBy ( $ filters , null , 0 < $ limit ? $ limit : null , $ page ) ; return $ count ? count ( $ data ) : $ data ; } }
|
Builds and fires the query for a given class . There will be no serialization here .
|
53,392
|
public static function parseQueryParams ( array $ finderParams = [ ] ) { $ filters = isset ( $ finderParams [ 'filters' ] ) ? self :: parseFilters ( $ finderParams [ 'filters' ] ) : [ ] ; $ sortBy = isset ( $ finderParams [ 'sortBy' ] ) ? self :: parseSortBy ( $ finderParams [ 'sortBy' ] ) : null ; $ page = isset ( $ finderParams [ 'page' ] ) ? ( int ) $ finderParams [ 'page' ] : 0 ; $ limit = isset ( $ finderParams [ 'limit' ] ) ? ( int ) $ finderParams [ 'limit' ] : - 1 ; $ hiddenFilters = isset ( $ finderParams [ 'hiddenFilters' ] ) ? self :: parseFilters ( $ finderParams [ 'hiddenFilters' ] ) : [ ] ; return [ 'filters' => $ filters , 'hiddenFilters' => $ hiddenFilters , 'allFilters' => array_merge_recursive ( $ filters , $ hiddenFilters ) , 'sortBy' => $ sortBy , 'page' => $ page , 'limit' => $ limit , ] ; }
|
Parses query params to their appropriate filter values .
|
53,393
|
public function findAllAvailable ( array $ enabledPlugins , $ context = null ) { $ query = $ this -> createQueryBuilder ( 'ds' ) -> leftJoin ( 'ds.plugin' , 'p' ) -> where ( 'CONCAT(p.vendorName, p.bundleName) IN (:plugins)' ) -> setParameter ( 'plugins' , $ enabledPlugins ) ; if ( $ context ) { $ query -> andWhere ( 'ds.context LIKE :context' ) -> setParameter ( 'context' , '%' . $ context . '%' ) ; } return $ query -> getQuery ( ) -> getResult ( ) ; }
|
Finds all available data sources in the platform . It only grabs sources from enabled plugins .
|
53,394
|
public function onSerialize ( DecorateResourceNodeEvent $ event ) { $ options = $ event -> getOptions ( ) ; if ( ! in_array ( Options :: SKIP_RESOURCE_NOTIFICATION , $ options ) ) { $ node = $ event -> getResourceNode ( ) ; $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; $ followResource = $ user !== 'anon.' ? $ this -> notificationManager -> getFollowerResource ( $ user -> getId ( ) , $ node -> getId ( ) , $ node -> getClass ( ) ) : false ; $ event -> add ( 'notifications' , [ 'enabled' => ! empty ( $ followResource ) ] ) ; } }
|
Add notifications option to serialized resource node when requested through API .
|
53,395
|
public function serialize ( $ object , array $ options = [ ] ) { return $ this -> mapEntityToObject ( $ this -> getSerializableProperties ( $ object ) , $ object , new \ StdClass ( ) ) ; }
|
Default serialize method .
|
53,396
|
public function deserialize ( $ data , $ object , array $ options = [ ] ) { $ properties = $ this -> getSerializableProperties ( $ object , [ self :: INCLUDE_MANY_TO_ONE ] ) ; $ data = json_decode ( json_encode ( $ data ) ) ; return $ this -> mapObjectToEntity ( $ properties , $ this -> resolveData ( $ properties , $ data , get_class ( $ object ) ) , $ object ) ; }
|
Default deserialize method .
|
53,397
|
protected function mapObjectToEntity ( array $ mapping , \ stdClass $ data , $ entity ) { foreach ( $ mapping as $ dataProperty => $ map ) { if ( property_exists ( $ data , $ dataProperty ) ) { if ( is_string ( $ map ) || is_object ( $ map ) || is_int ( $ map ) ) { try { $ setter = $ this -> getEntitySetter ( $ entity , $ map ) ; if ( $ data -> { $ dataProperty } ) { call_user_func ( [ $ entity , $ setter ] , $ data -> { $ dataProperty } ) ; } } catch ( \ LogicException $ e ) { } } else { call_user_func ( $ map , $ entity , $ data ) ; } } } return $ entity ; }
|
Maps raw object data into entity properties .
|
53,398
|
protected function mapEntityToObject ( array $ mapping , $ entity , \ stdClass $ data ) { foreach ( $ mapping as $ dataProperty => $ map ) { $ value = null ; if ( is_string ( $ map ) ) { $ getter = $ this -> getEntityGetter ( $ entity , $ map ) ; $ value = call_user_func ( [ $ entity , $ getter ] ) ; } elseif ( is_callable ( $ map ) ) { $ value = call_user_func ( $ map , $ entity ) ; } $ data -> { $ dataProperty } = $ value ; } return $ data ; }
|
Maps entity properties into raw object .
|
53,399
|
private function getEntityGetter ( $ entity , $ property ) { $ getter = null ; $ prefixes = [ 'get' , 'is' , 'has' , '' ] ; foreach ( $ prefixes as $ prefix ) { $ test = $ prefix . ucfirst ( $ property ) ; if ( method_exists ( $ entity , $ test ) ) { $ getter = $ test ; break ; } } if ( null === $ getter ) { throw new \ LogicException ( "Entity has no getter for property `{$property}`." ) ; } return $ getter ; }
|
Gets the correct getter name for an entity property .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.