idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
2,000
public static function createContactFromStdClass ( \ stdClass $ stdContact ) : Contact { if ( empty ( $ stdContact -> FirstName ) ) { throw new \ InvalidArgumentException ( "stdClass argument must contain FirstName attribute" ) ; } if ( empty ( $ stdContact -> Phone ) ) { throw new \ InvalidArgumentException ( "stdClass argument must contain Phone attribute" ) ; } $ contact = new Contact ( $ stdContact -> FirstName , $ stdContact -> Phone , $ stdContact -> LastName ?? null , $ stdContact -> Title ?? null , $ stdContact -> Organization ?? null , $ stdContact -> Email ?? null , $ stdContact -> Notes ?? null ) ; return $ contact ; }
Creates a Contact using the stdClass given .
2,001
public static function createContactFromAttributes ( string $ firstName , string $ phoneNumber , ? string $ lastName = null , ? string $ title = null , ? string $ organization = null , ? string $ email = null , ? string $ notes = null ) : Contact { return new Contact ( $ firstName , $ phoneNumber , $ lastName , $ title , $ organization , $ email , $ notes ) ; }
Creates a Contact using the parameters given .
2,002
public static function createProcessedContactFromStdClassArray ( array $ contactArray ) : ClassValidationArray { $ contacts = new ClassValidationArray ( ) ; foreach ( $ contactArray as $ c ) { $ contacts [ ] = self :: createProcessedContactFromStdClass ( $ c ) ; } return $ contacts ; }
Take an array filled with contact stdClasses and returns a ClassValidationArray filled with ProcessedContact .
2,003
public static function createProcessedContactFromStdClass ( \ stdClass $ stdContact ) : ProcessedContact { if ( empty ( $ stdContact -> FirstName ) ) { throw new \ InvalidArgumentException ( "stdClass argument must contain FirstName attribute" ) ; } if ( empty ( $ stdContact -> Phone ) ) { throw new \ InvalidArgumentException ( "stdClass argument must contain Phone attribute" ) ; } $ contact = new ProcessedContact ( $ stdContact -> FirstName , $ stdContact -> Phone , $ stdContact -> ID , $ stdContact -> OwnerID , $ stdContact -> LastName ?? null , $ stdContact -> Title ?? null , $ stdContact -> Organization ?? null , $ stdContact -> Email ?? null , $ stdContact -> Notes ?? null , isset ( $ stdContact -> Created ) ? new \ DateTime ( $ stdContact -> Created , new \ DateTimeZone ( "UTC" ) ) : null , isset ( $ stdContact -> Modified ) ? new \ DateTime ( $ stdContact -> Modified , new \ DateTimeZone ( "UTC" ) ) : null ) ; return $ contact ; }
Creates a ProcessedContact using the stdClass given .
2,004
public static function createProcessedGroupFromStdClass ( \ stdClass $ stdGroup ) : ProcessedGroup { return new ProcessedGroup ( $ stdGroup -> Name , $ stdGroup -> Color , $ stdGroup -> ID , $ stdGroup -> OwnerID , new \ DateTime ( $ stdGroup -> Created ) , new \ DateTime ( $ stdGroup -> Modified ) ) ; }
Takes a stdClass group and returns a ProcessedGroup .
2,005
public static function createProcessedOutGoingSMSFromStdClass ( \ stdClass $ stdClassSMS ) : ProcessedOutGoingSMS { return new ProcessedOutGoingSMS ( $ stdClassSMS -> From , $ stdClassSMS -> Message , $ stdClassSMS -> To , $ stdClassSMS -> ID , new \ DateTime ( $ stdClassSMS -> Created ?? null ) , new \ DateTime ( $ stdClassSMS -> Updated ?? null ) , $ stdClassSMS -> Status , $ stdClassSMS -> StatusDescription , $ stdClassSMS -> BundleID ) ; }
Creates a ProcessedOutGoingSMS from an stdClass object .
2,006
public static function createProcessedOutGoingSMSFromStdClassArray ( array $ stdClassArray ) : ClassValidationArray { $ array = new ClassValidationArray ( ProcessedOutGoingSMS :: class ) ; foreach ( $ stdClassArray as $ stdClass ) { $ array [ ] = self :: createProcessedOutGoingSMSFromStdClass ( $ stdClass ) ; } return $ array ; }
Creates a ClassValidationArray filled with ProcessedOutGoingSMS given an array of stdClass .
2,007
public function fetchConfig ( ) { if ( Cache :: has ( $ this -> getCacheKey ( ) ) ) { return Cache :: get ( $ this -> getCacheKey ( ) ) ; } return null ; }
Fetch the stored config from the cache .
2,008
public function loadEnvironment ( ) { $ this -> environment = app ( ) -> environment ( ) ; $ this -> website_id = null ; $ website_data = WebsiteModel :: currentWebsiteData ( ) ; if ( ! empty ( $ website_data ) ) { if ( ! empty ( $ website_data [ 'environment' ] ) ) { $ this -> environment = $ website_data [ 'environment' ] ; } $ this -> website_id = $ website_data [ 'id' ] ; } $ this -> cache_key = 'site-config.' . $ this -> environment . '.' . $ this -> website_id ; return $ this ; }
Loads the internal website_id and environment
2,009
public function loadConfiguration ( ) { $ repository = $ this -> loadEnvironment ( ) ; $ cache = $ repository -> fetchConfig ( ) ; if ( ! empty ( $ cache ) ) { return $ cache ; } $ config = [ ] ; foreach ( $ repository -> fetchAllGroups ( ) as $ group ) { $ groupConfig = ConfigModel :: fetchSettings ( $ repository -> getEnvironment ( ) , $ repository -> getWebsiteId ( ) , $ group ) ; $ config [ $ group ] = $ groupConfig ; } $ repository -> storeConfig ( $ config ) ; return $ config ; }
Load the database backed configuration .
2,010
public function setRunningConfiguration ( RepositoryContract $ config ) { foreach ( $ this -> loadConfiguration ( ) as $ group => $ groupConfig ) { $ config -> set ( $ group , $ groupConfig ) ; } }
Load the database backed configuration and save it
2,011
public static function matchFilter ( array & $ datas , array $ get ) { if ( sizeof ( $ get ) > 0 ) { $ datas = array_filter ( $ datas , function ( $ obj ) use ( $ get ) { return array_intersect_assoc ( ( array ) $ obj , $ get ) == $ get ; } ) ; } }
Return mathing objects with get filter
2,012
private function registerErrorRenderer ( ) { if ( $ this -> kernel ( ) -> isCli ( ) ) { $ this -> container ( ) -> bind ( ErrorRendererContract :: class , ConsoleErrorRenderer :: class ) ; } else { $ this -> container ( ) -> bind ( ErrorRendererContract :: class , HttpErrorRenderer :: class ) ; } }
Registers the default error renderer .
2,013
private function registerErrorReporters ( ) { $ this -> container ( ) -> factory ( ErrorReporterAggregateContract :: class , function ( ) { $ reporters = new ErrorReporterAggregate ( $ this -> container ( ) ) ; $ reporters -> push ( LogErrorReporter :: class ) ; return $ reporters ; } , true ) ; }
Registers default error reporters .
2,014
private function freezeExpiration ( DateTimeInterface $ expires ) : DateTimeImmutable { if ( ! $ expires instanceof DateTimeImmutable ) { $ expires = new DateTimeImmutable ( $ expires -> format ( DateTime :: ISO8601 ) , $ expires -> getTimezone ( ) ) ; } return $ expires ; }
Creates immutable date time instance from the provided one .
2,015
private function shuffleAssoc ( array $ values ) { $ keys = array_keys ( $ values ) ; shuffle ( $ keys ) ; $ output = [ ] ; foreach ( $ keys as $ key ) { $ output [ $ key ] = $ values [ $ key ] ; } return $ output ; }
Shuffle an array while preserving keys .
2,016
final public function updateUserAgentsWithDeviceIDMap ( $ userAgent , $ deviceID ) { if ( isset ( $ this -> userAgentsWithDeviceID [ $ this -> normalizeUserAgent ( $ userAgent ) ] ) ) { $ this -> logger -> debug ( $ this -> userAgentsWithDeviceID [ $ this -> normalizeUserAgent ( $ userAgent ) ] . "\t" ) ; $ this -> logger -> debug ( $ deviceID . "\t" ) ; $ this -> logger -> debug ( $ this -> normalizeUserAgent ( $ userAgent ) . "\t\n" ) ; $ this -> overwritten_devices [ ] = $ this -> userAgentsWithDeviceID [ $ this -> normalizeUserAgent ( $ userAgent ) ] ; } $ this -> userAgentsWithDeviceID [ $ this -> normalizeUserAgent ( $ userAgent ) ] = $ deviceID ; }
Updates the map containing the classified user agents . These are stored in the associative array userAgentsWithDeviceID like user_agent = > deviceID . Before adding the user agent to the map it normalizes by using the normalizeUserAgent function .
2,017
public function getUserAgentsForBucket ( ) { if ( empty ( $ this -> userAgents ) ) { $ this -> userAgents = $ this -> persistenceProvider -> load ( $ this -> getPrefix ( self :: PREFIX_UA_BUCKET ) ) ; } return $ this -> userAgents ; }
Returns a list of User Agents associated with the bucket
2,018
private static function normalizeBrowser ( Device $ device ) { if ( $ device -> getBrowser ( ) -> name === 'IE' && preg_match ( '#Trident/([\d\.]+)#' , $ device -> getDeviceUa ( ) , $ matches ) ) { if ( array_key_exists ( $ matches [ 1 ] , self :: $ trident_map ) ) { $ compatibilityViewCheck = self :: $ trident_map [ $ matches [ 1 ] ] ; if ( $ device -> getBrowser ( ) -> version !== $ compatibilityViewCheck ) { $ device -> getBrowser ( ) -> version = $ compatibilityViewCheck . '(Compatibility View)' ; } return ; } } }
normalize the Browser Information
2,019
public function add ( string $ type , RowFieldNormalizerInterface $ normalizer ) { $ this -> normalizers [ $ type ] = $ normalizer ; return $ this ; }
Add a new normalized field
2,020
public function addModule ( $ module ) { $ this -> registerModule ( $ module ) ; if ( is_object ( $ module ) ) $ module = $ module -> name ; $ this -> userModules [ ] = $ module ; }
Adds a module to the current doctype by first registering it and then tacking it on to the active doctype
2,021
public function getElements ( ) { $ elements = array ( ) ; foreach ( $ this -> modules as $ module ) { if ( ! $ this -> trusted && ! $ module -> safe ) continue ; foreach ( $ module -> info as $ name => $ v ) { if ( isset ( $ elements [ $ name ] ) ) continue ; $ elements [ $ name ] = $ this -> getElement ( $ name ) ; } } foreach ( $ elements as $ n => $ v ) { if ( $ v === false ) unset ( $ elements [ $ n ] ) ; } return $ elements ; }
Retrieves merged element definitions .
2,022
public function trans ( $ message ) { $ theme = wp_get_theme ( ) ; $ domain = $ theme -> get ( 'TextDomain' ) ; return __ ( $ message , $ domain ) ; }
Translate message .
2,023
public static function loadFile ( $ path ) { if ( ! realpath ( $ path ) ) { throw new \ RuntimeException ( 'Unable to load configuration file from ' . $ path ) ; } $ data = Yaml :: parse ( $ path ) ; return new static ( pathinfo ( $ path , PATHINFO_DIRNAME ) , $ data ) ; }
Load configuration data from the specified file
2,024
public function getParam ( $ name ) { if ( ! $ this -> parsed ) { $ this -> parseParams ( ) ; } $ longName = strlen ( $ name ) === 1 ? $ this -> definitions -> getLongName ( $ name ) : $ name ; if ( isset ( $ this -> params [ $ longName ] ) ) { return $ this -> params [ $ longName ] ; } else { if ( $ this -> definitions -> allowsValue ( $ longName ) ) { return null ; } else { return false ; } } }
returns parameter matching provided name
2,025
public static function get ( $ url , $ parameters = [ ] , $ host = null , $ protocol = null ) { if ( empty ( $ url ) ) { throw new InvalidArgumentException ( __METHOD__ . ': The given url is empty.' ) ; } $ urlInfo = static :: info ( $ url ) ; $ finalUrl = ArrayHelper :: get ( $ urlInfo , 'path.plain' , '' , true ) ; $ urlParameters = ArrayHelper :: get ( $ urlInfo , 'path.parameters' , [ ] , true ) ; $ parameters = ArrayHelper :: merge ( $ parameters , $ urlParameters ) ; if ( ! empty ( $ parameters ) ) { $ finalUrl .= '?' . http_build_query ( $ parameters ) ; } $ host = $ host ? : $ urlInfo [ 'host' ] ; $ protocol = $ protocol ? : $ urlInfo [ 'protocol' ] ; return ( empty ( $ host ) ? '' : $ protocol . '://' ) . static :: normalize ( $ host . '/' . $ finalUrl ) ; }
Creates and returns a url with parameters in url encoding .
2,026
public function addFiles ( $ type , $ fileArray ) { $ method = 'add' . ucfirst ( $ type ) . "Files" ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ fileArray ) ; } else { $ this -> say ( 'Missing method: ' . $ method ) ; } return true ; }
Add files to array
2,027
public function getFiles ( $ type ) { $ f = $ type . 'Files' ; if ( property_exists ( $ this , $ f ) ) { return self :: $ { $ f } ; } $ this -> say ( 'Missing Files: ' . $ type ) ; return "" ; }
Retrieve the files
2,028
protected function copyTarget ( $ path , $ tar ) { $ map = array ( ) ; $ hdl = opendir ( $ path ) ; while ( $ entry = readdir ( $ hdl ) ) { $ p = $ path . "/" . $ entry ; if ( substr ( $ entry , 0 , 1 ) != '.' ) { if ( isset ( $ this -> getJConfig ( ) -> exclude ) && in_array ( $ entry , explode ( ',' , $ this -> getJConfig ( ) -> exclude ) ) ) { continue ; } if ( is_file ( $ p ) ) { $ map [ ] = array ( "file" => $ entry ) ; $ this -> _copy ( $ p , $ tar . "/" . $ entry ) ; } else { $ map [ ] = array ( "folder" => $ entry ) ; $ this -> _copyDir ( $ p , $ tar . "/" . $ entry ) ; } } } closedir ( $ hdl ) ; return $ map ; }
Copies the files and maps them into an array
2,029
public function generatePluginFileList ( $ files , $ plugin ) { if ( ! count ( $ files ) ) { return "" ; } $ text = array ( ) ; foreach ( $ files as $ f ) { foreach ( $ f as $ type => $ value ) { $ p = "" ; if ( $ value == $ plugin . ".php" ) { $ p = ' plugin="' . $ plugin . '"' ; } $ text [ ] = "<" . $ type . $ p . ">" . $ value . "</" . $ type . ">" ; } } return implode ( "\n" , $ text ) ; }
Generate a list of files for plugins
2,030
public function generateModuleFileList ( $ files , $ module ) { if ( ! count ( $ files ) ) { return "" ; } $ text = array ( ) ; foreach ( $ files as $ f ) { foreach ( $ f as $ type => $ value ) { $ p = "" ; if ( $ value == $ module . ".php" ) { $ p = ' module="' . $ module . '"' ; } $ text [ ] = "<" . $ type . $ p . ">" . $ value . "</" . $ type . ">" ; } } return implode ( "\n" , $ text ) ; }
Generate a list of files for modules
2,031
public function resetFiles ( ) { self :: $ backendFiles = array ( ) ; self :: $ backendLanguageFiles = array ( ) ; self :: $ frontendFiles = array ( ) ; self :: $ frontendLanguageFiles = array ( ) ; self :: $ mediaFiles = array ( ) ; }
Reset the files list before build another part
2,032
public static function findByResource ( $ resourceName , $ optParams = [ ] ) { $ optParams = ( $ optParams ) ? $ optParams : [ 'personFields' => self :: $ personFields , ] ; self :: $ person = self :: getService ( ) -> people -> get ( $ resourceName , $ optParams ) ; self :: $ resourceName = $ resourceName ; return new self ; }
find a contact to cache
2,033
public static function listPeopleConnections ( $ optParams = [ ] ) { $ optParams = ( $ optParams ) ? $ optParams : [ 'pageSize' => 0 , 'personFields' => self :: $ personFields , ] ; return self :: getService ( ) -> people_connections -> listPeopleConnections ( 'people/me' , $ optParams ) ; }
list People Connections
2,034
public static function getSimpleContacts ( ) { $ contactObj = self :: listPeopleConnections ( ) ; $ contacts = [ ] ; if ( count ( $ contactObj -> getConnections ( ) ) != 0 ) { foreach ( $ contactObj -> getConnections ( ) as $ person ) { $ data = [ ] ; $ data [ 'id' ] = $ person -> getResourceName ( ) ; $ data [ 'name' ] = isset ( $ person -> getNames ( ) [ 0 ] ) ? $ person -> getNames ( ) [ 0 ] -> getDisplayName ( ) : null ; $ data [ 'email' ] = isset ( $ person -> getEmailAddresses ( ) [ 0 ] ) ? $ person -> getEmailAddresses ( ) [ 0 ] -> getValue ( ) : null ; $ data [ 'phone' ] = isset ( $ person -> getPhoneNumbers ( ) [ 0 ] ) ? $ person -> getPhoneNumbers ( ) [ 0 ] -> getValue ( ) : null ; $ contacts [ ] = $ data ; } } return $ contacts ; }
Get simple contact data with parser
2,035
public static function createContact ( ) { $ person = self :: getPerson ( ) ; if ( isset ( $ person -> resourceName ) ) { throw new Exception ( "You should use newPeron() before create" , 500 ) ; } return self :: getService ( ) -> people -> createContact ( $ person ) ; }
Create a People Contact
2,036
public static function updateContact ( $ optParams = null ) { self :: checkFind ( ) ; $ optParams = ( is_null ( $ optParams ) ) ? [ 'updatePersonFields' => self :: $ personFields ] : $ optParams ; return self :: getService ( ) -> people -> updateContact ( self :: $ resourceName , self :: getPerson ( ) , $ optParams ) ; }
Update a People Contact
2,037
public function beforeSave ( $ insert ) { if ( ! $ this -> sort_order ) { $ property = Property :: findById ( $ this -> property_id ) ; $ this -> sort_order = count ( static :: valuesForProperty ( $ property ) ) ; } return parent :: beforeSave ( $ insert ) ; }
Performs beforeSave event
2,038
public function actions ( ) { return [ 'add-model-property-group' => [ 'class' => AddModelPropertyGroup :: class , ] , 'delete-model-property-group' => [ 'class' => DeleteModelPropertyGroup :: class , ] , 'list-property-groups' => [ 'class' => ListPropertyGroups :: class , ] , 'edit-property-group' => [ 'class' => EditPropertyGroup :: class , ] , 'delete-property-group' => [ 'class' => DeletePropertyGroup :: class , ] , 'list-group-properties' => [ 'class' => ListGroupProperties :: class , ] , 'edit-property' => [ 'class' => EditProperty :: class , ] , 'edit-static-value' => [ 'class' => EditStaticValue :: class , ] , 'delete-static-value' => [ 'class' => DeleteStaticValue :: class , ] , 'delete-property' => [ 'class' => DeleteProperty :: class , ] , 'get-attributes-names' => [ 'class' => GetAttributeNames :: class , ] , 'ajax-related-entities' => [ 'class' => AjaxRelatedEntities :: class , ] , 'restore-property' => [ 'class' => RestoreProperty :: class ] , 'restore-property-group' => [ 'class' => RestorePropertyGroup :: class ] , 'restore-static-value' => [ 'class' => RestoreStaticValue :: class ] ] ; }
This controller just uses actions in extension
2,039
public function setTimestamp ( $ unixTs ) { $ this -> ts = strtotime ( date ( 'Y-m-d' , $ unixTs ) ) ; $ this -> month = date ( 'n' , $ this -> ts ) ; $ this -> year = date ( 'Y' , $ this -> ts ) ; $ this -> monthTs = strtotime ( date ( 'Y-m-01' , $ unixTs ) ) ; }
Set the timestamp which will be used to store the data . By default current time is used .
2,040
public function save ( ) { $ entries = $ this -> logBuffer -> getEntries ( ) ; $ entrySkeleton = [ 'ts' => $ this -> ts , 'month' => $ this -> month , 'year' => $ this -> year ] ; $ dimensionSkeleton = [ 'ts' => $ this -> ts , 'month' => $ this -> month , 'year' => $ this -> year ] ; foreach ( $ entries as $ e ) { $ entry = $ entrySkeleton ; $ entry [ 'entity' ] = $ e -> getName ( ) ; $ entry [ 'ref' ] = $ e -> getRef ( ) ; if ( count ( $ e -> getAttributes ( ) ) > 0 ) { $ entry [ 'attributes' ] = $ e -> getAttributes ( ) ; } $ this -> mongo -> update ( self :: ADB_STATS_DAILY , [ 'entity' => $ e -> getName ( ) , 'ref' => $ e -> getRef ( ) , 'ts' => $ this -> ts ] , [ '$inc' => [ 'count' => $ e -> getIncrement ( ) ] , '$setOnInsert' => $ entry ] , [ 'upsert' => true ] ) ; unset ( $ entry [ 'ts' ] ) ; $ entry [ 'month' ] = $ this -> month ; $ entry [ 'year' ] = $ this -> year ; $ this -> mongo -> update ( self :: ADB_STATS_MONTHLY , [ 'entity' => $ e -> getName ( ) , 'ref' => $ e -> getRef ( ) , 'ts' => $ this -> monthTs ] , [ '$inc' => [ 'count' => $ e -> getIncrement ( ) ] , '$setOnInsert' => $ entry ] , [ 'upsert' => true ] ) ; $ dimEntry = $ dimensionSkeleton ; $ dimEntry [ 'entity' ] = $ e -> getName ( ) ; foreach ( $ e -> getDimensions ( ) as $ dim ) { $ dimEntry [ 'name' ] = $ dim -> getName ( ) ; $ dimEntry [ 'value' ] = $ dim -> getValue ( ) ; $ this -> mongo -> update ( self :: ADB_DIMS , [ 'name' => $ dim -> getName ( ) , 'value' => $ dim -> getValue ( ) , 'entity' => $ e -> getName ( ) , 'ts' => $ this -> ts ] , [ '$inc' => [ 'count.' . $ e -> getRef ( ) => $ dim -> getIncrement ( ) , 'total' => $ dim -> getIncrement ( ) ] , '$setOnInsert' => $ dimEntry ] , [ 'upsert' => true ] ) ; } } $ this -> logBuffer = new LogBuffer ( ) ; }
Save all the entries from the buffer .
2,041
public function query ( $ entity , $ ref = 0 , array $ dateRange ) { return new Query ( $ this -> mongo , $ entity , $ ref , $ dateRange ) ; }
Query the analytics data .
2,042
private function createCollections ( ) { $ collections = $ this -> mongo -> listCollections ( ) ; $ collectionsCreated = false ; foreach ( $ collections as $ collection ) { if ( $ collection -> getName ( ) == self :: ADB_STATS_DAILY ) { $ collectionsCreated = true ; break ; } } if ( ! $ collectionsCreated ) { $ this -> mongo -> createCollection ( self :: ADB_STATS_DAILY ) ; $ this -> mongo -> createCollection ( self :: ADB_STATS_MONTHLY ) ; $ this -> mongo -> createCollection ( self :: ADB_DIMS ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_DAILY , new CompoundIndex ( 'entityTsEntry' , [ 'entity' , 'ref' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_DAILY , new CompoundIndex ( 'entityTsAttrEntry' , [ 'entity' , 'ts' , 'attributes.name' , 'attributes.value' ] , false , false ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_MONTHLY , new CompoundIndex ( 'entityMonthEntry' , [ 'entity' , 'ref' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_STATS_MONTHLY , new CompoundIndex ( 'entityMonthAttrEntry' , [ 'entity' , 'ts' , 'attributes.name' , 'attributes.value' ] , false , false ) ) ; $ this -> mongo -> createIndex ( self :: ADB_DIMS , new CompoundIndex ( 'dimension' , [ 'name' , 'value' , 'entity' , 'ts' ] , true , true ) ) ; $ this -> mongo -> createIndex ( self :: ADB_DIMS , new CompoundIndex ( 'dimension_entity' , [ 'entity' , 'ts' ] , true ) ) ; } }
Creates the necessary indexes and collections if they don t exist .
2,043
public static function uploadImage ( UploadedFile $ uploadedFile , $ context , $ storage = 'local' , $ fileName = null ) { $ file = Facades \ File :: get ( $ uploadedFile ) ; $ processor = app ( 'icr.processor' ) ; return $ processor -> upload ( $ context , $ file , $ uploadedFile -> getClientOriginalExtension ( ) , Facades \ Storage :: disk ( $ storage ) , $ fileName ) ; }
Handles upload image . Returns exception instance on error or file name on success .
2,044
public static function deleteImage ( $ fileName , $ context , $ storage = 'local' ) { $ processor = app ( 'icr.processor' ) ; return $ processor -> delete ( $ fileName , $ context , Facades \ Storage :: disk ( $ storage ) ) ; }
Handles delete image . Returns exception instance on error .
2,045
public static function renameImage ( $ oldFileName , $ newFileName , $ context , $ storage = 'local' ) { $ filesystemAdapter = Facades \ Storage :: disk ( $ storage ) ; $ processor = app ( 'icr.processor' ) ; return $ processor -> rename ( $ oldFileName , $ newFileName , $ context , $ filesystemAdapter ) ; }
Renames existing image
2,046
protected function handleProcedures ( array $ procedures ) { foreach ( $ procedures as $ procedure ) { $ this -> handleProcedureOuter ( $ procedure ) ; if ( $ procedure -> hasChildren ( ) ) { $ this -> handleProcedures ( $ procedure -> getChildren ( ) ) ; } } }
Handles procedures .
2,047
protected function handleSource ( SourceAdapterInterface $ adapter , Request $ request ) { $ this -> injectDependencies ( $ adapter ) ; $ response = $ adapter -> receive ( $ request ) ; if ( $ response === null ) { throw new MissingResponseException ( $ adapter ) ; } return $ response ; }
Handles source .
2,048
protected function handleSources ( array $ sources ) { $ responses = array ( ) ; foreach ( $ sources as $ source ) { list ( $ adapter , $ request ) = $ source ; $ responses [ ] = $ this -> handleSource ( $ adapter , $ request ) ; } $ iterator = new \ AppendIterator ( ) ; foreach ( $ responses as $ response ) { $ iterator -> append ( $ response -> getIterator ( ) ) ; } return $ iterator ; }
Handles sources .
2,049
protected function handleWorker ( WorkerInterface $ worker , $ object , StorageInterface $ storage ) { $ this -> injectDependencies ( $ worker ) ; $ modifiedObject = $ worker -> handle ( $ object ) ; if ( $ modifiedObject === null && $ object !== null ) { $ storage -> remove ( $ object ) ; } elseif ( $ modifiedObject !== $ object ) { $ storage -> remove ( $ object ) ; $ storage -> add ( $ modifiedObject ) ; } return $ modifiedObject ; }
Handles worker .
2,050
protected function handleWorkers ( array $ workers , StorageInterface $ storage ) { foreach ( $ workers as $ worker ) { foreach ( $ storage -> all ( ) as $ element ) { $ this -> handleWorker ( $ worker , $ element , $ storage ) ; } } }
Handles workers .
2,051
protected function handleTarget ( TargetAdapterInterface $ adapter , Request $ request ) { $ this -> injectDependencies ( $ adapter ) ; $ response = $ adapter -> send ( $ request ) ; if ( $ response === null ) { throw new MissingResponseException ( $ adapter ) ; } return $ response ; }
Handles target .
2,052
protected function handleTargets ( array $ targets , Request $ request ) { $ responses = array ( ) ; foreach ( $ targets as $ target ) { $ responses [ ] = $ this -> handleTarget ( $ target , $ request ) ; } return $ responses ; }
Handles targets .
2,053
protected function nextObject ( \ Iterator $ iterator ) { if ( $ iterator -> valid ( ) ) { $ object = $ iterator -> current ( ) ; $ iterator -> next ( ) ; return $ object ; } return false ; }
Returns next object for an iterator .
2,054
protected function createStorage ( $ scope ) { $ storage = new InMemoryStorage ( ) ; $ this -> stack -> setScope ( $ scope , $ storage ) ; return $ storage ; }
Creates scoped storage .
2,055
protected function injectDependencies ( $ component ) { if ( $ component instanceof StorageStackAwareInterface ) { $ component -> setStorageStack ( $ this -> stack ) ; } if ( $ component instanceof LoggerAwareInterface && $ this -> logger instanceof LoggerInterface ) { $ component -> setLogger ( $ this -> logger ) ; } }
Injects dependencies .
2,056
protected function mergeStorage ( StorageInterface $ storage ) { foreach ( $ storage -> all ( ) as $ id => $ object ) { $ this -> stack -> getScope ( 'global' ) -> add ( $ object ) ; } }
Merges local storage with global storage .
2,057
public function process ( EventInterface $ event ) { $ events = $ this -> getEventManager ( ) ; $ mapper = $ this -> getMapper ( ) ; $ optionsProvider = $ this -> getOptionsProvider ( ) ; $ translator = $ this -> getTranslator ( ) ; $ pane = $ event -> getParam ( 'pane' ) ; if ( ! $ optionsProvider -> hasIdentifier ( $ pane ) ) { return ; } $ options = $ optionsProvider -> getOptions ( $ pane ) ; if ( $ options -> getType ( ) == 'search' || $ options -> getRoot ( ) == 'site' ) { return ; } try { $ mapper -> beginTransaction ( ) ; $ tid = $ mapper -> getTransactionIdentifier ( ) ; $ events -> trigger ( __FUNCTION__ . '.clean.pre' , null , [ 'tid' => $ tid , ] ) ; $ mapper -> clean ( $ tid ) ; $ mapper -> commit ( ) ; } catch ( Exception $ e ) { if ( DEBUG_MODE ) { throw new DebugException ( $ translator -> translate ( 'Error: ' ) . $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } $ meta = $ mapper -> findMetaById ( $ id ) ; $ name = isset ( $ meta [ 'title' ] ) ? $ meta [ 'title' ] : $ id ; $ this -> setValue ( $ name ) -> error ( self :: UnexpectedError ) ; } return $ this -> redirect ( $ event , 'sc-admin/file/delete' ) ; }
Emptying the trash
2,058
public function acquire ( bool $ blocker = false ) : bool { if ( ! is_resource ( $ this -> lock ) ) { return false ; } return flock ( $ this -> lock , ( $ blocker ) ? LOCK_EX : LOCK_EX | LOCK_NB ) ; }
Acquires the lock .
2,059
public function actionTreeMove ( $ id , $ pid ) { $ child = $ this -> findModel ( $ id ) ; $ oldParent = $ this -> findModel ( $ pid ) ; $ newParent = $ this -> findModel ( Yii :: $ app -> request -> post ( 'pid' ) ) ; $ child -> move ( $ oldParent , $ newParent ) ; echo json_encode ( $ child -> nodeAttributes ( $ child , $ newParent -> id , time ( ) ) ) ; }
Detaches model from old parent . And attaches to the new one .
2,060
public function addToken ( $ name , $ position ) { $ token = new Token ( $ name , $ position ) ; $ this -> tokens [ ] = $ token ; switch ( substr ( $ name , - 4 ) ) { case AbstractBlockRule :: OPEN : $ this -> openedTokens [ ] = substr ( $ name , 0 , - 5 ) ; break ; case AbstractBlockRule :: CLOSE : while ( count ( $ this -> openedTokens ) > 0 ) { $ lastOpenToken = array_pop ( $ this -> openedTokens ) ; $ this -> tokens [ ] = new Token ( $ lastOpenToken . AbstractBlockRule :: CLOSE , $ position ) ; if ( $ lastOpenToken == substr ( $ name , 0 , - 5 ) ) { break ; } } break ; } return $ token ; }
Add token to token list
2,061
public function getTokenAt ( $ index ) { if ( $ index < 0 ) { $ index = count ( $ this -> tokens ) + $ index ; } return $ this -> tokens [ $ index ] ; }
Get token at given position
2,062
public function insertTokenAt ( $ name , $ position , $ index ) { array_splice ( $ this -> tokens , $ index , 0 , [ $ token = new Token ( $ name , $ position ) ] ) ; return $ token ; }
Add token to specific index position
2,063
public function removeTokenAt ( $ index ) { if ( $ index < 0 ) { $ index = count ( $ this -> tokens ) + $ index ; } array_splice ( $ this -> tokens , $ index , 1 ) ; }
Remove token at specific index position
2,064
public function lastByName ( $ name ) { for ( $ i = count ( $ this -> tokens ) - 1 ; $ i >= 0 ; $ i -- ) { if ( $ this -> tokens [ $ i ] -> getName ( ) === $ name ) { return $ this -> tokens [ $ i ] ; } } return null ; }
Get last token that match provided name
2,065
public function lastIndexByName ( $ name ) { for ( $ i = count ( $ this -> tokens ) - 1 ; $ i >= 0 ; $ i -- ) { if ( $ this -> tokens [ $ i ] -> getName ( ) === $ name ) { return $ i ; } } return null ; }
Get last token index that match provided name
2,066
public function merge ( TokenList $ tokenList ) { $ tokenList -> closeOpenTokens ( ) ; $ lastTokenPosition = $ this -> last ( ) === null ? 0 : $ this -> last ( ) -> getPosition ( ) ; foreach ( $ tokenList -> getTokens ( ) as $ token ) { $ token -> setPosition ( $ token -> getPosition ( ) + $ lastTokenPosition ) ; $ this -> tokens [ ] = $ token ; } }
Merge two token list
2,067
public function closeOpenTokens ( ) { $ lastToken = $ this -> last ( ) ; while ( count ( $ this -> openedTokens ) > 0 ) { $ lastOpenToken = array_pop ( $ this -> openedTokens ) ; $ this -> tokens [ ] = new Token ( $ lastOpenToken . AbstractBlockRule :: CLOSE , $ lastToken -> getPosition ( ) ) ; } }
Automatically close unclosed tags
2,068
public static function connection ( $ name ) { $ schema = static :: $ app [ 'db' ] -> connection ( $ name ) -> getSchemaBuilder ( ) ; $ schema -> blueprintResolver ( function ( $ table , $ callback ) { return new Blueprint ( $ table , $ callback ) ; } ) ; return $ schema ; }
Get a schema builder instance for a connection .
2,069
public static function userAssignments ( $ user ) { $ names = self :: find ( ) -> where ( [ 'user_id' => $ user -> id ] ) -> select ( 'item_name' ) -> column ( ) ; return AuthItem :: find ( ) -> where ( [ 'in' , 'name' , $ names ] ) ; }
Searches all user assignments .
2,070
public function setCheckboxAttribute ( $ a , $ v ) { foreach ( $ this -> checkboxes as $ checkbox ) { $ checkbox -> setAttribute ( $ a , $ v ) ; if ( $ a == 'tabindex' ) { $ v ++ ; } } return $ this ; }
Set an attribute for the input checkbox elements
2,071
public function setCheckboxAttributes ( array $ a ) { foreach ( $ this -> checkboxes as $ checkbox ) { $ checkbox -> setAttributes ( $ a ) ; if ( isset ( $ a [ 'tabindex' ] ) ) { $ a [ 'tabindex' ] ++ ; } } return $ this ; }
Set an attribute or attributes for the input checkbox elements
2,072
public function setValue ( $ value ) { $ this -> checked = ( ! is_array ( $ value ) ) ? [ $ value ] : $ value ; if ( ( count ( $ this -> checked ) > 0 ) && ( $ this -> hasChildren ( ) ) ) { foreach ( $ this -> childNodes as $ child ) { if ( $ child instanceof Input \ Checkbox ) { if ( in_array ( $ child -> getValue ( ) , $ this -> checked ) ) { $ child -> check ( ) ; } else { $ child -> uncheck ( ) ; } } } } return $ this ; }
Set the checked value of the checkbox form elements
2,073
public function render ( $ depth = 0 , $ indent = null , $ inner = false ) { if ( ! empty ( $ this -> legend ) ) { $ this -> addChild ( new Child ( 'legend' , $ this -> legend ) ) ; } return parent :: render ( $ depth , $ indent , $ inner ) ; }
Render the child and its child nodes
2,074
public function getDataInInterval ( $ coordinatesRequest , DateTime $ date , $ timeMinuteLimit = 30 , $ sorted = true ) { $ parameters = [ ] ; $ queriedStations = [ ] ; $ date = Carbon :: instance ( $ date ) -> setTimezone ( 'utc' ) ; foreach ( $ this -> services as $ var => $ hourlyService ) { $ stations = $ this -> getStations ( $ hourlyService , true ) ; if ( isset ( $ stations ) ) { try { $ nearestStations = DWDStationsController :: getNearestStations ( $ stations , $ coordinatesRequest ) ; } catch ( DWDLibException $ exception ) { DWDUtil :: log ( self :: class , "Failed to retrieve any nearest active stations. Retrying after forcedownloading new station infos." , Logger :: WARNING ) ; $ stations = $ this -> getStations ( $ hourlyService , true , true ) ; $ nearestStations = DWDStationsController :: getNearestStations ( $ stations , $ coordinatesRequest ) ; } foreach ( $ nearestStations as $ nearestStation ) { $ zipFilePath = $ this -> retrieveFile ( $ hourlyService , $ nearestStation ) ; $ content = isset ( $ zipFilePath ) ? DWDUtil :: getDataFromZip ( $ zipFilePath , DWDConfiguration :: getHourlyConfiguration ( ) -> zipExtractionPrefix ) : null ; if ( $ content == null ) { DWDUtil :: log ( self :: class , 'file for station=' . $ nearestStation . ' could not be loaded, trying next station' ) ; continue ; } $ parameters [ $ var ] = $ this -> retrieveData ( $ content , $ nearestStation , $ coordinatesRequest , $ hourlyService , $ date , $ timeMinuteLimit ) ; if ( count ( $ parameters [ $ var ] ) > 0 && ! isset ( $ queriedStations [ 'station-' . $ nearestStation -> getId ( ) ] ) ) { $ queriedStations [ 'station-' . $ nearestStation -> getId ( ) ] = $ nearestStation ; } if ( count ( $ parameters [ $ var ] ) > 0 ) break ; } } } if ( $ sorted && isset ( $ parameters ) ) ksort ( $ parameters ) ; return [ $ parameters , $ queriedStations ] ; }
Retrieve data from one of the nearest stations . This method retrieves all stations in a specific diameter around the location . It then queries the stations one by one until one station s results could be found .
2,075
public function getDataByDay ( Coordinate $ coordinatesRequest , DateTime $ day ) { $ parameters = [ ] ; $ queriedStations = [ ] ; $ day = Carbon :: instance ( $ day ) -> setTimezone ( 'utc' ) ; foreach ( $ this -> services as $ var => $ hourlyService ) { $ stations = $ this -> getStations ( $ hourlyService , true ) ; if ( isset ( $ stations ) ) { try { $ nearestStations = DWDStationsController :: getNearestStations ( $ stations , $ coordinatesRequest ) ; } catch ( DWDLibException $ exception ) { $ stations = $ this -> getStations ( $ hourlyService , true , true ) ; $ nearestStations = DWDStationsController :: getNearestStations ( $ stations , $ coordinatesRequest ) ; } foreach ( $ nearestStations as $ nearestStation ) { $ zipFilePath = $ this -> retrieveFile ( $ hourlyService , $ nearestStation ) ; $ content = isset ( $ zipFilePath ) ? DWDUtil :: getDataFromZip ( $ zipFilePath , DWDConfiguration :: getHourlyConfiguration ( ) -> zipExtractionPrefix ) : null ; if ( $ content == null ) { DWDUtil :: log ( self :: class , 'file for station=' . $ nearestStation . ' could not be loaded, trying next station' ) ; continue ; } $ start = Carbon :: instance ( $ day ) -> startOfDay ( ) ; $ end = Carbon :: instance ( $ day ) -> endOfDay ( ) ; $ parameters [ $ var ] = $ hourlyService -> parseHourlyData ( $ content , $ nearestStation , $ coordinatesRequest , $ start , $ end ) ; if ( count ( $ parameters [ $ var ] ) > 0 && ! isset ( $ queriedStations [ 'station-' . $ nearestStation -> getId ( ) ] ) ) { $ queriedStations [ 'station-' . $ nearestStation -> getId ( ) ] = $ nearestStation ; } if ( isset ( $ parameters [ $ var ] ) ) break ; } } } return [ $ parameters , $ queriedStations ] ; }
Get all data for the given day . The parameter day is converted to UTC!
2,076
public function getStations ( AbstractHourlyService $ controller , bool $ activeOnly = false , bool $ forceDownloadFile = false ) { $ downloadFile = false || $ forceDownloadFile ; $ stationsFTPPath = DWDConfiguration :: getHourlyConfiguration ( ) -> parameters ; $ stationsFTPPath = get_object_vars ( $ stationsFTPPath ) [ $ controller -> getParameter ( ) ] -> stations ; $ filePath = $ controller -> getStationFTPPath ( $ stationsFTPPath ) ; if ( file_exists ( $ filePath ) ) { $ lastModifiedStationFile = Carbon :: createFromTimestamp ( filemtime ( $ filePath ) ) ; $ diffInHours = Carbon :: now ( ) -> diffInHours ( Carbon :: createFromTimestamp ( filemtime ( $ filePath ) ) ) ; DWDUtil :: log ( self :: class , "last modified? " . $ lastModifiedStationFile . "; difference to today (h)? " . $ diffInHours ) ; $ downloadFile = $ diffInHours >= 12 ; } else $ downloadFile = true ; if ( $ downloadFile ) { DWDUtil :: log ( self :: class , "Downloading station file=" . $ filePath ) ; DWDStationsController :: getStationFile ( $ stationsFTPPath , $ filePath ) ; } $ stations = DWDStationsController :: parseStations ( $ filePath ) ; DWDUtil :: log ( self :: class , "Got stations... " . count ( $ stations ) ) ; if ( $ activeOnly && count ( $ stations ) > 0 ) { $ stations = array_filter ( $ stations , function ( DWDStation $ station ) { return $ station -> isActive ( ) ; } ) ; } DWDUtil :: log ( self :: class , "Got stations after filtering... " . count ( $ stations ) ) ; return $ stations ; }
Retrieves the correct stations file can be filtered to only show stations that are flagges as active . Conditions for this can be
2,077
public function retrieveFile ( AbstractHourlyService $ service , DWDStation $ nearestStation , $ forceDownloadFile = false ) { $ config = DWDConfiguration :: getConfiguration ( ) ; $ ftpConfig = $ config -> ftp ; $ fileName = $ service -> getFileName ( $ nearestStation -> getId ( ) ) ; $ ftpPath = $ service -> getFileFTPPath ( $ nearestStation -> getId ( ) ) ; $ localPath = $ service -> getFilePath ( $ fileName ) ; DWDUtil :: log ( self :: class , '$fileName=' . $ fileName ) ; DWDUtil :: log ( self :: class , '$ftpPath=' . $ ftpPath ) ; DWDUtil :: log ( self :: class , '$localPath=' . $ localPath ) ; $ ftp_connection = ftp_connect ( $ ftpConfig -> url ) ; $ files = array ( ) ; if ( file_exists ( $ localPath ) ) { $ lastModifiedStationFile = Carbon :: createFromFormat ( 'U' , ( filemtime ( $ localPath ) ) ) ; } if ( $ forceDownloadFile || ! file_exists ( $ localPath ) || ( isset ( $ lastModifiedStationFile ) && $ lastModifiedStationFile -> diffInDays ( Carbon :: now ( ) ) >= 1 ) ) { $ path = pathinfo ( $ localPath ) ; if ( ! is_dir ( $ path [ 'dirname' ] ) ) { mkdir ( $ path [ 'dirname' ] , 0755 , true ) ; } if ( ftp_login ( $ ftp_connection , $ ftpConfig -> userName , $ ftpConfig -> userPassword ) ) { if ( ftp_size ( $ ftp_connection , $ ftpPath ) > - 1 && ftp_get ( $ ftp_connection , $ localPath , $ ftpPath , FTP_BINARY ) ) { $ files [ ] = $ localPath ; } else { return null ; } ftp_close ( $ ftp_connection ) ; return $ localPath ; } } return $ localPath ; }
Retrieves a file for the controller by querying the nearest station .
2,078
private function retrieveData ( $ content , DWDStation $ nearestStation , Coordinate $ coordinate , AbstractHourlyService $ hourlyController , DateTime $ dateTime , $ timeMinuteLimit ) { $ timeBefore = Carbon :: instance ( $ dateTime ) ; $ timeAfter = Carbon :: instance ( $ dateTime ) ; $ timeBefore -> addMinute ( $ timeMinuteLimit ) ; $ timeAfter -> addMinute ( - $ timeMinuteLimit ) ; $ data = $ hourlyController -> parseHourlyData ( $ content , $ nearestStation , $ coordinate , $ timeAfter , $ timeBefore ) ; if ( count ( $ data ) == 0 && $ timeMinuteLimit < 90 ) { DWDUtil :: log ( self :: class , "retrieving data for a +-90min time limit..." ) ; $ data = $ this -> retrieveData ( $ content , $ nearestStation , $ coordinate , $ hourlyController , $ dateTime , 90 ) ; } else if ( count ( $ data ) == 0 && $ timeMinuteLimit < 210 ) { DWDUtil :: log ( self :: class , "retrieving data for a +-210min time limit..." ) ; $ data = $ this -> retrieveData ( $ content , $ nearestStation , $ coordinate , $ hourlyController , $ dateTime , 210 ) ; } return $ data ; }
DWD Hourly data is not really hourly as such first try to query with the specified limit then if the limit is smaller than + - 1 . 5h or + - 3 . 5h Query those values and return them .
2,079
public function sendCodeceptionOutputToSlack ( $ slackChannel , $ slackToken = null , $ codeceptionOutputFolder = null ) { if ( is_null ( $ slackToken ) ) { $ this -> say ( 'we are in Travis environment, getting token from ENV' ) ; $ slackToken = getenv ( 'SLACK_ENCRYPTED_TOKEN' ) ; } $ result = $ this -> taskSendCodeceptionOutputToSlack ( $ slackChannel , $ slackToken , $ codeceptionOutputFolder ) -> run ( ) ; return $ result ; }
Sends Codeception errors to Slack
2,080
public function input ( $ key , $ default = false ) { return $ this -> getRequestInputByType ( ) -> has ( $ key ) ? $ this -> getRequestInputByType ( ) -> get ( $ key ) : $ default ; }
Get a request parameter by key .
2,081
public function getRequestInputByType ( ) { $ data = $ this -> instance -> getRealMethod ( ) == 'GET' ? HttpFoundation :: createFromGlobals ( ) -> query : HttpFoundation :: createFromGlobals ( ) -> request ; if ( $ data ) { foreach ( $ data -> all ( ) as $ key => $ value ) { session ( ) -> createFlashMessage ( $ key , $ value ) ; } session ( ) -> createFlashMessage ( 'request' , $ data ) ; } return $ data ; }
get the request data base on request method .
2,082
public function getHeader ( $ key , $ default = false ) { return $ this -> headers -> has ( $ key ) ? $ this -> headers -> get ( $ key ) : $ default ; }
Get specific header .
2,083
public static function old ( $ key = null ) { if ( is_null ( $ key ) ) { return session ( ) -> getFlashMessage ( 'request' ) ? : '' ; } return session ( ) -> getFlashMessage ( $ key ) ? : '' ; }
Get old request value from session .
2,084
public static function createFromDefinition ( array $ definition , Procedure $ parent = null ) { $ procedure = new self ( $ definition [ 'name' ] , $ definition [ 'sources' ] , $ definition [ 'workers' ] , $ definition [ 'targets' ] , $ parent ) ; foreach ( $ definition [ 'children' ] as $ child ) { $ procedure -> addChild ( self :: createFromDefinition ( $ child , $ procedure ) ) ; } return $ procedure ; }
Creates a procedure from a definition .
2,085
private function getParentSettings ( $ type , $ context = null ) { $ context = $ this -> normalizeContext ( $ context ) ; $ methods = array ( 'source' => 'getSources' , 'worker' => 'getWorkers' , 'target' => 'getTargets' , ) ; if ( ! array_key_exists ( $ type , $ methods ) || $ context -> getParent ( ) === null ) { return array ( ) ; } $ settings = array_merge ( $ this -> getParentComponentSettings ( $ context -> getParent ( ) , $ methods [ $ type ] ) , $ this -> getParentSettings ( $ type , $ context -> getParent ( ) ) ) ; return $ settings ; }
Returns parent settings .
2,086
protected function path ( ) { if ( $ this -> parent ) { return $ this -> parent -> path ( ) . '/devices' ; } $ class = static :: $ resourceClass ; $ path = $ class :: $ path ; if ( $ this -> catalog ) { $ path .= '/catalog' ; } return $ path ; }
Return the API path for the query
2,087
public function getAttribute ( int $ index ) : ? Node { return isset ( $ this -> attributes [ $ index ] ) ? $ this -> attributes [ $ index ] : null ; }
Gets an attribute node
2,088
public function getChild ( int $ index ) : Node { if ( ! isset ( $ this -> children [ $ index ] ) ) { throw new AegisError ( 'Could not get child from node, because there\'s no child at index ' . $ i ) ; } return $ this -> children [ $ index ] ; }
Gets the child at the given index
2,089
public function removeChild ( int $ index ) { if ( ! isset ( $ this -> children [ $ index ] ) ) { throw new AegisError ( 'Could remove child from node, because there\'s no child at index ' . $ index ) ; } unset ( $ this -> children [ $ index ] ) ; }
Removes the child node at the given index
2,090
public function setValue ( $ value ) { if ( $ value == $ this -> getAttribute ( 'value' ) ) { $ this -> check ( ) ; } else { $ this -> uncheck ( ) ; } return $ this ; }
Set the value of the form input element object
2,091
public function isSubmitted ( ) { $ postParams = $ this -> request -> getParsedBody ( ) ; if ( count ( $ postParams ) > 0 ) { $ this -> setFieldValues ( $ postParams ) ; } return ( count ( $ postParams ) > 0 ) ; }
Method to verify a form isSubmitted
2,092
public function createFieldset ( $ legend = null , $ container = null ) { $ fieldset = new Fieldset ( ) ; if ( null !== $ legend ) { $ fieldset -> setLegend ( $ legend ) ; } if ( null !== $ container ) { $ fieldset -> setContainer ( $ container ) ; } $ this -> addFieldset ( $ fieldset ) ; $ id = ( null !== $ this -> getAttribute ( 'id' ) ) ? $ this -> getAttribute ( 'id' ) . '-fieldset-' . ( $ this -> current + 1 ) : 'pop-form-fieldset-' . ( $ this -> current + 1 ) ; $ class = ( null !== $ this -> getAttribute ( 'class' ) ) ? $ this -> getAttribute ( 'id' ) . '-fieldset' : 'pop-form-fieldset' ; $ fieldset -> setAttribute ( 'id' , $ id ) ; $ fieldset -> setAttribute ( 'class' , $ class ) ; return $ fieldset ; }
Method to create a new fieldset object
2,093
public function setAttribute ( $ a , $ v ) { parent :: setAttribute ( $ a , $ v ) ; if ( $ a == 'id' ) { foreach ( $ this -> fieldsets as $ i => $ fieldset ) { $ id = $ v . '-fieldset-' . ( $ i + 1 ) ; $ fieldset -> setAttribute ( 'id' , $ id ) ; } } else if ( $ a == 'class' ) { foreach ( $ this -> fieldsets as $ i => $ fieldset ) { $ class = $ v . '-fieldset' ; $ fieldset -> setAttribute ( 'class' , $ class ) ; } } return $ this ; }
Method to set an attribute
2,094
public function setAttributes ( array $ a ) { foreach ( $ a as $ name => $ value ) { $ this -> setAttribute ( $ name , $ value ) ; } return $ this ; }
Method to set attributes
2,095
public function addFieldset ( Fieldset $ fieldset ) { $ this -> fieldsets [ ] = $ fieldset ; $ this -> current = count ( $ this -> fieldsets ) - 1 ; return $ this ; }
Method to add fieldset
2,096
public function removeFieldset ( $ i ) { if ( isset ( $ this -> fieldsets [ ( int ) $ i ] ) ) { unset ( $ this -> fieldsets [ ( int ) $ i ] ) ; } $ this -> fieldsets = array_values ( $ this -> fieldsets ) ; if ( ! isset ( $ this -> fieldsets [ $ this -> current ] ) ) { $ this -> current = ( count ( $ this -> fieldsets ) > 0 ) ? count ( $ this -> fieldsets ) - 1 : 0 ; } return $ this ; }
Method to remove fieldset
2,097
public function getFieldset ( ) { return ( isset ( $ this -> fieldsets [ $ this -> current ] ) ) ? $ this -> fieldsets [ $ this -> current ] : null ; }
Method to get current fieldset
2,098
public function addColumn ( $ fieldsets , $ class = null ) { if ( ! is_array ( $ fieldsets ) ) { $ fieldsets = [ $ fieldsets ] ; } foreach ( $ fieldsets as $ i => $ num ) { $ fieldsets [ $ i ] = ( int ) $ num - 1 ; } if ( null === $ class ) { $ class = 'pop-form-column-' . ( count ( $ this -> columns ) + 1 ) ; } $ this -> columns [ $ class ] = $ fieldsets ; return $ this ; }
Method to add form column
2,099
public function setCurrent ( $ i ) { $ this -> current = ( int ) $ i ; if ( ! isset ( $ this -> fieldsets [ $ this -> current ] ) ) { $ this -> fieldsets [ $ this -> current ] = $ this -> createFieldset ( ) ; } return $ this ; }
Method to get current fieldset index