idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
49,600
|
public function destroy ( $ sessionId ) { try { $ this -> _tableRestProxy -> deleteEntity ( $ this -> _sessionContainer , $ this -> _sessionContainerParition , $ sessionId ) ; return TRUE ; } catch ( ServiceException $ e ) { return FALSE ; } }
|
Callback function for session handler . It s invoked while the session is being destroyed .
|
49,601
|
public function gc ( $ lifeTime ) { $ filter = 'PartitionKey eq\'' . $ this -> _sessionContainerPartition . '\' and expires lt ' . ( time ( ) - $ lifeTime ) ; try { $ result = $ this -> _tableRestProxy -> queryEntities ( $ this -> _sessionContainer , $ filter ) ; $ entities = $ result -> getEntities ( ) ; foreach ( $ entities as $ entitiy ) { $ this -> _tableRestProxy -> deleteEntity ( $ this -> _sessionContainer , $ this -> _sessionContainerParition , $ entity -> getRowKey ( ) ) ; } return TRUE ; } catch ( ServiceException $ e ) { return FALSE ; } }
|
Callback function for session handler . It s invoked while the session garbage collection starts .
|
49,602
|
public static function mount ( $ path , $ controller_klass ) { $ mounted = null ; $ methods = get_class_methods ( $ controller_klass ) ; if ( ! $ methods ) { debug ( "'{$controller_klass}' has no methods." ) ; return ; } foreach ( $ methods as $ method_name ) { if ( $ method_name == '__construct' ) { continue ; } if ( $ method_name == 'mounted' ) { $ mounted = call_user_func ( array ( $ controller_klass , 'mounted' ) , $ path ) ; continue ; } preg_match_all ( '/^(get|put|post|patch|delete)(.*)/' , $ method_name , $ matches ) ; $ has_matches = ( count ( $ matches [ 1 ] ) > 0 ) ; $ http_method = $ has_matches ? $ matches [ 1 ] [ 0 ] : 'any' ; $ route_name = $ has_matches ? $ matches [ 2 ] [ 0 ] : $ method_name ; $ route = str_finish ( $ path , '/' ) ; if ( $ route_name !== 'index' ) { $ route .= snake_case ( $ route_name ) ; } static :: $ instance -> { $ http_method } ( $ route , "{$controller_klass}:{$method_name}" ) ; } return $ mounted ; }
|
Bind controller methods into a path
|
49,603
|
public static function template ( $ name ) { $ template = null ; if ( preg_match ( '/^[A-Za-z0-9_\.\-\/]+\.html$/' , $ name ) ) { $ template = static :: get ( self :: TYPE_TEMPLATE , $ name ) ; if ( ! $ template ) { $ fallback_template_path = shared_storage_dir ( ) . '/default/templates/' . $ name ; if ( ! file_exists ( $ fallback_template_path ) ) { throw new Exceptions \ MethodFailureException ( "Template not found: '{$name}'. Please run `hook generate:template {$name}` to generate one." ) ; } $ template = new static ( array ( 'type' => self :: TYPE_TEMPLATE , 'code' => file_get_contents ( $ fallback_template_path ) , 'name' => $ name ) ) ; } } if ( ! $ template ) { $ template = new static ( array ( 'type' => self :: TYPE_TEMPLATE , 'code' => $ name , 'name' => 'inline-template.html' ) ) ; } return $ template ; }
|
Get a template module instance trying to fallback to a general template
|
49,604
|
public static function get ( $ type , $ name ) { return ModuleCompiler :: get ( $ type , $ name ) ? : static :: where ( 'type' , $ type ) -> where ( 'name' , $ name ) -> first ( ) ; }
|
Get a module instance
|
49,605
|
public function compile ( $ options = array ( ) ) { $ app = Slim \ Slim :: getInstance ( ) ; $ extension = '.' . pathinfo ( $ this -> name , PATHINFO_EXTENSION ) ; $ name = basename ( $ this -> name , $ extension ) ; if ( $ this -> type == static :: TYPE_OBSERVER || $ this -> type == static :: TYPE_CHANNEL || $ this -> type == static :: TYPE_ROUTE ) { $ aliases = '' ; $ aliases .= 'use Hook\Application\Context;' ; $ aliases .= 'use Hook\Model\Module;' ; $ aliases .= 'use Hook\Model\File;' ; $ aliases .= 'use Hook\Model\Auth;' ; $ aliases .= 'use Hook\Model\AuthToken;' ; $ aliases .= 'use Hook\Model\Collection;' ; $ aliases .= 'use Hook\Cache\Cache;' ; $ aliases .= 'use Hook\Logger\Logger;' ; if ( $ this -> type == self :: TYPE_OBSERVER || $ this -> type == self :: TYPE_CHANNEL ) { $ klass = 'CustomModule' . uniqid ( ) ; eval ( $ aliases . preg_replace ( '/class ([^\ {]+)/' , 'class ' . $ klass , $ this -> code , 1 ) ) ; if ( class_exists ( $ klass ) ) { return new $ klass ; } else { throw new Exceptions \ MethodFailureException ( "Module '{$name}.php' must define a class." ) ; } } elseif ( $ this -> type == self :: TYPE_ROUTE ) { try { eval ( $ aliases . $ this -> code ) ; } catch ( \ Exception $ e ) { $ message = $ this -> name . ': ' . $ e -> getMessage ( ) ; $ app -> log -> info ( $ message ) ; $ app -> response -> headers -> set ( 'X-Error-' . uniqid ( ) , $ message ) ; file_put_contents ( 'php://stderr' , $ message ) ; } } } elseif ( $ this -> type == static :: TYPE_TEMPLATE ) { $ app -> view -> setTemplateString ( $ this -> code ) ; $ options [ 'app_key' ] = \ Hook \ Application \ Context :: getKey ( ) ; return $ app -> view -> render ( $ this -> name , $ options ) ; } }
|
compile Compile module code
|
49,606
|
public static function current ( ) { if ( static :: $ _current === null ) { if ( $ token = AuthToken :: current ( ) ) { $ token -> auth ( ) ; static :: $ _current = $ token -> auth ; } } return static :: $ _current ; }
|
current - get current active Auth instance
|
49,607
|
public function create_new ( array $ attributes = array ( ) ) { $ instance = null ; if ( ! $ this -> is_collection ) { $ instance = new self :: $ custom_collections [ $ this -> name ] ( ) ; } else { $ instance = new Collection ( array ( 'table_name' => $ this -> name ) ) ; } $ instance -> fill ( $ attributes ) ; if ( isset ( $ attributes [ '_id' ] ) && Context :: isTrusted ( ) ) { $ instance -> _id = $ attributes [ '_id' ] ; } return $ instance ; }
|
Create a new Collection instance . No database operations here .
|
49,608
|
public function create ( array $ attributes ) { if ( array_values ( $ attributes ) == $ attributes ) { $ that = $ this ; $ collection = new IlluminateCollection ( $ attributes ) ; return $ collection -> map ( function ( $ attrs ) use ( $ that ) { return $ that -> create ( $ attrs ) ; } ) ; } $ model = $ this -> create_new ( $ attributes ) ; $ model -> save ( ) ; $ eagerLoads = $ this -> query -> getEagerLoads ( ) ; if ( count ( $ eagerLoads ) > 0 ) { $ relations = $ this -> query -> eagerLoadRelations ( array ( $ model ) ) ; $ model = $ relations [ 0 ] ; } return $ model ; }
|
Create a new record into the database .
|
49,609
|
public function from ( $ addresses , $ name = null ) { $ this -> message -> setFrom ( $ addresses , $ name ) ; return $ this ; }
|
Set the From address of this message .
|
49,610
|
protected function dropIndex ( & $ table_name , & $ table_prefix , & $ blueprint , $ previous_attribute_definition = null , $ index = null , $ is_unique = false ) { if ( ! $ previous_attribute_definition ) { return ; } if ( ! $ is_unique && ( ( isset ( $ previous_attribute_definition [ 'index' ] ) && $ previous_attribute_definition [ 'index' ] == 'unique' ) || ( isset ( $ previous_attribute_definition [ 'unique' ] ) && $ previous_attribute_definition [ 'unique' ] == true ) ) ) { $ blueprint -> dropUnique ( $ table_prefix . $ table_name . '_' . $ previous_attribute_definition [ 'name' ] . '_unique' ) ; } if ( ! $ index && ( isset ( $ previous_attribute_definition [ 'index' ] ) && $ previous_attribute_definition [ 'index' ] !== 'unique' ) ) { $ blueprint -> dropIndex ( $ table_prefix . $ table_name . '_' . $ previous_attribute_definition [ 'name' ] . '_index' ) ; } }
|
Drop index from field if necessary .
|
49,611
|
public function setResponseArray ( array $ args = [ ] ) { foreach ( $ args as $ name => $ text ) { return $ this -> response [ $ name ] = $ text ; } return $ this ; }
|
Use to set multiples messages and after get on custom error function
|
49,612
|
static private function formatStringValue ( $ baseType , $ stringValue ) { switch ( strtolower ( $ baseType ) ) { case 'string' : case 'duration' : return $ stringValue ; case 'identifier' : return self :: trimIdentifier ( $ stringValue ) ; case 'integer' : return intval ( $ stringValue ) ; case 'float' : return floatval ( $ stringValue ) ; case 'boolean' : return ( trim ( $ stringValue ) === 'true' || $ stringValue === true ) ? true : false ; case 'pair' : case 'directedpair' : $ pair = explode ( ' ' , trim ( $ stringValue ) ) ; if ( count ( $ pair ) != 2 ) { throw new \ common_Exception ( 'invalid pair string' ) ; } return [ self :: trimIdentifier ( $ pair [ 0 ] ) , self :: trimIdentifier ( $ pair [ 1 ] ) ] ; case 'point' : $ pair = explode ( ' ' , trim ( $ stringValue ) ) ; if ( count ( $ pair ) != 2 ) { throw new \ common_Exception ( 'invalid point string' ) ; } return [ intval ( $ pair [ 0 ] ) , intval ( $ pair [ 1 ] ) ] ; default : throw new \ common_exception_NotImplemented ( 'unknown basetype' ) ; } }
|
Format a string into the appropriate format according to the base type
|
49,613
|
static public function formatVariableToPci ( ResponseVariable $ var ) { $ value = $ var -> getValue ( ) ; switch ( $ var -> getCardinality ( ) ) { case 'single' : if ( strlen ( $ value ) === 0 ) { $ formatted = [ 'base' => null ] ; } else { try { $ formatted = [ 'base' => [ $ var -> getBaseType ( ) => self :: formatStringValue ( $ var -> getBaseType ( ) , $ value ) ] ] ; } catch ( \ common_exception_NotImplemented $ e ) { $ formatted = [ 'base' => null ] ; } } break ; case 'ordered' : case 'multiple' : if ( strlen ( $ value ) === 0 ) { $ formatted = [ 'list' => [ $ var -> getBaseType ( ) => [ ] ] ] ; } else { preg_match_all ( '/([^\[\];<>]+)/' , $ value , $ matches ) ; $ list = [ ] ; foreach ( $ matches [ 1 ] as $ valueString ) { if ( empty ( trim ( $ valueString ) ) ) { continue ; } try { $ list [ ] = self :: formatStringValue ( $ var -> getBaseType ( ) , $ valueString ) ; } catch ( \ common_exception_NotImplemented $ e ) { } } $ formatted = [ 'list' => [ $ var -> getBaseType ( ) => $ list ] ] ; } break ; default : throw new \ common_Exception ( 'unknown response cardinality' ) ; } return $ formatted ; }
|
Format a ResponseVariable into a associative array directly usable on the client side .
|
49,614
|
public function getDefaultItemType ( ) { if ( $ this -> hasOption ( self :: OPTION_DEFAULT_ITEM_TYPE ) ) { return $ this -> getOption ( self :: OPTION_DEFAULT_ITEM_TYPE ) ; } return false ; }
|
Gets the default item type the viewer should manage
|
49,615
|
private function exportIntoFolder ( \ core_kernel_classes_Class $ deliveryClass , $ destination ) { foreach ( $ deliveryClass -> getInstances ( false ) as $ delivery ) { ( new SingleDeliveryResultsExporter ( $ delivery , $ this -> resultsService , ( new ColumnsProvider ( $ delivery , $ this -> resultsService ) ) ) ) -> setServiceLocator ( $ this -> getServiceLocator ( ) ) -> export ( $ destination ) ; } if ( $ subClasses = $ deliveryClass -> getSubClasses ( false ) ) { foreach ( $ subClasses as $ subClass ) { $ newDestination = $ destination . DIRECTORY_SEPARATOR . \ tao_helpers_Display :: textCleaner ( $ subClass -> getLabel ( ) , '*' ) ; mkdir ( $ newDestination ) ; $ this -> exportIntoFolder ( $ subClass , $ newDestination ) ; } } }
|
Recursively exports all results under a class into a folder .
|
49,616
|
public function prepare ( $ resources , $ columns ) { $ resultsService = ResultsService :: singleton ( ) ; $ undefinedStr = __ ( 'unknown' ) ; foreach ( $ resources as $ result ) { $ itemresults = $ resultsService -> getVariables ( $ result , false ) ; foreach ( $ itemresults as $ itemResultUri => $ vars ) { if ( common_cache_FileCache :: singleton ( ) -> has ( 'itemResultItemCache' . $ itemResultUri ) ) { $ object = json_decode ( common_cache_FileCache :: singleton ( ) -> get ( 'itemResultItemCache' . $ itemResultUri ) , true ) ; } else { $ object = $ resultsService -> getItemFromItemResult ( $ itemResultUri ) ; if ( is_null ( $ object ) ) { $ object = $ resultsService -> getVariableFromTest ( $ itemResultUri ) ; } if ( ! is_null ( $ object ) ) { common_cache_FileCache :: singleton ( ) -> put ( json_encode ( $ object ) , 'itemResultItemCache' . $ itemResultUri ) ; } } if ( $ object ) { if ( $ object instanceof core_kernel_classes_Resource ) { $ contextIdentifier = $ object -> getUri ( ) ; } else { $ contextIdentifier = $ object [ 'uriResource' ] ; } } else { $ contextIdentifier = $ undefinedStr ; } foreach ( $ vars as $ var ) { $ var = $ var [ 0 ] ; $ varData = $ var -> variable ; if ( $ varData -> getBaseType ( ) === 'file' ) { $ decodedFile = Datatypes :: decodeFile ( $ varData -> getValue ( ) ) ; $ varData -> setValue ( $ decodedFile [ 'name' ] ) ; } $ variableIdentifier = ( string ) $ varData -> getIdentifier ( ) ; foreach ( $ columns as $ column ) { if ( $ variableIdentifier == $ column -> getIdentifier ( ) and $ contextIdentifier == $ column -> getContextIdentifier ( ) ) { $ epoch = $ varData -> getEpoch ( ) ; $ readableTime = "" ; if ( $ epoch != "" ) { $ readableTime = "@" . tao_helpers_Date :: displayeDate ( tao_helpers_Date :: getTimeStamp ( $ epoch ) , tao_helpers_Date :: FORMAT_VERBOSE ) ; } $ value = $ varData -> getValue ( ) ; if ( $ column -> getIdentifier ( ) === 'duration' ) { $ qtiDuration = new QtiDuration ( $ value ) ; $ value = $ qtiDuration -> getSeconds ( ) . '.' . $ qtiDuration -> getMicroseconds ( ) ; } $ this -> cache [ get_class ( $ varData ) ] [ $ result ] [ $ column -> getContextIdentifier ( ) . $ variableIdentifier ] [ ( string ) $ epoch ] = array ( $ value , $ readableTime ) ; } } } } } }
|
Short description of method prepare
|
49,617
|
static public function decodeFile ( $ binary ) { $ returnValue = array ( 'name' => '' , 'mime' => '' , 'data' => '' ) ; if ( empty ( $ binary ) === false ) { $ filenameLen = current ( unpack ( 'S' , substr ( $ binary , 0 , 2 ) ) ) ; if ( $ filenameLen > 0 ) { $ returnValue [ 'name' ] = substr ( $ binary , 2 , $ filenameLen ) ; } $ mimetypeLen = current ( unpack ( 'S' , substr ( $ binary , 2 + $ filenameLen , 2 ) ) ) ; $ returnValue [ 'mime' ] = substr ( $ binary , 4 + $ filenameLen , $ mimetypeLen ) ; $ returnValue [ 'data' ] = substr ( $ binary , 4 + $ filenameLen + $ mimetypeLen ) ; } return $ returnValue ; }
|
Decode a binary string representing a file into an array .
|
49,618
|
public function getDeliveryColumns ( ) { $ columns = [ ] ; $ customProps = $ this -> getClass ( $ this -> delivery -> getOnePropertyValue ( $ this -> getProperty ( OntologyRdf :: RDF_TYPE ) ) ) -> getProperties ( ) ; $ deliveryProps = array_merge ( $ this -> deliveryProperties , $ customProps ) ; foreach ( $ deliveryProps as $ property ) { $ property = $ this -> getProperty ( $ property ) ; $ loginCol = new ContextTypePropertyColumn ( ContextTypePropertyColumn :: CONTEXT_TYPE_DELIVERY , $ property ) ; if ( $ property -> getUri ( ) == OntologyRdfs :: RDFS_LABEL ) { $ loginCol -> label = __ ( 'Delivery' ) ; } $ columns [ ] = $ loginCol -> toArray ( ) ; } return $ columns ; }
|
Get delivery columns to be exported .
|
49,619
|
private function decodeColumns ( $ columnsJson ) { return ( $ columnsData = json_decode ( $ columnsJson , true ) ) !== null && json_last_error ( ) === JSON_ERROR_NONE ? $ columnsData : [ ] ; }
|
Decode the JSON encoded columns .
|
49,620
|
public function delete ( ) { if ( ! $ this -> isXmlHttpRequest ( ) ) { throw new common_exception_BadRequest ( 'wrong request mode' ) ; } $ deliveryExecutionUri = tao_helpers_Uri :: decode ( $ this -> getRequestParameter ( 'uri' ) ) ; $ de = $ this -> getServiceProxy ( ) -> getDeliveryExecution ( $ deliveryExecutionUri ) ; try { $ this -> getResultStorage ( $ de -> getDelivery ( ) ) ; $ deleted = $ this -> getResultsService ( ) -> deleteResult ( $ deliveryExecutionUri ) ; $ this -> returnJson ( array ( 'deleted' => $ deleted ) ) ; } catch ( \ common_exception_Error $ e ) { $ this -> returnJson ( array ( 'error' => $ e -> getMessage ( ) ) ) ; } }
|
Delete a result or a result class
|
49,621
|
private function isCacheable ( $ resultIdentifier ) { return $ this -> getServiceProxy ( ) -> getDeliveryExecution ( $ resultIdentifier ) -> getState ( ) -> getUri ( ) == DeliveryExecutionInterface :: STATE_FINISHIED ; }
|
Is the given delivery execution aka . result cacheable?
|
49,622
|
public function downloadXML ( ) { try { if ( ! $ this -> hasRequestParameter ( 'id' ) || empty ( $ this -> getRequestParameter ( 'id' ) ) ) { throw new \ common_exception_MissingParameter ( 'Result id is missing from the request.' , $ this -> getRequestURI ( ) ) ; } if ( ! $ this -> hasRequestParameter ( 'delivery' ) || empty ( $ this -> getRequestParameter ( 'delivery' ) ) ) { throw new \ common_exception_MissingParameter ( 'Delivery id is missing from the request.' , $ this -> getRequestURI ( ) ) ; } $ qtiResultService = $ this -> getServiceManager ( ) -> get ( QtiResultsService :: SERVICE_ID ) ; $ xml = $ qtiResultService -> getQtiResultXml ( $ this -> getRequestParameter ( 'delivery' ) , $ this -> getRawParameter ( 'id' ) ) ; header ( 'Set-Cookie: fileDownload=true' ) ; setcookie ( "fileDownload" , "true" , 0 , "/" ) ; header ( 'Content-Disposition: attachment; filename="delivery_execution_' . date ( 'YmdHis' ) . '.xml"' ) ; header ( 'Content-Type: application/xml' ) ; echo $ xml ; } catch ( \ common_exception_UserReadableException $ e ) { $ this -> returnJson ( array ( 'error' => $ e -> getUserMessage ( ) ) ) ; } }
|
Download delivery execution XML
|
49,623
|
public function getFile ( ) { $ variableUri = $ _POST [ "variableUri" ] ; $ delivery = $ this -> getResource ( tao_helpers_Uri :: decode ( $ this -> getRequestParameter ( 'deliveryUri' ) ) ) ; try { $ this -> getResultStorage ( $ delivery ) ; $ file = $ this -> getResultsService ( ) -> getVariableFile ( $ variableUri ) ; header ( 'Set-Cookie: fileDownload=true' ) ; setcookie ( "fileDownload" , "true" , 0 , "/" ) ; header ( "Content-type: " . $ file [ "mimetype" ] ) ; if ( ! isset ( $ file [ "filename" ] ) || $ file [ "filename" ] == "" ) { header ( 'Content-Disposition: attachment; filename=download' ) ; } else { header ( 'Content-Disposition: attachment; filename=' . $ file [ "filename" ] ) ; } echo $ file [ "data" ] ; } catch ( \ common_exception_Error $ e ) { echo $ e -> getMessage ( ) ; } }
|
Get the data for the file in the response and allow user to download it
|
49,624
|
protected function getResultStorage ( $ delivery ) { $ resultServerService = $ this -> getServiceManager ( ) -> get ( ResultServerService :: SERVICE_ID ) ; $ resultStorage = $ resultServerService -> getResultStorage ( $ delivery -> getUri ( ) ) ; if ( $ resultStorage instanceof NoResultStorage ) { throw NoResultStorageException :: create ( ) ; } if ( ! $ resultStorage instanceof \ taoResultServer_models_classes_ReadableResultStorage ) { throw new \ common_exception_Error ( 'The results storage it is not readable' ) ; } $ this -> getResultsService ( ) -> setImplementation ( $ resultStorage ) ; return $ resultStorage ; }
|
Returns the currently configured result storage
|
49,625
|
protected function getResultVariables ( $ resultId , $ filterSubmission , $ filterTypes = array ( ) ) { $ resultService = $ this -> getResultsService ( ) ; $ variables = $ resultService -> getStructuredVariables ( $ resultId , $ filterSubmission , array_merge ( $ filterTypes , [ \ taoResultServer_models_classes_ResponseVariable :: class ] ) ) ; $ displayedVariables = $ resultService -> filterStructuredVariables ( $ variables , $ filterTypes ) ; $ responses = ResponseVariableFormatter :: formatStructuredVariablesToItemState ( $ variables ) ; $ excludedVariables = array_flip ( [ 'numAttempts' , 'duration' ] ) ; foreach ( $ displayedVariables as & $ item ) { if ( ! isset ( $ item [ 'uri' ] ) ) { continue ; } $ itemUri = $ item [ 'uri' ] ; $ item [ 'state' ] = isset ( $ responses [ $ itemUri ] [ $ item [ 'attempt' ] ] ) ? json_encode ( array_diff_key ( $ responses [ $ itemUri ] [ $ item [ 'attempt' ] ] , $ excludedVariables ) ) : null ; } return $ displayedVariables ; }
|
Extracts the result variables with respect to the user s filter and inject item states to allow preview with results
|
49,626
|
public function getResultsListPlugin ( ) { $ pluginService = $ this -> getServiceLocator ( ) -> get ( ResultsPluginService :: SERVICE_ID ) ; $ event = new ResultsListPluginEvent ( $ pluginService -> getAllPlugins ( ) ) ; $ this -> getServiceLocator ( ) -> get ( EventManager :: SERVICE_ID ) -> trigger ( $ event ) ; return array_filter ( $ event -> getPlugins ( ) , function ( $ plugin ) { return ! is_null ( $ plugin ) && $ plugin -> isActive ( ) ; } ) ; }
|
Get the list of active plugins for the list of results
|
49,627
|
public function export ( ) { if ( ! $ this -> isXmlHttpRequest ( ) ) { throw new \ Exception ( 'Only ajax call allowed.' ) ; } if ( ! $ this -> hasRequestParameter ( self :: PARAMETER_DELIVERY_CLASS_URI ) && ! $ this -> hasRequestParameter ( self :: PARAMETER_DELIVERY_URI ) ) { throw new \ common_Exception ( 'Parameter "' . self :: PARAMETER_DELIVERY_CLASS_URI . '" or "' . self :: PARAMETER_DELIVERY_URI . '" missing' ) ; } $ resourceUri = $ this -> hasRequestParameter ( self :: PARAMETER_DELIVERY_URI ) ? \ tao_helpers_Uri :: decode ( $ this -> getRequestParameter ( self :: PARAMETER_DELIVERY_URI ) ) : \ tao_helpers_Uri :: decode ( $ this -> getRequestParameter ( self :: PARAMETER_DELIVERY_CLASS_URI ) ) ; $ exporter = $ this -> propagate ( new ResultsExporter ( $ resourceUri , ResultsService :: singleton ( ) ) ) ; return $ this -> returnTaskJson ( $ exporter -> createExportTask ( ) ) ; }
|
Exports results by either a class or a single delivery .
|
49,628
|
public function getDeliveryItemType ( $ resultIdentifier ) { $ resultsViewerService = $ this -> getServiceLocator ( ) -> get ( ResultsViewerService :: SERVICE_ID ) ; return $ resultsViewerService -> getDeliveryItemType ( $ resultIdentifier ) ; }
|
Ges the type of items contained by the delivery
|
49,629
|
public function filterStructuredVariables ( array $ structure , array $ filter ) { $ all = [ \ taoResultServer_models_classes_ResponseVariable :: class , \ taoResultServer_models_classes_OutcomeVariable :: class , \ taoResultServer_models_classes_TraceVariable :: class ] ; $ toRemove = array_diff ( $ all , $ filter ) ; $ filtered = $ structure ; foreach ( $ filtered as $ timestamp => $ entry ) { foreach ( $ entry as $ key => $ value ) { if ( in_array ( $ key , $ toRemove ) ) { unset ( $ filtered [ $ timestamp ] [ $ key ] ) ; } } } return $ filtered ; }
|
Filters the complex array structure for variable classes
|
49,630
|
public function getVariableDataFromDeliveryResult ( $ resultIdentifier , $ wantedTypes = array ( \ taoResultServer_models_classes_ResponseVariable :: class , \ taoResultServer_models_classes_OutcomeVariable :: class , \ taoResultServer_models_classes_TraceVariable :: class ) ) { $ variablesData = array ( ) ; foreach ( $ this -> getTestsFromDeliveryResult ( $ resultIdentifier ) as $ testResult ) { foreach ( $ this -> getVariablesFromObjectResult ( $ testResult ) as $ variable ) { if ( $ variable [ 0 ] -> callIdTest != "" && in_array ( get_class ( $ variable [ 0 ] -> variable ) , $ wantedTypes ) ) { $ variablesData [ ] = $ variable [ 0 ] -> variable ; } } } usort ( $ variablesData , function ( $ a , $ b ) { list ( $ usec , $ sec ) = explode ( " " , $ a -> getEpoch ( ) ) ; $ floata = ( ( float ) $ usec + ( float ) $ sec ) ; list ( $ usec , $ sec ) = explode ( " " , $ b -> getEpoch ( ) ) ; $ floatb = ( ( float ) $ usec + ( float ) $ sec ) ; if ( ( floatval ( $ floata ) - floatval ( $ floatb ) ) > 0 ) { return 1 ; } elseif ( ( floatval ( $ floata ) - floatval ( $ floatb ) ) < 0 ) { return - 1 ; } else { return 0 ; } } ) ; return $ variablesData ; }
|
return all variables linked to the delviery result and that are not linked to a particular itemResult
|
49,631
|
public function getVariableFile ( $ variableUri ) { $ baseType = $ this -> getVariableBaseType ( $ variableUri ) ; if ( core_kernel_classes_DbWrapper :: singleton ( ) -> getPlatForm ( ) -> getName ( ) == 'mysql' ) { if ( defined ( "PDO::MYSQL_ATTR_MAX_BUFFER_SIZE" ) ) { $ maxBuffer = ( is_int ( ini_get ( 'upload_max_filesize' ) ) ) ? ( ini_get ( 'upload_max_filesize' ) * 1.5 ) : 10485760 ; core_kernel_classes_DbWrapper :: singleton ( ) -> getSchemaManager ( ) -> setAttribute ( \ PDO :: MYSQL_ATTR_MAX_BUFFER_SIZE , $ maxBuffer ) ; } } switch ( $ baseType ) { case "file" : { $ value = $ this -> getVariableCandidateResponse ( $ variableUri ) ; common_Logger :: i ( var_export ( strlen ( $ value ) , true ) ) ; $ decodedFile = Datatypes :: decodeFile ( $ value ) ; common_Logger :: i ( "FileName:" ) ; common_Logger :: i ( var_export ( $ decodedFile [ "name" ] , true ) ) ; common_Logger :: i ( "Mime Type:" ) ; common_Logger :: i ( var_export ( $ decodedFile [ "mime" ] , true ) ) ; $ file = array ( "data" => $ decodedFile [ "data" ] , "mimetype" => "Content-type: " . $ decodedFile [ "mime" ] , "filename" => $ decodedFile [ "name" ] ) ; break ; } default : { $ file = array ( "data" => $ this -> getVariableCandidateResponse ( $ variableUri ) , "mimetype" => "Content-type: text/xml" , "filename" => "trace.xml" ) ; } } return $ file ; }
|
Return the file data associate to a variable
|
49,632
|
public function getColumnNames ( array $ columns ) { return array_reduce ( $ columns , function ( $ carry , \ tao_models_classes_table_Column $ column ) { $ carry [ $ this -> getColumnId ( $ column ) ] = $ column -> getLabel ( ) ; return $ carry ; } ) ; }
|
Get the array of column names indexed by their unique column id .
|
49,633
|
private function meetFilters ( $ row , array $ filters ) { $ matched = true ; if ( count ( $ filters ) && count ( array_diff ( self :: PERIODS , array_keys ( $ filters ) ) ) ) { $ startDate = current ( $ row [ 'delivery_execution_started_at' ] ) ; $ startTime = $ startDate ? \ tao_helpers_Date :: getTimeStamp ( $ startDate ) : 0 ; $ endDate = current ( $ row [ 'delivery_execution_finished_at' ] ) ; $ endTime = $ endDate ? \ tao_helpers_Date :: getTimeStamp ( $ endDate ) : 0 ; if ( $ startTime ) { if ( $ matched && array_key_exists ( 'startfrom' , $ filters ) && $ filters [ 'startfrom' ] ) { $ matched = $ startTime >= $ filters [ 'startfrom' ] ; } if ( $ matched && array_key_exists ( 'startto' , $ filters ) && $ filters [ 'startto' ] ) { $ matched = $ startTime <= $ filters [ 'startto' ] ; } } if ( $ endTime && $ matched ) { if ( $ matched && array_key_exists ( 'endfrom' , $ filters ) && $ filters [ 'endfrom' ] ) { $ matched = $ endTime >= $ filters [ 'endfrom' ] ; } if ( $ matched && array_key_exists ( 'endto' , $ filters ) && $ filters [ 'endto' ] ) { $ matched = $ endTime <= $ filters [ 'endto' ] ; } } } return $ matched ; }
|
Check that data is apply to these filter params
|
49,634
|
private function isResultVariable ( $ variable , $ variableClassUri ) { $ responseVariableClass = \ taoResultServer_models_classes_ResponseVariable :: class ; $ outcomeVariableClass = \ taoResultServer_models_classes_OutcomeVariable :: class ; $ class = isset ( $ variable -> class ) ? $ variable -> class : get_class ( $ variable -> variable ) ; return ( null != $ variable -> item || null != $ variable -> test ) && ( $ class == $ outcomeVariableClass && $ variableClassUri == $ outcomeVariableClass ) || ( $ class == $ responseVariableClass && $ variableClassUri == $ responseVariableClass ) ; }
|
Check if provided variable is a result variable .
|
49,635
|
public static function filterCellData ( $ observationsList , $ filterData , $ allDelimiter = '|' ) { if ( ! is_array ( $ observationsList ) ) { return $ observationsList ; } uksort ( $ observationsList , "oat\\taoOutcomeUi\\model\\ResultsService::sortTimeStamps" ) ; $ observationsList = array_map ( function ( $ obs ) { return $ obs [ 0 ] ; } , $ observationsList ) ; switch ( $ filterData ) { case self :: VARIABLES_FILTER_LAST_SUBMITTED : $ value = array_pop ( $ observationsList ) ; break ; case self :: VARIABLES_FILTER_FIRST_SUBMITTED : $ value = array_shift ( $ observationsList ) ; break ; case self :: VARIABLES_FILTER_ALL : default : $ value = implode ( $ allDelimiter , $ observationsList ) ; break ; } return [ $ value ] ; }
|
Sort the list of variables by filters
|
49,636
|
protected function initColumns ( ) { $ returnValue = ( bool ) false ; $ excludedProperties = ( is_array ( $ this -> options ) && isset ( $ this -> options [ 'excludedProperties' ] ) ) ? $ this -> options [ 'excludedProperties' ] : array ( ) ; $ columnNames = ( is_array ( $ this -> options ) && isset ( $ this -> options [ 'columnNames' ] ) ) ? $ this -> options [ 'columnNames' ] : array ( ) ; $ processProperties = array ( OntologyRdfs :: RDFS_LABEL => __ ( 'Label' ) , ResultService :: DELIVERY_CLASS_URI => __ ( 'Delivery' ) , ResultService :: SUBJECT_CLASS_URI => __ ( 'Test taker' ) , OntologyRdf :: RDF_TYPE => __ ( 'Class' ) ) ; foreach ( $ processProperties as $ processPropertyUri => $ label ) { if ( ! isset ( $ excludedProperties [ $ processPropertyUri ] ) ) { $ column = $ this -> grid -> addColumn ( $ processPropertyUri , $ label ) ; } } $ this -> grid -> setColumnsAdapter ( array_keys ( $ processProperties ) , new tao_helpers_grid_Cell_ResourceLabelAdapter ( ) ) ; return ( bool ) $ returnValue ; }
|
Short description of method initColumns
|
49,637
|
protected function ensureValidResult ( ) { $ deliveryExecution = ServiceProxy :: singleton ( ) -> getDeliveryExecution ( $ this -> instanceCache [ $ this -> currentInstance ] ) ; try { $ deliveryExecution -> getDelivery ( ) ; } catch ( \ common_exception_NotFound $ e ) { $ message = 'Skip result ' . $ deliveryExecution -> getIdentifier ( ) . ' with message ' . $ e -> getMessage ( ) ; \ common_Logger :: e ( $ message ) ; $ this -> next ( ) ; } }
|
Ensure the current item is valid result
|
49,638
|
public function index ( ) { $ deliveryService = DeliveryAssemblyService :: singleton ( ) ; if ( $ this -> getRequestParameter ( 'classUri' ) !== $ deliveryService -> getRootClass ( ) -> getUri ( ) ) { $ filter = $ this -> getRequestParameter ( 'filter' ) ; $ uri = $ this -> getRequestParameter ( 'uri' ) ; if ( ! \ common_Utils :: isUri ( tao_helpers_Uri :: decode ( $ uri ) ) ) { throw new \ tao_models_classes_MissingRequestParameterException ( 'uri' ) ; } $ this -> setData ( 'filter' , $ filter ) ; $ this -> setData ( 'uri' , $ uri ) ; $ this -> setView ( 'resultTable.tpl' ) ; } else { $ this -> setData ( 'type' , 'info' ) ; $ this -> setData ( 'error' , __ ( 'No tests have been taken yet. As soon as a test-taker will take a test his results will be displayed here.' ) ) ; $ this -> setView ( 'index.tpl' ) ; } }
|
Return the Result Table entry page displaying the datatable and the filters to be applied .
|
49,639
|
public function feedDataTable ( ) { if ( ! $ this -> isXmlHttpRequest ( ) ) { throw new \ Exception ( 'Only ajax call allowed.' ) ; } if ( ! $ this -> hasRequestParameter ( self :: PARAMETER_COLUMNS ) ) { throw new common_Exception ( 'Parameter "' . self :: PARAMETER_COLUMNS . '" missing' ) ; } $ this -> returnJson ( ( new ResultsPayload ( $ this -> getExporterService ( ) -> getExporter ( ) ) ) -> getPayload ( ) ) ; }
|
Feeds js datatable component with the values to be exported .
|
49,640
|
public function getCategories ( ) { if ( null === $ this -> _categories ) { $ collection = Mage :: getModel ( 'catalog/category' ) -> getCollection ( ) ; $ pathLike = Mage_Catalog_Model_Category :: TREE_ROOT_ID . '/' . Mage :: app ( ) -> getStore ( ) -> getRootCategoryId ( ) . '/%' ; $ collection -> initCache ( Mage :: app ( ) -> getCacheInstance ( ) , self :: class , [ Mage_Catalog_Model_Category :: CACHE_TAG ] ) -> setStoreId ( Mage :: app ( ) -> getStore ( ) -> getId ( ) ) -> addAttributeToSelect ( '*' ) -> addFieldToFilter ( 'path' , [ 'like' => $ pathLike , ] ) -> addIsActiveFilter ( ) -> addAttributeToFilter ( 'include_in_menu' , 1 ) -> joinUrlRewrite ( ) ; $ collection -> getSelect ( ) -> reset ( Zend_Db_Select :: ORDER ) ; $ collection -> addOrder ( 'position' , Varien_Data_Collection_Db :: SORT_ORDER_ASC ) ; foreach ( $ collection as $ id => $ category ) { $ this -> _categories [ $ id ] = $ category ; } } return $ this -> _categories ; }
|
Give all categories of the current store
|
49,641
|
public function getCategoriesTree ( ) { $ allCategories = $ this -> getCategories ( ) ; $ topCategories = [ ] ; $ currentCategory = null ; foreach ( $ allCategories as $ idCat => $ category ) { $ topLevel = 2 ; if ( $ category -> getLevel ( ) == $ topLevel && ! isset ( $ topCategories [ $ idCat ] ) ) { $ topCategories [ $ idCat ] = $ category ; } else { if ( ! isset ( $ allCategories [ $ category -> getParentId ( ) ] ) ) { continue ; } $ parent = $ allCategories [ $ category -> getParentId ( ) ] ; $ children = $ parent -> getData ( '_children' ) ? : [ ] ; $ children [ $ idCat ] = $ category ; $ category -> setData ( '_parent' , $ parent ) ; $ parent -> setData ( '_children' , $ children ) ; } if ( ( int ) $ idCat === $ this -> getCurrentCategoryId ( ) ) { $ currentCategory = $ category ; } } if ( null !== $ currentCategory ) { $ setCategoryAsCurrent = function ( Mage_Catalog_Model_Category $ category , $ isParent = false ) use ( & $ setCategoryAsCurrent ) { if ( $ isParent ) { $ category -> setContainsCurrentCategory ( true ) ; } else { $ category -> setIsCurrentCategory ( true ) ; } if ( $ parentCategory = $ category -> getData ( '_parent' ) ) { $ setCategoryAsCurrent ( $ parentCategory , true ) ; } } ; $ setCategoryAsCurrent ( $ currentCategory ) ; } return $ topCategories ; }
|
Retrieve the categories tree
|
49,642
|
public function delete ( ) { $ this -> getContext ( ) -> invokeApiPost ( 'DATABASES' , [ 'action' => 'accesshosts' , 'delete' => 'yes' , 'db' => $ this -> database -> getDatabaseName ( ) , 'select0' => $ this -> getName ( ) , ] ) ; $ this -> database -> clearCache ( ) ; }
|
Deletes the access host .
|
49,643
|
public static function create ( Domain $ domain , $ prefix ) { $ domain -> invokePost ( 'SUBDOMAIN' , 'create' , [ 'subdomain' => $ prefix ] ) ; return new self ( $ prefix , $ domain ) ; }
|
Creates a new subdomain .
|
49,644
|
public function createAdmin ( $ username , $ password , $ email ) { return $ this -> createAccount ( $ username , $ password , $ email , [ ] , 'ACCOUNT_ADMIN' , Admin :: class ) ; }
|
Creates a new Admin level account .
|
49,645
|
public function createReseller ( $ username , $ password , $ email , $ domain , $ package = [ ] , $ ip = 'shared' ) { $ options = array_merge ( [ 'ip' => $ ip , 'domain' => $ domain , 'serverip' => 'ON' , 'dns' => 'OFF' ] , is_array ( $ package ) ? $ package : [ 'package' => $ package ] ) ; return $ this -> createAccount ( $ username , $ password , $ email , $ options , 'ACCOUNT_RESELLER' , Reseller :: class ) ; }
|
Creates a new Reseller level account .
|
49,646
|
public function getAllAccounts ( ) { $ accounts = array_merge ( $ this -> getAllUsers ( ) , $ this -> getResellers ( ) , $ this -> getAdmins ( ) ) ; ksort ( $ accounts ) ; return $ accounts ; }
|
Returns a full list of all accounts of any type on the server .
|
49,647
|
public function getReseller ( $ username ) { $ resellers = $ this -> getResellers ( ) ; return isset ( $ resellers [ $ username ] ) ? $ resellers [ $ username ] : null ; }
|
Returns a specific reseller by name or NULL if there is no reseller by this name .
|
49,648
|
public function impersonateAdmin ( $ username , $ validate = false ) { return new self ( $ this -> getConnection ( ) -> loginAs ( $ username ) , $ validate ) ; }
|
Returns a new AdminContext acting as the specified admin .
|
49,649
|
public function impersonateReseller ( $ username , $ validate = false ) { return new ResellerContext ( $ this -> getConnection ( ) -> loginAs ( $ username ) , $ validate ) ; }
|
Returns a new ResellerContext acting as the specified reseller .
|
49,650
|
public static function connectAdmin ( $ url , $ username , $ password , $ validate = false ) { return new AdminContext ( new self ( $ url , $ username , $ password ) , $ validate ) ; }
|
Connects to DirectAdmin with an admin account .
|
49,651
|
public static function connectReseller ( $ url , $ username , $ password , $ validate = false ) { return new ResellerContext ( new self ( $ url , $ username , $ password ) , $ validate ) ; }
|
Connects to DirectAdmin with a reseller account .
|
49,652
|
public static function connectUser ( $ url , $ username , $ password , $ validate = false ) { return new UserContext ( new self ( $ url , $ username , $ password ) , $ validate ) ; }
|
Connects to DirectAdmin with a user account .
|
49,653
|
public function invokeApi ( $ method , $ command , $ options = [ ] ) { $ result = $ this -> rawRequest ( $ method , '/CMD_API_' . $ command , $ options ) ; if ( ! empty ( $ result [ 'error' ] ) ) { throw new DirectAdminException ( "$method to $command failed: $result[details] ($result[text])" ) ; } return Conversion :: sanitizeArray ( $ result ) ; }
|
Invokes the DirectAdmin API with specific options .
|
49,654
|
public function rawRequest ( $ method , $ uri , $ options ) { try { $ response = $ this -> connection -> request ( $ method , $ uri , $ options ) ; if ( $ response -> getHeader ( 'Content-Type' ) [ 0 ] == 'text/html' ) { throw new DirectAdminException ( sprintf ( 'DirectAdmin API returned text/html to %s %s containing "%s"' , $ method , $ uri , strip_tags ( $ response -> getBody ( ) -> getContents ( ) ) ) ) ; } $ body = $ response -> getBody ( ) -> getContents ( ) ; return Conversion :: responseToArray ( $ body ) ; } catch ( TransferException $ exception ) { throw new DirectAdminException ( sprintf ( '%s request to %s failed' , $ method , $ uri ) , 0 , $ exception ) ; } }
|
Sends a raw request to DirectAdmin .
|
49,655
|
protected static function processUnlimitedOption ( array & $ options , $ key ) { $ ukey = "u{$key}" ; unset ( $ options [ $ ukey ] ) ; if ( array_key_exists ( $ key , $ options ) && ( $ options [ $ key ] === 'unlimited' || ! isset ( $ options [ $ key ] ) ) ) { $ options [ $ ukey ] = 'ON' ; } }
|
Expands a single option to its unlimited counterpart if NULL or literal unlimited .
|
49,656
|
public static function sanitizeArray ( $ result ) { if ( count ( $ result ) == 1 && isset ( $ result [ 'list[]' ] ) ) { $ result = $ result [ 'list[]' ] ; } return is_array ( $ result ) ? $ result : [ $ result ] ; }
|
Ensures a DA - style response element is wrapped properly as an array .
|
49,657
|
public function getContextUser ( ) { if ( ! isset ( $ this -> user ) ) { $ this -> user = User :: fromConfig ( $ this -> invokeApiGet ( 'SHOW_USER_CONFIG' ) , $ this ) ; } return $ this -> user ; }
|
Returns the actual user object behind the context .
|
49,658
|
public static function create ( User $ user , $ domainName , $ bandwidthLimit = null , $ diskLimit = null , $ ssl = null , $ php = null , $ cgi = null ) { $ options = [ 'action' => 'create' , 'domain' => $ domainName , ( isset ( $ bandwidthLimit ) ? 'bandwidth' : 'ubandwidth' ) => $ bandwidthLimit , ( isset ( $ diskLimit ) ? 'quota' : 'uquota' ) => $ diskLimit , 'ssl' => Conversion :: onOff ( $ ssl , $ user -> hasSSL ( ) ) , 'php' => Conversion :: onOff ( $ php , $ user -> hasPHP ( ) ) , 'cgi' => Conversion :: onOff ( $ cgi , $ user -> hasCGI ( ) ) , ] ; $ user -> getContext ( ) -> invokeApiPost ( 'DOMAIN' , $ options ) ; $ config = $ user -> getContext ( ) -> invokeApiGet ( 'ADDITIONAL_DOMAINS' ) ; return new self ( $ domainName , $ user -> getContext ( ) , $ config [ $ domainName ] ) ; }
|
Creates a new domain under the specified user .
|
49,659
|
public function createPointer ( $ domain , $ alias = false ) { $ parameters = [ 'domain' => $ this -> domainName , 'from' => $ domain , 'action' => 'add' , ] ; if ( $ alias ) { $ parameters [ 'alias' ] = 'yes' ; $ list = & $ this -> aliases ; } else { $ list = & $ this -> pointers ; } $ this -> getContext ( ) -> invokeApiPost ( 'DOMAIN_POINTER' , $ parameters ) ; $ list [ ] = $ domain ; $ list = array_unique ( $ list ) ; }
|
Creates a pointer or alias .
|
49,660
|
public function delete ( ) { $ this -> getContext ( ) -> invokeApiPost ( 'DOMAIN' , [ 'delete' => true , 'confirmed' => true , 'select0' => $ this -> domainName , ] ) ; $ this -> owner -> clearCache ( ) ; }
|
Deletes this domain from the user .
|
49,661
|
public function getDomainNames ( ) { return $ this -> getCache ( 'domainNames' , function ( ) { $ list = array_merge ( $ this -> aliases , $ this -> pointers , [ $ this -> getDomainName ( ) ] ) ; sort ( $ list ) ; return $ list ; } ) ; }
|
Returns unified sorted list of main domain name aliases and pointers .
|
49,662
|
private function setConfig ( UserContext $ context , array $ config ) { $ this -> domainName = $ config [ 'domain' ] ; if ( $ config [ 'username' ] === $ context -> getUsername ( ) ) { $ this -> owner = $ context -> getContextUser ( ) ; } else { throw new DirectAdminException ( 'Could not determine relationship between context user and domain' ) ; } $ bandwidths = array_map ( 'trim' , explode ( '/' , $ config [ 'bandwidth' ] ) ) ; $ this -> bandwidthUsed = floatval ( $ bandwidths [ 0 ] ) ; $ this -> bandwidthLimit = ! isset ( $ bandwidths [ 1 ] ) || ctype_alpha ( $ bandwidths [ 1 ] ) ? null : floatval ( $ bandwidths [ 1 ] ) ; $ this -> diskUsage = floatval ( $ config [ 'quota' ] ) ; $ this -> aliases = array_filter ( explode ( '|' , $ config [ 'alias_pointers' ] ) ) ; $ this -> pointers = array_filter ( explode ( '|' , $ config [ 'pointers' ] ) ) ; }
|
Sets configuration options from raw DirectAdmin data .
|
49,663
|
protected function getCache ( $ key , $ default ) { if ( ! isset ( $ this -> cache [ $ key ] ) ) { $ this -> cache [ $ key ] = is_callable ( $ default ) ? $ default ( ) : $ default ; } return $ this -> cache [ $ key ] ; }
|
Retrieves an item from the internal cache .
|
49,664
|
protected function getCacheItem ( $ key , $ item , $ defaultKey , $ defaultItem = null ) { if ( empty ( $ cache = $ this -> getCache ( $ key , $ defaultKey ) ) ) { return $ defaultItem ; } if ( ! is_array ( $ cache ) ) { throw new DirectAdminException ( "Cache item $key is not an array" ) ; } return isset ( $ cache [ $ item ] ) ? $ cache [ $ item ] : $ defaultItem ; }
|
Retrieves a keyed item from inside a cache item .
|
49,665
|
public static function toObjectArray ( array $ items , $ class , UserContext $ context ) { return array_combine ( $ items , array_map ( function ( $ item ) use ( $ class , $ context ) { return new $ class ( $ item , $ context ) ; } , $ items ) ) ; }
|
Converts an array of string items to an associative array of objects of the specified type .
|
49,666
|
public static function create ( Domain $ domain , $ prefix , $ recipients ) { $ domain -> invokePost ( 'EMAIL_FORWARDERS' , 'create' , [ 'user' => $ prefix , 'email' => is_array ( $ recipients ) ? implode ( ',' , $ recipients ) : $ recipients , ] ) ; return new self ( $ prefix , $ domain , $ recipients ) ; }
|
Creates a new forwarder .
|
49,667
|
public function createUser ( $ username , $ password , $ email , $ domain , $ ip , $ package = [ ] ) { $ options = array_merge ( [ 'ip' => $ ip , 'domain' => $ domain ] , is_array ( $ package ) ? $ package : [ 'package' => $ package ] ) ; return $ this -> createAccount ( $ username , $ password , $ email , $ options , 'ACCOUNT_USER' , User :: class ) ; }
|
Creates a new user on the server .
|
49,668
|
protected function createAccount ( $ username , $ password , $ email , $ options , $ endpoint , $ returnType ) { $ this -> invokeApiPost ( $ endpoint , array_merge ( $ options , [ 'action' => 'create' , 'add' => 'Submit' , 'email' => $ email , 'passwd' => $ password , 'passwd2' => $ password , 'username' => $ username , ] ) ) ; return new $ returnType ( $ username , $ this ) ; }
|
Internal helper function for creating new accounts .
|
49,669
|
public function deleteAccounts ( array $ usernames ) { $ options = [ 'confirmed' => 'Confirm' , 'delete' => 'yes' ] ; foreach ( array_values ( $ usernames ) as $ idx => $ username ) { $ options [ "select{$idx}" ] = $ username ; } $ this -> invokeApiPost ( 'SELECT_USERS' , $ options ) ; }
|
Deletes multiple accounts .
|
49,670
|
public function getUser ( $ username ) { $ resellers = $ this -> getUsers ( ) ; return isset ( $ resellers [ $ username ] ) ? $ resellers [ $ username ] : null ; }
|
Returns a single user by name .
|
49,671
|
protected function getData ( $ key ) { return $ this -> getCacheItem ( self :: CACHE_DATA , $ key , function ( ) { $ result = $ this -> getContext ( ) -> invokeApiGet ( 'POP' , [ 'domain' => $ this -> getDomainName ( ) , 'action' => 'full_list' , ] ) ; return \ GuzzleHttp \ Psr7 \ parse_query ( $ result [ $ this -> getPrefix ( ) ] ) ; } ) ; }
|
Cache wrapper to keep mailbox stats up to date .
|
49,672
|
public static function create ( User $ user , $ name , $ username , $ password ) { $ options = [ 'action' => 'create' , 'name' => $ name , ] ; if ( ! empty ( $ password ) ) { $ options += [ 'user' => $ username , 'passwd' => $ password , 'passwd2' => $ password ] ; } else { $ options += [ 'userlist' => $ username ] ; } $ user -> getContext ( ) -> invokeApiPost ( 'DATABASES' , $ options ) ; return new self ( $ name , $ user , $ user -> getContext ( ) ) ; }
|
Creates a new database under the specified user .
|
49,673
|
public function delete ( ) { $ this -> getContext ( ) -> invokeApiPost ( 'DATABASES' , [ 'action' => 'delete' , 'select0' => $ this -> getDatabaseName ( ) , ] ) ; $ this -> getContext ( ) -> getContextUser ( ) -> clearCache ( ) ; }
|
Deletes this database from the user .
|
49,674
|
public function createDatabase ( $ name , $ username , $ password = null ) { $ db = Database :: create ( $ this -> getSelfManagedUser ( ) , $ name , $ username , $ password ) ; $ this -> clearCache ( ) ; return $ db ; }
|
Creates a new database under this user .
|
49,675
|
public function createDomain ( $ domainName , $ bandwidthLimit = null , $ diskLimit = null , $ ssl = null , $ php = null , $ cgi = null ) { $ domain = Domain :: create ( $ this -> getSelfManagedUser ( ) , $ domainName , $ bandwidthLimit , $ diskLimit , $ ssl , $ php , $ cgi ) ; $ this -> clearCache ( ) ; return $ domain ; }
|
Creates a new domain under this user .
|
49,676
|
public function modifyConfig ( array $ newConfig ) { $ this -> getContext ( ) -> invokeApiPost ( 'MODIFY_USER' , array_merge ( $ this -> loadConfig ( ) , Conversion :: processUnlimitedOptions ( $ newConfig ) , [ 'action' => 'customize' , 'user' => $ this -> getUsername ( ) ] ) ) ; $ this -> clearCache ( ) ; }
|
Modifies the configuration of the user . For available keys in the array check the documentation on CMD_API_MODIFY_USER in the linked document .
|
49,677
|
public static function fromConfig ( $ config , UserContext $ context ) { $ name = $ config [ 'username' ] ; switch ( $ config [ 'usertype' ] ) { case DirectAdmin :: ACCOUNT_TYPE_USER : return new self ( $ name , $ context , $ config ) ; case DirectAdmin :: ACCOUNT_TYPE_RESELLER : return new Reseller ( $ name , $ context , $ config ) ; case DirectAdmin :: ACCOUNT_TYPE_ADMIN : return new Admin ( $ name , $ context , $ config ) ; default : throw new DirectAdminException ( "Unknown user type '$config[usertype]'" ) ; } }
|
Constructs the correct object from the given user config .
|
49,678
|
private function getUsage ( $ item ) { return $ this -> getCacheItem ( self :: CACHE_USAGE , $ item , function ( ) { return $ this -> getContext ( ) -> invokeApiGet ( 'SHOW_USER_USAGE' , [ 'user' => $ this -> getUsername ( ) ] ) ; } ) ; }
|
Internal function to safe guard usage changes and cache them .
|
49,679
|
public static function generateTitle ( ) { $ first = self :: getRandomNoun ( ) ; $ second = self :: getRandomNoun ( $ first ) ; switch ( rand ( 0 , 6 ) ) { case 0 : return 'The ' . $ first . ' of ' . self :: getRandomAdj ( ) . ' ' . $ second ; case 1 : return ucfirst ( $ first ) . ' and ' . ucfirst ( $ second ) ; case 2 : return 'The ' . self :: getRandomAdj ( ) . ' ' . $ second ; case 3 : return ucfirst ( self :: addAn ( self :: getRandomAdj ( ) ) ) . ' ' . $ second ; case 4 : return 'The ' . $ first . ' in ' . $ second ; case 5 : return 'Of ' . $ first . ' and ' . $ second ; case 6 : return ucfirst ( self :: getRandomAdj ( ) ) . ' ' . ucfirst ( $ second ) ; } }
|
Generates a random title for a resource
|
49,680
|
protected function generateTool ( ) { $ this -> data = $ this -> getMappedArguments ( ) ; $ generatorPath = str_replace ( DIRECTORY_SEPARATOR , '/' , dirname ( __DIR__ ) ) . '/studentToolGenerator' ; $ targetPath = $ generatorPath . '/generated-code/' . $ this -> data [ 'client' ] . '/' . $ this -> data [ 'tool-id' ] ; $ templatePath = $ generatorPath . '/template' ; $ objects = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ templatePath ) , \ RecursiveIteratorIterator :: SELF_FIRST ) ; $ patterns = $ this -> getPatterns ( ) ; $ replacements = $ this -> getReplacements ( ) ; foreach ( $ objects as $ tplFile => $ cursor ) { if ( in_array ( basename ( $ tplFile ) , array ( '.' , '..' ) ) ) { continue ; } $ toolFile = str_replace ( $ templatePath , $ targetPath , $ tplFile ) ; if ( $ cursor -> isDir ( ) && ! is_dir ( $ toolFile ) ) { mkdir ( $ toolFile , 0755 , true ) ; } else if ( $ cursor -> isFile ( ) ) { $ toolFile = dirname ( $ toolFile ) . '/' . str_replace ( 'template' , $ this -> data [ 'tool-base' ] , basename ( $ toolFile ) ) ; $ toolContent = str_replace ( $ patterns , $ replacements , file_get_contents ( $ tplFile ) ) ; file_put_contents ( $ toolFile , $ toolContent ) ; } } return $ targetPath ; }
|
Take template and create the tool
|
49,681
|
protected function getPatterns ( ) { $ patterns = array ( ) ; foreach ( $ this -> data as $ pattern => $ replacement ) { $ patterns [ ] = '{' . $ pattern . '}' ; } return $ patterns ; }
|
First arg for str_replace
|
49,682
|
public function pack ( ) { try { $ testPacker = $ this -> getTestPacker ( ) ; $ testPack = $ testPacker -> packTest ( $ this -> test ) ; } catch ( Exception $ e ) { throw new common_Exception ( 'The test ' . $ this -> test -> getUri ( ) . ' cannot be packed : ' . $ e -> getMessage ( ) ) ; } return $ testPack ; }
|
Pack a test .
|
49,683
|
protected function addSampleTheme ( ) { $ values = array ( '{themeLabel}' => $ this -> label . ' default theme' , '{themeId}' => StringUtils :: camelize ( $ this -> label . ' default theme' ) , '{platformTheme}' => StringUtils :: camelize ( $ this -> label . ' default theme' , true ) ) ; $ pathValues = array ( ) ; foreach ( $ values as $ key => $ value ) { $ pathValues [ trim ( $ key , '{}' ) ] = $ value ; } $ samplePath = \ common_ext_ExtensionsManager :: singleton ( ) -> getExtensionById ( 'taoDevTools' ) -> getDir ( ) . 'models' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR ; $ paths = array ( array ( 'model' , 'theme' , '*.sample' ) , array ( 'scripts' , 'install' , '*.sample' ) , array ( 'views' , 'templates' , 'themes' , 'platform' , 'themeId' , '*.sample' ) , array ( 'views' , 'scss' , 'themes' , 'items' , '*.sample' ) , array ( 'views' , 'scss' , 'themes' , 'platform' , 'themeId' , '*.sample' ) ) ; $ templates = array ( ) ; foreach ( $ paths as $ path ) { $ templates = array_merge ( $ templates , glob ( $ samplePath . implode ( DIRECTORY_SEPARATOR , $ path ) ) ) ; } foreach ( $ templates as $ template ) { $ template = \ tao_helpers_File :: getRelPath ( $ samplePath , $ template ) ; $ template = substr ( $ template , 0 , strrpos ( $ template , '.' ) ) ; $ this -> copyFile ( $ template , str_replace ( array_keys ( $ pathValues ) , $ pathValues , $ template ) , $ values ) ; } }
|
Adds sample code for theme support
|
49,684
|
protected function addAutoloader ( ) { $ autoloaderFile = VENDOR_PATH . 'composer/autoload_psr4.php' ; $ content = file_get_contents ( $ autoloaderFile ) ; $ lineToAdd = PHP_EOL . ' \'' . $ this -> authorNamespace . '\\\\' . $ this -> id . '\\\\\' => array($baseDir . \'/' . $ this -> id . '\'),' ; $ content = str_replace ( 'return array(' , 'return array(' . $ lineToAdd , $ content ) ; $ content = file_put_contents ( $ autoloaderFile , $ content ) ; }
|
Add the autoloader manually to the composer will break on next update
|
49,685
|
public function createItems ( ) { $ count = $ this -> hasRequestParameter ( 'count' ) ? $ this -> getRequestParameter ( 'count' ) : 100 ; DataGenerator :: generateItems ( $ count ) ; echo 'created ' . $ count . ' items' ; }
|
Work in progress
|
49,686
|
public function fromArray ( $ data ) { if ( $ data ) { if ( isset ( $ data [ 'tags' ] ) ) { $ this -> setTags ( $ data [ 'tags' ] ) ; } if ( isset ( $ data [ 'ts' ] ) ) { $ this -> setTimestamp ( $ data [ 'ts' ] ) ; } if ( isset ( $ data [ 'type' ] ) ) { $ this -> setType ( $ data [ 'type' ] ) ; } if ( isset ( $ data [ 'target' ] ) ) { $ this -> setTarget ( $ data [ 'target' ] ) ; } } }
|
Imports the internal state from an array
|
49,687
|
public function addTag ( $ tag ) { $ this -> tags [ ] = ( string ) $ tag ; $ this -> ref = null ; return $ this ; }
|
Adds another tag to the TimePoint
|
49,688
|
public function removeTag ( $ tag ) { $ index = array_search ( $ tag , $ this -> tags ) ; if ( $ index !== false ) { array_splice ( $ this -> tags , $ index , 1 ) ; $ this -> ref = null ; } return $ this ; }
|
Removes a tag from the TimePoint
|
49,689
|
public function getTag ( $ index = 0 ) { $ index = min ( max ( 0 , $ index ) , count ( $ this -> tags ) ) ; return $ this -> tags [ $ index ] ; }
|
Gets a tag from the TimePoint . By default it will return the first tag .
|
49,690
|
public function setTags ( $ tags ) { $ this -> tags = [ ] ; $ this -> ref = null ; if ( is_array ( $ tags ) ) { foreach ( $ tags as $ tag ) { $ this -> addTag ( $ tag ) ; } } else { $ this -> addTag ( $ tags ) ; } return $ this ; }
|
Sets the tags of the TimePoint
|
49,691
|
public function getRef ( ) { if ( is_null ( $ this -> ref ) ) { $ tags = $ this -> tags ; sort ( $ tags ) ; $ this -> ref = md5 ( implode ( '-' , $ tags ) ) ; } return $ this -> ref ; }
|
Gets a unique reference to name the TimePoint
|
49,692
|
public function match ( array $ tags = null , $ target = self :: TARGET_ALL , $ type = self :: TYPE_ALL ) { $ match = ( $ this -> getType ( ) & $ type ) && ( $ this -> getTarget ( ) & $ target ) ; if ( $ match && isset ( $ tags ) ) { $ match = ( count ( array_intersect ( $ tags , $ this -> getTags ( ) ) ) == count ( $ tags ) ) ; } return $ match ; }
|
Checks if a TimePoint matches the criteria
|
49,693
|
public static function sort ( array & $ range ) { usort ( $ range , function ( TimePoint $ a , TimePoint $ b ) { return $ a -> compare ( $ b ) ; } ) ; return $ range ; }
|
Sorts a range of TimePoint
|
49,694
|
public function roles ( ) { $ currentSession = $ this -> getSession ( ) ; if ( $ currentSession instanceof \ common_session_RestrictedSession ) { $ this -> setData ( 'roles' , $ currentSession -> getUserRoles ( ) ) ; $ this -> setView ( 'userdebug/restore.tpl' ) ; } else { $ myFormContainer = new UserDebugRoles ( ) ; $ myForm = $ myFormContainer -> getForm ( ) ; if ( $ myForm -> isSubmited ( ) && $ myForm -> isValid ( ) ) { $ user = $ this -> getUserService ( ) -> getCurrentUser ( ) ; $ filter = $ myForm -> getValue ( 'rolefilter' ) ; $ userUri = $ myForm -> getValue ( 'user' ) ; if ( $ userUri != $ currentSession -> getUserUri ( ) ) { throw new \ common_exception_Error ( 'Security exception, user to be changed is not the current user' ) ; } $ session = new \ common_session_RestrictedSession ( $ this -> getSession ( ) , $ myForm -> getValue ( 'rolefilter' ) ) ; \ common_session_SessionManager :: startSession ( $ session ) ; $ this -> setData ( 'roles' , $ currentSession -> getUserRoles ( ) ) ; $ this -> setView ( 'userdebug/restore.tpl' ) ; } else { $ this -> setData ( 'formTitle' , __ ( "Restrict Roles" ) ) ; $ this -> setData ( 'myForm' , $ myForm -> render ( ) ) ; $ this -> setView ( 'form.tpl' , 'tao' ) ; } } }
|
Action dedicated to fake roles
|
49,695
|
public function processFontArchive ( ) { $ this -> init ( ) ; $ uploadResult = $ this -> uploadArchive ( ) ; if ( ! empty ( $ uploadResult [ 'error' ] ) ) { $ this -> returnJson ( $ uploadResult ) ; return false ; } $ extractResult = $ this -> extractArchive ( $ uploadResult ) ; if ( ! empty ( $ extractResult [ 'error' ] ) ) { $ this -> returnJson ( $ extractResult ) ; return false ; } $ currentSelection = json_decode ( file_get_contents ( $ extractResult . '/selection.json' ) ) ; $ oldSelection = json_decode ( file_get_contents ( $ this -> currentSelection ) ) ; $ integrityCheck = $ this -> checkIntegrity ( $ currentSelection , $ oldSelection ) ; if ( ! empty ( $ integrityCheck [ 'error' ] ) ) { $ this -> returnJson ( $ integrityCheck ) ; return false ; } $ scssGenerationResult = $ this -> generateTaoScss ( $ extractResult , $ currentSelection -> icons ) ; if ( ! empty ( $ scssGenerationResult [ 'error' ] ) ) { $ this -> returnJson ( $ scssGenerationResult ) ; return false ; } $ ckGenerationResult = $ this -> generateCkScss ( $ extractResult , $ currentSelection -> icons ) ; if ( ! empty ( $ ckGenerationResult [ 'error' ] ) ) { $ this -> returnJson ( $ ckGenerationResult ) ; return false ; } $ phpGenerationResult = $ this -> generatePhpClass ( $ currentSelection -> icons ) ; if ( ! empty ( $ phpGenerationResult [ 'error' ] ) ) { $ this -> returnJson ( $ phpGenerationResult ) ; return false ; } $ distribution = $ this -> distribute ( $ extractResult ) ; if ( ! empty ( $ distribution [ 'error' ] ) ) { $ this -> returnJson ( $ distribution ) ; return false ; } chdir ( $ this -> taoDir . '/views/build' ) ; $ compilationResult = $ this -> compileCss ( ) ; if ( ! empty ( $ compilationResult [ 'error' ] ) ) { $ this -> returnJson ( $ compilationResult ) ; return false ; } $ this -> returnJson ( array ( 'success' => 'The TAO icon font has been updated' ) ) ; return true ; }
|
Process the font archive
|
49,696
|
protected function uploadArchive ( ) { if ( $ _FILES [ 'content' ] [ 'error' ] !== UPLOAD_ERR_OK ) { \ common_Logger :: w ( 'File upload failed with error ' . $ _FILES [ 'content' ] [ 'error' ] ) ; switch ( $ _FILES [ 'content' ] [ 'error' ] ) { case UPLOAD_ERR_INI_SIZE : case UPLOAD_ERR_FORM_SIZE : $ error = __ ( 'Archive size must be lesser than : ' ) . ini_get ( 'post_max_size' ) ; break ; case UPLOAD_ERR_NO_FILE : $ error = __ ( 'No file uploaded' ) ; break ; default : $ error = __ ( 'File upload failed' ) ; break ; } return array ( 'error' => $ error ) ; } $ filePath = $ this -> tmpDir . '/' . $ _FILES [ 'content' ] [ 'name' ] ; if ( ! move_uploaded_file ( $ _FILES [ 'content' ] [ 'tmp_name' ] , $ filePath ) ) { return array ( 'error' => __ ( 'Unable to move uploaded file' ) ) ; } return $ filePath ; }
|
Upload the zip archive to a tmp directory
|
49,697
|
protected function extractArchive ( $ archiveFile ) { $ archiveDir = dirname ( $ archiveFile ) ; $ archiveObj = new ZipArchive ( ) ; $ archiveHandle = $ archiveObj -> open ( $ archiveFile ) ; if ( true !== $ archiveHandle ) { return array ( 'error' => __ ( 'Could not open archive' ) ) ; } if ( ! $ archiveObj -> extractTo ( $ archiveDir ) ) { $ archiveObj -> close ( ) ; return array ( 'error' => __ ( 'Could not extract archive' ) ) ; } $ archiveObj -> close ( ) ; return $ archiveDir ; }
|
Unzip archive from icomoon
|
49,698
|
protected function checkIntegrity ( $ currentSelection , $ oldSelection ) { $ metadataExists = property_exists ( $ currentSelection , 'metadata' ) && property_exists ( $ currentSelection -> metadata , 'name' ) ; $ prefExists = property_exists ( $ currentSelection , 'preferences' ) && property_exists ( $ currentSelection -> preferences , 'fontPref' ) && property_exists ( $ currentSelection -> preferences -> fontPref , 'metadata' ) && property_exists ( $ currentSelection -> preferences -> fontPref -> metadata , 'fontFamily' ) ; if ( ( $ metadataExists && $ currentSelection -> metadata -> name !== 'tao' ) || ( $ prefExists && $ currentSelection -> preferences -> fontPref -> metadata -> fontFamily !== 'tao' ) || ( ! $ prefExists && ! $ metadataExists ) ) { return array ( 'error' => __ ( 'You need to change the font name to "tao" in the icomoon preferences' ) ) ; } $ newSet = $ this -> dataToGlyphSet ( $ currentSelection ) ; $ oldSet = $ this -> dataToGlyphSet ( $ oldSelection ) ; return ! ! count ( array_diff ( $ oldSet , $ newSet ) ) ? array ( 'error' => __ ( 'Font incomplete! Is the extension in sync width git? Have you removed any glyphs?' ) ) : true ; }
|
Checks whether the new font contains at least all glyphs from the previous version
|
49,699
|
protected function dataToGlyphSet ( $ data ) { $ glyphs = array ( ) ; foreach ( $ data -> icons as $ iconProperties ) { $ glyphs [ ] = $ iconProperties -> properties -> name ; } return $ glyphs ; }
|
Generate a listing of all glyph names in a font
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.