idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
14,000
public function getParticipants ( $ tournament ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/participants" ) ; $ participants = [ ] ; foreach ( $ response as $ team ) { $ participant = new Participant ( $ team -> participant ) ; $ participant -> tournament_slug = $ tournament ; $ participants [ ] = $ part...
Retrieve a tournament s participant list .
14,001
public function randomizeParticipants ( $ tournament ) { $ response = Guzzle :: post ( "tournaments/{$tournament}/participants/randomize" ) ; $ participants = [ ] ; foreach ( $ response as $ team ) { $ participant = new Participant ( $ team -> participant ) ; $ participant -> tournament_slug = $ tournament ; $ particip...
Randomize seeds among participants .
14,002
public function getParticipant ( $ tournament , $ participant ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/participants/{$participant}" ) ; $ participant = new Participant ( $ response -> participant ) ; $ participant -> tournament_slug = $ tournament ; return $ participant ; }
Retrieve a single participant record for a tournament .
14,003
public function getMatches ( $ tournament ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/matches" ) ; $ matches = [ ] ; foreach ( $ response as $ match ) { $ matchModel = new Match ( $ match -> match ) ; $ matchModel -> tournament_slug = $ tournament ; $ matches [ ] = $ matchModel ; } return $ matches ; }
Retrieve a tournament s match list .
14,004
public function getMatch ( $ tournament , $ match ) { $ response = Guzzle :: get ( "tournaments/{$tournament}/matches/{$match}" ) ; $ match = new Match ( $ response -> match ) ; $ match -> tournament_slug = $ tournament ; return $ match ; }
Retrieve a single match record for a tournament .
14,005
public static function getCurrenciesData ( $ locale ) { if ( null === self :: $ currencies ) { self :: prepareCurrencies ( $ locale ) ; } return self :: $ currencies ; }
Returns the currencies data .
14,006
public static function getDisplayCurrencies ( $ locale ) { if ( null === self :: $ currenciesNames ) { self :: prepareCurrencies ( $ locale ) ; } return self :: $ currenciesNames ; }
Returns the currencies names for a locale .
14,007
public function updateCMSFields ( FieldList $ fields ) { if ( $ this -> owner -> class != 'Folder' ) { $ set = $ this -> owner -> getTranslatableTabSet ( ) ; $ set -> removeByName ( Translatable :: default_locale ( ) ) ; foreach ( $ set -> FieldList ( ) as $ tab ) { $ fields -> addFieldToTab ( 'Root' , $ tab ) ; } } }
Update the field values for the files & images section
14,008
public static function get_extra_config ( $ class , $ extension , $ args ) { if ( ! self :: is_translatable_installed ( ) ) { if ( SapphireTest :: is_running_test ( ) ) { return null ; } user_error ( 'Translatable module is not installed but required.' , E_USER_WARNING ) ; return null ; } if ( $ args ) { self :: $ argu...
Use table information and locales to dynamically build required table fields
14,009
public function updateCMSFields ( FieldList $ fields ) { parent :: updateCMSFields ( $ fields ) ; if ( ! isset ( self :: $ collectorCache [ $ this -> owner -> class ] ) ) { return ; } foreach ( self :: $ collectorCache [ $ this -> owner -> class ] as $ translatableField => $ type ) { $ fields -> removeByName ( $ transl...
Alter the CMS Fields in order to automatically present the correct ones based on current language .
14,010
public function getLocalizedFormField ( $ fieldName , $ locale ) { $ baseName = $ this -> getBasename ( $ fieldName ) ; $ fieldLabels = $ this -> owner -> fieldLabels ( ) ; $ localizedFieldName = self :: localized_field ( $ fieldName , $ locale ) ; $ fieldLabel = isset ( $ fieldLabels [ $ baseName ] ) ? $ fieldLabels [...
Get a form field for the given field name
14,011
public function getLocalizedRelationField ( $ fieldName , $ locale ) { $ baseName = $ this -> getBasename ( $ fieldName ) ; $ localizedFieldName = self :: localized_field ( $ fieldName , $ locale ) ; $ field = null ; if ( $ field = $ this -> getFieldForRelation ( $ fieldName ) ) { $ relationField = clone $ field ; $ re...
Get a form field for the given relation name
14,012
public function updateFieldLabels ( & $ labels ) { parent :: updateFieldLabels ( $ labels ) ; $ statics = self :: $ collectorCache [ $ this -> ownerBaseClass ] ; foreach ( $ statics as $ field => $ type ) { $ parts = explode ( TRANSLATABLE_COLUMN_SEPARATOR , $ field ) ; $ labels [ $ field ] = FormField :: name_to_label...
Present translatable form fields in a more readable fashion
14,013
public function isLocalizedField ( $ fieldName ) { $ fields = self :: get_localized_class_fields ( $ this -> ownerBaseClass ) ; return in_array ( $ fieldName , $ fields ) ; }
Check if the given field name is a localized field
14,014
public function getLocalizedFieldName ( $ fieldName ) { if ( $ this -> isLocalizedField ( $ fieldName ) || $ this -> isLocalizedRelation ( $ fieldName ) ) { return self :: localized_field ( $ fieldName ) ; } trigger_error ( "Field '$fieldName' is not a localized field" , E_USER_ERROR ) ; }
Get the field name in the current reading locale
14,015
public function getLocalizedRelation ( $ fieldName , $ strict = true ) { $ localizedField = $ this -> getLocalizedFieldName ( $ fieldName ) ; if ( $ strict ) { return $ this -> owner -> getRelation ( $ localizedField ) ; } if ( $ value = $ this -> owner -> getRelation ( $ localizedField ) ) { return $ value ; } return ...
Get the localized object for a given relation .
14,016
public function getLocalizedValue ( $ fieldName , $ strict = true , $ parseShortCodes = false ) { $ localizedField = $ this -> getLocalizedFieldName ( $ fieldName ) ; $ strict = filter_var ( $ strict , FILTER_VALIDATE_BOOLEAN ) ; $ value = $ this -> owner -> dbObject ( $ localizedField ) ; if ( ! $ strict && ! $ value ...
Get the localized value for a given field .
14,017
public function onBeforeWrite ( ) { if ( ! isset ( self :: $ localizedFields [ $ this -> ownerBaseClass ] ) ) { return ; } $ fields = self :: $ localizedFields [ $ this -> ownerBaseClass ] ; foreach ( $ fields as $ field => $ localized ) { foreach ( self :: get_target_locales ( ) as $ locale ) { $ fieldName = self :: l...
On before write hook . Check if any translatable field has changed and if permissions are sufficient
14,018
public static function get_localized_class_fields ( $ class ) { $ fieldNames = null ; $ ancestry = array_reverse ( ClassInfo :: ancestry ( $ class ) ) ; foreach ( $ ancestry as $ className ) { if ( isset ( self :: $ localizedFields [ $ className ] ) ) { if ( $ fieldNames === null ) { $ fieldNames = array ( ) ; } foreac...
Get an array with all localized fields for the given class
14,019
public static function localized_field ( $ field , $ locale = null ) { if ( $ locale === null ) { $ locale = Translatable :: get_current_locale ( ) ; } if ( $ locale == Translatable :: default_locale ( ) ) { return $ field ; } return $ field . TRANSLATABLE_COLUMN_SEPARATOR . $ locale ; }
Given a field name and a locale name create a composite string that represents the field in the database .
14,020
public static function set_locales ( $ locales ) { if ( is_array ( $ locales ) ) { $ list = array ( ) ; foreach ( $ locales as $ locale ) { if ( i18n :: validate_locale ( $ locale ) ) { $ list [ ] = $ locale ; } } $ list = array_unique ( $ list ) ; Config :: inst ( ) -> update ( 'TranslatableDataObject' , 'locales' , e...
Explicitly set the locales that should be translated .
14,021
protected static function collectDBFields ( $ class ) { if ( isset ( self :: $ collectorCache [ $ class ] ) ) { return self :: $ collectorCache [ $ class ] ; } if ( isset ( self :: $ collectorLock [ $ class ] ) && self :: $ collectorLock [ $ class ] ) { return null ; } self :: $ collectorLock [ $ class ] = true ; $ fie...
Collect all additional database fields of the given class .
14,022
protected static function get_target_locales ( ) { if ( is_array ( self :: config ( ) -> locales ) ) { return ( array ) self :: config ( ) -> locales ; } else if ( is_array ( Translatable :: get_allowed_locales ( ) ) ) { return ( array ) Translatable :: get_allowed_locales ( ) ; } return array_keys ( Translatable :: ge...
Get the locales that should be translated
14,023
protected static function get_arguments ( $ class ) { if ( isset ( self :: $ arguments [ $ class ] ) ) { return self :: $ arguments [ $ class ] ; } else { if ( $ staticFields = Config :: inst ( ) -> get ( $ class , 'translatable_fields' , Config :: FIRST_SET ) ) { if ( is_array ( $ staticFields ) && ! empty ( $ staticF...
Get the custom arguments for a given class . Either directly from how the extension was defined or lookup the translatable_fields static variable
14,024
public function setFieldForRelation ( $ fieldName , FormField $ field ) { if ( self :: isLocalizedRelation ( $ fieldName ) ) { self :: $ localizedFields [ $ this -> ownerBaseClass . '_has_one' ] [ $ fieldName ] [ 'FormField' ] = $ field ; } }
Setter for relation specific FormField . Will be cloned in scaffolding functions
14,025
public static function getDisplayCountries ( $ locale ) { if ( ! isset ( self :: $ countries [ $ locale ] ) ) { self :: $ countries [ $ locale ] = Intl :: getRegionBundle ( ) -> getCountryNames ( $ locale ) ; } return self :: $ countries [ $ locale ] ; }
Returns the country names for a locale .
14,026
public static function getDisplayLanguages ( $ locale ) { if ( ! isset ( self :: $ languages [ $ locale ] ) ) { self :: $ languages [ $ locale ] = Intl :: getLanguageBundle ( ) -> getLanguageNames ( $ locale ) ; } return self :: $ languages [ $ locale ] ; }
Returns the language names for a locale .
14,027
public static function getDisplayLocales ( $ locale ) { if ( ! isset ( self :: $ locales [ $ locale ] ) ) { self :: $ locales [ $ locale ] = Intl :: getLocaleBundle ( ) -> getLocaleNames ( $ locale ) ; } return self :: $ locales [ $ locale ] ; }
Returns the locale names for a locale .
14,028
public function exitWorkerManager ( int $ sig , array $ pid ) : void { $ this -> logger -> debug ( 'fork manager [' . $ pid [ 'pid' ] . '] exit with [' . $ sig . ']' , [ 'category' => get_class ( $ this ) , ] ) ; pcntl_waitpid ( $ pid [ 'pid' ] , $ status , WNOHANG | WUNTRACED ) ; $ this -> cleanup ( SIGTERM ) ; }
Wait for worker manager .
14,029
protected function initWorkerManager ( ) { $ pid = pcntl_fork ( ) ; $ this -> manager_pid = $ pid ; if ( - 1 === $ pid ) { throw new SpawnForkException ( 'failed to spawn fork manager' ) ; } if ( ! $ pid ) { $ manager = $ this -> factory -> buildManager ( ) ; $ manager -> process ( ) ; exit ( ) ; } }
Fork a worker manager .
14,030
protected function main ( ) : void { $ this -> logger -> info ( 'start job listener' , [ 'category' => get_class ( $ this ) , ] ) ; $ cursor_jobs = $ this -> jobs -> getCursor ( [ '$or' => [ [ 'status' => JobInterface :: STATUS_WAITING ] , [ 'status' => JobInterface :: STATUS_POSTPONED ] , ] , ] ) ; $ cursor_events = $...
Fork handling blocking process .
14,031
public function does_it_meet_required_php_version ( $ version = PHP_VERSION ) { if ( $ this -> version_passes_requirement ( $ this -> minimum_version , $ version ) ) { return true ; } $ this -> load_version_notice ( array ( $ this , 'minimum_admin_notice' ) ) ; return false ; }
Check given PHP version against minimum required version .
14,032
public function does_it_meet_recommended_php_version ( $ version = PHP_VERSION ) { if ( $ this -> version_passes_requirement ( $ this -> recommended_version , $ version ) ) { return true ; } $ this -> load_version_notice ( array ( $ this , 'recommended_admin_notice' ) ) ; return false ; }
Check given PHP version against recommended version .
14,033
public function get_admin_notice ( $ level = 'minimum' ) { if ( 'recommended' === $ level ) { if ( ! empty ( $ this -> plugin_name ) ) { return '<p>' . $ this -> plugin_name . ' recommends a PHP version higher than ' . $ this -> recommended_version . '. Read more information about <a href="http://www.wpupdatephp.com/up...
Return the string to be shown in the admin notice .
14,034
private static function splAutoloader ( $ class_name ) { if ( 'Treffynnon\\Navigator' === substr ( ltrim ( $ class_name , '\\' ) , 0 , 20 ) ) { $ class_path = realpath ( __DIR__ . '/..' ) . '/' . str_replace ( '\\' , DIRECTORY_SEPARATOR , $ class_name ) ; require_once $ class_path . '.php' ; } }
Convert class names into file paths for inclusion
14,035
public static function distanceFactory ( $ lat1 , $ long1 , $ lat2 , $ long2 ) { $ point1 = new L ( new C ( $ lat1 ) , new C ( $ long1 ) ) ; $ point2 = new L ( new C ( $ lat2 ) , new C ( $ long2 ) ) ; return new D ( $ point1 , $ point2 ) ; }
Get a primed instance of the distance object
14,036
public static function getDistance ( $ lat1 , $ long1 , $ lat2 , $ long2 ) { return self :: distanceFactory ( $ lat1 , $ long1 , $ lat2 , $ long2 ) -> get ( ) ; }
Get the distance in metres
14,037
public function exitWorker ( int $ sig , array $ pid ) : self { $ this -> logger -> debug ( 'worker [' . $ pid [ 'pid' ] . '] exit with [' . $ sig . ']' , [ 'category' => get_class ( $ this ) , ] ) ; pcntl_waitpid ( $ pid [ 'pid' ] , $ status , WNOHANG | WUNTRACED ) ; foreach ( $ this -> forks as $ id => $ process ) { ...
Wait for child and terminate .
14,038
protected function spawnInitialWorkers ( ) { $ this -> logger -> debug ( 'spawn initial [' . $ this -> min_children . '] workers' , [ 'category' => get_class ( $ this ) , ] ) ; if ( self :: PM_DYNAMIC === $ this -> pm || self :: PM_STATIC === $ this -> pm ) { for ( $ i = $ this -> count ( ) ; $ i < $ this -> min_childr...
Start initial workers .
14,039
protected function spawnMinimumWorkers ( ) { $ this -> logger -> debug ( 'verify that the minimum number [' . $ this -> min_children . '] of workers are running' , [ 'category' => get_class ( $ this ) , ] ) ; for ( $ i = $ this -> count ( ) ; $ i < $ this -> min_children ; ++ $ i ) { $ this -> spawnWorker ( ) ; } }
Start minumum number of workers .
14,040
public function getJob ( ObjectId $ id ) : Process { $ result = $ this -> db -> { $ this -> job_queue } -> findOne ( [ '_id' => $ id , ] , [ 'typeMap' => self :: TYPE_MAP , ] ) ; if ( null === $ result ) { throw new JobNotFoundException ( 'job ' . $ id . ' was not found' ) ; } return new Process ( $ result , $ this , $...
Get job by Id .
14,041
public function cancelJob ( ObjectId $ id ) : bool { $ result = $ this -> updateJob ( $ id , JobInterface :: STATUS_CANCELED ) ; if ( 1 !== $ result -> getMatchedCount ( ) ) { throw new JobNotFoundException ( 'job ' . $ id . ' was not found' ) ; } $ this -> db -> { $ this -> event_queue } -> insertOne ( [ 'job' => $ id...
Cancel job .
14,042
public function addJob ( string $ class , $ data , array $ options = [ ] ) : Process { $ document = $ this -> prepareInsert ( $ class , $ data , $ options ) ; $ result = $ this -> db -> { $ this -> job_queue } -> insertOne ( $ document ) ; $ this -> logger -> debug ( 'queue job [' . $ result -> getInsertedId ( ) . '] a...
Add job to queue .
14,043
public function addJobOnce ( string $ class , $ data , array $ options = [ ] ) : Process { $ filter = [ 'class' => $ class , '$or' => [ [ 'status' => JobInterface :: STATUS_WAITING ] , [ 'status' => JobInterface :: STATUS_POSTPONED ] , [ 'status' => JobInterface :: STATUS_PROCESSING ] , ] , ] ; $ requested = $ options ...
Only add job if not in queue yet .
14,044
public function listen ( Closure $ callback , array $ query = [ ] ) : self { if ( 0 === count ( $ query ) ) { $ query = [ 'timestamp' => [ '$gte' => new UTCDateTime ( ) ] , ] ; } $ cursor = $ this -> events -> getCursor ( $ query ) ; while ( true ) { if ( null === $ cursor -> current ( ) ) { if ( $ cursor -> getInnerIt...
Listen for events .
14,045
protected function prepareInsert ( string $ class , $ data , array & $ options = [ ] ) : array { $ defaults = [ self :: OPTION_AT => $ this -> default_at , self :: OPTION_INTERVAL => $ this -> default_interval , self :: OPTION_RETRY => $ this -> default_retry , self :: OPTION_RETRY_INTERVAL => $ this -> default_retry_i...
Prepare insert .
14,046
public function transformFormField ( FormField $ field ) { $ newfield = $ field -> performReadOnlyTransformation ( ) ; $ fieldname = $ field -> getName ( ) ; if ( $ this -> original -> isLocalizedField ( $ fieldname ) ) { $ field -> setName ( $ this -> original -> getLocalizedFieldName ( $ fieldname ) ) ; $ value = $ t...
Transform a given form field into a composite field where the translation is editable and the original value is added as a read - only field .
14,047
public function start ( ) { if ( $ this -> state != 'pending' ) { throw new AlreadyStartedException ( 'Tournament is already underway.' ) ; } $ response = Guzzle :: post ( "tournaments/{$this->id}/start" ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Start a tournament opening up first round matches for score reporting .
14,048
public function finalize ( ) { if ( $ this -> state != 'awaiting_review' ) { throw new StillRunningException ( 'Tournament is still running.' ) ; } $ response = Guzzle :: post ( "tournaments/{$this->id}/finalize" ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Finalize a tournament that has had all match scores submitted rendering its results permanent .
14,049
public function update ( $ params = [ ] ) { $ response = Guzzle :: put ( "tournaments/{$this->id}" , $ params ) ; return $ this -> updateModel ( $ response -> tournament ) ; }
Update a tournament s attributes .
14,050
public function get ( D \ Calculator \ CalculatorInterface $ calculator = null , D \ Converter \ ConverterInterface $ unit_converter = null ) { if ( is_null ( $ calculator ) ) { $ calculator = new D \ Calculator \ Vincenty ; } $ distance = $ calculator -> calculate ( $ this -> point1 , $ this -> point2 ) ; if ( ! is_nu...
Calculate the distance between two points . Defaults to Vincenty if no calculator is supplied . If no unit converter is supplied then the formula will return a value in metres .
14,051
protected function getPackageReplacementTokens ( PackageInterface $ package ) { $ vars = array ( '{$type}' => $ package -> getType ( ) , ) ; $ prettyName = $ package -> getPrettyName ( ) ; if ( strpos ( $ prettyName , '/' ) !== false ) { $ pieces = explode ( '/' , $ prettyName ) ; $ vars [ '{$vendor}' ] = $ pieces [ 0 ...
Retrieve replacement tokens for the given package .
14,052
protected function getPluginConfiguration ( ) { if ( ! isset ( $ this -> configuration ) ) { $ extra = $ this -> composer -> getPackage ( ) -> getExtra ( ) ; $ legacy = false ; if ( isset ( $ extra [ 'custom-installer' ] ) ) { $ legacy = true ; foreach ( $ extra [ 'custom-installer' ] as $ key => $ val ) { if ( is_arra...
Retrieve plugin configuration object .
14,053
public function getTaxonomyKey ( ) { $ called_class_segments = explode ( '\\' , get_called_class ( ) ) ; $ class_name = end ( $ called_class_segments ) ; return ( is_null ( $ this -> taxonomy_key ) ) ? Str :: machine ( Str :: camelToHuman ( $ class_name ) , Base :: SEPARATOR ) : $ this -> taxonomy_key ; }
Get the taxonomy key
14,054
public function getOptionID ( $ term_id = null ) { return join ( '_' , array ( $ this -> getTaxonomyKey ( ) , ( $ term_id ) ? $ term_id : $ this -> get ( self :: ID ) ) ) ; }
Get the option ID
14,055
public function renderAdminColumn ( $ column_name , $ term_id ) { $ this -> load ( $ term_id ) ; parent :: renderAdminColumn ( $ column_name , $ term_id ) ; }
Render an admin column Note param order is flipped from parent
14,056
public function getEditPermalink ( $ object_type = null ) { if ( is_null ( $ object_type ) ) { $ object_type = $ this -> get ( 'object_id' ) ; if ( ! $ object_type ) { throw new \ Exception ( 'No object_type nor object_id' ) ; } } return get_edit_term_link ( $ this -> get ( 'term_id' ) , $ this -> getTaxonomyKey ( ) , ...
Get the edit permalink
14,057
public static function getWhere ( $ args = array ( ) ) { $ instance = Term \ Factory :: create ( get_called_class ( ) ) ; $ default_args = array ( 'orderby' => $ instance -> getDefaultOrderBy ( ) , 'order' => $ instance -> getDefaultOrder ( ) , 'hide_empty' => false , ) ; $ criteria = array_merge ( $ default_args , $ a...
Get terms with conditions
14,058
public static function getOneWhere ( $ args = array ( ) ) { $ args [ 'number' ] = 1 ; $ result = static :: getWhere ( $ args ) ; return ( count ( $ result ) ) ? current ( $ result ) : null ; }
Get one term
14,059
public static function find ( $ term_id ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; $ instance -> load ( $ term_id ) ; return $ instance ; }
Find a term
14,060
public static function loadAll ( ) { global $ taxonomies_infos ; $ subclasses = self :: getSubclasses ( ) ; foreach ( $ subclasses as $ class ) { $ instance = new $ class ; $ taxonomies_infos = array_merge ( $ taxonomies_infos , $ instance -> getTaxonomiesInfo ( ) ) ; self :: load ( $ class ) ; } }
Load all the posts
14,061
public static function load ( $ class ) { $ instance = new $ class ; $ post_type = $ instance -> getPostType ( ) ; if ( strlen ( $ post_type ) > 20 ) { throw new \ Exception ( 'Post Type name exceeds maximum 20 characters: ' . $ post_type ) ; } if ( ! $ post_type ) { return false ; } $ instance -> registerPostType ( ) ...
Load a post type
14,062
public static function getSubclasses ( ) { $ subclasses = array ( ) ; foreach ( get_declared_classes ( ) as $ class ) { if ( method_exists ( $ class , 'isLoadable' ) && $ class :: isLoadable ( ) === false ) { continue ; } if ( is_subclass_of ( $ class , 'Taco\Post' ) ) { $ subclasses [ ] = $ class ; } } return $ subcla...
Get all subclasses
14,063
public function calculate ( N \ LatLong $ point1 , N \ LatLong $ point2 ) { $ celestialBody = $ this -> getCelestialBody ( ) ; $ deltaLat = $ point2 -> getLatitude ( ) -> get ( ) - $ point1 -> getLatitude ( ) -> get ( ) ; $ deltaLong = $ point2 -> getLongitude ( ) -> get ( ) - $ point1 -> getLongitude ( ) -> get ( ) ; ...
Calculate the distance between two points using the Haversine formula .
14,064
public function update ( $ params = [ ] ) { $ response = Guzzle :: put ( "tournaments/{$this->tournament_slug}/participants/{$this->id}" , $ params ) ; return $ this -> updateModel ( $ response -> participant ) ; }
Update the attributes of a tournament participant .
14,065
public function transform ( $ object ) { if ( ( $ collection = $ this -> normalize ( $ object ) ) instanceof Collection ) { return $ this -> transformCollection ( $ collection ) ; } if ( $ this -> relatedCount ) { return $ this -> transformWithRelated ( $ object ) ; } if ( is_callable ( $ this -> transformationMethod )...
Transforms the object . Called recursively when transforming a collection or a relation .
14,066
protected function normalize ( $ object ) { if ( $ object instanceof Paginator ) { return collect ( $ object -> items ( ) ) ; } elseif ( is_array ( $ object ) ) { return collect ( $ object ) ; } return $ object ; }
Normalizes the object to a collection if it is some sort of a container to multiple items .
14,067
public function transformWithRelated ( $ item ) { $ transformedItem = $ this -> getTransformation ( $ item ) ; return $ this -> transformRelated ( $ transformedItem , $ item ) ; }
Transforms the item with its related models .
14,068
public function with ( $ relation ) { $ this -> reset ( ) ; if ( func_num_args ( ) > 1 ) { return $ this -> with ( func_get_args ( ) ) ; } if ( is_array ( $ relation ) ) { $ this -> related = array_merge ( $ this -> related , $ relation ) ; } else { $ this -> related [ ] = $ relation ; } $ this -> relatedCount = count ...
Adds a relation to the transformer .
14,069
public function setTransformation ( $ transformation ) { if ( is_callable ( $ transformation ) ) { $ this -> transformationMethod = $ transformation ; return $ this ; } $ methodName = str_replace ( 'Transformation' , '' , $ transformation ) . "Transformation" ; if ( ! method_exists ( $ this , $ methodName ) ) { throw n...
Sets the current transformation .
14,070
protected function transformRelated ( $ itemTransformation , $ item ) { foreach ( $ this -> related as $ relation ) { $ relationName = explode ( '.' , $ relation , 2 ) [ 0 ] ; $ itemTransformation [ $ relationName ] = $ this -> getRelatedTransformation ( $ item , $ relation ) ; } return $ itemTransformation ; }
Transforms the related item and adds it to the transformation array .
14,071
protected function getRelatedTransformation ( $ item , $ relation ) { $ nestedRelations = explode ( '.' , $ relation , 2 ) ; $ relation = $ nestedRelations [ 0 ] ; $ result = $ item -> { $ relation } ; $ related = $ result ; $ transformer = null ; if ( ! is_object ( $ related ) ) { return $ related ; } if ( $ related i...
Resolves the transformation for the related model .
14,072
public function calculate ( N \ LatLong $ point1 , N \ LatLong $ point2 ) { $ celestialBody = $ this -> getCelestialBody ( ) ; $ degrees = acos ( sin ( $ point1 -> getLatitude ( ) -> get ( ) ) * sin ( $ point2 -> getLatitude ( ) -> get ( ) ) + cos ( $ point1 -> getLatitude ( ) -> get ( ) ) * cos ( $ point2 -> getLatitu...
Calculate the distance between two points using the Great Circle formula .
14,073
public static function image ( $ sEmail , $ iSize = null , $ sDefaultImage = null , $ sRating = null , $ sExtension = null , $ bForceDefault = false ) { $ gravatarImage = ( new Image ( ) ) -> setEmail ( $ sEmail ) -> setSize ( $ iSize ) -> setDefaultImage ( $ sDefaultImage , $ bForceDefault ) -> setMaxRating ( $ sRatin...
Return the Gravatar image based on the provided email address .
14,074
public static function images ( array $ aEmail , $ iSize = null , $ sDefaultImage = null , $ sRating = null , $ sExtension = null , $ bForceDefault = false ) { $ aImages = [ ] ; foreach ( $ aEmail as $ sEmail ) { $ gravatarImage = ( new Image ( ) ) -> setEmail ( $ sEmail ) -> setSize ( $ iSize ) -> setDefaultImage ( $ ...
Return multiples Gravatar images based on the provided array of emails addresses .
14,075
public static function profiles ( array $ aEmail , $ sFormat = null ) { $ aProfils = [ ] ; foreach ( $ aEmail as $ sEmail ) { $ gravatarProfil = ( new Profile ( ) ) -> setEmail ( $ sEmail ) -> setFormat ( $ sFormat ) ; $ aProfils [ $ sEmail ] = $ gravatarProfil ; } return $ aProfils ; }
Return multiples Gravatar profiles based on the provided array of emails addresses .
14,076
public function email ( $ sEmail = null ) { if ( null === $ sEmail ) { return $ this -> getEmail ( ) ; } return $ this -> setEmail ( $ sEmail ) ; }
Get or set the address email to be used .
14,077
public static function create ( $ post , $ load_terms = true ) { if ( is_string ( $ post ) && class_exists ( $ post ) ) { return new $ post ; } $ original_post = $ post ; if ( ! is_object ( $ post ) ) { $ post = get_post ( $ post ) ; } if ( ! is_object ( $ post ) ) { throw new \ Exception ( sprintf ( 'Post %s not found...
Create an instance based on a WP post This basically autoloads the meta data
14,078
public static function createMultiple ( $ posts , $ load_terms = true ) { if ( ! Arr :: iterable ( $ posts ) ) { return $ posts ; } $ out = array ( ) ; foreach ( $ posts as $ k => $ post ) { if ( ! get_post_status ( $ post ) ) { continue ; } $ record = self :: create ( $ post , $ load_terms ) ; $ out [ $ k ] = $ record...
Create multiple instances based on WP posts This basically autoloads the meta data
14,079
public function draw ( Dm_Image $ image , $ x = 0 , $ y = 0 , $ width = null , $ height = null ) { $ srcImageResource = $ image -> getImageResource ( ) ; if ( is_null ( $ width ) ) $ width = $ image -> getWidth ( ) ; if ( is_null ( $ height ) ) $ height = $ image -> getHeight ( ) ; return imagecopy ( $ this -> getImage...
Copy and merge part of an image
14,080
public function saveTo ( $ path , $ type = 'png' , $ quality = null ) { if ( ! $ path ) return false ; return $ this -> outputTo ( $ path , $ type , $ quality ) ; }
The path to save the file to .
14,081
public function destroy ( ) { imagedestroy ( $ this -> _imageResource ) ; $ this -> graphics -> destroy ( ) ; $ this -> graphics = null ; $ this -> textGraphics -> destroy ( ) ; $ this -> textGraphics = null ; }
Destroy an image .
14,082
public function toDataSchemeURI ( ) { $ md5 = md5 ( microtime ( 1 ) . rand ( 10000 , 99999 ) ) ; $ filePath = $ this -> tempDirPath ( ) . DIRECTORY_SEPARATOR . "temp" . $ md5 . ".png" ; $ this -> saveTo ( $ filePath ) ; $ uri = 'data:' . mime_content_type ( $ filePath ) . ';base64,' ; $ uri .= base64_encode ( file_get_...
Return data scheme URI .
14,083
public function serve ( $ salt = '' ) { $ protocol = isset ( $ _SERVER [ 'SERVER_PROTOCOL' ] ) ? $ _SERVER [ 'SERVER_PROTOCOL' ] : 'HTTP/1.0' ; if ( $ input = $ this -> findInput ( ) ) { $ output = $ this -> cacheName ( $ salt . $ input ) ; $ etag = $ noneMatch = trim ( $ this -> getIfNoneMatchHeader ( ) , '"' ) ; if (...
Compile requested scss and serve css . Outputs HTTP response .
14,084
public function getPrefixGroupedMetaBoxes ( ) { $ fields = $ this -> getFields ( ) ; $ groups = array ( ) ; foreach ( $ fields as $ k => $ field ) { $ prefix = current ( explode ( '_' , $ k ) ) ; if ( ! array_key_exists ( $ prefix , $ groups ) ) { $ groups [ $ prefix ] = array ( ) ; } $ groups [ $ prefix ] [ ] = $ k ; ...
Get meta boxes grouped by prefix
14,085
public function replaceMetaBoxGroupMatches ( $ meta_boxes ) { if ( ! Arr :: iterable ( $ meta_boxes ) ) { return $ meta_boxes ; } foreach ( $ meta_boxes as $ k => $ group ) { $ group = ( is_array ( $ group ) ) ? $ group : array ( $ group ) ; if ( array_key_exists ( 'fields' , $ group ) ) { continue ; } $ fields = $ thi...
Replace any meta box group matches
14,086
public function getMetaBoxConfig ( $ config , $ key = null ) { if ( ! array_key_exists ( 'fields' , $ config ) ) { $ fields = array ( ) ; foreach ( $ config as $ field ) { if ( preg_match ( '/^\</' , $ field ) && preg_match ( '/\>$/' , $ field ) ) { $ fields [ md5 ( mt_rand ( ) ) ] = array ( 'type' => 'html' , 'label' ...
Get a meta box config handling defaults
14,087
public function assign ( $ vals ) { if ( count ( $ vals ) === 0 ) { return 0 ; } $ n = 0 ; foreach ( $ vals as $ k => $ v ) { if ( $ this -> set ( $ k , $ v ) ) { $ n ++ ; } } return $ n ; }
Set multiple fields
14,088
public function isValid ( $ vals ) { $ fields = $ this -> getFields ( ) ; if ( ! Arr :: iterable ( $ fields ) ) { return true ; } $ result = true ; foreach ( $ fields as $ k => $ field ) { if ( $ this -> isRequired ( $ field ) ) { if ( ! array_key_exists ( $ k , $ vals ) || is_null ( $ vals [ $ k ] ) || $ vals [ $ k ] ...
Is this a valid entry?
14,089
public function getMetaBoxTitle ( $ key = null ) { return ( $ key ) ? Str :: human ( $ key ) : sprintf ( '%s' , $ this -> getSingular ( ) ) ; }
Get the meta box title
14,090
private static function scrubAttributes ( $ field , $ type = null ) { $ invalid_keys = [ 'default' , 'description' , 'label' , 'options' , ] ; if ( $ type && $ type === 'textarea' ) { $ invalid_keys [ ] = 'value' ; } foreach ( $ invalid_keys as $ invalid_key ) { if ( array_key_exists ( $ invalid_key , $ field ) ) { uns...
Remove invalid HTML attribute keys from field definition
14,091
public function getCheckboxDisplay ( $ column_name ) { $ displays = $ this -> getCheckboxDisplays ( ) ; if ( array_key_exists ( $ column_name , $ displays ) ) { return $ displays [ $ column_name ] ; } if ( array_key_exists ( 'default' , $ displays ) ) { return $ displays [ 'default' ] ; } return array ( 'Yes' , 'No' ) ...
Get checkbox display for a specific admin column
14,092
public function renderAdminColumn ( $ column_name , $ item_id ) { $ columns = $ this -> getAdminColumns ( ) ; if ( ! in_array ( $ column_name , $ columns ) ) { return ; } $ field = $ this -> getField ( $ column_name ) ; if ( is_array ( $ field ) ) { $ class = get_called_class ( ) ; $ entry = new $ class ; $ entry -> lo...
Render an admin column
14,093
public function makeAdminColumnsSortable ( $ columns ) { $ admin_columns = $ this -> getAdminColumns ( ) ; if ( ! Arr :: iterable ( $ admin_columns ) ) { return $ columns ; } foreach ( $ admin_columns as $ k ) { $ columns [ $ k ] = $ k ; } return $ columns ; }
Make the admin columns sortable
14,094
public function getPlural ( ) { $ singular = $ this -> getSingular ( ) ; if ( preg_match ( '/y$/' , $ singular ) ) { return preg_replace ( '/y$/' , 'ies' , $ singular ) ; } return ( is_null ( $ this -> plural ) ) ? Str :: human ( $ singular ) . 's' : $ this -> plural ; }
Get the plural name
14,095
public function getThe ( $ key , $ convert_value = false , $ return_wrapped = true ) { if ( $ return_wrapped ) { return apply_filters ( 'the_content' , $ this -> get ( $ key , $ convert_value ) ) ; } remove_filter ( 'the_content' , 'wpautop' ) ; $ value = apply_filters ( 'the_content' , $ this -> get ( $ key , $ conver...
Get any value run through the_content filter
14,096
public function getLabelText ( $ field_key ) { $ field = $ this -> getField ( $ field_key ) ; if ( ! is_array ( $ field ) ) { return null ; } return ( array_key_exists ( 'label' , $ field ) ) ? $ field [ 'label' ] : Str :: human ( str_replace ( '-' , ' ' , preg_replace ( '/_id$/i' , '' , $ field_key ) ) ) ; }
Get the label text for a field
14,097
public function getRenderLabel ( $ field_key , $ required_mark = ' <span class="required">*</span>' ) { return sprintf ( '<label for="%s">%s%s</label>' , $ field_key , $ this -> getLabelText ( $ field_key ) , ( $ required_mark && $ this -> isRequired ( $ field_key ) ) ? $ required_mark : null ) ; }
Get the label HTML for a field
14,098
public function isRequired ( $ field_key ) { $ field = ( is_array ( $ field_key ) ) ? $ field_key : $ this -> getField ( $ field_key ) ; return ( is_array ( $ field ) && array_key_exists ( 'required' , $ field ) && $ field [ 'required' ] ) ; }
Is the field required?
14,099
public function parse ( $ coord ) { $ coordinate = null ; $ matches = array ( ) ; preg_match ( $ this -> input_format , $ coord , $ matches ) ; if ( count ( $ matches ) == 5 ) { $ degrees = $ matches [ 1 ] ; $ minutes = $ matches [ 2 ] * ( 1 / 60 ) ; $ seconds = $ matches [ 3 ] * ( 1 / 60 * 1 / 60 ) ; $ coordinate = ''...
Used when setting a value in the Coordinate class .