idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
49,800
protected function paginate ( $ collection , $ options = array ( ) , $ dataRenderer = null ) { return ( new Paginator ( ) ) -> paginate ( $ collection , $ options , $ dataRenderer ) ; }
Wrap a datatable action to paginator to have subset of data
49,801
protected function getStorage ( ) { if ( ! $ this -> storage ) { $ storage = $ this -> getServiceLocator ( ) -> get ( Storage :: SERVICE_ID ) ; if ( ! $ storage instanceof PaginatedStorage ) { throw new StorageException ( __ ( 'The storage service provided to store the diagnostic results must be upgraded to support reads!' ) ) ; } $ this -> storage = $ storage ; } return $ this -> storage ; }
Get diangostic storage
49,802
public function login ( ) { try { if ( ! $ this -> hasRequestParameter ( 'successCallback' ) ) { throw new \ common_exception_MissingParameter ( 'Internal error, please retry in few moment' ) ; } if ( $ this -> isRequestPost ( ) ) { $ authorizationService = $ this -> getServiceLocator ( ) -> get ( Authorization :: SERVICE_ID ) ; if ( ! $ authorizationService instanceof RequireUsername ) { throw new InvalidCallException ( 'Authenticator need to be call by requireusername' ) ; } if ( $ authorizationService -> validateLogin ( $ this -> getRequestParameter ( 'login' ) ) ) { $ baseUrl = $ this -> getServiceLocator ( ) -> get ( \ common_ext_ExtensionsManager :: SERVICE_ID ) -> getExtensionById ( 'taoClientDiagnostic' ) -> getConstant ( 'BASE_URL' ) ; $ elements = parse_url ( $ baseUrl ) ; $ this -> setCookie ( 'login' , $ this -> getRequestParameter ( 'login' ) , null , $ elements [ 'path' ] ) ; $ this -> redirect ( $ this -> getRequestParameter ( 'successCallback' ) ) ; } } } catch ( InvalidLoginException $ e ) { $ this -> setData ( 'errorMessage' , $ e -> getUserMessage ( ) ) ; } $ this -> setData ( 'successCallback' , $ this -> getRequestParameter ( 'successCallback' ) ) ; $ this -> setData ( 'client_config_url' , $ this -> getClientConfigUrl ( ) ) ; $ this -> setData ( 'content-controller' , 'taoClientDiagnostic/controller/Authenticator/login' ) ; $ this -> setData ( 'content-template' , 'Authenticator' . DIRECTORY_SEPARATOR . 'login.tpl' ) ; $ this -> setView ( 'index.tpl' ) ; }
Login process Check if url successCallback is set If login form is post valid setcookie & redirect to successCallback Else create LoginForm with ?errorMessage
49,803
protected function getData ( $ check = false ) { $ data = parent :: getData ( $ check ) ; $ data [ 'login' ] = UserHelper :: getUserLogin ( \ common_session_SessionManager :: getSession ( ) -> getUser ( ) ) ; if ( $ this -> hasRequestParameter ( 'workstation' ) ) { $ data [ PaginatedSqlStorage :: DIAGNOSTIC_WORKSTATION ] = \ tao_helpers_Display :: sanitizeXssHtml ( trim ( $ this -> getRequestParameter ( 'workstation' ) ) ) ; } return $ data ; }
Fetch POST data Get login by cookie If check parameters is true check mandatory parameters
49,804
public function workstation ( ) { $ response = [ 'success' => false , 'workstation' => uniqid ( 'workstation-' ) ] ; $ diagnostic = $ this -> getDiagnosticDataTable ( ) -> getDiagnostic ( $ this -> getId ( ) ) ; if ( isset ( $ diagnostic ) ) { $ response [ 'success' ] = true ; $ workstation = trim ( $ diagnostic [ PaginatedSqlStorage :: DIAGNOSTIC_WORKSTATION ] ) ; if ( $ workstation ) { $ response [ 'workstation' ] = $ workstation ; } } $ this -> returnJson ( $ response ) ; }
Gets the name of the workstation being tested If current id is found on database associated workstation is retrieve Else an uniqid is generated
49,805
public function recordThat ( Message $ event ) : void { if ( ! \ array_key_exists ( $ event -> messageName ( ) , $ this -> eventApplyMap ) ) { throw new \ RuntimeException ( 'Wrong event recording detected. Unknown event passed to GenericAggregateRoot: ' . $ event -> messageName ( ) ) ; } $ this -> version += 1 ; $ event = $ event -> withAddedMetadata ( '_aggregate_id' , $ this -> aggregateId ( ) ) ; $ event = $ event -> withAddedMetadata ( '_aggregate_version' , $ this -> version ) ; $ this -> recordedEvents [ ] = $ event ; $ this -> apply ( $ event ) ; }
Record an aggregate changed event
49,806
public function upsertDoc ( string $ collectionName , string $ docId , array $ docOrSubset ) : void { if ( $ this -> hasDoc ( $ collectionName , $ docId ) ) { $ this -> updateDoc ( $ collectionName , $ docId , $ docOrSubset ) ; } else { $ this -> addDoc ( $ collectionName , $ docId , $ docOrSubset ) ; } }
Same as updateDoc except that doc is added to collection if it does not exist .
49,807
public function getQueueByWeight ( ) { $ weights = array_map ( function ( QueueInterface $ queue ) { return $ queue -> getWeight ( ) ; } , $ this -> getQueues ( ) ) ; $ rand = mt_rand ( 1 , array_sum ( $ weights ) ) ; foreach ( $ this -> getQueues ( ) as $ queue ) { $ rand -= $ queue -> getWeight ( ) ; if ( $ rand <= 0 ) { $ this -> logDebug ( 'Queue "' . strtoupper ( $ queue -> getName ( ) ) . '" selected by weight.' ) ; return $ queue ; } } }
Gets random queue based on weight .
49,808
protected function runWorker ( QueueInterface $ queue ) { ( new Worker ( $ this , $ this -> getTaskLog ( ) , false ) ) -> setDedicatedQueue ( $ queue , 1 ) -> run ( ) ; }
Run worker on - the - fly for one round .
49,809
public function getTaskResource ( \ core_kernel_classes_Resource $ resource ) { $ tasksRootClass = $ this -> getClass ( Task :: TASK_CLASS ) ; $ taskResources = $ tasksRootClass -> searchInstances ( [ Task :: PROPERTY_LINKED_RESOURCE => $ resource -> getUri ( ) ] ) ; return empty ( $ taskResources ) ? null : current ( $ taskResources ) ; }
Get resource from rdf storage which represents task in the task queue by linked resource Returns null if there is no task linked to given resource
49,810
public function getReportByLinkedResource ( \ core_kernel_classes_Resource $ resource ) { $ taskResource = $ this -> getTaskResource ( $ resource ) ; if ( $ taskResource !== null ) { $ report = $ taskResource -> getOnePropertyValue ( $ this -> getProperty ( Task :: PROPERTY_REPORT ) ) ; if ( $ report ) { $ report = Report :: jsonUnserialize ( $ report -> literal ) ; } else { $ status = $ this -> getTaskLog ( ) -> getStatus ( $ taskResource -> getUri ( ) ) ; $ msg = __ ( 'Task is in \'%s\' state' , $ status ) ; $ report = $ status == TaskLogInterface :: STATUS_FAILED ? Report :: createFailure ( $ msg ) : Report :: createInfo ( $ msg ) ; } } else { $ report = Report :: createFailure ( __ ( 'Resource is not the task placeholder' ) ) ; } return $ report ; }
It will be deprecated once we have the general GUI for displaying different info of a task for the user .
49,811
private function pickQueueByWight ( array $ queues ) { $ weights = array_map ( function ( QueueInterface $ queue ) { return $ queue -> getWeight ( ) ; } , $ queues ) ; $ rand = mt_rand ( 1 , array_sum ( $ weights ) ) ; foreach ( $ queues as $ queue ) { $ rand -= $ queue -> getWeight ( ) ; if ( $ rand <= 0 ) { return $ queue ; } } }
Picks randomly a queue based on weight .
49,812
public function initResultServer ( $ compiledDelivery , $ executionIdentifier , $ userUri ) { $ storage = $ this -> getResultStorage ( $ compiledDelivery ) ; $ storage -> storeRelatedTestTaker ( $ executionIdentifier , $ userUri ) ; $ storage -> storeRelatedDelivery ( $ executionIdentifier , $ compiledDelivery -> getUri ( ) ) ; }
Starts or resume a taoResultServerStateFull session for results submission
49,813
protected function getQtiResultService ( ) { if ( ! $ this -> service ) { $ this -> service = $ this -> getServiceManager ( ) -> get ( ResultService :: SERVICE_ID ) ; } return $ this -> service ; }
Return the service for Result
49,814
public function byDeliveryExecution ( ) { try { $ this -> checkMethod ( ) ; $ this -> validateParams ( array ( self :: DELIVERY_EXECUTION ) ) ; $ deliveryExecution = $ this -> getQtiResultService ( ) -> getDeliveryExecutionById ( $ this -> getRequestParameter ( self :: DELIVERY_EXECUTION ) ) ; $ this -> returnValidXml ( $ this -> getQtiResultService ( ) -> getDeliveryExecutionXml ( $ deliveryExecution ) ) ; } catch ( Exception $ e ) { $ this -> returnFailure ( $ e ) ; } }
It requires only Delivery Execution in URI format .
49,815
protected function validateParams ( array $ params ) { foreach ( $ params as $ param ) { if ( ! $ this -> hasRequestParameter ( $ param ) ) { throw new common_exception_MissingParameter ( $ param . ' is missing from the request.' , $ this -> getRequestURI ( ) ) ; } if ( empty ( $ this -> getRequestParameter ( $ param ) ) ) { throw new common_exception_ValidationFailed ( $ param , $ param . ' cannot be empty' ) ; } } }
Validates the given parameters .
49,816
protected function returnValidXml ( $ data ) { if ( empty ( $ data ) ) { throw new common_exception_NotFound ( 'Delivery execution not found.' ) ; } $ doc = @ simplexml_load_string ( $ data ) ; if ( ! $ doc ) { common_Logger :: i ( 'invalid xml result' ) ; throw new Exception ( 'Xml output is malformed.' ) ; } header ( 'Content-Type: application/xml' ) ; echo $ data ; exit ( 0 ) ; }
Return XML response if it is valid .
49,817
public function spawnResult ( ) { $ result = null ; foreach ( $ this -> getAllImplementations ( StorageWrite :: class ) as $ impl ) { $ result = $ impl -> spawnResult ( ) ; } return $ result ; }
Not sure how multiple engines are supposed to handle this
49,818
protected function getDeliveryExecutionService ( ) { if ( ! $ this -> deliveryExecutionService ) { $ this -> deliveryExecutionService = $ this -> getServiceLocator ( ) -> get ( ServiceProxy :: SERVICE_ID ) ; } return $ this -> deliveryExecutionService ; }
Get the implementation of delivery execution service
49,819
public function getDeliveryExecutionById ( $ deliveryExecutionId ) { $ deliveryExecution = $ this -> getDeliveryExecutionService ( ) -> getDeliveryExecution ( $ deliveryExecutionId ) ; try { $ deliveryExecution -> getDelivery ( ) ; } catch ( \ common_exception_NotFound $ e ) { throw new \ common_exception_NotFound ( 'Provided parameters don\'t match with any delivery execution.' ) ; } return $ deliveryExecution ; }
Get Delivery execution from resource
49,820
public function getDeliveryExecutionXml ( DeliveryExecutionInterface $ deliveryExecution ) { return $ this -> getQtiResultXml ( $ deliveryExecution -> getDelivery ( ) -> getUri ( ) , $ deliveryExecution -> getIdentifier ( ) ) ; }
Return delivery execution as xml of testtaker based on delivery
49,821
public function push ( TaskInterface $ task ) { return ( bool ) $ this -> getPersistence ( ) -> insert ( $ this -> getTableName ( ) , [ 'message' => $ this -> serializeTask ( $ task ) , 'created_at' => $ this -> getPersistence ( ) -> getPlatForm ( ) -> getNowExpression ( ) ] ) ; }
Insert a new task into the queue table .
49,822
protected function doPop ( ) { $ this -> getPersistence ( ) -> getPlatform ( ) -> beginTransaction ( ) ; $ logContext = [ 'Queue' => $ this -> getQueueNameWithPrefix ( ) ] ; try { $ qb = $ this -> getQueryBuilder ( ) -> select ( 'id, message' ) -> from ( $ this -> getTableName ( ) ) -> andWhere ( 'visible = :visible' ) -> orderBy ( 'created_at' ) -> setMaxResults ( $ this -> getNumberOfTasksToReceive ( ) ) ; $ sql = $ qb -> getSQL ( ) . ' ' . $ this -> getPersistence ( ) -> getPlatForm ( ) -> getWriteLockSQL ( ) ; if ( $ dbResult = $ this -> getPersistence ( ) -> query ( $ sql , [ 'visible' => 1 ] ) -> fetchAll ( \ PDO :: FETCH_ASSOC ) ) { $ qb = $ this -> getQueryBuilder ( ) -> update ( $ this -> getTableName ( ) ) -> set ( 'visible' , ':visible' ) -> where ( 'id IN (' . implode ( ',' , array_column ( $ dbResult , 'id' ) ) . ')' ) -> setParameter ( 'visible' , 0 ) ; $ qb -> execute ( ) ; foreach ( $ dbResult as $ row ) { if ( $ task = $ this -> unserializeTask ( $ row [ 'message' ] , $ row [ 'id' ] , $ logContext ) ) { $ task -> setMetadata ( 'RdsMessageId' , $ row [ 'id' ] ) ; $ this -> pushPreFetchedMessage ( $ task ) ; } } } else { $ this -> logDebug ( 'No task in the queue.' , $ logContext ) ; } $ this -> getPersistence ( ) -> getPlatform ( ) -> commit ( ) ; } catch ( \ Exception $ e ) { $ this -> getPersistence ( ) -> getPlatform ( ) -> rollBack ( ) ; $ this -> logError ( 'Popping tasks failed with MSG: ' . $ e -> getMessage ( ) , $ logContext ) ; } }
Does the DBAL specific pop mechanism .
49,823
public function delete ( TaskInterface $ task ) { $ this -> doDelete ( $ task -> getMetadata ( 'RdsMessageId' ) , [ 'InternalMessageId' => $ task -> getId ( ) , 'RdsMessageId' => $ task -> getMetadata ( 'RdsMessageId' ) ] ) ; }
Delete the message after being processed by the worker .
49,824
public function get ( ) { try { $ this -> returnSuccess ( $ this -> getTaskEntity ( ) -> toArray ( ) ) ; } catch ( \ Exception $ e ) { $ this -> returnFailure ( $ e ) ; } }
Returns the details of a task independently from the owner .
49,825
public function addAvailableFilters ( $ userId ) { $ this -> neq ( TaskLogBrokerInterface :: COLUMN_STATUS , TaskLogInterface :: STATUS_ARCHIVED ) ; if ( $ userId !== TaskLogInterface :: SUPER_USER ) { $ this -> eq ( TaskLogBrokerInterface :: COLUMN_OWNER , $ userId ) ; } return $ this ; }
Add a basic filter to query only rows belonging to a given user and not having status ARCHIVED .
49,826
public function createQueue ( ) { try { $ result = $ this -> getClient ( ) -> createQueue ( [ 'QueueName' => $ this -> getQueueNameWithPrefix ( ) , 'Attributes' => [ 'DelaySeconds' => 0 , 'VisibilityTimeout' => 600 ] ] ) ; if ( $ result -> hasKey ( 'QueueUrl' ) ) { $ this -> queueUrl = $ result -> get ( 'QueueUrl' ) ; $ this -> getCache ( ) -> put ( $ this -> getUrlCacheKey ( ) , $ this -> queueUrl ) ; $ this -> logDebug ( 'Queue ' . $ this -> queueUrl . ' created and cached' ) ; } else { $ this -> logError ( 'Queue ' . $ this -> getQueueNameWithPrefix ( ) . ' not created' ) ; } } catch ( AwsException $ e ) { $ this -> logError ( 'Creating queue ' . $ this -> getQueueNameWithPrefix ( ) . ' failed with MSG: ' . $ e -> getMessage ( ) ) ; if ( PHP_SAPI == 'cli' ) { throw $ e ; } } }
Creates queue .
49,827
protected function doPop ( ) { if ( ! $ this -> queueExists ( ) ) { $ this -> createQueue ( ) ; } $ logContext = [ 'QueueUrl' => $ this -> queueUrl ] ; try { $ result = $ this -> getClient ( ) -> receiveMessage ( [ 'AttributeNames' => [ ] , 'MaxNumberOfMessages' => $ this -> getNumberOfTasksToReceive ( ) , 'MessageAttributeNames' => [ ] , 'QueueUrl' => $ this -> queueUrl , 'WaitTimeSeconds' => 20 ] ) ; if ( count ( $ result -> get ( 'Messages' ) ) > 0 ) { $ this -> logDebug ( 'Received ' . count ( $ result -> get ( 'Messages' ) ) . ' messages.' , $ logContext ) ; foreach ( $ result -> get ( 'Messages' ) as $ message ) { $ task = $ this -> unserializeTask ( $ message [ 'Body' ] , $ message [ 'ReceiptHandle' ] , [ 'SqsMessageId' => $ message [ 'MessageId' ] ] ) ; if ( $ task ) { $ task -> setMetadata ( 'SqsMessageId' , $ message [ 'MessageId' ] ) ; $ task -> setMetadata ( 'ReceiptHandle' , $ message [ 'ReceiptHandle' ] ) ; $ this -> pushPreFetchedMessage ( $ task ) ; } } } else { $ this -> logDebug ( 'No messages in queue.' , $ logContext ) ; } } catch ( AwsException $ e ) { $ this -> logError ( 'Popping tasks failed with MSG: ' . $ e -> getAwsErrorMessage ( ) , $ logContext ) ; } }
Does the SQS specific pop mechanism .
49,828
protected function doDelete ( $ receipt , array $ logContext = [ ] ) { if ( ! $ this -> queueExists ( ) ) { $ this -> createQueue ( ) ; } $ logContext = array_merge ( [ 'QueueUrl' => $ this -> queueUrl ] , $ logContext ) ; try { $ this -> getClient ( ) -> deleteMessage ( [ 'QueueUrl' => $ this -> queueUrl , 'ReceiptHandle' => $ receipt ] ) ; $ this -> logDebug ( 'Task deleted from queue.' , $ logContext ) ; } catch ( AwsException $ e ) { $ this -> logError ( 'Deleting task failed with MSG: ' . $ e -> getAwsErrorMessage ( ) , $ logContext ) ; } }
Delete a task by its receipt .
49,829
protected function queueExists ( ) { if ( isset ( $ this -> queueUrl ) ) { return true ; } if ( $ this -> getCache ( ) -> has ( $ this -> getUrlCacheKey ( ) ) ) { $ this -> queueUrl = $ this -> getCache ( ) -> get ( $ this -> getUrlCacheKey ( ) ) ; return true ; } try { $ result = $ this -> getClient ( ) -> getQueueUrl ( [ 'QueueName' => $ this -> getQueueNameWithPrefix ( ) ] ) ; $ this -> queueUrl = $ result -> get ( 'QueueUrl' ) ; if ( $ result -> hasKey ( 'QueueUrl' ) ) { $ this -> queueUrl = $ result -> get ( 'QueueUrl' ) ; } else { $ this -> logError ( 'Queue url for' . $ this -> getQueueNameWithPrefix ( ) . ' not fetched' ) ; } if ( $ this -> queueUrl !== null ) { $ this -> getCache ( ) -> put ( $ this -> queueUrl , $ this -> getUrlCacheKey ( ) ) ; $ this -> logDebug ( 'Queue url ' . $ this -> queueUrl . ' fetched and cached' ) ; return true ; } } catch ( AwsException $ e ) { $ this -> logWarning ( 'Fetching queue url for ' . $ this -> getQueueNameWithPrefix ( ) . ' failed. MSG: ' . $ e -> getAwsErrorMessage ( ) ) ; } return false ; }
Checks if queue exists
49,830
public function getVariable ( $ callId , $ variableIdentifier ) { $ rawVariable = $ this -> getDbStorage ( ) -> getVariable ( $ callId , $ variableIdentifier ) ; if ( $ this -> canFileBeRestored ( $ rawVariable [ 0 ] -> variable ) ) { $ rawVariable [ 0 ] -> variable = $ this -> restoreFile ( $ rawVariable [ 0 ] -> variable ) ; } return $ rawVariable ; }
Get The variable that match params
49,831
public function storeItemVariable ( $ deliveryResultIdentifier , $ test , $ item , taoResultServer_models_classes_Variable $ itemVariable , $ callIdItem ) { $ variable = $ this -> handleFiles ( $ deliveryResultIdentifier , $ itemVariable ) ; $ this -> getDbStorage ( ) -> storeItemVariable ( $ deliveryResultIdentifier , $ test , $ item , $ variable , $ callIdItem ) ; }
Store Item Variable
49,832
public function getDefaultResultServer ( ) { $ ext = common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoResultServer' ) ; if ( $ ext -> hasConfig ( self :: DEFAULT_RESULTSERVER_KEY ) ) { $ uri = $ ext -> getConfig ( self :: DEFAULT_RESULTSERVER_KEY ) ; } else { $ uri = ResultServerService :: INSTANCE_VOID_RESULT_SERVER ; } return new core_kernel_classes_Resource ( $ uri ) ; }
Return the default result server to use
49,833
public function setDefaultResultServer ( core_kernel_classes_Resource $ resultServer ) { $ ext = common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoResultServer' ) ; $ ext -> setConfig ( self :: DEFAULT_RESULTSERVER_KEY , $ resultServer -> getUri ( ) ) ; }
Sets the default result server to use
49,834
protected function getLocalizedRedirect ( $ locale ) { return is_string ( $ localizedUrl = $ this -> localization -> getLocalizedURL ( $ locale ) ) ? $ this -> makeRedirectResponse ( $ localizedUrl ) : null ; }
Get the redirection response .
49,835
public function direction ( ) { if ( empty ( $ this -> direction ) ) { $ rtlScripts = [ 'Arab' , 'Hebr' , 'Mong' , 'Tfng' , 'Thaa' ] ; $ this -> setDirection ( in_array ( $ this -> script , $ rtlScripts ) ? self :: DIRECTION_RIGHT_TO_LEFT : self :: DIRECTION_LEFT_TO_RIGHT ) ; } return $ this -> direction ; }
Get locale direction .
49,836
public function toArray ( ) { return [ 'key' => $ this -> key ( ) , 'name' => $ this -> name ( ) , 'script' => $ this -> script ( ) , 'dir' => $ this -> direction ( ) , 'native' => $ this -> native ( ) , 'regional' => $ this -> regional ( ) , ] ; }
Get the locale entity as an array .
49,837
public function createUrlFromUri ( $ uri ) { $ uri = ltrim ( $ uri , '/' ) ; return empty ( $ this -> baseUrl ) ? $ this -> app [ \ Illuminate \ Contracts \ Routing \ UrlGenerator :: class ] -> to ( $ uri ) : $ this -> baseUrl . $ uri ; }
Create an url from the uri .
49,838
public function localesNavbar ( ) { $ view = $ this -> app [ ViewFactoryContract :: class ] ; return $ view -> make ( 'localization::navbar' , [ 'supportedLocales' => $ this -> getSupportedLocales ( ) ] ) -> render ( ) ; }
Get locales navigation bar .
49,839
private function findTranslatedRouteByUrl ( $ url , $ attributes , $ locale ) { if ( empty ( $ url ) ) return false ; foreach ( $ this -> routeTranslator -> getTranslatedRoutes ( ) as $ translatedRoute ) { $ translatedUrl = $ this -> getUrlFromRouteName ( $ locale , $ translatedRoute , $ attributes ) ; if ( $ this -> getNonLocalizedURL ( $ translatedUrl ) === $ this -> getNonLocalizedURL ( $ url ) ) return $ translatedRoute ; } return false ; }
Returns the translated route for an url and the attributes given and a locale
49,840
public function getUrlFromRouteName ( $ locale , $ transKey , array $ attributes = [ ] , $ showHiddenLocale = false ) { $ this -> isLocaleSupportedOrFail ( $ locale ) ; $ route = $ this -> routeTranslator -> getUrlFromRouteName ( $ locale , $ this -> getDefaultLocale ( ) , $ transKey , $ attributes , $ this -> isDefaultLocaleHiddenInUrl ( ) , $ showHiddenLocale ) ; if ( empty ( $ route ) ) return false ; return rtrim ( $ this -> createUrlFromUri ( $ route ) ) ; }
Returns an URL adapted to the route name and the locale given .
49,841
public function setRouteNameFromRequest ( Request $ request ) { $ routeName = $ this -> routeTranslator -> getRouteNameFromPath ( $ request -> getUri ( ) , $ this -> getCurrentLocale ( ) ) ; $ this -> routeTranslator -> setCurrentRoute ( $ routeName ) ; }
Set route name from request .
49,842
public function negotiate ( Request $ request ) { $ this -> request = $ request ; if ( ! is_null ( $ locale = $ this -> getFromAcceptedLanguagesHeader ( ) ) ) return $ locale ; if ( ! is_null ( $ locale = $ this -> getFromHttpAcceptedLanguagesServer ( ) ) ) return $ locale ; if ( ! is_null ( $ locale = $ this -> getFromRemoteHostServer ( ) ) ) return $ locale ; return $ this -> defaultLocale ; }
Negotiate the request .
49,843
private function getFromAcceptedLanguagesHeader ( ) { $ matches = $ this -> getMatchesFromAcceptedLanguages ( ) ; if ( $ locale = $ this -> inSupportedLocales ( $ matches ) ) { return $ locale ; } if ( isset ( $ matches [ '*' ] ) ) { return $ this -> supportedLocales -> first ( ) -> key ( ) ; } return null ; }
Get locale from accepted languages header .
49,844
private function getFromHttpAcceptedLanguagesServer ( ) { $ httpAcceptLanguage = $ this -> request -> server ( 'HTTP_ACCEPT_LANGUAGE' ) ; if ( ! class_exists ( 'Locale' ) || empty ( $ httpAcceptLanguage ) ) return null ; $ locale = Locale :: acceptFromHttp ( $ httpAcceptLanguage ) ; if ( $ this -> isSupported ( $ locale ) ) return $ locale ; return null ; }
Get locale from http accepted languages server .
49,845
private function getFromRemoteHostServer ( ) { if ( empty ( $ remoteHost = $ this -> request -> server ( 'REMOTE_HOST' ) ) ) return null ; $ remoteHost = explode ( '.' , $ remoteHost ) ; $ locale = strtolower ( end ( $ remoteHost ) ) ; return $ this -> isSupported ( $ locale ) ? $ locale : null ; }
Get locale from remote host server .
49,846
private function inSupportedLocales ( array $ matches ) { foreach ( array_keys ( $ matches ) as $ locale ) { if ( $ this -> isSupported ( $ locale ) ) return $ locale ; foreach ( $ this -> supportedLocales as $ key => $ entity ) { if ( $ entity -> regional ( ) == $ locale ) return $ key ; } } return null ; }
Check if matches a supported locale .
49,847
private function getMatchesFromAcceptedLanguages ( ) { $ matches = [ ] ; $ acceptLanguages = $ this -> request -> header ( 'Accept-Language' ) ; if ( ! empty ( $ acceptLanguages ) ) { $ acceptLanguages = explode ( ',' , $ acceptLanguages ) ; $ genericMatches = $ this -> retrieveGenericMatches ( $ acceptLanguages , $ matches ) ; $ matches = array_merge ( $ genericMatches , $ matches ) ; arsort ( $ matches , SORT_NUMERIC ) ; } return $ matches ; }
Return all the accepted languages from the browser
49,848
private function retrieveGenericMatches ( $ acceptLanguages , & $ matches ) { $ genericMatches = [ ] ; foreach ( $ acceptLanguages as $ option ) { $ option = array_map ( 'trim' , explode ( ';' , $ option ) ) ; $ locale = $ option [ 0 ] ; $ quality = $ this -> getQualityFactor ( $ locale , $ option ) ; $ quality = isset ( $ quality ) ? $ quality : 1000 - count ( $ matches ) ; $ matches [ $ locale ] = $ quality ; $ localeOptions = explode ( '-' , $ locale ) ; array_pop ( $ localeOptions ) ; while ( ! empty ( $ localeOptions ) ) { $ quality -= 0.001 ; $ opt = implode ( '-' , $ localeOptions ) ; if ( empty ( $ genericMatches [ $ opt ] ) || $ genericMatches [ $ opt ] > $ quality ) { $ genericMatches [ $ opt ] = $ quality ; } array_pop ( $ localeOptions ) ; } } return $ genericMatches ; }
Get the generic matches .
49,849
private function getQualityFactor ( $ locale , $ option ) { if ( isset ( $ option [ 1 ] ) ) return ( float ) str_replace ( 'q=' , '' , $ option [ 1 ] ) ; if ( $ locale === '*/*' ) return 0.01 ; if ( substr ( $ locale , - 1 ) === '*' ) return 0.02 ; return null ; }
Get the quality factor .
49,850
public function getTranslatedRoute ( $ baseUrl , & $ parsedUrl , $ defaultLocale , LocaleCollection $ supportedLocales ) { if ( empty ( $ parsedUrl ) || ! isset ( $ parsedUrl [ 'path' ] ) ) { $ parsedUrl [ 'path' ] = '' ; } else { $ path = $ parsedUrl [ 'path' ] = str_replace ( $ baseUrl , '' , '/' . ltrim ( $ parsedUrl [ 'path' ] , '/' ) ) ; foreach ( $ supportedLocales -> keys ( ) as $ locale ) { foreach ( [ "%^/?$locale/%" , "%^/?$locale$%" ] as $ pattern ) { $ parsedUrl [ 'path' ] = preg_replace ( $ pattern , '$1' , $ parsedUrl [ 'path' ] ) ; if ( $ parsedUrl [ 'path' ] !== $ path ) { $ defaultLocale = $ locale ; break 2 ; } } } } $ parsedUrl [ 'path' ] = ltrim ( $ parsedUrl [ 'path' ] , '/' ) ; return $ this -> findTranslatedRouteByPath ( $ parsedUrl [ 'path' ] , $ defaultLocale ) ; }
Get the translated route .
49,851
public function getRouteNameFromPath ( $ uri , $ locale ) { $ attributes = Url :: extractAttributes ( $ uri ) ; $ uri = str_replace ( [ url ( '/' ) , "/$locale/" ] , '' , $ uri ) ; $ uri = trim ( $ uri , '/' ) ; foreach ( $ this -> translatedRoutes as $ routeName ) { $ url = Url :: substituteAttributes ( $ attributes , $ this -> translate ( $ routeName ) ) ; if ( $ url === $ uri ) return $ routeName ; } return false ; }
Returns the translation key for a given path .
49,852
public function findTranslatedRouteByPath ( $ path , $ locale ) { foreach ( $ this -> translatedRoutes as $ route ) { if ( $ this -> translate ( $ route , $ locale ) == rawurldecode ( $ path ) ) return $ route ; } return false ; }
Returns the translated route for the path and the url given .
49,853
public function getUrlFromRouteName ( $ locale , $ defaultLocale , $ transKey , $ attributes = [ ] , $ defaultHidden = false , $ showHiddenLocale = false ) { if ( ! is_string ( $ locale ) ) $ locale = $ defaultLocale ; $ url = '' ; if ( ! ( $ locale === $ defaultLocale && $ defaultHidden ) || $ showHiddenLocale ) $ url = '/' . $ locale ; if ( $ this -> hasTranslation ( $ transKey , $ locale ) ) $ url = Url :: substituteAttributes ( $ attributes , $ url . '/' . $ this -> trans ( $ transKey , $ locale ) ) ; return $ url ; }
Get URL from route name .
49,854
public static function extractAttributes ( $ url = false ) { $ parse = parse_url ( $ url ) ; $ path = isset ( $ parse [ 'path' ] ) ? explode ( '/' , $ parse [ 'path' ] ) : [ ] ; $ url = [ ] ; foreach ( $ path as $ segment ) { if ( ! empty ( $ segment ) ) $ url [ ] = $ segment ; } $ router = app ( 'router' ) ; return self :: extractAttributesFromRoutes ( $ url , $ router -> getRoutes ( ) ) ; }
Extract attributes for current url .
49,855
private static function extractAttributesFromRoutes ( $ url , $ routes ) { $ attributes = [ ] ; foreach ( $ routes as $ route ) { $ request = Request :: create ( implode ( '/' , $ url ) ) ; if ( ! $ route -> matches ( $ request ) ) continue ; $ match = self :: hasAttributesFromUriPath ( $ url , $ route -> uri ( ) , $ attributes ) ; if ( $ match ) break ; } return $ attributes ; }
Extract attributes from routes .
49,856
private static function hasAttributesFromUriPath ( $ url , $ path , & $ attributes ) { $ i = 0 ; $ match = true ; $ path = explode ( '/' , $ path ) ; foreach ( $ path as $ j => $ segment ) { if ( isset ( $ url [ $ i ] ) ) { if ( $ segment !== $ url [ $ i ] ) { self :: extractAttributesFromSegment ( $ url , $ path , $ i , $ j , $ segment , $ attributes ) ; } $ i ++ ; continue ; } elseif ( ! preg_match ( '/{[\w]+\?}/' , $ segment ) ) { $ match = false ; break ; } } if ( isset ( $ url [ $ i + 1 ] ) ) $ match = false ; return $ match ; }
Check if has attributes from a route .
49,857
private static function extractAttributesFromSegment ( $ url , $ path , $ i , $ j , $ segment , & $ attributes ) { if ( preg_match ( '/{[\w]+}/' , $ segment ) ) { $ attributeName = preg_replace ( [ '/{/' , '/\?/' , '/}/' ] , '' , $ segment ) ; $ attributes [ $ attributeName ] = $ url [ $ i ] ; } if ( preg_match ( '/{[\w]+\?}/' , $ segment ) && ( ! isset ( $ path [ $ j + 1 ] ) || $ path [ $ j + 1 ] !== $ url [ $ i ] ) ) { $ attributeName = preg_replace ( [ '/{/' , '/\?/' , '/}/' ] , '' , $ segment ) ; $ attributes [ $ attributeName ] = $ url [ $ i ] ; } }
Extract attribute from a segment .
49,858
private static function checkParsedUrl ( array $ parsed ) { $ scheme = & $ parsed [ 'scheme' ] ; $ user = & $ parsed [ 'user' ] ; $ pass = & $ parsed [ 'pass' ] ; $ host = & $ parsed [ 'host' ] ; $ port = & $ parsed [ 'port' ] ; $ path = & $ parsed [ 'path' ] ; $ path = '/' . ltrim ( $ path , '/' ) ; $ query = & $ parsed [ 'query' ] ; $ fragment = & $ parsed [ 'fragment' ] ; return compact ( 'scheme' , 'user' , 'pass' , 'host' , 'port' , 'path' , 'query' , 'fragment' ) ; }
Check parsed URL .
49,859
private static function getHierPart ( array $ parsed ) { return strlen ( $ authority = self :: getAuthority ( $ parsed ) ) ? '//' . $ authority . $ parsed [ 'path' ] : $ parsed [ 'path' ] ; }
Get hier part .
49,860
private static function getAuthority ( array $ parsed ) { $ host = self :: getHost ( $ parsed ) ; return strlen ( $ userInfo = self :: getUserInfo ( $ parsed ) ) ? $ userInfo . '@' . $ host : $ host ; }
Get authority .
49,861
private function registerLocaleNegotiator ( ) { $ this -> bind ( NegotiatorContract :: class , function ( $ app ) { $ manager = $ app [ LocalesManagerContract :: class ] ; return new Negotiator ( $ manager -> getDefaultLocale ( ) , $ manager -> getSupportedLocales ( ) ) ; } ) ; }
Register LocaleNegotiator utility .
49,862
private function getTranslatedUrl ( Request $ request ) { $ route = $ request -> route ( ) ; if ( ! ( $ route instanceof Route ) || is_null ( $ route -> getName ( ) ) ) return null ; return $ this -> translateRoute ( $ route -> getName ( ) , $ route -> parameters ( ) ) ; }
Get translated URL .
49,863
public function translateRoute ( $ routeName , $ attributes = [ ] ) { if ( empty ( $ attributes ) ) return null ; $ transAttributes = $ this -> fireEvent ( $ this -> getCurrentLocale ( ) , $ routeName , $ attributes ) ; if ( ! empty ( $ transAttributes ) && $ transAttributes !== $ attributes ) return route ( $ routeName , $ transAttributes ) ; return null ; }
Translate route .
49,864
private function fireEvent ( $ locale , $ route , $ attributes ) { $ response = event ( self :: EVENT_NAME , [ $ locale , $ route , $ attributes ] ) ; if ( ! empty ( $ response ) ) $ response = array_shift ( $ response ) ; if ( is_array ( $ response ) ) $ attributes = array_merge ( $ attributes , $ response ) ; return $ attributes ; }
Fire translation event .
49,865
public function getAttributeValue ( $ key ) { return $ this -> isTranslatableAttribute ( $ key ) ? $ this -> getTranslation ( $ key , $ this -> getLocale ( ) ) : parent :: getAttributeValue ( $ key ) ; }
Get the translated attribute value .
49,866
public function getTranslations ( $ key = null ) { if ( $ key !== null ) { $ this -> guardAgainstNonTranslatableAttribute ( $ key ) ; return array_filter ( json_decode ( $ this -> getAttributeFromArray ( $ key ) ?? '' ? : '{}' , true ) ? : [ ] , function ( $ value ) { return $ value !== null && $ value !== false && $ value !== '' ; } ) ; } return array_reduce ( $ this -> getTranslatableAttributes ( ) , function ( $ result , $ item ) { $ result [ $ item ] = $ this -> getTranslations ( $ item ) ; return $ result ; } ) ; }
Get the translations for the given key .
49,867
public function setTranslation ( $ key , $ locale , $ value ) { $ this -> guardAgainstNonTranslatableAttribute ( $ key ) ; $ translations = $ this -> getTranslations ( $ key ) ; $ oldValue = $ translations [ $ locale ] ?? '' ; if ( $ this -> hasSetMutator ( $ key ) ) { $ this -> { 'set' . Str :: studly ( $ key ) . 'Attribute' } ( $ value ) ; $ value = $ this -> attributes [ $ key ] ; } $ translations [ $ locale ] = $ value ; $ this -> attributes [ $ key ] = $ this -> asJson ( $ translations ) ; event ( new TranslationHasBeenSet ( $ this , $ key , $ locale , $ oldValue , $ value ) ) ; return $ this ; }
Set a translation .
49,868
public function setTranslations ( $ key , array $ translations ) { $ this -> guardAgainstNonTranslatableAttribute ( $ key ) ; foreach ( $ translations as $ locale => $ translation ) { $ this -> setTranslation ( $ key , $ locale , $ translation ) ; } return $ this ; }
Set the translations .
49,869
public function forgetTranslation ( $ key , $ locale ) { $ translations = $ this -> getTranslations ( $ key ) ; unset ( $ translations [ $ locale ] ) ; if ( $ this -> hasSetMutator ( $ key ) ) $ this -> attributes [ $ key ] = $ this -> asJson ( $ translations ) ; else $ this -> setAttribute ( $ key , $ translations ) ; return $ this ; }
Forget a translation .
49,870
protected function guardAgainstNonTranslatableAttribute ( $ key ) { if ( ! $ this -> isTranslatableAttribute ( $ key ) ) { throw UntranslatableAttributeException :: make ( $ key , $ this -> getTranslatableAttributes ( ) ) ; } }
Guard against untranslatable attribute .
49,871
protected function normalizeLocale ( $ key , $ locale , $ useFallback ) { if ( in_array ( $ locale , $ this -> getTranslatedLocales ( $ key ) ) || ! $ useFallback ) return $ locale ; return config ( 'app.fallback_locale' ) ? : $ locale ; }
Normalize the locale .
49,872
private function load ( ) { $ this -> locales -> loadFromArray ( $ this -> getConfig ( 'locales' ) ) ; $ this -> setSupportedLocales ( $ this -> getConfig ( 'supported-locales' ) ) ; $ this -> setDefaultLocale ( ) ; }
Load all locales data .
49,873
public function setLocale ( $ locale = null ) { if ( empty ( $ locale ) || ! is_string ( $ locale ) ) { $ locale = $ this -> request ( ) -> segment ( 1 ) ; } if ( $ this -> isSupportedLocale ( $ locale ) ) { $ this -> setCurrentLocale ( $ locale ) ; } else { $ locale = null ; $ this -> getCurrentOrDefaultLocale ( ) ; } $ this -> app -> setLocale ( $ this -> getCurrentLocale ( ) ) ; $ this -> updateRegional ( ) ; return $ locale ; }
Set and return current locale .
49,874
public function setSupportedLocales ( array $ supportedLocales ) { if ( ! is_array ( $ supportedLocales ) || empty ( $ supportedLocales ) ) throw new UndefinedSupportedLocalesException ; $ this -> supportedLocales = $ this -> filterLocales ( $ supportedLocales ) ; return $ this ; }
Set supported locales .
49,875
private function negotiateLocale ( ) { return Negotiator :: make ( $ this -> getDefaultLocale ( ) , $ this -> getSupportedLocales ( ) ) -> negotiate ( $ this -> request ( ) ) ; }
Get negotiated locale .
49,876
private function filterLocales ( array $ supportedLocales ) { return $ this -> locales -> filter ( function ( Locale $ locale ) use ( $ supportedLocales ) { return in_array ( $ locale -> key ( ) , $ supportedLocales ) ; } ) ; }
Filter locale collection .
49,877
private function updateRegional ( ) { $ currentLocale = $ this -> getCurrentLocaleEntity ( ) ; if ( ! empty ( $ regional = $ currentLocale -> regional ( ) ) ) { $ suffix = $ this -> getConfig ( 'utf-8-suffix' , '.UTF-8' ) ; setlocale ( LC_TIME , $ regional . $ suffix ) ; setlocale ( LC_MONETARY , $ regional . $ suffix ) ; } }
Update locale regional .
49,878
public function getSupported ( ) { return new SupportedLocaleCollection ( $ this -> filter ( function ( Locale $ locale ) { return in_array ( $ locale -> key ( ) , $ this -> supported ) ; } ) ) ; }
Get supported locales collection .
49,879
public function loadFromArray ( array $ locales ) { $ this -> items = [ ] ; foreach ( $ locales as $ key => $ locale ) { $ this -> put ( $ key , Locale :: make ( $ key , $ locale ) ) ; } return $ this ; }
Load locales from array .
49,880
protected function getRedirectionUrl ( Request $ request ) { $ locale = $ request -> segment ( 1 , null ) ; if ( $ this -> getSupportedLocales ( ) -> has ( $ locale ) ) return $ this -> isDefaultLocaleHidden ( $ locale ) ? $ this -> localization -> getNonLocalizedURL ( ) : false ; if ( $ this -> getCurrentLocale ( ) !== $ this -> getDefaultLocale ( ) || ! $ this -> hideDefaultLocaleInURL ( ) ) { return $ this -> localization -> getLocalizedURL ( session ( 'locale' ) , $ request -> fullUrl ( ) ) ; } return false ; }
Get redirection .
49,881
private function registerLocalization ( ) { $ this -> singleton ( Contracts \ Localization :: class , Localization :: class ) ; if ( $ alias = $ this -> config ( ) -> get ( 'localization.facade' ) ) { $ this -> alias ( $ alias , Facades \ Localization :: class ) ; $ this -> registerAliases ( ) ; } }
Register Localization .
49,882
protected function selectDelivery ( ) { $ ltiSession = LtiService :: singleton ( ) -> getLtiSession ( ) ; if ( $ ltiSession -> getLaunchData ( ) -> hasVariable ( LtiLaunchData :: RESOURCE_LINK_TITLE ) ) { $ this -> setData ( 'linkTitle' , $ ltiSession -> getLaunchData ( ) -> getVariable ( LtiLaunchData :: RESOURCE_LINK_TITLE ) ) ; } $ this -> setData ( 'link' , $ ltiSession -> getLtiLinkResource ( ) -> getUri ( ) ) ; $ this -> setData ( 'submitUrl' , _url ( 'setDelivery' ) ) ; $ deliveries = DeliveryAssemblyService :: singleton ( ) -> getAllAssemblies ( ) ; if ( count ( $ deliveries ) > 0 ) { $ this -> setData ( 'deliveries' , $ deliveries ) ; $ this -> setView ( 'instructor/selectDelivery.tpl' ) ; } else { $ this -> returnError ( __ ( 'No deliveries available' ) ) ; } }
Displays the form to select a delivery
49,883
public function setDelivery ( ) { $ link = new core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'link' ) ) ; $ compiled = new core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'uri' ) ) ; $ link -> editPropertyValues ( new core_kernel_classes_Property ( LTIDeliveryTool :: PROPERTY_LINK_DELIVERY ) , $ compiled ) ; $ this -> redirect ( _url ( 'showDelivery' , null , null , array ( 'uri' => $ compiled -> getUri ( ) ) ) ) ; }
called onSelect of a delivery
49,884
public function configureDelivery ( ) { $ compiledDelivery = LTIDeliveryTool :: singleton ( ) -> getDeliveryFromLink ( ) ; if ( is_null ( $ compiledDelivery ) ) { $ this -> selectDelivery ( ) ; } else { $ this -> redirect ( _url ( 'showDelivery' , null , null , array ( 'uri' => $ compiledDelivery -> getUri ( ) ) ) ) ; } }
Either displays the currently associated delivery or calls selectDelivery in order to allow the user to select a delivery
49,885
public function showDelivery ( ) { $ delivery = new core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'uri' ) ) ; $ this -> setData ( 'delivery' , $ delivery ) ; $ ltiSession = LtiService :: singleton ( ) -> getLtiSession ( ) ; if ( $ ltiSession -> getLaunchData ( ) -> hasVariable ( LtiLaunchData :: RESOURCE_LINK_TITLE ) ) { $ this -> setData ( 'linkTitle' , $ ltiSession -> getLaunchData ( ) -> getVariable ( LtiLaunchData :: RESOURCE_LINK_TITLE ) ) ; } if ( ServiceProxy :: singleton ( ) -> implementsMonitoring ( ) ) { $ executions = ServiceProxy :: singleton ( ) -> getExecutionsByDelivery ( $ delivery ) ; $ this -> setData ( 'executionCount' , count ( $ executions ) ) ; } $ this -> setView ( 'instructor/viewDelivery.tpl' ) ; }
Displays the currently associated delivery
49,886
protected function showControls ( ) { $ themeService = $ this -> getServiceManager ( ) -> get ( ThemeServiceInterface :: SERVICE_ID ) ; if ( $ themeService instanceof ThemeServiceInterface || $ themeService instanceof LtiHeadless ) { return ! $ themeService -> isHeadless ( ) ; } return false ; }
Defines if the top and bottom action menu should be displayed or not
49,887
public function ltiOverview ( ) { $ this -> setData ( 'delivery' , $ this -> getRequestParameter ( 'delivery' ) ) ; $ this -> setData ( 'allowRepeat' , true ) ; $ this -> setView ( 'learner/overview.tpl' ) ; }
Shown uppon returning to a finished delivery execution
49,888
public function finishDeliveryExecution ( ) { $ deliveryExecution = null ; if ( $ this -> hasRequestParameter ( 'deliveryExecution' ) ) { $ deliveryExecution = ServiceProxy :: singleton ( ) -> getDeliveryExecution ( $ this -> getRequestParameter ( 'deliveryExecution' ) ) ; if ( $ deliveryExecution -> getState ( ) !== DeliveryExecution :: STATE_FINISHIED ) { $ stateService = $ this -> getServiceManager ( ) -> get ( StateServiceInterface :: SERVICE_ID ) ; $ stateService -> finish ( $ deliveryExecution ) ; } } $ redirectUrl = LTIDeliveryTool :: singleton ( ) -> getFinishUrl ( $ this -> getLtiMessage ( $ deliveryExecution ) , $ deliveryExecution ) ; $ this -> redirect ( $ redirectUrl ) ; }
Redirect user to return URL
49,889
public function collect ( $ force = false ) { $ active = $ this -> getPersistence ( ) -> get ( self :: class ) ; if ( ! $ active || $ force ) { $ action = new GetActiveDeliveryExecution ( ) ; $ this -> propagate ( $ action ) ; $ active = $ action -> getNumberOfActiveActions ( ) ; $ this -> getPersistence ( ) -> set ( self :: class , $ active , $ this -> getOption ( self :: OPTION_TTL ) ) ; } return $ active ; }
Collect values caches
49,890
public function index ( ) { $ feedBackMessage = '' ; $ selectedDelivery = new core_kernel_classes_Resource ( tao_helpers_Uri :: decode ( $ this -> getRequestParameter ( 'uri' ) ) ) ; $ this -> setData ( 'launchUrl' , LTIDeliveryTool :: singleton ( ) -> getLaunchUrl ( array ( 'delivery' => $ selectedDelivery -> getUri ( ) ) ) ) ; if ( ! empty ( $ feedBackMessage ) ) { $ this -> setData ( 'warning' , $ feedBackMessage ) ; } $ class = new core_kernel_classes_Class ( ConsumerService :: CLASS_URI ) ; $ this -> setData ( 'consumers' , $ class -> getInstances ( ) ) ; $ this -> setData ( 'deliveryLabel' , $ selectedDelivery -> getLabel ( ) ) ; $ this -> setView ( 'linkManagement.tpl' , 'ltiDeliveryProvider' ) ; }
Displays the LTI link for the consumer with respect to the currently selected delviery at tdelviery level checks if the delviery is related to a resultserver cofnigured with the correct outcome service impelmentation
49,891
protected function showThankyou ( LtiLaunchData $ launchData ) { if ( ! $ launchData -> hasReturnUrl ( ) ) { return true ; } if ( $ launchData -> hasVariable ( DeliveryTool :: PARAM_SKIP_THANKYOU ) ) { switch ( $ launchData -> getVariable ( DeliveryTool :: PARAM_SKIP_THANKYOU ) ) { case 'true' : return false ; case 'false' : return true ; default : $ this -> logWarning ( 'Unexpected value for \'' . DeliveryTool :: PARAM_SKIP_THANKYOU . '\': ' . $ launchData -> getVariable ( DeliveryTool :: PARAM_SKIP_THANKYOU ) ) ; } } return $ this -> getOption ( self :: OPTION_THANK_YOU_SCREEN ) ; }
Whenever or not to show the thank you screen
49,892
protected function validateLtiParams ( LtiLaunchData $ launchData ) { if ( $ launchData -> hasVariable ( self :: CUSTOM_LTI_SECURE ) ) { $ val = mb_strtolower ( $ launchData -> getVariable ( self :: CUSTOM_LTI_SECURE ) ) ; if ( $ val !== 'true' && $ val !== 'false' ) { throw new LtiException ( __ ( 'Wrong value of "secure" variable.' ) , LtiErrorMessage :: ERROR_INVALID_PARAMETER ) ; } } }
Validate and prepare launch variables
49,893
public function storeResultAlias ( $ deliveryExecutionId , $ resultId ) { $ data = [ self :: DELIVERY_EXECUTION_ID => $ deliveryExecutionId , self :: RESULT_ID => $ resultId , ] ; $ queryBuilder = $ this -> getQueryBuilder ( ) ; $ queryBuilder -> delete ( $ this -> getTableName ( ) ) ; $ queryBuilder -> where ( self :: RESULT_ID . '=? OR ' . self :: DELIVERY_EXECUTION_ID . '= ?' ) ; $ queryBuilder -> setParameters ( [ $ resultId , $ deliveryExecutionId ] ) ; $ res = $ this -> persistence -> query ( $ queryBuilder -> getSQL ( ) , $ queryBuilder -> getParameters ( ) ) -> execute ( ) ; $ result = $ this -> getPersistence ( ) -> insert ( self :: TABLE_NAME , $ data ) === 1 ; return $ result ; }
Add record to the storage
49,894
protected function verifyToken ( \ core_kernel_classes_Resource $ delivery , User $ user ) { $ propMaxExec = $ delivery -> getOnePropertyValue ( $ this -> getProperty ( DeliveryContainerService :: PROPERTY_MAX_EXEC ) ) ; $ maxExec = is_null ( $ propMaxExec ) ? 0 : $ propMaxExec -> literal ; $ currentSession = $ this -> getServiceLocator ( ) -> get ( SessionService :: SERVICE_ID ) -> getCurrentSession ( ) ; if ( $ currentSession instanceof TaoLtiSession ) { $ launchData = $ currentSession -> getLaunchData ( ) ; if ( $ launchData -> hasVariable ( self :: LTI_MAX_ATTEMPTS_VARIABLE ) ) { $ val = $ launchData -> getVariable ( self :: LTI_MAX_ATTEMPTS_VARIABLE ) ; if ( ! is_numeric ( $ val ) ) { throw new LtiException ( __ ( '"max_attempts" variable must me numeric.' ) , LtiErrorMessage :: ERROR_INVALID_PARAMETER ) ; } $ maxExec = ( integer ) $ val ; } } $ usedTokens = count ( $ this -> getServiceLocator ( ) -> get ( AttemptServiceInterface :: SERVICE_ID ) -> getAttempts ( $ delivery -> getUri ( ) , $ user ) ) ; if ( ( $ maxExec != 0 ) && ( $ usedTokens >= $ maxExec ) ) { $ this -> logDebug ( "Attempt to start the compiled delivery " . $ delivery -> getUri ( ) . " without tokens" ) ; throw new LtiException ( __ ( 'Attempts limit has been reached.' ) , LtiErrorMessage :: ERROR_LAUNCH_FORBIDDEN ) ; } return true ; }
Check Max . number of executions
49,895
public function startDelivery ( core_kernel_classes_Resource $ delivery , core_kernel_classes_Resource $ link , User $ user ) { $ this -> getAuthorizationProvider ( ) -> verifyStartAuthorization ( $ delivery -> getUri ( ) , $ user ) ; $ assignmentService = $ this -> getServiceLocator ( ) -> get ( LtiAssignment :: SERVICE_ID ) ; if ( ! $ assignmentService -> isDeliveryExecutionAllowed ( $ delivery -> getUri ( ) , $ user ) ) { throw new \ common_exception_Unauthorized ( __ ( 'User is not authorized to run this delivery' ) ) ; } $ stateService = $ this -> getServiceLocator ( ) -> get ( StateServiceInterface :: SERVICE_ID ) ; $ deliveryExecution = $ stateService -> createDeliveryExecution ( $ delivery -> getUri ( ) , $ user , $ delivery -> getLabel ( ) ) ; $ this -> getServiceLocator ( ) -> get ( LtiDeliveryExecutionService :: SERVICE_ID ) -> createDeliveryExecutionLink ( $ user -> getIdentifier ( ) , $ link -> getUri ( ) , $ deliveryExecution -> getIdentifier ( ) ) ; return $ deliveryExecution ; }
Start a new delivery execution
49,896
private function getDelivery ( ) { $ returnValue = null ; if ( $ this -> hasRequestParameter ( 'delivery' ) ) { $ returnValue = new core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'delivery' ) ) ; } else { $ launchData = LtiService :: singleton ( ) -> getLtiSession ( ) -> getLaunchData ( ) ; $ launchDataService = $ this -> getServiceLocator ( ) -> get ( LtiLaunchDataService :: SERVICE_ID ) ; $ returnValue = $ launchDataService -> findDeliveryFromLaunchData ( $ launchData ) ; } return $ returnValue ; }
Returns the delivery associated with the current link either from url or from the remote_link if configured returns null if none found
49,897
public function getUrl ( ) { try { if ( $ this -> getRequestMethod ( ) != \ Request :: HTTP_GET ) { throw new \ common_exception_NotImplemented ( 'Only GET method is accepted to request this service.' ) ; } if ( ! $ this -> hasRequestParameter ( 'deliveryId' ) ) { $ this -> returnFailure ( new \ common_exception_MissingParameter ( 'At least one mandatory parameter was required but found missing in your request' ) ) ; } $ selectedDelivery = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'deliveryId' ) ) ; if ( ! $ selectedDelivery -> isInstanceOf ( new \ core_kernel_classes_Class ( TaoOntology :: CLASS_URI_DELIVERY ) ) ) { $ this -> returnFailure ( new \ common_exception_NotFound ( 'Delivery not found' ) ) ; } $ this -> returnSuccess ( LTIDeliveryTool :: singleton ( ) -> getLaunchUrl ( array ( 'delivery' => $ selectedDelivery -> getUri ( ) ) ) ) ; } catch ( \ Exception $ ex ) { $ this -> returnFailure ( $ ex ) ; } }
return a LTI link URI from a valid delivery id
49,898
public function getDriver ( $ driver = null ) { $ driver = ( $ driver ) ? : array_get ( $ this -> config , 'driver' , '' ) ; $ method = 'create' . ucfirst ( camel_case ( $ driver ) ) . 'Driver' ; if ( ! method_exists ( $ this , $ method ) ) { throw new InvalidDriverException ( sprintf ( 'Driver [%s] not supported.' , $ driver ) ) ; } return $ this -> { $ method } ( array_get ( $ this -> config , $ driver , [ ] ) ) ; }
Get the driver based on config .
49,899
public function getRaw ( $ ip ) { try { return json_decode ( $ this -> guzzle -> get ( $ this -> getUrl ( $ ip ) ) -> getBody ( ) , true ) ; } catch ( RequestException $ e ) { } return [ ] ; }
Get the raw GeoIP info using ipstack .