idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
12,200
public function skip ( $ message = '' ) { if ( $ this -> skipped !== true ) { $ this -> skipped = true ; $ this -> skipped_because = $ message ; } return $ this ; }
Unless the Block has been skipped elsewhere this marks the block as skipped with the given message .
12,201
public function getContextChain ( ) { $ block_chain = array ( ) ; $ this -> traversePost ( function ( $ block ) use ( & $ block_chain ) { $ befores = array_merge ( $ block -> beforeAlls ( ) , $ block -> befores ( ) ) ; $ block_chain = array_merge ( $ block_chain , $ befores ) ; } ) ; return array_filter ( array_map ( f...
Returns an aray of related contexts in their intended call order .
12,202
public function path ( $ offset = null , $ length = null ) { $ ancestors = array_map ( function ( $ ancestor ) { return $ ancestor -> getName ( ) ; } , $ this -> ancestors ( ) ) ; $ ancestors = array_slice ( array_reverse ( $ ancestors ) , $ offset , $ length ) ; $ res = implode ( ":" , $ ancestors ) ; return $ res ; }
With no arguments returns the complete path to this block down from it s root ancestor .
12,203
public static function flatten ( $ array , $ return = array ( ) ) { foreach ( $ array as $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { $ return = self :: flatten ( $ value , $ return ) ; } else { $ return [ ] = $ value ; } } return $ return ; }
Converts a multidimensional array into a uni - dimensional array .
12,204
public function afterSelect ( Select $ event ) { if ( $ this -> lazyLoad ) { return ; } $ data = $ event -> data ; $ multiple = $ data instanceof RecordList ; if ( $ multiple ) { $ data = $ event -> data -> getArrayCopy ( ) ; } else { $ data = [ $ data ] ; } if ( empty ( $ data ) ) { return ; } $ related = Entity \ Man...
Fixes the data to be sent to entity creation with related entity object
12,205
public function assertHex ( string $ hex ) { if ( mb_strlen ( $ hex ) !== 7 ) { throw new RuntimeException ( sprintf ( 'Invalid HEX value %s.' , $ hex ) ) ; } if ( mb_substr ( $ hex , 0 , 1 ) !== '#' ) { throw new RuntimeException ( sprintf ( 'Invalid HEX value %s.' , $ hex ) ) ; } for ( $ i = 1 ; $ i < mb_strlen ( $ h...
Assert HEX format .
12,206
public function rgb2hex ( array $ rgb ) : string { $ this -> assertRgb ( $ rgb ) ; list ( $ red , $ green , $ blue ) = $ rgb ; return sprintf ( '#%02x%02x%02x' , $ red , $ green , $ blue ) ; }
Convert color in RGB to HEX format .
12,207
public function assertRgb ( array $ rgb ) { if ( count ( $ rgb ) !== 3 ) { throw new RuntimeException ( sprintf ( 'Invalid RGB value [%s].' , implode ( ', ' , $ rgb ) ) ) ; } foreach ( $ rgb as $ value ) { if ( $ value < 0 || $ value > 255 ) { throw new RuntimeException ( sprintf ( 'Invalid RGB value [%s].' , implode (...
Assert RGB format .
12,208
public function required ( $ value ) { if ( ! is_null ( $ value ) && $ value !== '' ) { return $ value ; } throw new Exceptions \ RequiredValueMissingException ( $ this -> v_type , $ this -> v_key ) ; }
Validation for required elements
12,209
public function valueRequired ( $ value ) { if ( is_string ( $ value ) || is_numeric ( $ value ) ) { return $ value ; } throw new Exceptions \ RequiredValueMissingException ( $ this -> v_type , $ this -> v_key ) ; }
Validation for options to specify that a value is required and not just flag
12,210
public function map ( callable $ callback ) : array { $ result = [ ] ; foreach ( $ this -> members as $ member ) { $ result [ ] = $ callback ( $ member ) ; } return $ result ; }
Apply a function to each member of this container .
12,211
public function offsetSet ( $ offset , $ object ) { if ( is_int ( $ offset ) && $ offset >= 0 && $ offset < $ this -> count ( ) ) { $ member = static :: checkMember ( $ object ) ; if ( ! $ this -> contains ( $ member ) ) { $ this -> members [ $ offset ] = $ member ; } } elseif ( is_null ( $ object ) ) { $ this -> close...
Set an object at the given offset .
12,212
public function append ( $ object ) { $ member = static :: checkMember ( $ object ) ; if ( ! $ this -> contains ( $ member ) ) { $ this -> members [ ] = $ member ; } }
Append an object at the end .
12,213
protected function getExceptionMessageAppendix ( ) { $ tmp = [ ] ; if ( $ this -> sourceBlueprint ) { $ tmp [ ] = 'Blueprint: ' . $ this -> sourceBlueprint -> getName ( ) ; } if ( $ this -> sourceType ) { $ tmp [ ] = 'Type:' . $ this -> sourceType ; } if ( $ this -> sourceKey ) { $ tmp [ ] = 'Key:' . $ this -> sourceKe...
Craft exception message appendix
12,214
protected function customiseFile ( File $ file ) { $ customizedfile = $ file -> customise ( array ( 'UploadFieldThumbnailURL' => $ this -> getThumbnailURLForFile ( $ file ) , 'UploadFieldDeleteLink' => $ this -> getItemHandler ( $ file -> ID ) -> DeleteLink ( ) , 'UploadFieldEditLink' => $ this -> getItemHandler ( $ fi...
Customises a file with additional details suitable for rendering in the UploadField . ss template
12,215
public function delete ( SS_HTTPRequest $ request ) { if ( $ this -> parent -> isDisabled ( ) || $ this -> parent -> isReadonly ( ) ) { return $ this -> httpError ( 403 ) ; } $ token = $ this -> parent -> getForm ( ) -> getSecurityToken ( ) ; if ( ! $ token -> checkRequest ( $ request ) ) { return $ this -> httpError (...
Action to handle deleting of a single file
12,216
public function edit ( SS_HTTPRequest $ request ) { if ( $ this -> parent -> isDisabled ( ) || $ this -> parent -> isReadonly ( ) ) { return $ this -> httpError ( 403 ) ; } $ item = $ this -> getItem ( ) ; if ( ! $ item ) { return $ this -> httpError ( 404 ) ; } $ memberID = Member :: currentUserID ( ) ; $ res = false ...
Action to handle editing of a single file
12,217
public function getRawQuery ( ) { $ sql = array ( ) ; foreach ( $ this -> getClauses ( ) as $ clause ) { if ( ! $ clause -> isEmpty ( ) ) { $ sql [ ] = $ clause ; } } return implode ( ' ' , $ sql ) ; }
Get the sql without any replacements
12,218
public function quote ( $ value ) { if ( $ this -> isDoubleQuoted ( ) ) { return $ this -> doubleQuote ( $ value ) ; } else { return $ this -> singleQuote ( $ value ) ; } }
Quote value with either double or single quotes depending on the configuration
12,219
public function quoteIfNecessary ( $ value ) { if ( $ this -> isNumber ( $ value ) || $ this -> isPlaceholder ( $ value ) ) { return $ value ; } return $ this -> quote ( $ value ) ; }
Quote value if it is not a number or placeholder
12,220
public function replacePlaceholders ( $ string , $ values , $ quoteIfNecessary = true ) { foreach ( $ values as $ placeholder => $ value ) { $ replacement = $ quoteIfNecessary ? $ this -> quoteIfNecessary ( $ value ) : $ value ; $ string = str_replace ( ":{$placeholder}" , $ replacement , $ string ) ; } return $ string...
Replace the given string with the given placeholders
12,221
public function getSession ( ) { if ( is_null ( $ this -> _session ) ) { $ this -> _session = $ this -> getContainer ( ) -> get ( 'session' ) ; } return $ this -> _session ; }
Lazy loads session component
12,222
protected function _getSelectFieldsAndTable ( ) { $ template = "SELECT %s FROM %s" ; if ( $ this -> _sql -> isDistinct ( ) ) { $ template = "SELECT DISTINCT %s FROM %s" ; } $ this -> _statement = sprintf ( $ template , $ this -> _getFieldList ( ) , $ this -> _sql -> getTable ( ) ) ; return $ this ; }
Sets the fields for this select query
12,223
protected function _getFieldList ( ) { $ fields [ ] = $ this -> _getFieldsFor ( $ this -> _sql ) ; foreach ( $ this -> _sql -> getJoins ( ) as $ join ) { $ str = $ this -> _getFieldsFor ( $ join ) ; if ( ! $ str ) { continue ; } $ fields [ ] = $ str ; } return implode ( ', ' , $ fields ) ; }
Sets table field list
12,224
protected function _getFieldsFor ( FieldListAwareInterface $ object ) { if ( is_null ( $ object -> getFields ( ) ) ) { return false ; } if ( is_string ( $ object -> getFields ( ) ) ) { return $ object -> getFields ( ) ; } $ alias = ( is_null ( $ object -> getAlias ( ) ) ) ? $ object -> getTable ( ) : $ object -> getAli...
Retrieve a field list from a FieldListAwareInterface object
12,225
protected function _setJoins ( ) { $ joins = $ this -> _sql -> getJoins ( ) ; foreach ( $ joins as $ join ) { $ this -> _statement .= $ this -> _createJoinStatement ( $ join ) ; } return $ this ; }
Sets the joins for this select statement
12,226
protected function _setOrder ( ) { $ order = $ this -> _sql -> getOrder ( ) ; if ( ! ( is_null ( $ order ) || empty ( $ order ) ) ) { $ this -> _statement .= " ORDER BY {$order}" ; } return $ this ; }
Sets the order by clause
12,227
protected function _setLimit ( ) { if ( is_null ( $ this -> _sql -> getLimit ( ) ) || intval ( $ this -> _sql -> getLimit ( ) ) < 1 ) { return $ this ; } if ( $ this -> _sql -> getOffset ( ) > 0 ) { return $ this -> _setLimitWithOffset ( ) ; } return $ this -> _setSimpleLimit ( ) ; }
Set limit clause
12,228
protected function _createJoinStatement ( Select \ Join $ join ) { $ template = " %s JOIN %s%s ON %s" ; $ alias = ( is_null ( $ join -> getAlias ( ) ) ) ? null : " AS {$join->getAlias()}" ; return sprintf ( $ template , $ join -> getType ( ) , $ join -> getTable ( ) , $ alias , $ join -> getOnClause ( ) ) ; }
Sets the proper join syntax for a provided join object
12,229
public function getLogger ( $ name = null ) { $ name = is_null ( $ name ) ? $ this -> defaultLogger : $ name ; $ name = "{$this->getPrefix()}$name" ; if ( ! isset ( static :: $ _loggers [ $ name ] ) ) { static :: $ _loggers [ $ name ] = new Logger ( $ name ) ; $ this -> _setDefaultHandlers ( static :: $ _loggers [ $ na...
Gets the logger for the channel with the provided name .
12,230
protected function _setDefaultHandlers ( Logger & $ logger ) { if ( empty ( $ this -> _handlers ) ) { $ socketHandler = new NullHandler ( ) ; array_push ( $ this -> _handlers , $ socketHandler ) ; } foreach ( $ this -> _handlers as $ handler ) { $ logger -> pushHandler ( $ handler ) ; } }
Adds the default log handlers to the provided logger .
12,231
public function getPrefix ( ) { if ( is_null ( $ this -> _prefix ) ) { $ hostName = gethostname ( ) ; try { $ this -> _prefix = Configuration :: get ( 'config' ) -> get ( 'logger.prefix' , $ hostName ) ; } catch ( FileNotFoundException $ exp ) { $ this -> _prefix = $ hostName ; } } return $ this -> _prefix ; }
Returns the logger prefix to use
12,232
public function set ( array $ data ) { foreach ( $ data as $ field => $ value ) { $ this -> fields [ ] = $ field ; $ this -> dataParameters [ ":{$field}" ] = $ value ; } return $ this ; }
Sets the data for current SQL query
12,233
public function confirm ( $ text = 'Do you wish to continue?' ) { $ this -> output -> writeln ( $ text ) ; return $ this -> convertToBool ( $ this -> input -> getInput ( ) ) ; }
Request basic confirmation returns a boolean value depending on the answer
12,234
public function convertToBool ( $ answer ) { if ( ! $ this -> caseSensitive ) { $ answer = strtoupper ( $ answer ) ; } if ( $ answer == $ this -> confirmYes ) { return true ; } if ( $ answer == $ this -> confirmNo || $ this -> explicit === false ) { return false ; } $ this -> output -> writeln ( $ this -> invalidConfir...
Converts the input to a boolean value depending on its answer
12,235
public function addExpected ( $ name , $ requirements ) { if ( ! array_key_exists ( $ name , static :: $ varPosition ) ) { static :: $ expected [ $ name ] = $ requirements ; static :: $ varPosition [ ] = $ name ; } return $ this ; }
Adds an expected argument to the expected array
12,236
public function computeWithoutBcMath ( DecimalNumber $ a , DecimalNumber $ b ) { if ( $ a -> isNegative ( ) ) { if ( $ b -> isNegative ( ) ) { return $ this -> computeWithoutBcMath ( $ b -> toPositive ( ) , $ a -> toPositive ( ) ) ; } else { return $ a -> toPositive ( ) -> plus ( $ b ) -> toNegative ( ) ; } } else if (...
Performs the subtraction without using BC Math
12,237
public function getInput ( ) { if ( is_null ( $ this -> _input ) ) { $ this -> _input = new Input ( $ this -> getName ( ) ) ; } return $ this -> _input ; }
Lazy loads the input fot this object
12,238
public function setValue ( $ value ) { $ this -> _value = $ value ; $ this -> getInput ( ) -> setValue ( $ value ) ; return $ this ; }
Sets element default value
12,239
public function newInputFilter ( array $ definition = array ( ) ) { if ( ! empty ( $ definition ) ) { $ this -> _definition = $ definition ; } $ this -> _inputFilter = new InputFilter ( ) ; foreach ( $ this -> _definition as $ key => $ item ) { if ( ! is_string ( $ key ) ) { $ key = $ item [ 'name' ] ; } $ this -> _add...
Creates a new input filter
12,240
protected function _addInput ( array $ data , $ name = null ) { $ this -> _inputFilter -> add ( $ this -> _newInput ( $ data , $ name ) ) ; }
Adds an input to the input filter
12,241
protected function _newInput ( array $ data , $ name = null ) { $ options = array ( ) ; foreach ( array_keys ( $ this -> _inputProperties ) as $ key ) { if ( isset ( $ data [ $ key ] ) ) { $ options [ $ key ] = $ data [ $ key ] ; } } $ input = new Input ( $ name , $ options ) ; if ( isset ( $ data [ 'filters' ] ) ) { $...
Creates a new input
12,242
protected function _addFilters ( Input & $ input , array $ filters ) { foreach ( $ filters as $ filter ) { $ input -> getFilterChain ( ) -> add ( StaticFilter :: create ( $ filter ) ) ; } }
Add filters to an input
12,243
protected function _addValidators ( Input & $ input , array $ validators ) { foreach ( $ validators as $ validator => $ message ) { $ input -> getValidatorChain ( ) -> add ( StaticValidator :: create ( $ validator , $ message ) ) ; } }
Add validators to an input
12,244
public static function create ( $ filter ) { if ( array_key_exists ( $ filter , static :: $ filters ) ) { $ class = static :: $ filters [ $ filter ] ; } else if ( is_subclass_of ( $ filter , 'Slick\Filter\FilterInterface' ) ) { $ class = $ filter ; } else { throw new Exception \ UnknownFilterClassException ( "The filte...
Creates a filter
12,245
protected function preventHtmlParserError ( $ html ) { $ pattern = "/<[^\/>]*>([\s]?)*<\/[^>]*>/m" ; $ html = preg_replace ( $ pattern , '' , $ html ) ; $ html = preg_replace ( $ pattern , '' , $ html ) ; return $ html ; }
Cleanup content so that we don t get getFirst errors
12,246
public function setRangeInput ( $ rangeInput ) { if ( $ rangeInput instanceof FormField ) { $ rangeInput -> addExtraClass ( "flatpickr-init" ) ; $ rangeInput = $ rangeInput -> ID ( ) ; } $ rangeInput = '#' . trim ( $ rangeInput , '#' ) ; $ this -> rangeInput = $ rangeInput ; return $ this ; }
Set range input
12,247
public function getParameter ( $ name ) { if ( isset ( $ this -> _parameters [ $ name ] ) ) { return $ this -> _parameters [ $ name ] ; } return null ; }
Returns the value of a given parameter name
12,248
public function allValues ( ) { $ raw = $ this -> _parameters [ '_raw' ] ; $ values = explode ( ',' , $ raw ) ; $ result = ArrayMethods :: trim ( $ values ) ; return $ result ; }
Returns the values as an array
12,249
protected function _checkCommonTags ( ) { if ( in_array ( $ this -> getName ( ) , $ this -> _commonTags ) ) { $ this -> _value = $ this -> _parameters [ '_raw' ] ; } }
Fix the parameters for string tags
12,250
public function query ( $ sql , $ parameters = [ ] ) { $ this -> _checkConnection ( ) ; $ query = $ sql ; if ( is_object ( $ sql ) ) { if ( ! ( $ sql instanceof SqlInterface ) ) { throw new InvalidArgumentException ( "The SQL provided is not a string or does not " . "implements the Slick\Database\Sql\SqlInterface inter...
Executes a SQL query and returns a record list
12,251
public function getColumns ( ) { if ( empty ( $ this -> _columns ) ) { $ properties = $ this -> getInspector ( ) -> getClassProperties ( ) ; foreach ( $ properties as $ property ) { $ annotations = $ this -> getInspector ( ) -> getPropertyAnnotations ( $ property ) ; if ( $ annotations -> hasAnnotation ( 'column' ) ) {...
Returns the list of entity columns
12,252
public function getRelations ( ) { if ( empty ( $ this -> _relations ) ) { $ properties = $ this -> getInspector ( ) -> getClassProperties ( ) ; foreach ( $ properties as $ property ) { $ annotations = $ this -> getInspector ( ) -> getPropertyAnnotations ( $ property ) ; foreach ( static :: $ _annotations as $ name => ...
Returns the list of relations of current entity
12,253
public function getRelation ( $ name ) { $ relation = false ; if ( $ this -> isRelation ( $ name ) ) { $ relation = $ this -> getRelations ( ) [ $ name ] ; } return $ relation ; }
Returns the relation defined in the provided property name or false if there is no relation defined with that name .
12,254
public function getInspector ( ) { if ( is_null ( $ this -> _inspector ) ) { $ this -> _inspector = new Inspector ( $ this -> _entity ) ; } return $ this -> _inspector ; }
Returns the inspector class for current entity
12,255
public function getEntity ( ) { if ( ! ( $ this -> _entity instanceof Entity ) ) { $ class = $ this -> _entity ; $ this -> setEntity ( new $ class ( ) ) ; } return $ this -> _entity ; }
Checks if the entity is not just the class name
12,256
public static function addRelationClass ( $ name , $ class ) { $ interface = 'Slick\Orm\RelationInterface' ; if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( "{$class} class does not exists" ) ; } $ rflClass = new ReflectionClass ( $ class ) ; if ( ! $ rflClass -> implementsInterface ( $ interfa...
Adds a new relation class to entity descriptor
12,257
public function compute ( DecimalNumber $ number , $ precision , $ roundingMode ) { switch ( $ roundingMode ) { case self :: ROUND_HALF_UP : return $ this -> roundHalfUp ( $ number , $ precision ) ; break ; case self :: ROUND_CEIL : return $ this -> ceil ( $ number , $ precision ) ; break ; case self :: ROUND_FLOOR : r...
Rounds a decimal number to a specified precision
12,258
public function truncate ( DecimalNumber $ number , $ precision ) { $ precision = $ this -> sanitizePrecision ( $ precision ) ; if ( $ number -> getPrecision ( ) <= $ precision ) { return $ number ; } if ( 0 === $ precision ) { return new DecimalNumber ( $ number -> getSign ( ) . $ number -> getIntegerPart ( ) ) ; } re...
Truncates a number to a target number of decimal digits .
12,259
public function ceil ( DecimalNumber $ number , $ precision ) { $ precision = $ this -> sanitizePrecision ( $ precision ) ; if ( $ number -> getPrecision ( ) <= $ precision ) { return $ number ; } if ( $ number -> isNegative ( ) ) { return $ this -> truncate ( $ number , $ precision ) ; } if ( $ precision > 0 ) { $ num...
Rounds a number up if its precision is greater than the target one .
12,260
public function floor ( DecimalNumber $ number , $ precision ) { $ precision = $ this -> sanitizePrecision ( $ precision ) ; if ( $ number -> getPrecision ( ) <= $ precision ) { return $ number ; } if ( $ number -> isPositive ( ) ) { return $ this -> truncate ( $ number , $ precision ) ; } if ( $ precision > 0 ) { $ nu...
Rounds a number down if its precision is greater than the target one .
12,261
public function roundHalfEven ( DecimalNumber $ number , $ precision ) { $ precision = $ this -> sanitizePrecision ( $ precision ) ; if ( $ number -> getPrecision ( ) <= $ precision ) { return $ number ; } $ fractionalPart = $ number -> getFractionalPart ( ) ; $ digit = ( int ) $ fractionalPart [ $ precision ] ; if ( $...
Rounds a number according to banker s rounding .
12,262
private function sanitizePrecision ( $ precision ) { if ( ! is_numeric ( $ precision ) || $ precision < 0 ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid precision: %s' , print_r ( $ precision , true ) ) ) ; } return ( int ) $ precision ; }
Ensures that precision is a positive int
12,263
protected function _createInstance ( ObjectDefinition $ definition , array $ parameters ) { $ classReflection = new ReflectionClass ( $ definition -> getClassName ( ) ) ; $ args = $ this -> _getMethodParameters ( $ definition -> getConstructor ( ) , $ classReflection -> getConstructor ( ) , $ parameters ) ; return $ cl...
Creates an instance of the class and injects dependencies .
12,264
protected function _getMethodParameters ( MethodInjection $ method = null , ReflectionMethod $ methodReflection = null , array $ parameters = [ ] ) { $ args = [ ] ; if ( $ methodReflection ) { foreach ( $ methodReflection -> getParameters ( ) as $ index => $ parameter ) { if ( array_key_exists ( $ parameter -> getName ...
Returns the parameters for the provided method
12,265
protected function _getParameterDefaultValue ( ReflectionParameter $ reflectionParameter , ReflectionMethod $ reflectionMethod ) { try { return $ reflectionParameter -> getDefaultValue ( ) ; } catch ( ReflectionException $ e ) { throw new DefinitionException ( sprintf ( "The parameter '%s' of %s::%s has no type defined...
Returns the default value of a function parameter .
12,266
protected function _injectMethodsAndProperties ( DefinitionInterface $ definition , $ instance ) { $ classReflection = new ReflectionClass ( $ instance ) ; foreach ( $ definition -> getProperties ( ) as $ property ) { $ this -> _propertyInjection ( $ instance , $ property , $ classReflection ) ; } foreach ( $ definitio...
Inject properties and methods on the provided instance
12,267
protected function _propertyInjection ( $ instance , PropertyInjection $ property , ReflectionClass $ classReflection ) { $ public = trim ( $ property -> getPropertyName ( ) , '_' ) ; $ notPublic = "_{$public}" ; $ propertyName = $ classReflection -> hasProperty ( $ notPublic ) ? $ notPublic : $ public ; $ propertyRefl...
Injects property value
12,268
public static function format ( $ value , $ precision = null , $ locale = null ) { if ( $ precision === null ) { $ precision = self :: $ default_precision ; } if ( $ locale ) { $ currentLocale = self :: $ _locale ; self :: $ _locale = $ locale ; } if ( is_array ( $ value ) ) { foreach ( $ value as & $ val ) { $ val = s...
Format a value as a number
12,269
public static function unformat ( $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as & $ val ) { $ val = self :: unformat ( $ val ) ; } return $ value ; } if ( ! $ value ) { $ value = 0 ; } $ neg = false ; if ( strpos ( $ value , '-' ) === 0 ) { $ neg = true ; } $ cleanString = preg_replace ( '/([^0-9\.,])/...
Similar implementation than accounting . js unformat method
12,270
public function getDbAttribute ( $ attribute , $ default = null ) { return isset ( $ this -> _dbAttributes [ $ attribute ] ) ? $ this -> _dbAttributes [ $ attribute ] : $ default ; }
Gets an attribute as it is in the database
12,271
public function changed ( $ field = null ) { if ( $ this -> owner -> isNewRecord ) return false ; if ( $ field ) return $ this -> getDbAttribute ( $ field ) != $ this -> owner -> getAttribute ( $ field ) ; foreach ( $ this -> owner -> getAttributes ( ) as $ k => $ v ) if ( $ this -> getDbAttribute ( $ k ) != $ v ) retu...
Check if any fields have changed
12,272
public function afterFind ( $ event ) { $ this -> _dbAttributes = $ this -> owner -> getAttributes ( ) ; parent :: afterFind ( $ event ) ; }
Actions to be performed after the model is loaded
12,273
public function afterSave ( $ event ) { if ( ! $ this -> enableAuditField ) { parent :: afterSave ( $ event ) ; return ; } $ date = time ( ) ; $ newAttributes = $ this -> owner -> attributes ; $ oldAttributes = $ this -> _dbAttributes ; $ auditModels = $ this -> getAuditModels ( ) ; $ auditRequestId = $ this -> getAudi...
Find changes to the model and save them as AuditField records Do not call this method directly it will be called after the model is saved .
12,274
public function afterDelete ( $ event ) { if ( ! $ this -> enableAuditField ) { parent :: afterDelete ( $ event ) ; return ; } $ date = time ( ) ; $ auditModels = $ this -> getAuditModels ( ) ; $ auditRequestId = $ this -> getAuditRequestId ( ) ; $ userId = Yii :: app ( ) -> user && Yii :: app ( ) -> user -> id ? Yii :...
Find changes to the model and save them as AuditField records . Do not call this method directly it will be called after the model is deleted .
12,275
protected function getAuditModels ( ) { $ auditModels = array ( ) ; if ( $ this -> auditModel ) { $ auditModels [ ] = array ( 'model_name' => $ this -> auditModelName ? $ this -> auditModelName : get_class ( $ this -> auditModel ) , 'model_id' => $ this -> getModelPrimaryKeyString ( $ this -> auditModel ) , 'prefix' =>...
Gets additional models to be used in the model and model_id fields .
12,276
protected function getModelFieldPrefix ( $ model ) { return ( get_class ( $ this -> owner ) != get_class ( $ model ) ) ? get_class ( $ this -> owner ) . '.' : '' ; }
If the model is not the same as the owner then prefix the field so we know the model .
12,277
protected function getModelPrimaryKeyString ( $ model ) { return is_array ( $ model -> getPrimaryKey ( ) ) ? implode ( '-' , $ model -> getPrimaryKey ( ) ) : $ model -> getPrimaryKey ( ) ; }
Returns Primary Key as a string
12,278
public static function toWesternYear ( $ year ) { if ( Analyzer :: hasKanji ( $ year ) ) { $ key = 'kanji' ; $ eraName = Helper :: extractKanji ( $ year ) ; $ eraName = $ eraName [ 0 ] ; $ eraValue = ( int ) Helper :: subString ( $ year , Analyzer :: length ( $ eraName ) , Analyzer :: length ( $ year ) ) ; } elseif ( A...
Converts a year in Japanese format into Western format .
12,279
protected function _load ( ) { $ file = new File ( $ this -> _file , "r" ) ; $ data = @ parse_ini_string ( $ file -> read ( ) , true ) ; if ( $ data === false ) { throw new Exception \ ParserErrorException ( "Error parsing configuration file {$this->_file}" ) ; } $ this -> _data = $ data ; }
Loads the data into this configuration driver
12,280
protected function assertResource ( $ resource ) { if ( ! is_resource ( $ resource ) || get_resource_type ( $ resource ) !== 'gd' ) { throw new InvalidArgumentException ( 'Invalid resource type.' ) ; } $ width = imagesx ( $ resource ) ; $ height = imagesy ( $ resource ) ; if ( $ width < 1 || $ height < 1 ) { throw new ...
Assert an image resource .
12,281
public static function createFromPath ( string $ path ) { $ createFunctions = [ 'image/png' => 'imagecreatefrompng' , 'image/jpeg' => 'imagecreatefromjpeg' , 'image/gif' => 'imagecreatefromgif' , ] ; $ mimeType = mime_content_type ( $ path ) ; if ( ! array_key_exists ( $ mimeType , $ createFunctions ) ) { throw new Inv...
Create an image from the path .
12,282
public static function guessClassFromTypes ( array $ types ) { if ( count ( $ types ) ) { foreach ( Resource :: CLASSES as $ class ) { $ class = "JSKOS\\$class" ; foreach ( $ class :: TYPES as $ uri ) { if ( in_array ( $ uri , $ types ) ) { return $ class ; } } } } }
Guess subclass from list of type URIs .
12,283
protected function _getUniqueConstraint ( Constraint \ Unique $ constraint ) { $ this -> _afterCreate [ ] = sprintf ( 'CREATE UNIQUE INDEX %s ON %s(%s)' , $ constraint -> getName ( ) , $ this -> _sql -> getTable ( ) , $ constraint -> getColumn ( ) ) ; return null ; }
Parse a Unique constraint to its SQL representation
12,284
protected function err ( $ msg , $ url = null ) { $ this -> saveDataInSession ( ) ; return $ this -> msg ( $ msg , self :: MSG_BAD , $ url ) ; }
Shortcut for an error
12,285
protected function success ( $ msg , $ url = null ) { return $ this -> msg ( $ msg , self :: MSG_GOOD , $ url ) ; }
Shortcut for a success
12,286
protected function msg ( $ msg , $ type , $ url = null ) { $ this -> sessionMessage ( $ msg , $ type ) ; if ( $ url ) { return $ this -> Controller ( ) -> redirect ( $ url ) ; } return $ this -> Controller ( ) -> redirectBack ( ) ; }
Return a response with a message for your form
12,287
protected function set_ancestors ( $ object_id , $ object_type ) { $ ancestors = get_ancestors ( $ object_id , $ object_type ) ; krsort ( $ ancestors ) ; if ( 'page' === $ object_type ) { foreach ( $ ancestors as $ ancestor_id ) { $ this -> set ( get_the_title ( $ ancestor_id ) , get_permalink ( $ ancestor_id ) ) ; } }...
Set the ancestors of the specified page or taxonomy
12,288
protected function get_post_type ( ) { global $ wp_query ; $ post_type = get_post_type ( ) ; if ( $ post_type ) { return $ post_type ; } if ( isset ( $ wp_query -> query [ 'post_type' ] ) ) { return $ wp_query -> query [ 'post_type' ] ; } return $ post_type ; }
Return the current post type
12,289
public function setConfiguration ( DriverInterface $ driver ) { $ this -> _configuration = $ driver ; $ this -> _namespace = null ; $ this -> _action = null ; $ this -> _controller = null ; return $ this ; }
Sets configuration driver
12,290
public function getController ( ) { if ( is_null ( $ this -> _controller ) ) { $ controller = $ this -> getConfiguration ( ) -> get ( 'router.controller' , 'pages' ) ; if ( isset ( $ this -> _params [ 'controller' ] ) ) { $ controller = $ this -> _params [ 'controller' ] ; } $ this -> _controllerName = $ controller ; $...
Returns controller class name
12,291
public function getNamespace ( ) { if ( is_null ( $ this -> _namespace ) ) { $ namespace = $ this -> getConfiguration ( ) -> get ( 'router.namespace' , 'Controllers' ) ; if ( isset ( $ this -> _params [ 'namespace' ] ) ) { $ namespace = $ this -> _params [ 'namespace' ] ; } $ this -> _namespace = trim ( $ namespace , '...
Returns the namespace for controller class
12,292
public function getArguments ( ) { if ( empty ( $ this -> _arguments ) ) { $ base = [ ] ; if ( isset ( $ this -> _params [ 'trailing' ] ) ) { $ base = explode ( '/' , $ this -> _params [ 'trailing' ] ) ; } $ names = [ 'controller' , 'action' , 'namespace' , 'trailing' ] ; foreach ( $ this -> _params as $ key => $ value...
Returns the list of arguments passed in the URL
12,293
public function setTarget ( $ target ) { if ( is_array ( $ target ) ) { $ this -> _params = array_merge ( $ this -> _params , $ target ) ; } $ this -> _target = $ target ; }
Sets target data
12,294
public function formatProfileMessage ( $ message ) { $ sqlStart = strpos ( $ message , '(' ) + 1 ; $ sqlEnd = strrpos ( $ message , ')' ) ; $ sqlLength = $ sqlEnd - $ sqlStart ; $ message = substr ( $ message , $ sqlStart , $ sqlLength ) ; $ message = strtr ( $ message , array ( ' FROM ' => "\nFROM " , ' VALUES ' => "\...
Format profile message
12,295
public function getTableName ( ) { if ( is_null ( $ this -> _tableName ) ) { $ parts = explode ( '\\' , $ this -> getClassName ( ) ) ; $ name = end ( $ parts ) ; $ this -> _tableName = Text :: plural ( strtolower ( $ name ) ) ; } return $ this -> _tableName ; }
Returns entity table name . If no name was give it returns the plural of the entity class name
12,296
public static function get ( $ id ) { $ entity = new static ( ) ; Manager :: getInstance ( ) -> get ( $ entity ) -> refreshRelations ( ) ; $ className = $ entity -> getClassName ( ) ; $ sql = Sql :: createSql ( $ entity -> getAdapter ( ) ) -> select ( $ entity -> getTableName ( ) ) -> where ( [ "{$entity->getTableName(...
Gets the record with the provided primary key
12,297
public static function find ( $ fields = '*' ) { $ entity = new static ( ) ; if ( $ fields == '*' ) { $ fields = $ entity -> getTableName ( ) . '.*' ; } Entity \ Manager :: getInstance ( ) -> get ( $ entity ) -> refreshRelations ( ) ; $ select = new \ Slick \ Orm \ Sql \ Select ( $ entity , $ fields ) ; return $ select...
Starts a select query on this model . Fields can be specified otherwise all fields are selected
12,298
public function save ( array $ data = [ ] ) { Manager :: getInstance ( ) -> get ( $ this ) -> refreshRelations ( ) ; $ action = Save :: INSERT ; $ pmk = $ this -> primaryKey ; if ( $ this -> $ pmk || isset ( $ data [ $ pmk ] ) ) { $ action = Save :: UPDATE ; } if ( $ action == Save :: UPDATE ) { return $ this -> _updat...
Saves the entity data or the provided data
12,299
public function delete ( ) { Manager :: getInstance ( ) -> get ( $ this ) -> refreshRelations ( ) ; $ pmk = $ this -> getPrimaryKey ( ) ; $ sql = Sql :: createSql ( $ this -> getAdapter ( ) ) -> delete ( $ this -> getTableName ( ) ) -> where ( [ "{$pmk} = :id" => [ ':id' => $ this -> $ pmk ] ] ) ; $ event = new Delete ...
Deletes current record from