idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
32,000 | public static function getProperDateFormat ( $ value ) { $ dateFormatString = 'Y-m-d\TH:i:s.u' ; $ date = date_format ( $ value , $ dateFormatString ) ; $ date = substr ( $ date , 0 , - 3 ) . 'Z' ; return $ date ; } | Get a date value in the format stored on Avos . |
32,001 | public function hasMemberInvitationOnTeam ( $ teamId ) { $ memberInvitationsOnTeam = $ this -> memberInvitations -> filter ( function ( $ memberInvitation ) use ( $ teamId ) { return ( $ memberInvitation -> member -> team_id === $ teamId ) && ( $ memberInvitation -> member -> status === "Invited" ) ; } ) ; return $ memberInvitationsOnTeam -> count ( ) > 0 ; } | Check for existing MemberInvitation on Team with UUID |
32,002 | private function kickIt ( ) { if ( $ this -> factory_method == '__construct' ) { $ a = $ this -> factory_args ; switch ( count ( $ this -> factory_args ) ) { case 0 : return new self ( ) ; case 1 : return new self ( $ a [ 0 ] ) ; case 2 : return new self ( $ a [ 0 ] , $ a [ 1 ] ) ; case 3 : return new self ( $ a [ 0 ] , $ a [ 1 ] , $ a [ 2 ] ) ; default : return new self ( $ a [ 0 ] , $ a [ 1 ] , $ a [ 2 ] , $ a [ 3 ] ) ; } } else { return call_user_func_array ( array ( __NAMESPACE__ . '\\Flupdo' , $ this -> factory_method ) , $ this -> factory_args ) ; } } | Now is the time . |
32,003 | final public function invokeAction ( ) { $ time = time ( ) ; $ success = $ this -> doAction ( ) ; $ this -> actionRequired = ! $ success ; $ this -> lastActionSuccess = $ success ; $ this -> lastActionAttemptTime = $ time ; if ( $ success ) { $ this -> lastActionSuccessTime = $ time ; } else { $ this -> lastActionFailTime = $ time ; } return $ success ; } | Used by the controller to invoke action based on delayedAction being used |
32,004 | static function Combine ( $ path1 , $ path2 ) { $ trimChars = '/' ; if ( PATH_SEPARATOR != $ trimChars ) $ trimChars .= PATH_SEPARATOR ; $ clean1 = System \ Str :: TrimRight ( $ path1 , $ trimChars ) ; $ clean2 = System \ Str :: TrimLeft ( $ path2 , $ trimChars ) ; return join ( '/' , array ( $ clean1 , $ clean2 ) ) ; } | Combines the paths . |
32,005 | static function RemoveExtension ( $ path ) { $ ext = self :: Extension ( $ path ) ; if ( $ ext ) { $ newLength = System \ Str :: Length ( $ path ) - System \ Str :: Length ( $ ext ) - 1 ; return System \ Str :: Start ( $ path , $ newLength ) ; } return $ path ; } | Removes extension from path . |
32,006 | static function AddExtension ( $ path , $ extension , $ replaceExisting = false ) { $ result = $ path ; if ( $ replaceExisting ) { $ result = self :: RemoveExtension ( $ path ) ; } if ( ! $ extension ) { return $ result ; } return join ( '.' , array ( $ result , System \ Str :: TrimLeft ( $ extension , '.' ) ) ) ; } | Adds given extension leading dot is optional . |
32,007 | public static function load ( $ className , $ arguments = null , $ singleton = null , $ constructor = null ) { return self :: instantiate ( $ className , $ arguments , $ constructor , $ singleton ) ; } | Returns an instance of className passed . |
32,008 | public function setValue ( $ value = null , $ submittedValue = null ) { if ( $ submittedValue !== null && $ submittedValue === $ value ) { $ this -> setAttribute ( 'selected' ) ; } else { $ this -> removeAttribute ( 'selected' ) ; } if ( $ value === null ) { } $ this -> setAttribute ( 'value' , $ value ) ; } | Setter for value of this element . |
32,009 | public static function fromMM ( $ stringData ) { if ( ! is_string ( $ stringData ) ) { throw new InvalidArgumentException ( 'Given data is not a string' ) ; } if ( ! preg_match ( '#^([0-9]+)mm$#' , $ stringData , $ matches ) ) { throw new RuntimeException ( 'Given focal length is not in a valid format. Need: "<number>mm"' ) ; } $ numerator = $ matches [ 1 ] ; return new self ( "{$numerator}/1" ) ; } | Creates new instance with data in milimeter |
32,010 | public function updateOrCreate ( array $ attributes , array $ updateAttributes ) { $ model = $ this -> get ( $ attributes ) ; if ( null === $ model ) { $ model = $ this -> getModel ( ) -> create ( ) ; $ model -> setIsNewRecord ( true ) ; } $ model -> setAttributes ( $ updateAttributes ) ; if ( $ model -> save ( ) ) { return $ model ; } return false ; } | Find and update model if exists . Else create model . |
32,011 | public static function bootLaraclip ( ) { static :: saved ( function ( $ instance ) { if ( is_array ( $ instance -> attachedFiles ) ) { foreach ( $ instance -> attachedFiles as $ attachedFile ) { $ attachedFile -> afterSave ( $ instance ) ; } } } ) ; static :: deleting ( function ( $ instance ) { if ( is_array ( $ instance -> attachedFiles ) ) { foreach ( $ instance -> attachedFiles as $ attachedFile ) { $ attachedFile -> beforeDelete ( $ instance ) ; } } } ) ; static :: deleted ( function ( $ instance ) { if ( is_array ( $ instance -> attachedFiles ) ) { foreach ( $ instance -> attachedFiles as $ attachedFile ) { $ attachedFile -> afterDelete ( $ instance ) ; } } } ) ; } | Register eloquent event handlers . We ll spin through each of the attached files defined on this class and register callbacks for the events we need to observe in order to handle file uploads . |
32,012 | public function setAttribute ( $ key , $ value ) { if ( array_key_exists ( $ key , $ this -> attachedFiles ) ) { if ( $ value ) { $ attachedFile = $ this -> attachedFiles [ $ key ] ; $ attachedFile -> setUploadedFile ( $ value ) ; } return ; } parent :: setAttribute ( $ key , $ value ) ; } | Handle the dynamic setting of attachment objects . |
32,013 | protected function registerAttachment ( $ name , $ options ) { $ options = $ this -> mergeOptions ( $ options ) ; App :: make ( 'AttachmentValidator' ) -> validateOptions ( $ options ) ; $ attachment = App :: make ( 'Attachment' , array ( 'name' => $ name , 'options' => $ options ) ) ; $ attachment -> setInstance ( $ this ) ; $ this -> attachedFiles [ $ name ] = $ attachment ; } | Register an attachment type . and add the attachment to the list of attachments to be processed during saving . |
32,014 | protected function mergeOptions ( $ options ) { $ defaultOptions = Config :: get ( 'laraclip::laraclip' ) ; $ options = array_merge ( $ defaultOptions , ( array ) $ options ) ; $ storage = $ options [ 'storage' ] ; $ options = array_merge ( Config :: get ( "laraclip::{$storage}" ) , $ options ) ; $ options [ 'styles' ] = array_merge ( ( array ) $ options [ 'styles' ] , array ( 'original' => '' ) ) ; return $ options ; } | Merge configuration options . Here we ll merge user defined options with the laraclip defaults in a cascading manner . We start with overall laraclip options . Next we merge in storage driver specific options . Finally we ll merge in attachment specific options on top of that . |
32,015 | function ToDBString ( $ value ) { if ( $ value === null ) return $ value ; if ( $ this -> IsRelatedObject ( $ value ) ) return $ value -> KeyValue ( ) ; else if ( $ this -> IsDatabaseObject ( $ value ) ) return $ this -> type -> ToDBString ( $ value ) ; else if ( ! is_object ( $ value ) && ! is_array ( $ value ) ) return ( string ) $ value ; throw new \ InvalidArgumentException ( 'Invalid argument for fieldmapper. Object could not be converted to database string.' ) ; } | Returns sql usable string or null for database NULL . |
32,016 | public function getCurrentModule ( ) { if ( $ this -> currentModule && ! ( $ this -> currentModule instanceof Module ) ) { $ this -> currentModule = $ this -> getModule ( $ this -> currentModule ) ; } return $ this -> currentModule ? : $ this ; } | get current module parsed from uri |
32,017 | public function getDefaultModule ( ) { if ( $ this -> defaultModule && ! ( $ this -> defaultModule instanceof Module ) ) { $ this -> defaultModule = $ this -> getModule ( $ this -> defaultModule ) ; } return $ this -> defaultModule ? : $ this ; } | get default module |
32,018 | public function isDefaultModule ( $ module = null ) { $ mname = '' ; if ( ! $ module ) { $ mname = $ this -> getCurrentModule ( ) -> getName ( ) ; } else { if ( is_string ( $ module ) ) { $ mname = $ module ; } elseif ( $ module instanceof Module ) { $ mname = $ module -> getName ( ) ; } } return $ mname == $ this -> getDefaultModule ( ) -> getName ( ) ; } | is default module |
32,019 | public function getRepeatedContentFromSlot ( $ slotName ) { if ( ! $ this -> checkSlotExists ( $ slotName ) ) return null ; return $ this -> slots [ $ slotName ] -> getRepeated ( ) ; } | Returns the repeated content status for the required slot |
32,020 | public function getContentFromSlot ( $ slotName ) { if ( ! $ this -> checkSlotExists ( $ slotName ) ) return null ; return $ this -> slots [ $ slotName ] -> getContent ( ) ; } | Returns the default html content when a new content is added to the slot |
32,021 | public function processing ( $ module = null ) { $ dbDeployPath = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../dbdeploy' ; if ( ! file_exists ( $ dbDeployPath ) ) { mkdir ( $ dbDeployPath ) ; if ( ! is_writable ( $ dbDeployPath ) || ! is_readable ( $ dbDeployPath ) ) { chmod ( $ dbDeployPath , 0777 ) ; } } else { if ( ! is_writable ( $ dbDeployPath ) || ! is_readable ( $ dbDeployPath ) ) { @ chmod ( $ dbDeployPath , 0777 ) ; } } $ deployService = $ this -> getServiceLocator ( ) -> get ( 'MelisDbDeployDeployService' ) ; if ( false === $ deployService -> isInstalled ( ) ) { $ deployService -> install ( ) ; } $ this -> copyDeltas ( $ module ) ; $ deployService -> applyDeltaPath ( realpath ( 'dbdeploy' . DIRECTORY_SEPARATOR . self :: CACHE_DELTAS_PATH ) ) ; } | Processing all Melis Platform Modules that need upgrade database |
32,022 | public function copyDeltas ( $ module = null ) { $ composer = $ this -> getComposer ( ) ; $ vendorDir = $ composer -> getConfig ( ) -> get ( 'vendor-dir' ) ; $ packages = $ this -> getLocalPackages ( ) ; $ deltas = [ ] ; foreach ( $ packages as $ package ) { $ vendor = explode ( '/' , $ package -> getName ( ) , 2 ) ; if ( empty ( $ vendor ) || static :: VENDOR !== $ vendor [ 0 ] ) { continue ; } $ extra = $ package -> getExtra ( ) ; if ( ! is_null ( $ module ) && ! empty ( $ module ) ) { if ( isset ( $ extra [ 'module-name' ] ) && trim ( $ extra [ 'module-name' ] ) === trim ( $ module ) ) { $ deltas = static :: copyDeltasFromPackage ( $ package , $ vendorDir ) ; break ; } } else { $ deltas = array_merge ( $ deltas , static :: copyDeltasFromPackage ( $ package , $ vendorDir ) ) ; } } return $ deltas ; } | Find melis delta migration that match condition of extra dbdeploy |
32,023 | public function Check ( $ value ) { $ this -> error = '' ; if ( $ this -> currentFile && $ value == $ this -> currentFile ) { return true ; } if ( ! Folder :: Exists ( $ this -> folder ) ) { return true ; } $ files = Folder :: GetFiles ( $ this -> folder ) ; if ( $ this -> fileExtension ) { $ value = Path :: AddExtension ( $ value , $ this -> fileExtension ) ; } if ( in_array ( $ value , $ files ) ) { $ this -> error = self :: ExistsInFolder ; } return $ this -> error == '' ; } | Checks if the file given in the value doesn t exist yet |
32,024 | public static function set ( string $ name , $ value , string $ namespace = '*' ) : void { self :: initialize ( ) ; $ _SESSION [ $ namespace ] [ $ name ] = $ value ; } | Set session - variable . |
32,025 | public static function get ( string $ name , $ defaultValue = null , string $ namespace = '*' ) { self :: initialize ( ) ; if ( self :: has ( $ name , $ namespace ) ) { return $ _SESSION [ $ namespace ] [ $ name ] ; } return $ defaultValue ; } | Get session - variable . |
32,026 | public static function has ( string $ name , string $ namespace = '*' ) : bool { self :: initialize ( ) ; return isset ( $ _SESSION [ $ namespace ] ) && array_key_exists ( $ name , $ _SESSION [ $ namespace ] ) ; } | Check if session - variable exists . |
32,027 | public static function delete ( string $ name , string $ namespace = '*' ) : void { self :: initialize ( ) ; if ( isset ( $ _SESSION [ $ namespace ] [ $ name ] ) ) { unset ( $ _SESSION [ $ namespace ] [ $ name ] ) ; if ( count ( $ _SESSION [ $ namespace ] ) === 0 ) { unset ( $ _SESSION [ $ namespace ] ) ; } } } | Delete session - varable . |
32,028 | public static function pageClear ( ? string $ page = null ) : void { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } self :: clear ( $ page ) ; } | Clear session by page filename . |
32,029 | public static function pageSet ( string $ name , $ value , ? string $ page = null ) : void { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } self :: set ( $ name , $ value , $ page ) ; } | Set session - variable by page - filename . |
32,030 | public static function pageGet ( string $ name , $ defaultValue = null , ? string $ page = null ) { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } return self :: get ( $ name , $ defaultValue , $ page ) ; } | Get session - variable by page - filename . |
32,031 | public static function pageGetArray ( ? string $ page = null ) : array { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } return self :: getArray ( $ page ) ; } | Get session array by page filename . |
32,032 | public static function pageHas ( string $ name , ? string $ page = null ) : bool { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } return self :: has ( $ name , $ page ) ; } | Check if session - variable exists by page - filename . |
32,033 | public static function pageDelete ( string $ name , ? string $ page = null ) : void { if ( $ page === null ) { $ page = $ _SERVER [ 'PHP_SELF' ] ; } self :: delete ( $ name , $ page ) ; } | Delete session - varable by page - filename . |
32,034 | public function transform ( $ value ) { $ template = $ this -> twig -> loadTemplate ( $ this -> resource ) ; $ variables = array_replace ( $ this -> variables , [ 'data' => $ value ] ) ; if ( null !== $ this -> blockname ) { $ value = $ template -> renderBlock ( $ this -> blockname , $ variables ) ; } else { $ value = $ template -> render ( $ variables ) ; } return $ value ; } | Transforms a twig template to html string . |
32,035 | public function setTemplateName ( $ v ) { $ this -> validateString ( $ v ) ; $ this -> templateName = strtolower ( $ v ) ; $ this -> assetsTemplateName = strtolower ( $ this -> templateName ) ; return $ this ; } | Sets the template name |
32,036 | public function setThemeName ( $ v ) { $ this -> validateString ( $ v ) ; $ this -> themeName = $ v ; $ this -> assetsThemeName = strtolower ( str_replace ( 'Bundle' , '' , $ this -> themeName ) ) ; return $ this ; } | Sets the theme name |
32,037 | public function list ( ) : string { if ( ! $ this -> types ) { return '' ; } $ meta = [ ] ; foreach ( $ this -> types as $ type ) { if ( 0 === \ stripos ( $ type , 'avatar__' ) ) { if ( $ this -> post -> author ( ) -> supported ( ) && ( $ avatar = $ this -> post -> thumbnail ( $ type ) ) ) { $ meta [ ] = $ avatar ; } } elseif ( 0 === \ stripos ( $ type , 'updated_ago' ) ) { $ meta [ ] = $ this -> updatedAgo ( \ preg_replace ( '/^updated\_ago(\_\_)?/i' , '' , $ type ) ) ; } elseif ( 0 === \ stripos ( $ type , 'published_ago' ) ) { $ meta [ ] = $ this -> publishedAgo ( \ preg_replace ( '/^published\_ago(\_\_)?/i' , '' , $ type ) ) ; } elseif ( \ is_callable ( [ $ this , ( $ call = "render_{$type}" ) ] ) && ( $ return = $ this -> $ call ( ) ) ) { $ meta [ ] = $ return ; } elseif ( $ filter = \ apply_filters ( $ type , '' , $ this -> post -> get ( ) -> ID , $ this -> separator ) ) { $ meta [ ] = $ filter ; } elseif ( $ post_meta = $ this -> post -> meta ( $ type , true ) ) { $ meta [ ] = $ post_meta ; } elseif ( $ terms = $ this -> termList ( $ type ) ) { $ meta [ ] = $ terms ; } } if ( ! $ meta ) { return '' ; } return $ this -> before . \ join ( ' <span class="meta-sep">' . $ this -> separator . '</span> ' , $ meta ) . $ this -> after ; } | Get post info concatenated with a separator . |
32,038 | protected function updatedAgo ( string $ format ) : string { return '<time class="updated entry-date" itemprop="dateModified" datetime="' . \ esc_attr ( \ get_the_modified_time ( 'Y-m-d\TH:i:sO' , '' , $ this -> post -> get ( ) ) ) . '">' . $ this -> post -> time ( 'updated' ) -> render ( $ format ) . '</time> </span>' ; } | Time since post was updated . |
32,039 | protected function publishedAgo ( string $ format ) : string { return '<time class="published entry-date" itemprop="dateModified" datetime="' . \ esc_attr ( \ get_the_date ( 'Y-m-d\TH:i:sO' , $ this -> post -> get ( ) ) ) . '">' . $ this -> post -> time ( 'published' ) -> render ( $ format ) . '</time>' ; } | Time since post was published . |
32,040 | public function startAction ( $ message , $ color = self :: CWHITE , $ microtime = null ) { $ this -> endAction ( ) ; $ this -> endProgressBar ( ) ; $ this -> currentActionHadLogs = false ; $ this -> pendingActionLogs = array ( ) ; $ this -> currentAction = array ( 'length' => 19 + strlen ( $ this -> timeTextSeparator ) + $ this -> getTextLength ( $ message ) , 'errors' => false , 'color' => $ color , 'message' => '' , 'time' => $ microtime ? $ microtime : microtime ( true ) ) ; $ r = $ this -> color ( $ message , $ color ) ; return $ this -> output ( $ r ) ; } | Start a new action |
32,041 | public function getTextLength ( $ text ) { $ colorsList = array ( '0;30' , '1;30' , '0;34' , '1;34' , '0;32' , '1;32' , '0;36' , '1;36' , '0;31' , '1;31' , '0;35' , '1;35' , '0;33' , '1;33' , '0;37' , '1;37' , '40' , '41' , '42' , '43' , '44' , '45' , '46' , '47' , '0' ) ; foreach ( $ colorsList as $ color ) { $ text = str_replace ( "\033[" . $ color . "m" , '' , $ text ) ; } return strlen ( $ text ) ; } | Return text length after removing colors |
32,042 | public function continueAction ( $ message , $ color = 'default' ) { if ( ! $ this -> currentAction ) return ; $ color = ( 'default' == $ color ) ? $ this -> currentAction [ 'color' ] : $ color ; $ r = ( ' ' . $ this -> timeItTook ( $ this -> currentAction [ 'time' ] ) . ' ' . $ this -> color ( $ message , $ color ) ) ; $ this -> currentAction [ 'length' ] += 2 + $ this -> lastTimeLenght + $ this -> getTextLength ( $ message ) ; return $ this -> output ( $ r ) ; } | Continue an action . |
32,043 | public function endAction ( $ message = 'done' , $ color = self :: CLIGHT_GREEN ) { $ r = '' ; if ( empty ( $ this -> currentAction ) ) { return $ this -> output ( $ r ) ; } $ r .= $ this -> currentAction [ 'message' ] ; $ time = $ this -> timeItTook ( $ this -> currentAction [ 'time' ] ) ; $ length = ( $ this -> currentActionHadLogs ? 0 : $ this -> currentAction [ 'length' ] ) + $ this -> lastTimeLenght + $ this -> getTextLength ( ' [' . $ message . '] ' ) ; $ spaceLength = $ this -> getScreen ( 'columns' ) - $ length - 2 ; $ r .= ' ' ; if ( $ spaceLength > 0 ) { $ r .= $ this -> color ( str_repeat ( '.' , $ spaceLength ) , self :: CDARK_GRAY ) ; } $ r .= $ this -> color ( ' [' . $ message . '] ' , $ color ) . $ this -> color ( $ time ) . "\n" ; $ this -> currentAction = null ; if ( $ this -> pendingActionLogs ) { $ r .= implode ( "\n" , $ this -> pendingActionLogs ) . "\n" ; } return $ this -> output ( $ r ) ; } | End a started action . |
32,044 | public function progressBar ( $ total = null , $ done = null , $ width = null ) { if ( empty ( $ total ) || ( $ total <= 0 ) ) { return false ; } $ columns = $ this -> getScreen ( 'columns' ) ; if ( $ columns < 50 ) return false ; if ( null === $ width ) { $ width = 200 ; } $ extraWidth = strlen ( ( string ) $ total ) * 2 + 1 ; if ( $ width + 35 + $ extraWidth > $ columns ) { $ width = $ columns - 35 - $ extraWidth ; } $ this -> activeProgressBar = array ( 'width' => $ width , 'done' => $ done , 'total' => $ total , 'startTime' => microtime ( true ) , 'startProgress' => $ done , ) ; $ this -> progress ( null , null , null , 0 ) ; } | Start a progress bar ; |
32,045 | public function input ( $ text , $ defaultValue = '' , $ color = null ) { $ text = $ text . ( $ defaultValue ? ": [$defaultValue]" : ": " ) ; echo $ color ? $ this -> color ( $ text , $ color ) : $ text ; return trim ( trim ( $ result = fgets ( fopen ( 'php://stdin' , 'r' ) ) ) ? $ result : $ defaultValue ) ; } | Get input from cli . |
32,046 | public function passwordInput ( $ text ) { if ( preg_match ( '/^win/i' , PHP_OS ) ) { $ vbscript = sys_get_temp_dir ( ) . 'prompt_password.vbs' ; file_put_contents ( $ vbscript , 'wscript.echo(InputBox("' . addslashes ( $ text ) . '", "", "password here"))' ) ; $ command = "cscript //nologo " . escapeshellarg ( $ vbscript ) ; $ password = rtrim ( shell_exec ( $ command ) ) ; unlink ( $ vbscript ) ; return $ password ; } $ command = "/usr/bin/env bash -c 'echo OK'" ; if ( rtrim ( shell_exec ( $ command ) ) !== 'OK' ) { trigger_error ( "Can't invoke bash" ) ; return ; } $ command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes ( $ text ) . "\" mypassword && echo \$mypassword'" ; $ password = rtrim ( shell_exec ( $ command ) ) ; echo "\n" ; return $ password ; } | Get hidden input from cli . |
32,047 | protected function instantiateClass ( $ class , array $ args ) { try { $ reflectionMethod = new ReflectionMethod ( $ class , '__construct' ) ; $ ordered_arguments = Helper :: parseParams ( $ reflectionMethod -> getParameters ( ) , $ args ) ; $ reflectionClass = new ReflectionClass ( $ class ) ; return $ reflectionClass -> newInstanceArgs ( ( array ) $ ordered_arguments ) ; } catch ( Exception $ exception ) { throw new InvalidArgumentException ( sprintf ( _ ( 'Failed to instantiate class "%1$s". Reason: %2$s' ) , $ class , $ exception -> getMessage ( ) ) ) ; } } | Check the accepted arguments for a given class constructor and pass associative array values in the right order . |
32,048 | public function writeFixedSizeFile ( $ fileName , $ fileSize ) { $ this -> createFile ( $ fileName , '' ) ; $ this -> inCurrentDir ( function ( ) use ( $ fileName , $ fileSize ) { $ fh = fopen ( $ fileName , 'w' ) ; fseek ( $ fh , $ fileSize - 1 ) ; fwrite ( $ fh , "\0" , 1 ) ; fclose ( $ fh ) ; } ) ; } | Write a fixed size file |
32,049 | public function checkFileSize ( $ fileName , $ fileSize ) { $ this -> inCurrentDir ( function ( ) use ( $ fileName , $ fileSize ) { if ( filesize ( $ fileName ) !== $ fileSize ) { throw new ExpectationException ( "Size of $fileName not equals $fileSize" ) ; } } ) ; } | Check a file s size |
32,050 | public function tearDown ( ) { $ this -> workingDir = array_slice ( $ this -> workingDir , 0 , 1 ) ; exec ( "rm -rf " . escapeshellarg ( $ this -> currentDir ( ) ) ) ; } | Tear down the working dir |
32,051 | public function assertNotPartialOutput ( $ expected , $ type = 'stdout' ) { $ expected = ( string ) $ expected ; $ actual = $ this -> getOutputByType ( $ type ) ; if ( false !== strpos ( $ actual , $ expected ) ) { throw new ExpectationException ( "Failed to assert \"$actual\" does not contain \"$expected\"" ) ; } } | Assert partial output |
32,052 | public function inCurrentDir ( \ Closure $ closure ) { $ old = getcwd ( ) ; $ this -> _mkdir ( $ this -> currentDir ( ) ) ; chdir ( $ this -> currentDir ( ) ) ; $ closure ( $ this ) ; chdir ( $ old ) ; } | In the current directory |
32,053 | public function checkFilePresence ( $ paths , $ expectPresence ) { $ this -> inCurrentDir ( function ( ) use ( $ paths , $ expectPresence ) { foreach ( ( array ) $ paths as $ file ) { $ present = file_exists ( $ file ) ; if ( $ expectPresence && ! $ present ) { throw new ExpectationException ( "Could not find file:$file" ) ; } if ( $ present && ! $ expectPresence ) { throw new ExpectationException ( "Found unexpected file:$file" ) ; } } } ) ; } | Check a file exists |
32,054 | public function checkFileContent ( $ file , $ partialContent , $ expectMatch ) { $ regexp = "/" . preg_quote ( $ partialContent , "/" ) . "/" ; $ this -> inCurrentDir ( function ( ) use ( $ file , $ regexp , $ expectMatch ) { $ contents = file_get_contents ( $ file ) ; $ match = preg_match ( $ regexp , $ contents ) ; if ( $ expectMatch && ! $ match ) { throw new ExpectationException ( "Could not match $match to $contents" ) ; } if ( $ match && ! $ expectMatch ) { throw new ExpectationException ( "Matched $match to $contents" ) ; } } ) ; } | Check a files contents |
32,055 | protected function run ( $ cmd ) { $ path = getenv ( 'PATH' ) ; if ( $ this -> prependPath ) { $ path = $ this -> prependPath . PATH_SEPARATOR . $ path ; } $ process = new Process ( $ cmd , $ this -> currentDir ( ) , array ( 'PATH' => $ path , ) ) ; $ process -> run ( ) ; $ this -> process = $ process ; return $ process ; } | Run a command |
32,056 | protected function getOutputByType ( $ type ) { switch ( $ type ) { case 'stderr' : $ actual = $ this -> process -> getErrorOutput ( ) ; break ; case 'all' : $ actual = $ this -> process -> getOutput ( ) . $ this -> process -> getErrorOutput ( ) ; break ; case 'stdout' : default : $ actual = $ this -> process -> getOutput ( ) ; break ; } return $ actual ; } | Get output by type |
32,057 | public function createNamed ( $ type , array $ options = [ ] ) { if ( $ type instanceof BlockInterface ) { return $ type ; } $ name = $ this -> getBlockName ( $ options ) ; return $ this -> factory -> createNamed ( $ name , $ type , null , $ options ) ; } | Create block named with the block_name options . |
32,058 | public function renderTwigBlock ( $ resource , $ blockName , array $ options = [ ] ) { if ( null !== $ this -> environment ) { $ template = $ this -> environment -> loadTemplate ( $ resource ) ; return $ template -> renderBlock ( $ blockName , $ options ) ; } return '' ; } | Render the block of twig resource . |
32,059 | public function rawClosure ( $ value , BlockView $ view ) { if ( $ value instanceof \ Closure ) { $ value = $ value ( $ view ) ; } return $ value ; } | Render closure value . |
32,060 | public function formatter ( $ value , $ type , array $ options = [ ] , array $ variables = [ ] ) { $ options = array_replace ( [ 'wrapped' => false , 'inherit_data' => false ] , $ options , [ 'data' => $ value ] ) ; $ type = isset ( $ this -> aliases [ $ type ] ) ? $ this -> aliases [ $ type ] : $ type ; if ( isset ( $ options [ 'entry_type' ] ) && isset ( $ this -> aliases [ $ options [ 'entry_type' ] ] ) ) { $ options [ 'entry_type' ] = $ this -> aliases [ $ options [ 'entry_type' ] ] ; } $ block = $ this -> createNamed ( $ type , $ options ) ; return $ this -> renderer -> searchAndRenderBlock ( $ block -> createView ( ) , 'widget' , $ variables ) ; } | Format the value . |
32,061 | protected function getBlockName ( array $ options = [ ] ) { return isset ( $ options [ 'block_name' ] ) ? $ options [ 'block_name' ] : ( isset ( $ options [ 'id' ] ) ? $ options [ 'id' ] : BlockUtil :: createUniqueName ( ) ) ; } | Get the block name . |
32,062 | public function prepareList ( ) { $ this -> setRequestParameters ( ) ; $ this -> setPerPage ( ) ; $ this -> setCurrentPage ( ) ; $ this -> setTotalCount ( ) ; $ this -> setPagination ( ) ; $ this -> setQueryOrder ( ) ; $ this -> setQueryOffset ( ) ; $ this -> setResultRows ( ) ; $ this -> setFinalParameters ( ) ; } | This will call all the method by sequence depends on the requirements of each other |
32,063 | private function setPerPage ( ) { if ( $ this -> hasInput ( 'per_page' ) ) { $ per_page_input = $ this -> getInput ( 'per_page' ) ; if ( $ this -> isValidPageNumber ( $ per_page_input ) ) { $ this -> perPage = $ per_page_input ; } else if ( $ per_page_input == 'all' ) { $ this -> perPage = 'all' ; } } } | This will just set the per_page property override default per page when there are per_page in the request parameter |
32,064 | private function setCurrentPage ( ) { if ( $ this -> perPage == 'all' ) return ; if ( $ this -> hasInput ( 'page' ) ) { $ page_input = $ this -> getInput ( 'page' ) ; if ( $ this -> isValidPageNumber ( $ page_input ) ) { $ this -> page = $ page_input ; } } } | This will just set the page property |
32,065 | private function setPagination ( ) { if ( $ this -> perPage == 'all' ) return ; $ this -> firstPage = 1 ; $ this -> lastPage = ceil ( $ this -> totalCount / $ this -> perPage ) ; $ this -> page = min ( $ this -> page , $ this -> lastPage ) ; $ this -> offset = ( $ this -> page - 1 ) * $ this -> perPage ; $ this -> limit = $ this -> perPage ; $ this -> nextPage = min ( $ this -> page + 1 , $ this -> lastPage ) ; $ this -> prevPage = max ( $ this -> page - 1 , $ this -> firstPage ) ; } | Will just calculate all the calculation needed to generate a pagination page |
32,066 | private function setQueryOffset ( ) { if ( $ this -> perPage == 'all' ) return ; $ this -> query -> skip ( $ this -> offset ) -> take ( $ this -> perPage ) ; } | This will just set the offset and limit of the query |
32,067 | private function setResultRows ( ) { $ this -> query -> select ( $ this -> columnsToSelect ) ; $ this -> resultRows = $ this -> query -> get ( ) ; } | This will get the data rows from the database with the all where queries |
32,068 | private function setFinalParameters ( ) { if ( ! $ this -> baseURL || Request :: url ( ) == $ this -> baseURL ) { $ this -> finalParameters = array_merge ( $ this -> requestParameters , $ this -> parameters ) ; } else { $ this -> finalParameters = $ this -> parameters ; } } | Set Final Parameters |
32,069 | private function getTableHf ( ) { if ( $ this -> HFContent ) return $ this -> HFContent ; ob_start ( ) ; ?> <tr> <?php ?> <?php foreach ( $ this -> columns as $ column_key => $ column_options ) : ?> <?php $ sortable_class = $ this -> getSortableClass ( $ column_key ) ; ?> <th data-column-name=" <?php echo $ column_key ; ?> " class=" <?php echo $ sortable_class ; ?> <?php echo $ this -> getColumnOption ( $ column_key , self :: COLUMN_OPTION_CLASSES ) ; ?> " <?php echo $ this -> getColumnOption ( $ column_key , self :: COLUMN_OPTION_THEAD_ATTR ) ?> > <?php echo $ this -> getColumnHeaderStructure ( $ column_key , $ column_options ) ; ?> </th> <?php endforeach ; ?> </tr> <?php $ this -> HFContent = ob_get_clean ( ) ; return $ this -> HFContent ; } | get the data for both header and footer . |
32,070 | protected function getSortableLinkStart ( $ column_key ) { if ( $ this -> getColumnOption ( $ column_key , self :: COLUMN_OPTION_SORTABLE , false ) ) { $ sortable_url = $ this -> createUrl ( array ( "column_orders[{$column_key}]" => ( isset ( $ this -> columnOrders [ $ column_key ] ) && $ this -> columnOrders [ $ column_key ] == 'asc' ) ? 'desc' : 'asc' , 'single_order' => $ column_key ) ) ; echo '<a href="' . $ sortable_url . '">' ; } } | Get sortable element link start |
32,071 | protected function getSortableClass ( $ column_key ) { $ classes = NULL ; if ( $ this -> getColumnOption ( $ column_key , self :: COLUMN_OPTION_SORTABLE ) ) { $ classes .= 'sorting ' ; if ( array_key_exists ( $ column_key , $ this -> columnOrders ) ) { $ order_method = $ this -> columnOrders [ $ column_key ] ; switch ( $ order_method ) { case 'desc' : $ classes .= 'sorting_asc ' ; break ; default : $ classes .= 'sorting_desc ' ; } } } return $ classes ; } | Get column sortable class |
32,072 | function getTableBody ( ) { ob_start ( ) ; ?> <tbody> <?php if ( $ this -> totalCount >= 1 ) : ?> <?php foreach ( $ this -> resultRows as $ row ) : ?> <tr data-id=" <?php echo $ row -> { $ this -> tableId } ?> "> <?php foreach ( $ this -> columns as $ column_key => $ column_options ) : ?> <td class=" <?php echo $ this -> getColumnOption ( $ column_key , self :: COLUMN_OPTION_CLASSES ) ?> "> <?php echo $ this -> getColumnStructure ( $ row , $ column_key ) ; ?> </td> <?php endforeach ; ?> </tr> <?php endforeach ; ?> <?php else : ?> <tr class="no-items"> <td colspan=" <?php echo $ this -> getTotalColumns ( ) ; ?> "> <?php echo $ this -> noResults ; ?> </td> </tr> <?php endif ; ?> </tbody> <?php return ob_get_clean ( ) ; } | Create the table body |
32,073 | public function getPagination ( ) { if ( $ this -> perPage == 'all' || ! $ this -> totalCount ) { return '<span class="pagination"> </span>' ; } ob_start ( ) ; if ( $ this -> pageJump ) { $ this -> jumpNext = min ( $ this -> page + $ this -> pageJump , $ this -> lastPage ) ; $ this -> jumpPrev = max ( $ this -> page - $ this -> pageJump , $ this -> firstPage ) ; } $ pagi_from = max ( $ this -> page - ceil ( $ this -> pageJump / 2 ) , $ this -> firstPage ) ; $ pagi_to = min ( $ pagi_from + $ this -> pageJump , $ this -> lastPage ) ; ?> <ul class="pagination pagination--offset pull-right"> <?php $ this -> createPagiList ( 1 , '<i class="icon-double-angle-left"></i> first' , $ this -> page == $ this -> firstPage ) ; if ( $ this -> pageJump ) { $ this -> createPagiList ( $ this -> jumpPrev , "<i class=\"icon-angle-left\"></i> - {$this->pageJump}" , $ this -> jumpPrev == $ this -> firstPage ) ; } $ this -> createPagiList ( $ this -> prevPage , '<i class="icon-angle-left"></i> prev' , $ this -> page == $ this -> firstPage ) ; for ( $ i = $ pagi_from ; $ i <= $ pagi_to ; $ i ++ ) { $ this -> createPagiList ( $ i , $ i , false , ( $ i == $ this -> page ) ) ; } $ this -> createPagiList ( $ this -> nextPage , 'next <i class="icon-angle-right"></i>' , $ this -> page == $ this -> lastPage ) ; if ( $ this -> pageJump ) { $ this -> createPagiList ( $ this -> jumpNext , "{$this->pageJump} + <i class=\"icon-angle-right\"></i>" , $ this -> jumpNext == $ this -> lastPage ) ; } $ this -> createPagiList ( $ this -> lastPage , 'last <i class="icon-double-angle-right"></i>' , $ this -> lastPage == $ this -> page ) ; ?> </ul> <?php return ob_get_clean ( ) ; } | Create the pagination list |
32,074 | protected function createPagiList ( $ page = 1 , $ anchor_content = 1 , $ disabled = false , $ active = false ) { $ disabled_class = $ disabled ? 'disabled' : NULL ; $ active_class = $ active ? 'active' : NULL ; ?> <li class=" <?php echo $ disabled_class ; ?> <?php echo $ active_class ?> " > <a href=" <?php echo $ this -> createUrl ( array ( 'page' => $ page ) ) ?> " data-page=" <?php echo $ page ; ?> " > <?php echo $ anchor_content ?> </a> </li> <?php } | Create the pagination ul list |
32,075 | public function createUrl ( array $ parameters = array ( ) ) { $ final_parameters = $ this -> getFinalParameters ( ) ; $ path = $ this -> getBaseURL ( ) ; $ final_parameters = array_merge ( $ final_parameters , $ parameters ) ; return $ path . "?" . http_build_query ( $ final_parameters , null , '&' ) . $ this -> buildFragment ( ) ; } | Create URL with parameters |
32,076 | public function setBaseURL ( $ url , $ parameters = array ( ) ) { $ this -> baseURL = $ url ; $ this -> parameters = $ parameters ; return $ this ; } | Set URL and Customer parameters for this tblist Note! This should have no query string should only be the url |
32,077 | protected function getColumnOption ( $ column_key , $ option_name , $ default = NULL ) { return isset ( $ this -> columns [ $ column_key ] [ $ option_name ] ) ? $ this -> columns [ $ column_key ] [ $ option_name ] : value ( $ default ) ; } | Return column option value |
32,078 | public function seek ( $ position ) { if ( ! isset ( $ this -> tokens [ $ position ] ) ) { throw $ this -> getOutOfBoundsException ( $ position ) ; } $ this -> position = $ position ; } | Tries to go to a position in the stack . |
32,079 | public function skipTypes ( $ tokenTypes , $ direction = self :: DIR_FORWARD ) { return $ this -> safeMove ( function ( ) use ( $ tokenTypes , $ direction ) { $ this -> moveWithCondition ( function ( ) use ( $ tokenTypes ) { return in_array ( $ this -> current ( ) -> getType ( ) , $ tokenTypes ) ; } , $ direction ) ; return $ this ; } ) ; } | Traverse the token tree passing any ignored types . |
32,080 | public function skipToNextNonWhitespace ( $ direction = self :: DIR_FORWARD ) { return $ this -> safeMove ( function ( ) use ( $ direction ) { $ this -> moveWithCondition ( function ( ) { return $ this -> current ( ) -> getType ( ) !== T_WHITESPACE ; } , $ direction ) ; return $ this ; } ) -> next ( ) ; } | Skips to the next non - whitespace token . |
32,081 | public function current ( ) { if ( ! isset ( $ this -> tokens [ $ this -> position ] ) ) { throw $ this -> getOutOfBoundsException ( ) ; } return $ this -> tokens [ $ this -> position ] ; } | Returns the current token in the stack . |
32,082 | private function moveWithCondition ( callable $ condition , $ direction = self :: DIR_FORWARD ) { while ( $ condition ( ) ) { $ this -> move ( $ direction ) ; if ( ! $ this -> valid ( ) ) { throw $ this -> getOutOfBoundsException ( ) ; } } return $ this ; } | Moves the positon based on a direction until the given condition is fulfilled . |
32,083 | public function move ( $ direction ) { if ( $ direction === self :: DIR_FORWARD ) { return $ this -> next ( ) ; } elseif ( $ direction === self :: DIR_BACKWARD ) { return $ this -> prev ( ) ; } throw new InvalidArgumentException ( sprintf ( 'Unknown direction %s' , $ direction ) ) ; } | Moves the positon based on a direction . |
32,084 | private function getOutOfBoundsException ( $ position = null ) { return new OutOfBoundsException ( sprintf ( 'Invalid token position (%d)' , $ position !== null ? $ position : $ this -> position ) ) ; } | Returns OutOfBoundsException based on current position within the iterator . |
32,085 | private function safeMove ( callable $ moveAction ) { $ oldPosition = $ this -> position ; try { return $ moveAction ( ) ; } catch ( OutOfBoundsException $ e ) { $ this -> position = $ oldPosition ; throw $ e ; } } | Restores previous position if OutOfBounds error occurs . |
32,086 | private function initialize ( ) { $ this -> entity = '' ; $ this -> source = '' ; $ this -> mode = self :: RSMODE_NOTCONNECTED ; $ this -> result = null ; $ this -> originalValues = null ; $ this -> datafields = [ ] ; $ this -> values = [ ] ; $ this -> idFields = [ ] ; } | Internal procedure to initiate all the variables |
32,087 | final public function getOriginalValue ( string $ fieldName , $ defaultValue = '' ) { if ( ! is_array ( $ this -> originalValues ) || ! array_key_exists ( $ fieldName , $ this -> originalValues ) ) { return $ defaultValue ; } return $ this -> originalValues [ $ fieldName ] ; } | Return the original value of a field |
32,088 | final public function addNew ( ) { $ this -> originalValues = null ; $ this -> values = $ this -> emptyValuesFromDataFields ( ) ; $ this -> mode = self :: RSMODE_CONNECTED_ADDNEW ; } | Prepares the recordset to make an insertion All the values are set to null |
32,089 | final public function valuesHadChanged ( ) : bool { if ( ! is_array ( $ this -> originalValues ) ) { throw new \ RuntimeException ( 'The recordset does not contain any original values' ) ; } foreach ( $ this -> originalValues as $ field => $ value ) { $ current = array_key_exists ( $ field , $ this -> values ) ? $ this -> values [ $ field ] : null ; if ( $ this -> valueIsDifferent ( $ value , $ current ) ) { return true ; } } return false ; } | Check whether the current values are different from the original ones The base are the original values |
32,090 | final protected static function valueIsDifferent ( $ original , $ current ) : bool { $ originalIsNull = ( null === $ original ) ; $ currentIsNull = ( null === $ current ) ; if ( $ originalIsNull && $ currentIsNull ) { return false ; } if ( $ originalIsNull || $ currentIsNull ) { return true ; } if ( is_object ( $ current ) ) { $ current = strval ( $ current ) ; } if ( is_string ( $ original ) && is_string ( $ current ) ) { return ( $ original !== $ current ) ; } return ( $ original != $ current ) ; } | Compare to values in order to see if they need to be updated |
32,091 | protected function sqlWhereConditions ( string $ extraWhereClause ) : array { $ conditions = [ ] ; if ( $ extraWhereClause ) { $ conditions [ ] = "($extraWhereClause)" ; } $ ids = $ this -> getIdFields ( ) ; if ( ! count ( $ ids ) ) { $ this -> logger -> warning ( 'Recordset: cannot get the ids to locate the current the record,' . ' will use all the fields to create the where clause' . "\n" . print_r ( [ 'entity' => $ this -> entity , 'values' => $ this -> values , ] , true ) ) ; $ ids = array_keys ( $ this -> datafields ) ; } foreach ( $ this -> datafields as $ fieldname => $ field ) { if ( ! array_key_exists ( $ fieldname , $ this -> values ) ) { continue ; } if ( ! in_array ( $ fieldname , $ ids ) ) { continue ; } if ( null === $ this -> originalValues [ $ fieldname ] ) { $ conditions [ ] = '(' . $ this -> dbal -> sqlIsNull ( $ this -> dbal -> sqlFieldEscape ( $ fieldname ) ) . ')' ; } else { $ conditions [ ] = '(' . $ this -> dbal -> sqlFieldEscape ( $ fieldname ) . ' = ' . $ this -> dbal -> sqlQuote ( $ this -> originalValues [ $ fieldname ] , $ field [ 'commontype' ] , false ) . ')' ; } } return $ conditions ; } | Create an array of conditions based on the current values and ids This function is used on Update and on Delete |
32,092 | protected function sqlInsert ( ) : string { $ inserts = [ ] ; foreach ( $ this -> datafields as $ fieldname => $ field ) { $ value = ( array_key_exists ( $ fieldname , $ this -> values ) ) ? $ this -> values [ $ fieldname ] : null ; $ escapedFieldName = $ this -> dbal -> sqlFieldEscape ( $ field [ 'name' ] ) ; $ inserts [ $ escapedFieldName ] = $ this -> dbal -> sqlQuote ( $ value , $ field [ 'commontype' ] , true ) ; } if ( ! count ( $ inserts ) ) { throw new \ LogicException ( 'Recordset: Insert does not have any fields to insert' ) ; } return 'INSERT INTO ' . $ this -> dbal -> sqlTableEscape ( $ this -> entity ) . ' (' . implode ( ', ' , array_keys ( $ inserts ) ) . ')' . ' VALUES (' . implode ( ', ' , $ inserts ) . ')' . ';' ; } | Create the sql statement for INSERT INTO |
32,093 | protected function sqlUpdate ( string $ extraWhereClause ) : string { $ conditions = $ this -> sqlWhereConditions ( $ extraWhereClause ) ; if ( ! count ( $ conditions ) ) { throw new \ LogicException ( 'Recordset: The current record does not have any conditions to update' ) ; } $ updates = [ ] ; foreach ( $ this -> datafields as $ fieldname => $ field ) { if ( ! array_key_exists ( $ fieldname , $ this -> values ) ) { $ this -> values [ $ fieldname ] = null ; } if ( $ this -> valueIsDifferent ( $ this -> originalValues [ $ fieldname ] , $ this -> values [ $ fieldname ] ) ) { $ updates [ ] = $ this -> dbal -> sqlFieldEscape ( $ fieldname ) . ' = ' . $ this -> dbal -> sqlQuote ( $ this -> values [ $ fieldname ] , $ field [ 'commontype' ] , true ) ; } } if ( ! count ( $ updates ) ) { return '' ; } return 'UPDATE' . ' ' . $ this -> dbal -> sqlTableEscape ( $ this -> entity ) . ' SET ' . implode ( ', ' , $ updates ) . ' WHERE ' . implode ( ' AND ' , $ conditions ) . ';' ; } | Create the sql statement for UPDATE If nothing to update then will return an empty string |
32,094 | protected function sqlDelete ( string $ extraWhereClause ) : string { $ conditions = $ this -> sqlWhereConditions ( $ extraWhereClause ) ; if ( ! count ( $ conditions ) ) { throw new \ LogicException ( 'Recordset: The current record does not have any conditions to delete' ) ; } return 'DELETE' . ' FROM ' . $ this -> dbal -> sqlTableEscape ( $ this -> entity ) . ' WHERE ' . implode ( ' AND ' , $ conditions ) . ';' ; } | Create the sql statement for DELETE |
32,095 | final public function update ( $ extraWhereClause = '' ) { if ( self :: RSMODE_CONNECTED_ADDNEW !== $ this -> mode && self :: RSMODE_CONNECTED_EDIT !== $ this -> mode ) { throw new \ LogicException ( "Recordset: The recordset is not on edit or addnew mode [current: {$this->mode}]" ) ; } if ( '' === $ this -> entity ) { throw new \ LogicException ( 'Recordset: The recordset does not have a valid unique entity' ) ; } $ sql = '' ; if ( self :: RSMODE_CONNECTED_ADDNEW == $ this -> mode ) { $ sql = $ this -> sqlInsert ( ) ; } if ( self :: RSMODE_CONNECTED_EDIT == $ this -> mode ) { if ( '' === $ sql = $ this -> sqlUpdate ( $ extraWhereClause ) ) { return 0 ; } } $ altered = $ this -> dbal -> execute ( $ sql ) ; if ( 0 === $ altered ) { $ diffs = [ ] ; if ( is_array ( $ this -> originalValues ) ) { foreach ( $ this -> originalValues as $ name => $ value ) { if ( ! $ this -> valueIsDifferent ( $ value , $ this -> values [ $ name ] ) ) { continue ; } $ diffs [ ] = $ name ; } } $ this -> logger -> warning ( print_r ( [ 'message' => "Recordset: The statement $sql return zero affected rows but the values are different" , 'entity' => $ this -> entity , 'extraWhereClause' => $ extraWhereClause , 'original' => $ this -> originalValues , 'current' => $ this -> values , 'diffs' => $ diffs , ] , true ) ) ; } return $ altered ; } | Build and execute an SQL UPDATE or INSERT sentence Return how many rows where altered if an update does not change any value then it return zero Return false in case of error execution |
32,096 | final public function delete ( $ extraWhereClause = '' ) { if ( self :: RSMODE_CONNECTED_EDIT !== $ this -> mode ) { throw new \ LogicException ( 'Recordset: The recordset is not on edit mode [current: ' . $ this -> mode . ']' ) ; } if ( '' === $ this -> entity ) { throw new \ LogicException ( 'Recordset: The recordset does not have a valid unique entity' ) ; } $ sql = $ this -> sqlDelete ( $ extraWhereClause ) ; $ altered = $ this -> dbal -> execute ( $ sql ) ; if ( 0 === $ altered ) { $ this -> logger -> warning ( print_r ( [ 'message' => "Recordset: The statement '$sql' return zero affected rows" . ' but it should delete at least one record' , 'entity' => $ this -> entity , 'extraWhereClause' => $ extraWhereClause , 'original' => $ this -> originalValues , ] , true ) ) ; } return $ altered ; } | Build and execute the SQL DELETE sentence Return how many rows where altered |
32,097 | private function setValuesFromDatafields ( array $ source ) : array { $ values = [ ] ; foreach ( $ this -> datafields as $ fieldname => $ field ) { $ values [ $ fieldname ] = $ this -> castValueWithCommonType ( array_key_exists ( $ fieldname , $ source ) ? $ source [ $ fieldname ] : null , $ field [ 'commontype' ] ) ; } return $ values ; } | Internal function that returns an array with the content of all datafields filled with the values casted |
32,098 | protected function castValueWithCommonType ( $ value , string $ commonType ) { if ( null === $ value ) { return null ; } if ( CommonTypes :: TTEXT === $ commonType ) { return strval ( $ value ) ; } if ( CommonTypes :: TINT === $ commonType ) { return intval ( $ value ) ; } if ( CommonTypes :: TNUMBER === $ commonType ) { return floatval ( $ value ) ; } if ( CommonTypes :: TBOOL === $ commonType ) { return ( bool ) $ value ; } if ( in_array ( $ commonType , [ CommonTypes :: TDATE , CommonTypes :: TTIME , CommonTypes :: TDATETIME ] , true ) ) { return strtotime ( $ value ) ; } return strval ( $ value ) ; } | Cast a generic value from the source to a typed value if null return null |
32,099 | private function fetchLoadValues ( ) : bool { $ row = $ this -> result ( ) -> fetchRow ( ) ; if ( false === $ row ) { $ this -> originalValues = null ; $ this -> values = [ ] ; return false ; } $ this -> originalValues = $ this -> setValuesFromDatafields ( $ row ) ; $ this -> values = $ this -> originalValues ; return true ; } | Try to load values fetching a new row Return true if success Return false if no row was fetched also put values to an empty array |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.