idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
34,900 | public function update ( $ index , $ data ) { $ db = $ this -> load ( ) ; $ db [ $ index ] = array_merge ( $ db [ $ index ] , $ data ) ; return $ this -> rewrite ( $ db ) ; } | Updates a row in the database . |
34,901 | public function index ( $ key , $ val ) { $ db = $ this -> load ( ) ; foreach ( $ db as $ index => $ row ) { if ( $ row [ $ key ] === $ val ) { return $ index ; break ; } } return - 1 ; } | Returns the index of a row where the given key matches value . |
34,902 | public function to ( $ field , $ to , $ key , $ val ) { $ db = $ this -> load ( ) ; foreach ( $ db as $ index => $ row ) { if ( $ row [ $ key ] === $ val ) { $ db [ $ index ] [ $ field ] = $ to ; } } return $ this -> rewrite ( $ db ) ; } | Changes the value of a field in rows satisfying a condition . |
34,903 | public function get ( $ field , $ key , $ val ) { $ db = $ this -> load ( ) ; foreach ( $ db as $ index => $ row ) { if ( $ row [ $ key ] === $ val && $ row [ $ field ] ) { return $ row [ $ field ] ; break ; } } return null ; } | Get the value of the specified field of the first row where a specified field contains a specified value . |
34,904 | private static function arraySelect ( $ fields = [ ] , $ arr ) { $ result = [ ] ; $ values = [ ] ; if ( $ fields === [ ] ) { foreach ( $ arr as $ index => $ row ) { foreach ( array_keys ( $ row ) as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } if ( $ values ) { $ result [ $ index ] = $ values ; } $ values = [ ] ; } } else { foreach ( $ arr as $ index => $ row ) { foreach ( ( array ) $ fields as $ c ) { if ( $ row [ $ c ] ) { $ values [ $ c ] = $ row [ $ c ] ; } } if ( $ values ) { $ result [ $ index ] = $ values ; } $ values = [ ] ; } } return $ result ; } | Gets an array of field names against values for every member of an array . |
34,905 | public function where ( $ field , $ key , $ val ) { $ db = $ this -> load ( ) ; $ result = [ ] ; $ values = [ ] ; if ( $ field === [ ] ) { foreach ( $ db as $ index => $ row ) { if ( $ row [ $ key ] === $ val ) { foreach ( array_keys ( $ row ) as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } else { foreach ( $ db as $ index => $ row ) { if ( $ row [ $ key ] === $ val ) { foreach ( ( array ) $ field as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } return $ result ; } | Gets an array of field names against values for every row in the data set where a field has a given value . |
34,906 | public function in ( $ fields , $ key , $ val ) { $ db = $ this -> load ( ) ; $ result = [ ] ; $ values = [ ] ; if ( $ fields === [ ] ) { foreach ( $ db as $ index => $ row ) { if ( in_array ( $ row [ $ key ] , $ val ) ) { foreach ( array_keys ( $ row ) as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } else { foreach ( $ db as $ index => $ row ) { if ( in_array ( $ row [ $ key ] , $ val ) ) { foreach ( ( array ) $ fields as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } return $ result ; } | Gets an array of field names against values for every row in the data set where a field has one of a given set of values . |
34,907 | public function like ( $ fields , $ key , $ regex ) { $ db = $ this -> load ( ) ; $ result = [ ] ; $ values = [ ] ; if ( $ fields === [ ] ) { foreach ( $ db as $ index => $ row ) { if ( preg_match ( $ regex , $ row [ $ key ] ) ) { foreach ( array_keys ( $ row ) as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } else { foreach ( $ db as $ index => $ row ) { if ( preg_match ( $ regex , $ row [ $ key ] ) ) { foreach ( ( array ) $ fields as $ c ) { $ values [ $ c ] = $ row [ $ c ] ; } $ result [ $ index ] = $ values ; $ values = [ ] ; } } } return $ result ; } | Matches keys and values based on a regular expression . |
34,908 | public function union ( $ fields , $ second ) { return array_map ( 'unserialize' , array_unique ( array_map ( 'serialize' , array_merge ( $ this -> select ( $ fields ) , $ second -> select ( $ fields ) ) ) ) ) ; } | Merges two databases removing duplicates . |
34,909 | public function join ( $ method , $ fields , $ second , $ match ) { $ left = $ this -> load ( ) ; $ right = $ second -> load ( ) ; $ result = [ ] ; $ values = [ ] ; if ( $ method === 'inner' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ result [ ] = array_merge ( $ l , $ r ) ; } } } } elseif ( $ method === 'left' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ values = array_merge ( $ l , $ r ) ; break ; } else { $ values = $ l ; } } $ result [ ] = $ values ; $ values = [ ] ; } } elseif ( $ method === 'right' ) { foreach ( $ left as $ l ) { foreach ( $ right as $ r ) { if ( $ l [ array_keys ( $ match ) [ 0 ] ] === $ r [ array_values ( $ match ) [ 0 ] ] ) { $ values = array_merge ( $ l , $ r ) ; break ; } else { $ values = $ r ; } } $ result [ ] = $ values ; $ values = [ ] ; } } elseif ( $ method === 'full' ) { $ result = array_map ( 'unserialize' , array_unique ( array_map ( 'serialize' , array_merge ( $ this -> join ( 'left' , $ fields , $ second , $ match ) , $ this -> join ( 'right' , $ fields , $ second , $ match ) ) ) ) ) ; } return self :: arraySelect ( $ fields , $ result ) ; } | Matches and merges fields between databases . |
34,910 | public function exists ( $ field , $ val ) { $ db = $ this -> load ( ) ; $ result = false ; foreach ( $ db as $ index => $ row ) { if ( $ row [ $ field ] === $ val ) { $ result = true ; } } return $ result ; } | Checks whether the database contains a field with the specified value . |
34,911 | public function count ( $ field = '' ) { if ( $ field === '' ) { $ query = [ ] ; } else { $ query = ( array ) $ field ; } return count ( $ this -> select ( $ query ) ) ; } | Counts the number of items per field or for all fields . |
34,912 | protected function initInstances ( ) { if ( empty ( $ this -> instances ) ) { foreach ( $ this -> servers as $ server ) { if ( $ server instanceof \ Redis ) { if ( $ server -> isConnected ( ) ) { $ redis = $ server ; } else { throw new \ InvalidArgumentException ( "If you use \\Redis objects as argument, the object must be connected." ) ; } } else { if ( empty ( $ server [ 0 ] ) ) { throw new \ InvalidArgumentException ( "A server hostname or IP is required" ) ; } if ( empty ( $ server [ 1 ] ) ) { $ server [ 1 ] = 6379 ; } if ( empty ( $ server [ 2 ] ) ) { $ server [ 2 ] = 0 ; } list ( $ host , $ port , $ timeout ) = $ server ; $ redis = new \ Redis ( ) ; $ redis -> connect ( $ host , $ port , $ timeout ) ; } $ this -> instances [ ] = $ redis ; } } } | Create the Redis connections |
34,913 | public function row ( ) { $ iterator = $ this -> getIterator ( ) ; if ( ! $ iterator -> current ( ) ) $ iterator -> next ( ) ; $ value = $ iterator -> current ( ) ; $ iterator -> next ( ) ; return $ value ; } | Returns the next available row as an associative array . |
34,914 | public function scalar ( $ idx = 0 ) { $ row = $ this -> row ( ) ; if ( is_null ( $ row ) ) return NULL ; $ values = is_numeric ( $ idx ) ? array_values ( $ row ) : $ row ; return $ values [ $ idx ] ; } | Returns the nth column from the current row . |
34,915 | public function fields ( ) { if ( ! isset ( $ this -> _fields ) ) $ this -> _fields = new Fields ( $ this -> _result ) ; return $ this -> _fields ; } | The fields returned in the result set as an array of fields |
34,916 | protected function query ( $ sql , $ params ) { return \ Pheasant :: instance ( ) -> finderFor ( $ this -> class ) -> query ( new \ Pheasant \ Query \ Criteria ( $ sql , $ params ) ) ; } | Delegates to the finder for querying |
34,917 | protected function adder ( $ object ) { $ rel = $ this ; return function ( $ value ) use ( $ object , $ rel ) { return $ rel -> add ( $ object , $ value ) ; } ; } | Helper function that creates a closure that calls the add function |
34,918 | public function getter ( $ key , $ cache = null ) { $ rel = $ this ; return function ( $ object ) use ( $ key , $ rel , $ cache ) { return $ rel -> get ( $ object , $ key , $ cache ) ; } ; } | delegate double dispatch calls to type |
34,919 | public static function normalizeMap ( $ array ) { $ nested = array ( ) ; foreach ( ( array ) $ array as $ key => $ value ) { if ( is_numeric ( $ key ) ) { $ nested [ $ value ] = array ( ) ; } else { $ nested [ $ key ] = $ value ; } } return $ nested ; } | Takes either a flat array of relationships or a nested key = > value array and returns it as a nested format |
34,920 | public static function addJoin ( $ query , $ parentAlias , $ schema , $ relName , $ nested = array ( ) , $ joinType = 'inner' ) { if ( ! in_array ( $ joinType , array ( 'inner' , 'left' , 'right' ) ) ) { throw new \ InvalidArgumentException ( "Unsupported join type: $joinType" ) ; } list ( $ relName , $ alias ) = self :: parseRelName ( $ relName ) ; $ rel = $ schema -> relationship ( $ relName ) ; $ instance = \ Pheasant :: instance ( ) ; $ localTable = $ instance -> mapperFor ( $ schema -> className ( ) ) -> table ( ) ; $ remoteSchema = $ instance -> schema ( $ rel -> class ) ; $ remoteTable = $ instance -> mapperFor ( $ rel -> class ) -> table ( ) ; $ joinMethod = $ joinType . 'Join' ; $ query -> $ joinMethod ( $ remoteTable -> name ( ) -> table , sprintf ( 'ON `%s`.`%s`=`%s`.`%s`' , $ parentAlias , $ rel -> local , $ alias , $ rel -> foreign ) , $ alias ) ; foreach ( self :: normalizeMap ( $ nested ) as $ relName => $ nested ) { self :: addJoin ( $ query , $ alias , $ remoteSchema , $ relName , $ nested , $ joinType ) ; } } | Adds a join clause to the given query for the given schema and relationship . Optionally takes a nested list of relationships that will be recursively joined as needed . |
34,921 | public function loadUserByAPIUser ( User $ apiUser ) { $ eZSyliusUser = $ this -> eZUserRepository -> findOneBy ( array ( 'eZUserId' => $ apiUser -> getUserId ( ) , 'syliusUserType' => $ this -> syliusUserType , ) ) ; if ( ! $ eZSyliusUser instanceof EzSyliusUser ) { return null ; } return $ this -> syliusUserRepository -> find ( $ eZSyliusUser -> getSyliusUserId ( ) ) ; } | Loads Sylius user based on provided eZ API user . |
34,922 | protected function loadAPIUser ( SyliusUserInterface $ user ) { $ eZSyliusUser = $ this -> eZUserRepository -> findOneBy ( array ( 'syliusUserId' => $ user -> getId ( ) , 'syliusUserType' => $ this -> syliusUserType , ) ) ; if ( ! $ eZSyliusUser instanceof EzSyliusUser ) { return null ; } try { return $ this -> repository -> getUserService ( ) -> loadUser ( $ eZSyliusUser -> getEzUserId ( ) ) ; } catch ( NotFoundException $ e ) { return null ; } } | Loads eZ API user based on provided Sylius user . |
34,923 | public static function array_merge_assoc_recursive ( $ array1 , $ array2 ) { foreach ( $ array2 as $ key => $ value ) { if ( is_int ( $ key ) && ! in_array ( $ array2 [ $ key ] , $ array1 , true ) ) { $ array1 [ ] = $ array2 [ $ key ] ; } elseif ( ! array_key_exists ( $ key , $ array1 ) ) { $ array1 [ $ key ] = $ value ; } elseif ( is_array ( $ value ) && is_array ( $ array1 [ $ key ] ) ) { $ array1 [ $ key ] = self :: array_merge_assoc_recursive ( $ array1 [ $ key ] , $ value ) ; } else { if ( ! in_array ( $ value , $ array1 , true ) ) { $ array1 [ $ key ] = $ value ; } } } return $ array1 ; } | Merge array2 into array1 without duplicates |
34,924 | public static function array_remove_assoc_recursive ( & $ array1 , $ array2 ) { foreach ( $ array2 as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ array1 ) ) { return $ array1 ; } elseif ( is_array ( $ value ) ) { self :: array_remove_assoc_recursive ( $ array1 [ $ key ] , $ value ) ; if ( 0 === count ( $ array1 [ $ key ] ) ) { unset ( $ array1 [ $ key ] ) ; } } else { unset ( $ array1 [ $ key ] ) ; } } } | Remove array2 from array1 |
34,925 | public static function array_column ( array $ array , $ column_key = null , $ index_key = null ) { if ( function_exists ( 'array_column' ) ) { return array_column ( $ array , $ column_key , $ index_key ) ; } $ result = [ ] ; foreach ( $ array as $ row ) { if ( ! is_array ( $ row ) ) { continue ; } $ key = count ( $ result ) ; if ( ! is_null ( $ index_key ) && array_key_exists ( $ index_key , $ row ) ) { $ key = ( string ) $ row [ $ index_key ] ; } if ( is_null ( $ column_key ) ) { $ result [ $ key ] = $ row ; } elseif ( array_key_exists ( $ column_key , $ row ) ) { $ result [ $ key ] = $ row [ $ column_key ] ; } } return $ result ; } | Implementation of array_column for PHP lower than 5 . 5 |
34,926 | public static function getType ( $ parameter ) { if ( is_bool ( $ parameter ) ) { return \ PDO :: PARAM_BOOL ; } elseif ( $ parameter === null ) { return \ PDO :: PARAM_NULL ; } elseif ( is_int ( $ parameter ) ) { return \ PDO :: PARAM_INT ; } else { return \ PDO :: PARAM_STR ; } } | Returns the fitting PDO type for the parameter |
34,927 | public function tokens ( $ source , $ offset ) { $ tokens = array ( ) ; $ rawTokens = token_get_all ( '<?php ' . substr ( $ source , $ offset ) ) ; array_shift ( $ rawTokens ) ; foreach ( $ rawTokens as $ token ) { $ tokens = array_merge ( $ tokens , $ this -> normalizeToken ( $ token ) ) ; } $ tokens = $ this -> collapseQuotedStrings ( $ tokens ) ; $ tokens = $ this -> collapseConsecutiveStrings ( $ tokens ) ; return $ tokens ; } | Produce tokens from the provided source . |
34,928 | public function createSortorderFromFileList ( ) { if ( file_exists ( $ this -> path ) ) { $ files = scandir ( $ this -> path , 0 ) ; if ( false !== $ files ) { $ sortorder = array ( ) ; foreach ( $ files as $ file ) { if ( ! is_dir ( $ this -> path . DIRECTORY_SEPARATOR . $ file ) ) { $ prefix = substr ( $ file , 0 , 1 ) ; if ( $ prefix != '.' && $ prefix != '_' ) { $ sortorder [ ] = $ file ; } } } return $ sortorder ; } throw new \ RuntimeException ( "Unable to access directory: " . $ this -> path ) ; } throw new \ InvalidArgumentException ( "Unable to read sortorder" ) ; } | Create a sortorder file content from file list within path |
34,929 | public function getSortorderPath ( ) { $ fileName = $ this -> path . DIRECTORY_SEPARATOR . '.sortorder' ; if ( file_exists ( $ fileName ) ) { return $ fileName ; } $ fileName = $ this -> path . DIRECTORY_SEPARATOR . '_sortorder' ; if ( file_exists ( $ fileName ) ) { return $ fileName ; } return false ; } | Returns file name of sortorder no matter whether this file is _ or . prefixed . Returns false if sortorder file doesn t exist . |
34,930 | public function getPropertiesPath ( ) { $ fileName = $ this -> path . DIRECTORY_SEPARATOR . '.properties' ; if ( file_exists ( $ fileName ) ) { return $ fileName ; } $ fileName = $ this -> path . DIRECTORY_SEPARATOR . '_properties' ; if ( file_exists ( $ fileName ) ) { return $ fileName ; } return false ; } | Returns file name of properties no matter whether this file is _ or . prefixed . Returns false if properties file doesn t exist . |
34,931 | public function table ( ) { if ( ! isset ( $ this -> _table ) ) $ this -> _table = $ this -> _connection -> table ( $ this -> _tableName ) ; return $ this -> _table ; } | Returns a table instance |
34,932 | public function sequenceName ( $ property ) { $ sequence = $ property -> type -> options ( ) -> sequence ; return $ sequence ? : sprintf ( "%s_%s_seq" , $ this -> _tableName , $ property -> name ) ; } | Generates a sequence name for a property |
34,933 | public static function createEnvironment ( $ paths , \ Symfony \ Component \ Translation \ Translator $ translator , $ options = array ( ) ) { $ viewPath = $ paths [ 'base' ] . '/' . DIRNAME_VIEWS ; $ twigBridgePath = $ paths [ 'lib' ] . '/symfony/twig-bridge/Symfony/Bridge/Twig' ; $ opts = array ( ) ; if ( Config :: get ( 'app.twig_debug' ) ) { $ opts [ 'debug' ] = true ; } elseif ( $ paths [ 'cache' ] ) { $ opts [ 'cache' ] = $ paths [ 'cache' ] ; } $ opts = array_merge_recursive ( $ opts , $ options ) ; $ twig = new Twig_Environment ( new Twig_Loader_Filesystem ( array ( $ twigBridgePath . '/Resources/views/Form' , ) ) , $ opts ) ; if ( is_object ( $ translator ) ) { $ twig -> addExtension ( new \ Symfony \ Bridge \ Twig \ Extension \ TranslationExtension ( $ translator ) ) ; } $ twig -> addExtension ( new Concrete5Extension ( ) ) ; if ( Config :: get ( 'app.package_dev_mode' ) ) { $ twig -> addExtension ( new Twig_Extension_Debug ( ) ) ; } return $ twig ; } | We need a context specific twig environment object because a ) The twig libraries or the Symfony twig bridge are not available in the core so we cannot rely on their availability any other way b ) We ll need to have a single twig environment per twig cache directory . |
34,934 | public function getFriendshipsNoRetweetsIds ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'friendships/no_retweets/ids' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from . |
34,935 | public function getFollowersIds ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'followers/ids' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user . |
34,936 | public function getFriendshipsShow ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'friendships/show' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns detailed information about the relationship between two arbitrary users . |
34,937 | public function getValidationRules ( ) { $ rules = [ ] ; foreach ( $ this -> rules as $ name => $ rule ) { $ ruleName = sprintf ( '2fa.*.settings.%s' , $ name ) ; $ rules [ $ ruleName ] = $ rule ; } return $ rules ; } | Returns the validation rules . |
34,938 | protected function registerJs ( ) { $ values = Json :: encode ( $ this -> values ) ; $ config = [ 'type' => $ this -> type , 'height' => $ this -> height , ] ; if ( $ this -> type !== self :: SPARKLINE_BAR ) { $ config [ 'width' ] = $ this -> width ; } $ config = Json :: encode ( ArrayHelper :: merge ( $ this -> sparklineConfig , $ config ) ) ; $ js = sprintf ( "$('#%s').sparkline(%s, %s);" , $ this -> id , $ values , $ config ) ; $ this -> view -> registerJs ( $ js ) ; } | Creates and registers the needed javascript code to run the widget |
34,939 | public function repopulate ( SimpleInput $ data = null ) { if ( is_null ( $ data ) ) { $ data = new SimpleInput ; } $ this -> populate ( $ data -> input ( ) ) ; return $ this ; } | Repopulates the fields using input data . By default uses a combination of get and post but other data can be used by passing a child of InputElement |
34,940 | public function populate ( $ data ) { foreach ( $ this -> getContents ( ) as $ item ) { if ( $ item instanceof InputContainer ) { $ item -> populate ( $ data ) ; } else { $ key = $ this -> inputNameToKey ( $ item -> getName ( ) ) ; $ value = Arr :: get ( $ data , $ key ) ; if ( ! is_null ( $ value ) ) { $ item -> setValue ( $ value ) ; } } } return $ this ; } | Populates the fields using the array passed . |
34,941 | public function dispatch ( $ method , $ params ) { if ( ( $ method == 'find' && empty ( $ params ) ) || $ method == 'all' ) { return $ this -> find ( ) ; } else if ( ( $ method == 'find' || $ method == 'one' ) && is_string ( $ params [ 0 ] ) ) { $ rs = $ this -> find ( new Criteria ( array_shift ( $ params ) , $ params ) ) ; return $ method == 'one' ? $ rs -> one ( ) : $ rs ; } else if ( preg_match ( '/^(findBy|oneBy)/' , $ method ) ) { $ rs = $ this -> find ( new Criteria ( $ this -> _sqlFromMethod ( $ method ) , $ params ) ) ; return preg_match ( '/^(oneBy)/' , $ method ) ? $ rs -> one ( ) : $ rs ; } else if ( $ method == 'byId' ) { return $ this -> _findById ( $ params ) ; } else if ( isset ( $ params [ 0 ] ) && $ params [ 0 ] instanceof Criteria ) { return $ this -> find ( $ params [ 0 ] ) ; } else { throw new \ BadMethodCallException ( "Unable to dispatch '$method' to finder" ) ; } } | Magically derives a query to send to the internal finder |
34,942 | public static function fromClass ( $ className ) { return new self ( \ Pheasant :: instance ( ) -> schema ( $ className ) , \ Pheasant :: instance ( ) -> finderFor ( $ className ) ) ; } | Helper to build Wizard |
34,943 | private function _findById ( $ params ) { if ( count ( $ params ) > 1 ) throw new \ InvalidArgumentException ( "byId doesn't support composite keys" ) ; $ keys = array_keys ( $ this -> _schema -> primary ( ) ) ; return $ this -> _finder -> find ( $ this -> _class , new Criteria ( "`{$keys[0]}`=?" , $ params [ 0 ] ) ) -> one ( ) ; } | Find an object by primary key |
34,944 | public function beginChangeset ( ) { $ model = $ this -> owner ; $ id = $ model -> getDb ( ) -> getSchema ( ) -> insert ( $ this -> changesetTableName , [ 'transaction_id' => new Expression ( 'txid_current()' ) , 'user_id' => Yii :: $ app -> user -> getId ( ) , 'session_id' => Yii :: $ app -> has ( 'session' ) ? Yii :: $ app -> session -> getId ( ) : null , 'request_date' => date ( 'Y-m-d H:i:s' ) , 'request_url' => Yii :: $ app -> request instanceof \ yii \ web \ Request ? Yii :: $ app -> request -> getUrl ( ) : null , 'request_addr' => Yii :: $ app -> request instanceof \ yii \ web \ Request ? Yii :: $ app -> request -> getUserIP ( ) : null , ] ) ; $ model -> getDb ( ) -> createCommand ( 'SET LOCAL audit.changeset_id = ' . reset ( $ id ) ) -> execute ( ) ; } | Creates a new db audit changeset which contains metadata like current user id request url and client ip address . |
34,945 | public function getAttributeVersions ( $ attribute ) { $ owner = $ this -> owner ; return ( new Query ) -> select ( [ 'value' => "CASE action_type " . "WHEN 'INSERT' THEN jsonb_object_field_text(row_data, :attribute::text) " . "ELSE jsonb_object_field_text(changed_fields, :attribute::text) END" , 'action_id' , ] ) -> from ( $ this -> auditTableName ) -> where ( [ 'AND' , 'relation_id = \'' . $ owner -> tableName ( ) . '\'::regclass' , 'statement_only = false' , [ 'OR' , [ 'AND' , 'action_type = \'INSERT\'' , "jsonb_exists(row_data, :attribute)" ] , [ 'AND' , 'action_type = \'UPDATE\'' , "jsonb_exists(changed_fields, :attribute)" ] , ] , 'row_data @> :primaryKey' , ] , [ ':attribute' => $ attribute , ':primaryKey' => json_encode ( $ owner -> getPrimaryKey ( true ) ) , ] ) -> orderBy ( 'action_id' ) -> indexBy ( 'action_id' ) -> column ( $ owner -> getDb ( ) ) ; } | Returns all recorded values for specified attribute . |
34,946 | public function getRecordVersions ( ) { $ owner = $ this -> owner ; return ( new Query ) -> select ( 'action_id' ) -> from ( $ this -> auditTableName ) -> where ( [ 'AND' , 'relation_id = (:tableName)::regclass' , 'statement_only = false' , [ 'OR' , 'action_type = \'INSERT\'' , 'action_type = \'UPDATE\'' ] , ':primaryKey' => json_encode ( $ owner -> getPrimaryKey ( true ) ) , ] , [ ':tableName' => $ owner -> tableName ( ) ] ) -> orderBy ( 'action_id' ) -> column ( $ owner -> getDb ( ) ) ; } | Returns ids of all recorded versions . |
34,947 | protected function drawPageHeader ( ) { $ data = $ this -> data ; $ title = utf8_decode ( $ data [ 'header_title' ] ?? '' ) ; $ body = utf8_decode ( $ data [ 'header_body' ] ?? '' ) ; $ info = utf8_decode ( $ this -> simpleTemplate ( $ data [ 'header_info' ] ?? '' ) ) ; $ this -> billetSetFont ( 'cell_data' ) ; if ( strlen ( $ title ) ) { $ this -> Cell ( 177 , 3 , $ title , 0 , 1 , 'C' ) ; $ this -> Ln ( 2 ) ; } if ( strlen ( $ body ) ) { $ this -> MultiCell ( 177 , 3 , $ body ) ; $ this -> Ln ( 2 ) ; } $ this -> billetSetFont ( 'digitable' ) ; $ this -> MultiCell ( 177 , 3.5 , $ info ) ; $ this -> Ln ( 4 ) ; } | Draws the Page Header |
34,948 | protected function drawBillhead ( ) { $ assignment = $ this -> title -> assignment ; $ assignor = $ assignment -> assignor ; $ person = $ assignor -> person ; $ this -> Ln ( 2 ) ; $ logo = self :: findFile ( "assignors/$person->id.*" , $ this -> logos ) ; if ( $ logo !== null ) { $ y = $ this -> GetY ( ) ; $ this -> Image ( $ logo , null , null , 40 , 0 , '' , $ assignor -> url ) ; $ y1 = $ this -> GetY ( ) ; $ this -> SetXY ( 50 , $ y ) ; } $ text = $ person -> name . "\n" . $ person -> getFormattedDocument ( ) . "\n" . $ assignment -> address -> outputLong ( ) ; $ this -> billetSetFont ( 'billhead' ) ; $ this -> MultiCell ( 103.2 , 2.5 , utf8_decode ( $ text ) ) ; $ this -> SetY ( max ( $ y1 ?? 0 , $ this -> GetY ( ) ) ) ; } | Draws the Billhead |
34,949 | protected function drawDash ( $ text = '' , $ text_first = false , $ align = 'R' ) { $ cell = function ( $ text , $ align ) { $ this -> Cell ( 177 , 4 , $ text , 0 , 1 , $ align ) ; } ; if ( $ text_first ) { $ cell ( $ text , $ align ) ; } $ this -> SetLineWidth ( static :: DEFAULT_LINE_WIDTH * 0.625 ) ; $ y = $ this -> GetY ( ) ; $ this -> SetDash ( ... static :: DASH_STYLE ) ; $ this -> Line ( 10 , $ y , 187 , $ y ) ; $ this -> SetDash ( ) ; $ this -> SetLineWidth ( static :: DEFAULT_LINE_WIDTH ) ; if ( ! $ text_first ) { $ cell ( $ text , $ align ) ; } } | Inserts a dashed line with optional text before or after |
34,950 | protected function drawBankHeader ( $ digitable_align = 'R' , $ line_width_factor = 2 ) { $ bank = $ this -> title -> assignment -> bank ; $ this -> Ln ( 3 ) ; $ logo = self :: findFile ( "banks/$bank->id.*" , $ this -> logos ) ; if ( $ logo !== null ) { $ this -> Image ( $ logo , null , null , 40 ) ; $ this -> SetXY ( 50 , $ this -> GetY ( ) - 7 ) ; } else { $ this -> billetSetFont ( 'cell_data' ) ; $ this -> Cell ( 40 , 7 , utf8_decode ( $ bank -> name ) ) ; } $ this -> SetLineWidth ( static :: DEFAULT_LINE_WIDTH * $ line_width_factor ) ; $ this -> billetSetFont ( 'bank_code' ) ; $ this -> Cell ( 15 , 7 , $ this -> formatBankCode ( ) , 'LR' , 0 , 'C' ) ; $ this -> billetSetFont ( 'digitable1' ) ; $ this -> Cell ( 122 , 7 , $ this -> data [ 'digitable' ] , 0 , 1 , $ digitable_align ) ; $ y = $ this -> GetY ( ) ; $ this -> Line ( 10 , $ y , 187 , $ y ) ; $ this -> SetLineWidth ( static :: DEFAULT_LINE_WIDTH ) ; } | Inserts the Bank header |
34,951 | protected function drawBarCode ( $ baseline = 0.8 , $ height = 13 ) { $ data = $ this -> data [ 'barcode' ] ; $ wide = $ baseline ; $ narrow = $ baseline / 3 ; $ map = [ '00110' , '10001' , '01001' , '11000' , '00101' , '10100' , '01100' , '00011' , '10010' , '01010' ] ; if ( ( strlen ( $ data ) % 2 ) != 0 ) { $ data = '0' . $ data ; } $ code = '0000' ; for ( $ i = 0 , $ l = strlen ( $ data ) ; $ i < $ l ; $ i += 2 ) { $ code .= implode ( '' , Utils \ Utils :: arrayInterpolate ( $ map [ $ data [ $ i ] ] , $ map [ $ data [ $ i + 1 ] ] ) ) ; } $ code .= '100' ; $ this -> SetFillColor ( 0 ) ; $ x = $ this -> GetX ( ) ; $ y = $ this -> GetY ( ) ; $ draw = true ; foreach ( str_split ( $ code , 1 ) as $ bit ) { $ width = ( $ bit == '0' ? $ narrow : $ wide ) ; if ( $ draw ) { $ this -> Rect ( $ x , $ y , $ width , $ height , 'F' ) ; } $ x += $ width ; $ draw = ! $ draw ; } $ this -> Ln ( $ height ) ; } | Produces a bar code from string of digits in style 2 of 5 intercalated |
34,952 | protected function drawRow ( $ cells , $ row_border = 1 ) { $ origin = [ 'x' => $ this -> GetX ( ) , 'y' => $ this -> GetY ( ) ] ; $ coords = [ ] ; $ x = $ origin [ 'x' ] ; foreach ( $ cells as $ cell ) { $ fields = ( array ) $ cell [ 'field' ] ; $ count = count ( $ fields ) ; $ align = $ cell [ 'align' ] ?? 'L' ; $ width = $ cell [ 'width' ] ; foreach ( $ fields as $ field ) { $ border = ( -- $ count > 0 ? 'B' : 0 ) ; $ field = $ this -> fields [ $ field ] ; $ title = $ field [ 'text' ] ?? '' ; $ data = $ field [ 'value' ] ?? '' ; $ this -> billetSetFont ( 'cell_title' ) ; $ this -> Cell ( $ width , 3.5 , $ title , 0 , 2 ) ; $ this -> billetSetFont ( 'cell_data' ) ; if ( strpos ( $ data , "\n" ) ) { $ this -> MultiCell ( $ width , 3.5 , $ data , $ border , $ align ) ; } else { $ this -> Cell ( $ width , 3.5 , $ data , $ border , 2 , $ align ) ; } } $ x += $ width ; $ coords [ ] = [ 'x' => $ x , 'y' => $ this -> GetY ( ) ] ; $ this -> SetXY ( $ x , $ origin [ 'y' ] ) ; } $ height = max ( array_column ( $ coords , 'y' ) ) - $ origin [ 'y' ] ; $ width = $ coords [ count ( $ coords ) - 1 ] [ 'x' ] - $ origin [ 'x' ] ; for ( $ i = count ( $ cells ) - 2 ; $ i >= 0 ; $ i -- ) { $ x = $ coords [ $ i ] [ 'x' ] ; $ this -> Line ( $ x , $ origin [ 'y' ] , $ x , $ origin [ 'y' ] + $ height ) ; } $ this -> SetXY ( $ origin [ 'x' ] , $ origin [ 'y' ] ) ; $ this -> Cell ( $ width , $ height , '' , $ row_border , 1 ) ; } | Inserts row of cells |
34,953 | protected function formatBankCode ( ) { $ code = $ this -> title -> assignment -> bank -> code ; $ checksum = Utils \ Validation :: mod11Pre ( $ code ) ; $ digit = $ checksum * 10 % 11 ; if ( $ digit == 10 ) { $ digit = 0 ; } return $ code . '-' . $ digit ; } | Calculates Bank code s check digit and formats it |
34,954 | protected static function formatDigitable ( $ bank_code , $ currency_code , $ check_digit , $ due_factor , $ value , $ free_space ) { $ fields = [ ] ; $ tmp = $ bank_code . $ currency_code . substr ( $ free_space , 0 , 5 ) ; $ tmp .= Utils \ Validation :: mod10 ( $ tmp ) ; $ fields [ ] = implode ( '.' , str_split ( $ tmp , 5 ) ) ; $ tmp = substr ( $ free_space , 5 , 10 ) ; $ fields [ ] = implode ( '.' , str_split ( $ tmp , 5 ) ) . Utils \ Validation :: mod10 ( $ tmp ) ; $ tmp = substr ( $ free_space , 15 , 10 ) ; $ fields [ ] = implode ( '.' , str_split ( $ tmp , 5 ) ) . Utils \ Validation :: mod10 ( $ tmp ) ; $ fields [ ] = $ check_digit ; $ fields [ ] = $ due_factor . $ value ; return implode ( ' ' , $ fields ) ; } | Formats the barcode into a Digitable line |
34,955 | protected function formatOurNumber ( $ mask = false ) { $ our_number = BankInterchange \ Utils :: padNumber ( $ this -> title -> our_number , static :: OUR_NUMBER_LENGTH ) ; return $ our_number . ( $ mask ? '-' : '' ) . $ this -> checkDigitOurNumber ( ) ; } | Calculates Our number s check digit and formats it |
34,956 | protected function billetSetFont ( $ font ) { $ f = static :: FONTS [ $ font ] ; $ this -> SetFont ( $ f [ 0 ] , $ f [ 1 ] , $ f [ 2 ] ) ; if ( count ( $ f ) > 3 ) { $ this -> SetTextColor ( ... $ f [ 3 ] ) ; } } | Allows an easy way to set current font |
34,957 | protected static function checkDigitBarcode ( $ code ) { $ tmp = Utils \ Validation :: mod11 ( $ code ) ; $ cd = ( $ tmp == 0 || $ tmp == 1 || $ tmp == 10 ) ? 1 : 11 - $ tmp ; return $ cd ; } | Calculates the check digit for Barcode |
34,958 | protected function dueFactor ( ) { $ date = \ DateTime :: createFromFormat ( 'Y-m-d' , $ this -> title -> due ) ; $ epoch = new \ DateTime ( '1997-10-07' ) ; if ( $ date && $ date > $ epoch ) { $ diff = substr ( $ date -> diff ( $ epoch ) -> format ( '%a' ) , - 4 ) ; return str_pad ( $ diff , 4 , '0' , STR_PAD_LEFT ) ; } return '0000' ; } | Calculate the amount of days since 1997 - 10 - 07 |
34,959 | protected static function findFile ( $ file , array $ paths ) { if ( $ file === null ) { return null ; } foreach ( $ paths as $ path ) { $ files = glob ( "$path/$file" ) ; if ( ! empty ( $ files ) ) { return $ files [ 0 ] ; } } } | Finds a file in a list of paths |
34,960 | protected function generateBarcode ( $ value ) { $ title = $ this -> title ; $ value = $ title -> currency -> format ( $ value , 'nomask' ) ; $ barcode = [ $ title -> assignment -> bank -> code , $ title -> getCurrencyCode ( ) -> billet , '' , $ this -> dueFactor ( ) , BankInterchange \ Utils :: padNumber ( $ value , 10 ) , $ this -> generateFreeSpace ( ) ] ; $ barcode [ 2 ] = self :: checkDigitBarcode ( implode ( '' , $ barcode ) ) ; return [ 'barcode' => implode ( '' , $ barcode ) , 'digitable' => self :: formatDigitable ( ... $ barcode ) , ] ; } | Generates the barcode data and its digitable line |
34,961 | protected function generateFields ( ) { $ data = $ this -> data ; $ title = $ this -> title ; $ assignment = $ title -> assignment ; $ assignor_person = $ title -> assignment -> assignor -> person ; $ doc_number = BankInterchange \ Utils :: padNumber ( $ title -> doc_number , 10 ) ; $ value = $ this -> formatMoney ( $ data [ 'value' ] ) ; $ demonstrative = $ this -> simpleTemplate ( $ data [ 'demonstrative' ] ?? '' ) ; $ instructions = $ this -> simpleTemplate ( $ data [ 'instructions' ] ?? '' ) ; $ guarantor = ( $ title -> guarantor !== null ) ? $ title -> guarantor -> person -> name . ' ' . $ title -> guarantor -> address -> outputShort ( ) : '' ; $ fields = [ 'accept' => $ title -> accept , 'addition' => $ data [ 'addition' ] ?? '' , 'agency_code' => $ this -> formatAgencyAccount ( true ) , 'amount' => $ data [ 'amount' ] ?? '' , 'assignor' => $ assignor_person -> name , 'bank_use' => $ data [ 'bank_use' ] ?? '' , 'charged' => $ data [ 'charged' ] ?? '' , 'client' => $ title -> client -> person -> name , 'cpf_cnpj' => $ assignor_person -> getFormattedDocument ( ) , 'currency' => $ title -> currency -> symbol , 'date_document' => self :: formatDate ( $ title -> emission ) , 'date_due' => self :: formatDate ( $ title -> due ) , 'date_process' => date ( 'd/m/Y' ) , 'deduction' => $ data [ 'deduction' ] ?? '' , 'demonstrative' => trim ( $ demonstrative ) , 'discount' => $ data [ 'discount' ] ?? '' , 'doc_number' => $ doc_number , 'doc_number_sh' => $ doc_number , 'doc_value' => $ value , 'doc_value=' => $ value , 'doc_valueU' => $ data [ 'doc_valueU' ] ?? '' , 'fine' => $ data [ 'fine' ] ?? '' , 'guarantor' => $ guarantor , 'instructions' => trim ( $ instructions ) , 'kind' => $ title -> kind -> symbol , 'our_number' => $ this -> formatOurNumber ( true ) , 'payment_place' => $ data [ 'payment_place' ] ?? '' , 'wallet' => $ assignment -> wallet -> symbol , ] ; $ result = [ ] ; foreach ( $ fields as $ field_key => $ field_value ) { $ result [ $ field_key ] = [ 'text' => $ this -> dictionary [ $ field_key ] , 'value' => utf8_decode ( $ field_value ) , ] ; } return $ result ; } | Generates fields to be drawn in the billet |
34,962 | protected function parseTemplateTag ( array $ match ) { $ keys = explode ( '->' , $ match [ 1 ] ) ; $ context = 'title' ; if ( $ keys [ 0 ] [ 0 ] === '$' ) { $ context = substr ( array_shift ( $ keys ) , 1 ) ; } $ previous = null ; $ model = $ this -> { $ context } ; foreach ( $ keys as $ key ) { $ previous = $ model ; $ model = ( is_object ( $ model ) ) ? $ model -> { $ key } : $ model [ $ key ] ; } if ( $ context === 'dictionary' ) { $ model = utf8_encode ( $ model ) ; } if ( $ model instanceof Medools \ Model ) { return implode ( '-' , $ model -> getPrimaryKey ( ) ) ; } switch ( $ key ) { case 'billet_tax' : case 'discount1_value' : case 'discount2_value' : case 'discount3_value' : case 'fine_value' : case 'interest_value' : case 'ioc_iof' : case 'rebate' : case 'tax_value' : case 'value_paid' : case 'value' : $ model = $ this -> formatMoney ( $ model ) ; break ; case 'discount1_date' : case 'discount2_date' : case 'discount3_type_date' : case 'due' : case 'emission' : case 'fine_date' : case 'interest_date' : $ model = $ this -> formatDate ( $ model ) ; break ; case 'document' : $ model = $ previous -> getFormattedDocument ( ) ; break ; case 'stamp' : case 'update' : $ model = date ( 'H:i:s d/m/Y' , strtotime ( $ model ) ) ; break ; case 'zipcode' : $ model = Utils \ Validation :: cep ( $ model ) ; break ; } return $ model ; } | Expands a template tag |
34,963 | protected function SetDash ( $ black = null , $ white = null ) { if ( $ black !== null ) { $ s = sprintf ( '[%.3F %.3F] 0 d' , $ black * $ this -> k , $ white * $ this -> k ) ; } else { $ s = '[] 0 d' ; } $ this -> _out ( $ s ) ; } | This extension allows to set a dash pattern and draw dashed lines or rectangles . |
34,964 | public function merge ( Collection $ collection ) { $ this -> requestCount += count ( $ collection ) ; foreach ( $ collection as $ item ) { $ this -> add ( $ item ) ; } } | Merge a collection with the current collection |
34,965 | public function getStatusesUserTimeline ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'statuses/user_timeline' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters . |
34,966 | public function getStatusesHomeTimeline ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'statuses/home_timeline' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow . |
34,967 | public function getStatusesRetweetsOfMe ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'statuses/retweets_of_me' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns the most recent tweets authored by the authenticating user that have been retweeted by others . |
34,968 | public function getStatusesLookup ( array $ parameters = array ( ) , $ multipart = false , $ appOnlyAuth = false ) { return $ this -> get ( 'statuses/lookup' , $ parameters , $ multipart , $ appOnlyAuth ) ; } | Returns fully - hydrated tweet objects for up to 100 tweets per request as specified by comma - separated values passed to the id parameter . |
34,969 | public function retrieveLocale ( UserInterface $ user = null , $ requestLocale = null ) { if ( $ requestLocale && is_string ( $ requestLocale ) ) { return $ requestLocale ; } if ( $ user && $ user -> getLocale ( ) ) { return $ user -> getLocale ( ) ; } return $ this -> fallbackLocale ; } | Function returns the locale that should be used by default . If request - locale is set then use this one . Else return the locale of the user . |
34,970 | public function getModelDisplayName ( ) { $ instance = $ this -> getModelInstance ( ) ; $ display = isset ( $ instance -> display ) ? $ instance -> display : ucfirst ( $ this -> model ) ; return $ display ; } | Get a models display name . |
34,971 | public function getModelInstance ( ) { if ( $ this -> instance !== null ) { return $ this -> instance ; } $ model = $ this -> getModel ( ) ; if ( $ model === false ) { return false ; } $ instance = new $ model ( ) ; return $ instance ; } | Get an instance of a model . |
34,972 | public function modal ( $ type ) { $ trimmed_item = $ this -> trimmedModel ( ) ; $ modalId = $ type . $ trimmed_item . 'Modal' ; $ display = $ this -> getModelDisplayName ( ) ; $ modal = ( object ) [ 'id' => $ modalId , 'title' => ucfirst ( $ type ) . ' ' . $ display , 'url' => $ this -> modalUrl ( $ type ) , ] ; return $ modal ; } | Generate a modal for a model . |
34,973 | private function modalUrl ( $ type ) { switch ( $ type ) { case 'edit' : $ action = 'update' ; break ; default : $ action = $ type ; break ; } return route ( 'crudapi.' . $ action . '.item' , $ this -> model ) ; } | Get the modals url . |
34,974 | public function renderFields ( $ type , $ fields = [ ] ) { if ( empty ( $ fields ) ) { $ fields = $ this -> getFields ( ) ; } $ output = '' ; switch ( $ type ) { case 'form-create' : $ output .= $ this -> fieldHelper -> formCreate ( $ fields ) ; break ; case 'form-edit' : $ output .= $ this -> fieldHelper -> formEdit ( $ fields ) ; break ; case 'table-headings' : $ output .= $ this -> fieldHelper -> tableHeadings ( $ fields ) ; break ; case 'table-content' : $ output .= $ this -> fieldHelper -> tableContent ( $ fields , $ this -> instance ) ; break ; case 'js-var' : foreach ( $ fields as $ f ) { $ output .= 'var ' . $ f . ' = ' . $ this -> instance -> $ f . '; ' ; } break ; case 'js-modal-create' : foreach ( $ fields as $ f ) { $ output .= '"' . $ f . '": $(\'#createItem' . $ f . '\').val(), ' ; } break ; default : break ; } echo $ output ; } | Render fields . |
34,975 | public function set ( ) { if ( ! $ this -> cookiesSet ) { foreach ( $ this -> jar as $ c ) $ c -> set ( ) ; $ this -> cookiesSet = true ; } } | Actually sets cookie in headers . |
34,976 | public function getBuyDetails ( $ itemTypeHref , $ regionDetailsJson ) { if ( ! $ regionDetailsJson ) { return false ; } return $ this -> getBuyOrders ( $ regionDetailsJson -> marketBuyOrders -> href , $ itemTypeHref ) ; } | Gets the buying details for a spefic item from a specific region . |
34,977 | public function getSellDetails ( $ itemTypeHref , $ regionDetailsJson ) { if ( ! $ regionDetailsJson ) { return false ; } return $ this -> getBuyOrders ( $ regionDetailsJson -> marketSellOrders -> href , $ itemTypeHref ) ; } | Gets the selling details for a spefic item from a specific region . |
34,978 | public function searchAllRegionsForOrders ( Array $ regionHrefs , OrderHandler $ orderHandler ) { $ orderHandler -> createRegionRequestsForPool ( $ regionHrefs ) ; $ pool = $ orderHandler -> processMultipleRegions ( ) ; $ promise = $ pool -> promise ( ) ; $ promise -> wait ( ) ; } | Searches All Regions for orders . |
34,979 | public function getOrderResponsesFromRegionSearch ( OrderHandler $ orderHandler , array $ createdRequests ) { $ pool = $ orderHandler -> processMultipleRequests ( $ createdRequests ) ; $ promise = $ pool -> promise ( ) ; $ promise -> wait ( ) ; return $ orderHandler -> getAcceptedResponsesJson ( ) ; } | Gets all the details about the market for a specific item |
34,980 | static public function find ( $ id ) { $ id = ( int ) $ id ; if ( $ model = self :: where ( [ 'id' => $ id ] ) -> first ( ) ) return $ model ; throw new Rails \ ActiveRecord \ Exception \ RecordNotFoundException ( sprintf ( "Couldn't find %s with id = %d." , self :: cn ( ) , $ id ) ) ; } | Find a model by id . |
34,981 | static public function paginate ( $ page , $ per_page ) { $ query = self :: createRelation ( ) ; return $ query -> paginate ( $ page , $ per_page ) ; } | For directly pagination without conditions . |
34,982 | static public function findBySql ( $ sql , array $ params = array ( ) , array $ extra_params = array ( ) ) { $ query = self :: createRelation ( ) ; $ query -> complete_sql ( $ sql , $ params , $ extra_params ) ; return $ query -> take ( ) ; } | When calling this method for pagination how do we tell it the values for page and per_page? That s what extra_params is for ... Although maybe it s not the most elegant solution . extra_params accepts page and per_page they will be sent to Query where they will be parsed . |
34,983 | public function actionIndex ( ) { $ dynamicModel = $ this -> createAuditForm ( ) ; $ auditForm = new AuditForm ; $ auditForm -> addFormValidators ( $ dynamicModel ) ; $ dataProvider = null ; $ arrayDiff = [ ] ; $ module = $ this -> module ; if ( $ dynamicModel -> load ( Yii :: $ app -> request -> get ( ) ) && $ dynamicModel -> validate ( ) ) { $ this -> setCurrentModel ( $ dynamicModel -> table ) ; $ this -> hiddenColumns = array_merge ( $ module -> auditColumns , $ module -> tables [ $ dynamicModel -> table ] [ 'hiddenColumns' ] ) ; $ dataProvider = $ this -> createDataProvider ( $ dynamicModel ) ; $ arrayDiff = [ ] ; $ previousModel = null ; foreach ( $ dataProvider -> getModels ( ) as $ model ) { $ auditId = $ model [ 'audit_id' ] ; $ model = $ this -> unsetHiddenColumns ( $ model ) ; $ arrayDiff [ $ auditId ] = $ this -> createDiff ( $ model , $ dynamicModel , $ previousModel , $ auditId ) ; $ previousModel = $ model ; } } return $ this -> render ( 'index' , [ 'model' => $ dynamicModel , 'dataProvider' => $ dataProvider , 'arrayDiff' => $ arrayDiff , 'fields' => $ auditForm -> getFormFields ( $ dynamicModel ) , 'hiddenColumns' => $ this -> hiddenColumns , ] ) ; } | Displays list of choosen audit table records |
34,984 | public function actionRestore ( ) { $ post = Yii :: $ app -> request -> post ( ) ; $ query = new Query ; $ audit = $ query -> from ( "audits.{$post['table']}" ) -> where ( 'audit_id = :audit_id' , [ 'audit_id' => $ post [ 'audit_id' ] ] ) -> one ( ) ; $ this -> setCurrentModel ( $ post [ 'table' ] ) ; $ criteria = [ ] ; $ model = $ this -> _currentModel ; foreach ( $ model -> primaryKey ( ) as $ primaryKey ) { $ criteria [ $ primaryKey ] = $ audit [ $ primaryKey ] ; } foreach ( $ this -> module -> tables [ $ post [ 'table' ] ] [ 'updateSkip' ] as $ column ) { if ( isset ( $ audit [ $ column ] ) ) { unset ( $ audit [ $ column ] ) ; } } $ record = $ model -> findOne ( $ criteria ) ; $ record -> setAttributes ( $ audit , false ) ; if ( $ record -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'app' , 'Record has been restored.' ) ) ; } else { Yii :: $ app -> session -> setFlash ( 'danger' , Yii :: t ( 'app' , 'Failed to restore record.' ) ) ; } return $ this -> redirect ( Yii :: $ app -> request -> referrer ) ; } | Restores record from audit |
34,985 | public function setCurrentModel ( $ table ) { if ( ! isset ( $ this -> module -> tables [ $ table ] [ 'model' ] ) ) { throw new InvalidConfigException ( Yii :: t ( 'app' , 'Table model has to be set in config file' ) ) ; } $ modelClass = $ this -> module -> tables [ $ table ] [ 'model' ] ; $ this -> _currentModel = new $ modelClass ; } | Sets to _currentModel property current model instance from configuration file |
34,986 | public function getRelations ( & $ query , $ table ) { $ relations = [ ] ; $ columns = [ ] ; $ module = $ this -> module ; if ( isset ( $ module -> tables [ $ table ] [ 'relations' ] ) ) { $ relations = $ module -> tables [ $ table ] [ 'relations' ] ; } foreach ( $ relations as $ relation => $ relationParams ) { $ query -> join ( $ relationParams [ 'type' ] , $ relationParams [ 'table' ] . ' ' . $ relationParams [ 'alias' ] , $ relationParams [ 'on' ] ) ; $ columns [ ] = $ relationParams [ 'alias' ] . '.' . $ relationParams [ 'representive_columns' ] . ' ' . $ relation ; } return $ columns ; } | Adds join statement to basic query from relations declared in config files |
34,987 | public function createDiff ( $ model , $ modelForm , $ previousModel , $ auditId ) { if ( $ previousModel ) { $ diff = array_diff_assoc ( $ model , $ previousModel ) ; } else { $ prev = $ this -> getPrevious ( $ modelForm , $ auditId ) ; if ( ! empty ( $ prev ) ) { $ diff = array_diff_assoc ( $ model , $ prev ) ; } else { $ diff = $ model ; } } $ arrayDiff = implode ( '; ' , array_map ( function ( $ v , $ k ) { return $ k . '=' . $ v ; } , $ diff , $ this -> getColumnsLabel ( array_keys ( $ diff ) , $ modelForm -> table ) ) ) ; return $ arrayDiff ; } | Gets differences between current and previous dataProvider element |
34,988 | public function getColumnsLabel ( $ columns , $ table ) { $ model = $ this -> _currentModel ; $ module = $ this -> module ; $ attributeLabels = $ model -> attributeLabels ( ) ; $ relations = $ module -> tables [ $ table ] [ 'relations' ] ; $ columnsLabel = [ ] ; foreach ( $ columns as $ attribute ) { if ( isset ( $ attributeLabels [ $ attribute ] ) ) { $ columnsLabel [ ] = $ attributeLabels [ $ attribute ] ; } elseif ( isset ( $ relations [ $ attribute ] [ 'label' ] ) ) { $ columnsLabel [ ] = $ relations [ $ attribute ] [ 'label' ] ; } else { $ columnsLabel [ ] = $ attribute ; } } return $ columnsLabel ; } | Gets attributes label from current model |
34,989 | public function getColumnLabel ( $ column , $ table ) { $ model = $ this -> _currentModel ; $ module = $ this -> module ; if ( isset ( $ model -> attributeLabels ( ) [ $ column ] ) ) { return $ model -> attributeLabels ( ) [ $ column ] ; } elseif ( $ module -> tables [ $ table ] [ 'relations' ] [ $ column ] [ 'label' ] ) { return $ module -> tables [ $ table ] [ 'relations' ] [ $ column ] [ 'label' ] ; } else { return $ column ; } } | Gets attribute label from current model |
34,990 | public function prepareCondition ( & $ query , $ modelForm ) { foreach ( $ modelForm -> attributes ( ) as $ attribute ) { if ( $ attribute === 'table' || is_null ( $ modelForm [ $ attribute ] ) ) { continue ; } $ filterConfig = Yii :: $ app -> controller -> module -> filters [ $ attribute ] ; $ query -> andWhere ( "{$filterConfig['attribute']} {$filterConfig['criteria']['operator']} :{$attribute}" , [ $ attribute => $ modelForm [ $ attribute ] , ] ) ; } } | Prepares where condition |
34,991 | public function getPrevious ( $ modelForm , $ auditId ) { $ query = new Query ; $ this -> prepareCondition ( $ query , $ modelForm ) ; $ query -> andWhere ( 'audit_id < :auditId' , [ 'auditId' => $ auditId ] ) ; $ query -> orderBy ( 'audit_id desc' ) ; $ columns = $ this -> getRelations ( $ query , $ modelForm -> table ) ; $ columns [ ] = 'audit.*' ; $ query -> select ( join ( ', ' , $ columns ) ) -> from ( "audits.{$modelForm->table} audit" ) ; $ row = $ query -> one ( ) ; return $ this -> unsetHiddenColumns ( $ row ) ; } | Gets previous element from database |
34,992 | public function unsetHiddenColumns ( $ model ) { foreach ( $ this -> hiddenColumns as $ column ) { if ( isset ( $ model [ $ column ] ) ) { unset ( $ model [ $ column ] ) ; } } return $ model ; } | Unset all columns from dataProvider element that shouldn t be displayed |
34,993 | public function createAuditForm ( ) { return new \ yii \ base \ DynamicModel ( array_merge ( [ 'table' ] , array_keys ( Yii :: $ app -> controller -> module -> filters ) ) ) ; } | Creates dynamic audit form |
34,994 | public function create ( OptionsBag $ options ) { $ connections = $ this -> parse ( $ options ) ; $ class = $ this -> class ; $ memcache = new $ class ( ) ; return $ this -> configure ( $ memcache , $ connections ) ; } | Creates a Memcache instance from the session options . |
34,995 | private function renderIncludeForContent ( Content $ content , $ fileName , $ parameters ) { $ directory = dirname ( $ fileName ) ; $ baseName = basename ( $ fileName ) ; $ realContentPath = realpath ( $ this -> contentPath ) ; if ( $ directory == '.' ) { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . dirname ( $ content -> getPath ( ) ) ) ; } elseif ( $ directory [ 0 ] == '.' ) { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . dirname ( $ content -> getPath ( ) ) . DIRECTORY_SEPARATOR . $ directory ) ; } else { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . $ directory ) ; } if ( strcmp ( $ realContentPath , $ realDirectory ) <= 0 ) { $ fullPath = $ realDirectory . DIRECTORY_SEPARATOR . $ baseName ; if ( file_exists ( $ fullPath ) ) { $ type = pathinfo ( $ fullPath , PATHINFO_EXTENSION ) ; return $ this -> render ( new Content ( $ type , substr ( $ fullPath , strlen ( $ realContentPath ) ) ) , $ parameters ) ; } throw new \ InvalidArgumentException ( "Include file [$fullPath] does not exist." ) ; } throw new \ InvalidArgumentException ( $ content -> getPath ( ) . "Unable to render [$realDirectory/$fileName]. It is outside of allowed content root path [$realContentPath]." ) ; } | Render a file to include |
34,996 | public function render ( Content $ content , $ parameters ) { if ( ! array_key_exists ( $ content -> getType ( ) , $ this -> filters ) ) { throw new RenderException ( 'Content filter [' . $ content -> getType ( ) . '] not found. Available filters: ' . implode ( ', ' , array_keys ( $ this -> filters ) ) . '.' ) ; } $ renderedContent = $ this -> filters [ $ content -> getType ( ) ] -> render ( $ content , $ parameters ) ; if ( preg_match_all ( '/\{\{\s*(include)\s+([a-z0-9\_\-\.\/]+)\s*\}\}/i' , $ renderedContent , $ matches ) ) { $ matchesCount = count ( $ matches [ 0 ] ) ; for ( $ i = 0 ; $ i < $ matchesCount ; $ i ++ ) { $ includedContent = $ this -> renderIncludeForContent ( $ content , $ matches [ 2 ] [ $ i ] , $ parameters ) ; $ renderedContent = str_replace ( $ matches [ 0 ] [ $ i ] , $ includedContent , $ renderedContent ) ; } } return $ renderedContent ; } | Render Content via a filter |
34,997 | protected function createPasswordResetsTable ( ) { Schema :: create ( 'password_resets' , function ( Blueprint $ table ) { $ table -> string ( 'email' ) -> index ( ) ; $ table -> string ( 'token' ) -> index ( ) ; $ table -> timestamp ( 'created_at' ) ; } ) ; } | Create password_resets table . |
34,998 | public function add ( $ sku , $ name , Money $ price , Closure $ action = null ) { $ product = new Product ( $ sku , $ name , $ price , $ this -> rate ) ; if ( $ action ) { $ product -> action ( $ action ) ; } $ this -> products -> add ( $ sku , $ product ) ; } | Add a product to the basket |
34,999 | public function update ( $ sku , Closure $ action ) { $ product = $ this -> pick ( $ sku ) ; $ product -> action ( $ action ) ; } | Update a product that is already in the basket |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.