idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
51,200
public function channelFollows ( $ channel , $ options = [ ] ) { $ availableOptions = [ 'limit' , 'offset' , 'direction' ] ; return $ this -> sendRequest ( 'GET' , 'channels/' . $ channel . '/follows' , false , $ options , $ availableOptions ) ; }
Get channel s list of following users .
51,201
public function userFollowsChannels ( $ user , $ options = [ ] ) { $ availableOptions = [ 'limit' , 'offset' , 'direction' , 'sortby' ] ; return $ this -> sendRequest ( 'GET' , 'users/' . $ user . '/follows/channels' , false , $ options , $ availableOptions ) ; }
Get list of who the user is following .
51,202
public function authenticatedUserFollowsChannel ( $ user , $ channel , $ options = [ ] , $ token = null ) { $ availableOptions = [ 'notifications' ] ; return $ this -> sendRequest ( 'PUT' , 'users/' . $ user . '/follows/channels/' . $ channel , $ this -> getToken ( $ token ) , $ options , $ availableOptions ) ; }
Follow a channel .
51,203
public function authenticatedUserUnfollowsChannel ( $ user , $ channel , $ token = null ) { return $ this -> sendRequest ( 'DELETE' , 'users/' . $ user . '/follows/channels/' . $ channel , $ this -> getToken ( $ token ) ) ; }
Unfollow a channel .
51,204
public function blocks ( $ user , $ token = null ) { return $ this -> sendRequest ( 'GET' , 'users/' . $ user . '/blocks' , $ this -> getToken ( $ token ) ) ; }
Get user s block list .
51,205
public function putBlock ( $ user , $ target , $ token = null ) { return $ this -> sendRequest ( 'PUT' , 'users/' . $ user . '/blocks/' . $ target , $ this -> getToken ( $ token ) ) ; }
Add target to user s block list .
51,206
public function deleteBlock ( $ user , $ target , $ token = null ) { return $ this -> sendRequest ( 'DELETE' , 'users/' . $ user . '/blocks/' . $ target , $ this -> getToken ( $ token ) ) ; }
Delete target from user s block list .
51,207
public function channelVideos ( $ channel , $ options = [ ] ) { $ availableOptions = [ 'limit' , 'offset' , 'broadcasts' , 'hls' ] ; return $ this -> sendRequest ( 'GET' , 'channels/' . $ channel . '/videos' , false , $ options , $ availableOptions ) ; }
Get list of video objects belonging to channel .
51,208
public function addButton ( $ label = null , $ options = array ( ) ) { $ but = $ this -> add ( 'Button' , $ options ) ; $ but -> set ( $ label ) ; if ( $ this -> vertical ) { $ but -> js ( true ) -> css ( 'margin-top' , '-3px' ) ; } return $ but ; }
Add button to buttonset .
51,209
public function addButton ( $ label , $ class = 'Button' ) { if ( ! $ this -> buttonset ) { $ this -> buttonset = $ this -> add ( 'ButtonSet' , null , 'grid_buttons' ) -> setClass ( 'atk-actions' ) ; } return $ this -> buttonset -> add ( $ class , 'gbtn' . count ( $ this -> elements ) ) -> set ( $ label ) ; }
Adds button .
51,210
public function removeColumn ( $ name ) { unset ( $ this -> columns [ $ name ] ) ; if ( $ this -> last_column == $ name ) { $ this -> last_column = null ; } return $ this ; }
Remove column from grid .
51,211
public function setFormatter ( $ field , $ formatter , $ options = null ) { if ( is_array ( $ field ) ) { foreach ( $ field as $ f ) { $ this -> setFormatter ( $ f , $ formatter , $ options ) ; } return $ this ; } if ( ! isset ( $ this -> columns [ $ field ] ) ) { throw new BaseException ( 'Cannot format nonexistant field ' . $ field ) ; } $ this -> columns [ $ field ] [ 'type' ] = '' ; $ this -> addFormatter ( $ field , $ formatter , $ options ) ; $ this -> last_column = $ field ; return $ this ; }
Replace current formatter for field .
51,212
public function addFormatter ( $ field , $ formatter , $ options = null ) { if ( is_array ( $ field ) ) { foreach ( $ field as $ f ) { $ this -> setFormatter ( $ f , $ formatter , $ options ) ; } return $ this ; } if ( ! isset ( $ this -> columns [ $ field ] ) ) { throw new BaseException ( 'Cannot format nonexistant field ' . $ field ) ; } if ( $ formatter instanceof Closure ) { $ m_name = uniqid ( ) ; $ this -> addMethod ( 'format_' . $ m_name , $ formatter ) ; $ formatter = $ m_name ; } if ( $ this -> columns [ $ field ] [ 'type' ] ) { $ this -> columns [ $ field ] [ 'type' ] .= ',' . $ formatter ; } else { $ this -> columns [ $ field ] [ 'type' ] = $ formatter ; } if ( $ options ) { $ this -> columns [ $ field ] = array_merge ( $ this -> columns [ $ field ] , $ options ) ; } $ descr = $ this -> columns [ $ field ] ; if ( strpos ( $ formatter , '\\' ) || strpos ( $ formatter , '/' ) ) { if ( ! $ this -> elements [ $ formatter . '_' . $ field ] ) { $ addon = $ this -> app -> normalizeClassName ( $ formatter , 'Controller_Grid_Format' ) ; $ this -> elements [ $ formatter . '_' . $ field ] = $ this -> add ( $ addon , $ formatter ) ; } $ addon = $ this -> getElement ( $ formatter . '_' . $ field ) ; if ( ! $ addon instanceof Controller_Grid_Format ) { throw $ this -> exception ( 'Grid formatter class should extend Controller_Grid_Format class' ) -> addMoreInfo ( 'formater' , $ formatter ) ; } $ addon -> initField ( $ field , $ descr ) ; return $ addon ; } elseif ( $ this -> hasMethod ( $ m = 'init_' . $ formatter ) ) { $ this -> $ m ( $ field , $ descr ) ; } return $ this ; }
Add extra formatter to existing field .
51,213
public function renderRows ( ) { $ this -> precacheTemplate ( ) ; parent :: renderRows ( ) ; if ( $ this -> total_rows ) { $ this -> template -> del ( 'not_found' ) ; } elseif ( $ this -> no_records_message ) { $ this -> template -> del ( 'header' ) ; $ this -> template -> set ( 'not_found_message' , $ this -> no_records_message ) ; } }
Render grid rows .
51,214
public function formatRow ( ) { parent :: formatRow ( ) ; if ( empty ( $ this -> columns ) ) { throw $ this -> exception ( 'No columns defined for grid' ) ; } foreach ( $ this -> columns as $ field => $ column ) { if ( ( is_array ( $ this -> current_row ) || $ this -> current_row instanceof ArrayAccess ) && array_key_exists ( $ field , $ this -> current_row ) ) { $ this -> current_row [ $ field . '_original' ] = $ this -> current_row [ $ field ] ; } if ( $ this -> model && $ f = $ this -> model -> hasElement ( $ field ) ) { $ v = $ this -> current_row [ $ field ] ; if ( $ this -> model instanceof \ atk4 \ data \ Model ) { if ( isset ( $ f -> enum ) && $ values = $ f -> enum ) { $ this -> current_row [ $ field ] = isset ( $ f -> ui [ 'valueList' ] [ $ v ] ) ? $ f -> ui [ 'valueList' ] [ $ v ] : $ values [ $ v ] ; } } else { if ( $ f -> type ( ) !== 'boolean' && $ values = $ f -> listData ( ) ) { $ this -> current_row [ $ field ] = $ values [ $ v ] ; } } } $ this -> executeFormatters ( $ field , $ column , 'format_' ) ; $ this -> applyTDParams ( $ field ) ; } }
Format grid row .
51,215
public function executeFormatters ( $ field , $ column , $ formatter_prefix = 'format_' , $ silent = false ) { if ( is_object ( $ column [ 'type' ] ) && $ column [ 'type' ] instanceof Closure ) { return $ this -> current_row [ $ field ] = call_user_func ( $ column [ 'type' ] , $ this -> current ) ; } $ formatters = explode ( ',' , $ column [ 'type' ] ) ; foreach ( $ formatters as $ formatter ) { if ( ! $ formatter ) { continue ; } if ( $ this -> hasMethod ( $ m = $ formatter_prefix . $ formatter ) ) { $ this -> $ m ( $ field , $ column ) ; } elseif ( strpos ( $ formatter , '\\' ) || strpos ( $ formatter , '/' ) ) { $ c = $ this -> getElement ( $ formatter . '_' . $ field ) ; $ c -> formatField ( $ field , $ column ) ; } else { if ( ! $ silent ) { throw new BaseException ( 'Grid does not know how to format type: ' . $ formatter ) ; } } } }
Format field value using appropriate formatters .
51,216
public function allowPage ( $ page ) { if ( is_array ( $ page ) ) { foreach ( $ page as $ p ) { $ this -> allowPage ( $ p ) ; } return $ this ; } $ this -> allowed_pages [ ] = $ page ; return $ this ; }
Specify page or array of pages which will exclude authentication . Add your registration page here or page containing terms and conditions .
51,217
public function isPageAllowed ( $ page ) { if ( $ this -> hook ( 'isPageAllowed' , array ( $ page ) ) === true ) { return true ; } return in_array ( $ page , $ this -> allowed_pages ) || in_array ( str_replace ( '_' , '/' , $ page ) , $ this -> allowed_pages ) ; }
Verifies if the specified page is allowed to be accessed without authentication .
51,218
public function encryptPassword ( $ password , $ salt = null ) { if ( ! is_string ( $ this -> password_encryption ) && is_callable ( $ this -> password_encryption ) ) { $ e = $ this -> password_encryption ; return $ e ( $ password , $ salt ) ; } if ( $ this -> password_encryption ) { $ this -> debug ( "Encrypting password: '$password' with " . $ this -> password_encryption . ' salt=' . $ salt ) ; } switch ( $ this -> password_encryption ) { case null : return $ password ; case 'php' : return password_hash ( $ password , $ this -> hash_algo , $ this -> hash_options ) ; case 'sha256/salt' : if ( $ salt === null ) { throw $ this -> exception ( 'sha256 requires salt (2nd argument to encryptPassword and is normaly an email)' ) ; } $ key = $ this -> app -> getConfig ( 'auth/key' , $ this -> app -> name ) ; if ( $ this -> password_encryption ) { $ this -> debug ( 'Using key ' . $ key ) ; } return hash_hmac ( 'sha256' , $ password . $ salt , $ key ) ; case 'sha1' : return sha1 ( $ password ) ; case 'md5' : return md5 ( $ password ) ; case 'rot13' : return str_rot13 ( $ password ) ; default : throw $ this -> exception ( 'No such encryption method' ) -> addMoreInfo ( 'encryption' , $ this -> password_encryption ) ; } }
Manually encrypt password
51,219
public function addInfo ( $ key , $ val = null ) { if ( is_array ( $ key ) ) { foreach ( $ key as $ a => $ b ) { $ this -> addInfo ( $ a , $ b ) ; } return $ this ; } $ this -> debug ( "Gathered info: $key=$val" ) ; $ this -> info [ $ key ] = $ val ; return $ this ; }
Add additional info to be stored in user session .
51,220
public function memorizeURL ( ) { if ( $ this -> app -> page !== 'index' && ! $ this -> recall ( 'page' , false ) ) { $ this -> memorize ( 'page' , $ this -> app -> page ) ; $ g = $ _GET ; unset ( $ g [ 'page' ] ) ; $ this -> memorize ( 'args' , $ g ) ; } }
Memorize current URL . Called when the first unsuccessful check is executed .
51,221
public function getURL ( ) { $ p = $ this -> recall ( 'page' ) ; if ( $ p == 'login' ) { return $ this -> app -> url ( '/' ) ; } $ url = $ this -> app -> url ( $ p , $ this -> recall ( 'args' , null ) ) ; $ this -> forget ( 'page' ) ; $ this -> forget ( 'args' ) ; return $ url ; }
Return originally requested URL .
51,222
public function memorizeModel ( ) { if ( ! $ this -> model -> loaded ( ) ) { throw $ this -> exception ( 'Authentication failure' , 'AccessDenied' ) ; } $ this -> model [ 'password' ] = null ; unset ( $ this -> model -> dirty [ 'password' ] ) ; $ this -> info = $ this -> model -> get ( ) ; $ this -> info [ 'username' ] = $ this -> info [ $ this -> login_field ] ; if ( $ this -> app -> hasMethod ( 'initializeSession' ) || session_id ( ) ) { $ this -> memorize ( 'info' , $ this -> info ) ; $ this -> memorize ( 'class' , get_class ( $ this -> model ) ) ; $ this -> memorize ( 'id' , $ this -> model -> id ) ; } $ this -> hook ( 'login' ) ; }
Store model in session data so that it can be retrieved faster .
51,223
public function loginBy ( $ field , $ value ) { $ this -> model -> tryLoadBy ( $ field , $ value ) ; $ this -> memorizeModel ( ) ; return $ this ; }
Manually Log in with specified condition .
51,224
public function login ( $ user ) { if ( is_object ( $ user ) ) { if ( ! $ this -> model ) { throw $ this -> exception ( 'Auth Model should be set' ) ; } $ c = get_class ( $ this -> model ) ; if ( ! $ user instanceof $ c ) { throw $ this -> exception ( 'Specified model with incompatible class' ) -> addMoreInfo ( 'required' , $ c ) -> addMoreInfo ( 'supplied' , get_class ( $ user ) ) ; } $ this -> model = $ user ; $ this -> memorizeModel ( ) ; return $ this ; } return $ this -> loginBy ( $ this -> login_field , $ user ) ; }
Manually Log in as specified users by using login name .
51,225
public function logout ( ) { $ this -> hook ( 'logout' ) ; $ this -> model -> unload ( ) ; $ this -> forget ( 'info' ) ; $ this -> forget ( 'id' ) ; setcookie ( session_name ( ) , '' , time ( ) - 42000 , '/' ) ; if ( session_status ( ) === PHP_SESSION_ACTIVE ) { session_destroy ( ) ; } $ this -> info = false ; return $ this ; }
Manually log out user .
51,226
public function setModel ( $ model , $ actual_fields = null ) { parent :: setModel ( $ model ) ; if ( $ this -> model instanceof \ atk4 \ data \ Model ) { if ( isset ( $ this -> default_controller ) ) { $ this -> default_controller = str_replace ( 'MVC' , 'AD' , $ this -> default_controller ) ; } else { $ this -> default_controller = 'ADView' ; } } if ( isset ( $ this -> model -> default_controller ) ) { $ this -> controller = $ this -> model -> setController ( $ this -> model -> default_controller ) ; } if ( $ this -> default_controller ) { $ this -> controller = $ this -> setController ( $ this -> default_controller ) ; } if ( $ this -> controller ) { if ( $ this -> controller -> hasMethod ( 'setActualFields' ) ) { $ this -> controller -> setActualFields ( $ actual_fields ) ; } if ( $ this -> controller -> hasMethod ( '_bindView' ) ) { $ this -> controller -> _bindView ( ) ; } } if ( $ this -> model instanceof SQL_Model ) { $ this -> dq = $ this -> model -> _dsql ( ) ; } $ this -> hook ( 'set-model' , [ $ this -> model , $ actual_fields ] ) ; return $ this -> model ; }
Associate view with a model . Additionally may initialize a controller which would copy fields from the model into the View .
51,227
public function getHTML ( $ destroy = true , $ execute_js = true ) { $ this -> addHook ( 'output' , array ( $ this , '_tsBuffer' ) ) ; $ this -> recursiveRender ( ) ; $ this -> removeHook ( 'output' , array ( $ this , '_tsBuffer' ) ) ; $ ret = $ this -> _tsBuffer ; $ this -> _tsBuffer = '' ; if ( $ execute_js && isset ( $ this -> app -> jquery ) ) { $ this -> app -> jquery -> getJS ( $ this ) ; } if ( $ destroy ) { $ this -> destroy ( ) ; } return $ ret ; }
Converting View into string will render recursively and produce HTML . If argument is passed JavaScript will be added into on_ready section of your document like when rendered normally . Note that you might require to destroy object if you don t want it s HTML to appear normally .
51,228
public function initializeTemplate ( $ template_spot = null , $ template_branch = null ) { if ( $ template_spot === null ) { $ template_spot = $ this -> defaultSpot ( ) ; } $ this -> spot = $ template_spot ; if ( @ $ this -> owner -> template && ! $ this -> owner -> template -> is_set ( $ this -> spot ) ) { throw $ this -> owner -> template -> exception ( 'Spot is not found in owner\'s template' ) -> addMoreInfo ( 'spot' , $ this -> spot ) ; } if ( ! isset ( $ template_branch ) ) { $ template_branch = $ this -> defaultTemplate ( ) ; } if ( isset ( $ template_branch ) ) { if ( is_object ( $ template_branch ) ) { $ this -> template = $ template_branch ; } elseif ( is_array ( $ template_branch ) ) { if ( is_object ( $ template_branch [ 0 ] ) ) { $ this -> template = $ template_branch [ 0 ] ; } else { $ this -> template = $ this -> app -> add ( 'Template' ) ; $ this -> template -> loadTemplate ( $ template_branch [ 0 ] ) ; } $ this -> template = $ this -> template -> cloneRegion ( isset ( $ template_branch [ 1 ] ) ? $ template_branch [ 1 ] : '_top' ) ; } else { if ( isset ( $ this -> owner -> template ) ) { $ this -> template = $ this -> owner -> template -> cloneRegion ( $ template_branch ) ; } else { $ this -> template = $ this -> add ( 'Template' ) ; } } $ this -> template -> owner = $ this ; } if ( $ this -> owner && ( isset ( $ this -> owner -> template ) ) && ( ! empty ( $ this -> owner -> template ) ) ) { $ this -> owner -> template -> del ( $ this -> spot ) ; } if ( $ this -> template ) { $ this -> template -> trySet ( '_name' , $ this -> getJSID ( ) ) ; } }
Called automatically during init for template initalization .
51,229
public function modelRender ( ) { if ( $ this -> model instanceof \ atk4 \ data \ Model ) { if ( $ this -> controller instanceof Controller_ADView ) { return ; } $ data = $ this -> model -> persistence -> typecastSaveRow ( $ this -> model , $ this -> model -> get ( ) ) ; } else { $ data = $ this -> model -> get ( ) ; } $ this -> template -> set ( $ data ) ; }
When model is specified for a view values of the model is inserted inside the template if corresponding tags exist . This is used as default values and filled out before the actual render kicks in .
51,230
public function moveJStoParent ( ) { $ this -> owner -> js = array_merge_recursive ( $ this -> owner -> js , $ this -> js ) ; }
Append our chains to owner s chains . JS chains bubble up to app which plugs them into template . If the object is being cut then only relevant chains will be outputed .
51,231
public function output ( $ txt ) { if ( ! is_null ( $ this -> hook ( 'output' , array ( $ txt ) ) ) ) { if ( isset ( $ this -> owner -> template ) && ! empty ( $ this -> owner -> template ) ) { $ this -> owner -> template -> append ( $ this -> spot , $ txt , false ) ; } elseif ( $ this -> owner instanceof App_CLI ) { echo $ txt ; } } }
Low level output function which append s to the parent object s template . For normal objects you simply need to specify a suitable template .
51,232
public function init ( ) { parent :: init ( ) ; $ that = $ this ; if ( $ this -> owner instanceof Controller_Validator ) { $ this -> owner -> addHook ( 'extraRules' , array ( $ this , 'extraRules' ) ) ; return ; } if ( ( $ this -> owner instanceof \ Model || $ this -> owner instanceof \ Form ) && ! $ this -> owner -> hasMethod ( 'is' ) ) { $ this -> source = $ this -> owner ; $ this -> owner -> validator = $ this ; $ this -> source -> addMethod ( 'is' , function ( $ m ) use ( $ that ) { $ args = func_get_args ( ) ; array_shift ( $ args ) ; call_user_func_array ( array ( $ that , 'is' ) , $ args ) ; $ that -> on ( 'beforeSave' , null , true ) ; return $ m ; } ) ; } }
{{{ Initialization method
51,233
public function is ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) == 1 && is_array ( $ args [ 0 ] ) ) { foreach ( $ args [ 0 ] as $ ruleset ) { if ( ! is_array ( $ ruleset ) ) { $ ruleset = array ( $ ruleset ) ; } call_user_func_array ( array ( $ this , 'is' ) , $ ruleset ) ; } return $ this ; } if ( count ( $ args ) == 1 ) { list ( $ field_definition , $ rules ) = $ this -> normalizeRules ( $ args [ 0 ] ) ; } else { $ rules = $ args ; $ field_definition = array_shift ( $ rules ) ; } $ fields = $ this -> expandFieldDefinition ( $ field_definition , $ rules ) ; foreach ( $ fields as $ field ) { $ this -> rules [ $ field ] [ ] = $ rules ; } return $ this ; }
This method will go through all the rules you specify expand and normalize them and assign into array indexed by field name .
51,234
public function applyRulesets ( ) { $ fields = $ this -> getActualFields ( ) ; foreach ( $ fields as $ field ) { $ rulesets = $ this -> getRules ( $ field ) ; $ this -> active_field = $ field ; $ this -> prefix = '' ; $ this -> caption = '' ; foreach ( $ rulesets as $ rules ) { $ this -> applyRules ( $ field , $ rules ) ; } } return $ this ; }
Go through the list of defined rules and call the corresponding filters and convertors .
51,235
public function pushRule ( ) { $ args = func_get_args ( ) ; foreach ( array_reverse ( $ args ) as $ arg ) { array_unshift ( $ this -> current_ruleset , $ arg ) ; } }
Adds new rule into a rule - set which will be executed next . You can specify single or multiple rules this method accepts variable arguments .
51,236
public function fail ( ) { $ args = func_get_args ( ) ; $ str = ucfirst ( $ this -> prefix . ( $ this -> caption ? : str_replace ( '_' , ' ' , $ this -> active_field ) ) . ' ' . lcfirst ( array_shift ( $ args ) ) ) ; if ( count ( $ args ) > 0 ) { $ n = 1 ; foreach ( $ args as $ arg ) { $ tag = sprintf ( '{{arg%s}}' , $ n ) ; $ str = str_replace ( $ tag , $ arg , $ str ) ; ++ $ n ; } } $ e = $ this -> exception ( ( string ) ( $ this -> custom_error ? : $ str ) ) ; throw $ e -> setField ( $ this -> active_field ) ; }
{{{ Methods which are called by the rules
51,237
public function applyRules ( $ field , $ ruleset ) { $ acc = $ this -> acc ; $ crs = $ this -> current_ruleset ; $ this -> bail_out = false ; $ this -> acc = $ this -> get ( $ field ) ; $ this -> current_ruleset = $ ruleset ; while ( ! is_null ( $ rule = $ this -> pullRule ( ) ) ) { $ this -> cast = false ; $ this -> custom_error = null ; if ( $ rule == 'required' ) { $ is_required = true ; } $ tmp = null ; $ this -> consumed = array ( $ rule ) ; try { if ( ( is_object ( $ rule ) || is_array ( $ rule ) ) && is_callable ( $ rule ) ) { $ tmp = $ rule ( $ this , $ this -> acc , $ field ) ; } else { if ( substr ( $ rule , 0 , 3 ) == 'to_' ) { if ( ! $ this -> hasMethod ( 'rule_' . $ rule ) ) { $ rule = substr ( $ rule , 3 ) ; } $ this -> cast = true ; } if ( $ rule === '' ) { if ( $ this -> cast ) { $ this -> set ( $ field , $ this -> acc ) ; } continue ; } $ rule = $ this -> resolveRuleAlias ( $ rule ) ; $ tmp = $ this -> { 'rule_' . $ rule } ( $ this -> acc , $ field ) ; } if ( $ this -> debug ) { echo "<font color=blue>rule_$rule({$this->acc}," . implode ( ',' , $ this -> consumed ) . ")=$tmp</font><br/>" ; } if ( ! is_null ( $ tmp ) ) { $ this -> acc = $ tmp ; } if ( $ this -> cast ) { $ this -> set ( $ field , $ tmp ) ; } if ( $ this -> bail_out ) { break ; } } catch ( \ Exception_ValidityCheck $ e ) { if ( $ this -> debug ) { echo "<font color=red>rule_$rule({$this->acc}," . implode ( ',' , $ this -> consumed ) . ') failed</font><br/>' ; } $ this -> acc = $ acc ; $ this -> current_ruleset = $ crs ; throw $ e -> setField ( $ field ) -> addMoreInfo ( 'val' , $ this -> acc ) -> addMoreInfo ( 'rule' , $ rule ) ; } } $ this -> acc = $ acc ; $ this -> current_ruleset = $ crs ; }
This is the main body for rule processing .
51,238
public function defaultTemplate ( ) { if ( isset ( $ _GET [ 'cut_page' ] ) ) { return array ( 'page' ) ; } $ page_name = 'page/' . strtolower ( $ this -> short_name ) ; try { $ p = $ this -> app -> locate ( 'template' , $ page_name . '.html' ) ; } catch ( Exception_PathFinder $ e ) { return array ( 'page' ) ; } return array ( $ page_name , '_top' ) ; }
Set default template
51,239
public function getBody ( ) { if ( is_null ( $ this -> body ) ) { $ this -> set ( 'body' , '' ) ; $ this -> app -> logger -> logLine ( 'Email body is null: ' . $ this -> get ( 'from' ) . ' >> ' . date ( $ this -> app -> getConfig ( 'locale/timestamp' , 'Y-m-d H:i:s' ) . "\n" ) , null , 'error' ) ; } $ this -> setBody ( is_object ( $ this -> body ) ? $ this -> body -> render ( ) : $ this -> body ) ; if ( isset ( $ this -> mime [ 'text' ] ) ) { $ this -> mime [ 'text' ] [ 'content' ] .= $ this -> getSign ( ) ; } if ( isset ( $ this -> mime [ 'html' ] ) ) { $ this -> mime [ 'html' ] [ 'content' ] .= $ this -> getSign ( ) ; } $ result = '' ; if ( count ( $ this -> mime ) == 0 ) { $ result .= $ this -> plain_text ; } foreach ( $ this -> mime as $ name => $ att ) { list ( $ type ) = explode ( ';' , $ att [ 'type' ] ) ; switch ( $ type ) { case 'text/plain' : if ( count ( $ this -> mime ) > 0 ) { $ result .= "\n\n--" . $ this -> getBoundary ( ) . "\n" . 'Content-Type: ' . $ att [ 'type' ] . '; ' ; } break ; case 'text/html' : if ( count ( $ this -> mime ) > 0 ) { $ result .= "\n\n--" . $ this -> getBoundary ( ) . "\n" . 'Content-Type: ' . $ att [ 'type' ] . '; ' ; } $ result .= 'Content-Transfer-Encoding: 8bit' ; $ att [ 'content' ] = rtrim ( wordwrap ( $ att [ 'content' ] ) ) ; break ; } if ( isset ( $ att [ 'attachment' ] ) ) { $ att [ 'content' ] = rtrim ( chunk_split ( $ att [ 'content' ] ) ) ; $ result .= "name=$name\n" . "Content-transfer-encoding: base64\nContent-Disposition: attachment;" ; } $ result .= "\n\n" ; $ result .= $ att [ 'content' ] ; } if ( count ( $ this -> mime ) > 0 ) { $ result .= "\n--" . $ this -> getBoundary ( ) . "\n" ; } return ltrim ( $ result ) ; }
Returns the rendered mail body sign included .
51,240
public function attachFile ( $ file , $ type , $ name = null , $ asstring = false ) { $ content = $ asstring ? $ file : file_get_contents ( $ file ) ; if ( ! $ content ) { throw new Exception_TMail ( 'Error reading attachment: ' . ( $ asstring ? $ name : $ file ) ) ; } if ( is_null ( $ name ) ) { if ( $ asstring ) { $ name = 'file_' . count ( $ this -> mime ) ; } else { $ name = basename ( $ file ) ; } } $ this -> mime [ '"' . $ name . '"' ] = array ( 'type' => $ type , 'content' => base64_encode ( $ content ) , 'attachment' => true , ) ; return $ this ; }
Attaches a saved file .
51,241
public function setFields ( ) { foreach ( $ this -> field_associations as $ form_field => $ model_field ) { $ this -> form -> set ( $ form_field , $ model_field -> get ( ) ) ; } }
Copies model field values into form .
51,242
public function update ( $ form ) { $ models = $ this -> getFields ( ) ; foreach ( $ models as $ model ) { $ model -> save ( ) ; } }
Update form model
51,243
public function join ( $ foreignTable , $ leftField = null , $ joinKind = null , $ joinAlias = null , $ relation = null , $ behaviour = 'cascade' ) { list ( $ rightTable , $ rightField ) = explode ( '.' , $ foreignTable , 2 ) ; if ( is_null ( $ rightField ) ) { $ rightField = 'id' ; } $ referenceType = ( $ rightField === 'id' ) ? 'hasOne' : 'hasMany' ; if ( $ referenceType === 'hasMany' ) { throw $ this -> exception ( 'has many join isn\'t supported' ) ; } $ leftTable = $ this -> table ; $ joinAlias = $ this -> _unique ( $ this -> relations , $ joinAlias ) ; $ field = $ this -> add ( $ this -> defaultSQLRelationFieldClass ) ; $ field -> setLeftTable ( $ relation ? : $ leftTable ) -> setLeftField ( $ leftField ) -> setRightTable ( $ rightTable ) -> setRightField ( $ rightField ) -> setJoinKind ( $ joinKind ) -> setJoinAlias ( $ joinAlias ) -> setModel ( $ this ) ; $ field -> referenceType = $ referenceType ; $ field -> setBehaviour ( $ behaviour ) ; $ this -> relations [ $ joinAlias ] = $ field ; return $ field ; }
See Field_SQL_Relation .
51,244
protected function createCallfireDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.callfire' , [ ] ) ; $ provider = new CallFireSMS ( new Client ( ) , $ config [ 'app_login' ] , $ config [ 'app_password' ] ) ; return $ provider ; }
Create an instance of the CallFire driver .
51,245
protected function createEztextingDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.eztexting' , [ ] ) ; $ provider = new EZTextingSMS ( new Client ( ) ) ; $ data = [ 'User' => $ config [ 'username' ] , 'Password' => $ config [ 'password' ] , ] ; $ provider -> buildBody ( $ data ) ; return $ provider ; }
Create an instance of the EZTexting driver .
51,246
protected function createLabsMobileDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.labsmobile' , [ ] ) ; $ provider = new LabsMobileSMS ( new Client ( ) ) ; $ auth = [ 'username' => $ config [ 'username' ] , 'password' => $ config [ 'password' ] , ] ; $ provider -> buildBody ( $ auth ) ; return $ provider ; }
Create an instance of the LabsMobile driver .
51,247
protected function createMozeoDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.mozeo' , [ ] ) ; $ provider = new MozeoSMS ( new Client ( ) ) ; $ auth = [ 'companykey' => $ config [ 'company_key' ] , 'username' => $ config [ 'username' ] , 'password' => $ config [ 'password' ] , ] ; $ provider -> buildBody ( $ auth ) ; return $ provider ; }
Create an instance of the Mozeo driver .
51,248
protected function createNexmoDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.nexmo' , [ ] ) ; $ provider = new NexmoSMS ( new Client ( ) , $ config [ 'api_key' ] , $ config [ 'api_secret' ] ) ; return $ provider ; }
Create an instance of the nexmo driver .
51,249
protected function createTwilioDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.twilio' , [ ] ) ; return new TwilioSMS ( new \ Services_Twilio ( $ config [ 'account_sid' ] , $ config [ 'auth_token' ] ) , $ config [ 'auth_token' ] , $ this -> app [ 'request' ] -> url ( ) , $ config [ 'verify' ] ) ; }
Create an instance of the Twillo driver .
51,250
protected function createZenviaDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.zenvia' , [ ] ) ; $ provider = new ZenviaSMS ( new Client ( ) , $ config [ 'account_key' ] , $ config [ 'passcode' ] , $ config [ 'callbackOption' ] ) ; return $ provider ; }
Create an instance of the Zenvia driver .
51,251
protected function createPlivoDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.plivo' , [ ] ) ; $ provider = new PlivoSMS ( $ config [ 'auth_id' ] , $ config [ 'auth_token' ] ) ; return $ provider ; }
Create an instance of the Plivo driver .
51,252
protected function createFlowrouteDriver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.flowroute' , [ ] ) ; $ provider = new FlowrouteSMS ( new Client ( ) , $ config [ 'access_key' ] , $ config [ 'secret_key' ] ) ; return $ provider ; }
Create an instance of the flowroute driver .
51,253
protected function createSms77Driver ( ) { $ config = $ this -> app [ 'config' ] -> get ( 'sms.sms77' , [ ] ) ; $ provider = new SMS77 ( new Client ( ) , $ config [ 'user' ] , $ config [ 'api_key' ] , $ config [ 'debug' ] ) ; return $ provider ; }
Create an instance of the SMS77 driver .
51,254
public function put ( $ pri , $ delay , $ ttr , $ data ) { $ this -> _write ( sprintf ( "put %d %d %d %d\r\n%s" , $ pri , $ delay , $ ttr , strlen ( $ data ) , $ data ) ) ; $ status = strtok ( $ this -> _read ( ) , ' ' ) ; switch ( $ status ) { case 'INSERTED' : case 'BURIED' : return ( integer ) strtok ( ' ' ) ; case 'EXPECTED_CRLF' : case 'JOB_TOO_BIG' : default : $ this -> _error ( $ status ) ; return false ; } }
The put command is for any process that wants to insert a job into the queue .
51,255
public function pauseTube ( $ tube , $ delay ) { $ this -> _write ( sprintf ( 'pause-tube %s %d' , $ tube , $ delay ) ) ; $ status = strtok ( $ this -> _read ( ) , ' ' ) ; switch ( $ status ) { case 'PAUSED' : return true ; case 'NOT_FOUND' : default : $ this -> _error ( $ status ) ; return false ; } }
Pause a tube delaying any new job in it being reserved for a given time .
51,256
public function bury ( $ id , $ pri ) { $ this -> _write ( sprintf ( 'bury %d %d' , $ id , $ pri ) ) ; $ status = $ this -> _read ( ) ; switch ( $ status ) { case 'BURIED' : return true ; case 'NOT_FOUND' : default : $ this -> _error ( $ status ) ; return false ; } }
Puts a job into the buried state Buried jobs are put into a FIFO linked list and will not be touched until a client kicks them .
51,257
protected function _decode ( $ data ) { $ data = array_slice ( explode ( "\n" , $ data ) , 1 ) ; $ result = [ ] ; foreach ( $ data as $ key => $ value ) { if ( $ value [ 0 ] === '-' ) { $ value = ltrim ( $ value , '- ' ) ; } elseif ( strpos ( $ value , ':' ) !== false ) { list ( $ key , $ value ) = explode ( ':' , $ value ) ; $ value = ltrim ( $ value , ' ' ) ; } if ( is_numeric ( $ value ) ) { $ value = ( integer ) $ value == $ value ? ( integer ) $ value : ( float ) $ value ; } $ result [ $ key ] = $ value ; } return $ result ; }
Decodes YAML data . This is a super naive decoder which just works on a subset of YAML which is commonly returned by beanstalk .
51,258
public function exec ( $ cmd , $ args = array ( ) ) { if ( ! is_array ( $ args ) ) { $ args = array ( $ args ) ; } foreach ( $ args as $ val ) { if ( ! is_string ( $ val ) ) { throw new BaseException ( 'You must specify arguments as strings' ) ; } $ this -> args [ ] = escapeshellarg ( $ val ) ; } $ this -> cmd = escapeshellcmd ( $ cmd ) ; $ this -> debug ( 'Executing ' . $ cmd . ( $ this -> args ? ' ' . implode ( ' ' , $ this -> args ) : '' ) ) ; $ this -> executeRaw ( $ this -> cmd . ' ' . implode ( ' ' , $ this -> args ) ) ; return $ this ; }
Execute the process and associate with this object .
51,259
protected function executeRaw ( $ command ) { $ pipes = null ; $ this -> process = proc_open ( $ command , $ this -> descriptorspec , $ pipes ) ; if ( ! is_resource ( $ this -> process ) ) { throw new Exception_SystemProcessIO ( 'Failed to execute' ) ; } $ this -> debug ( 'Execute successful' ) ; $ this -> debugStatus ( ) ; $ this -> pipes [ 'in' ] = & $ pipes [ 0 ] ; $ this -> pipes [ 'out' ] = & $ pipes [ 1 ] ; $ this -> pipes [ 'err' ] = & $ pipes [ 2 ] ; return $ pipes ; }
This function just executes command and returns hash of descriptors . Hash will have keys in out and err .
51,260
public function write ( $ str ) { if ( ! is_resource ( $ this -> pipes [ 'in' ] ) ) { throw new Exception_SystemProcessIO ( "stdin is closed or haven't been opened. Cannot write to process" ) ; } $ this -> debug ( 'writing ' . $ str . '+newline into stdin' ) ; fwrite ( $ this -> pipes [ 'in' ] , $ str . "\n" ) ; $ this -> debugStatus ( ) ; return $ this ; }
Sends string to process but process will wait for more input . Always adds newline at the end .
51,261
public function readLine ( $ res = 'out' ) { $ str = fgets ( $ this -> pipes [ $ res ] ) ; if ( substr ( $ str , - 1 ) == "\n" ) { $ str = substr ( $ str , 0 , - 1 ) ; } return $ str ; }
Reads one line of output . Careful - if no output is provided it this function will be waiting .
51,262
public function readAll ( $ res = 'out' ) { $ str = '' ; $ this -> debugStatus ( ) ; $ this -> debug ( 'reading all output' ) ; $ str = stream_get_contents ( $ this -> pipes [ $ res ] ) ; $ this -> close ( $ res ) ; if ( substr ( $ str , - 1 ) != "\n" ) { $ str .= "\n" ; } return $ str ; }
Reads all output and returns . Closes stdout when EOF reached .
51,263
public function terminate ( $ sig = null ) { foreach ( $ this -> pipes as $ key => $ res ) { $ this -> close ( $ key ) ; } $ this -> debug ( 'process terminated' ) ; proc_terminate ( $ this -> process , $ sig ) ; }
Closing IO and terminating .
51,264
public function dsql ( $ class = null ) { $ class = $ class ? : $ this -> dsql_class ; $ obj = $ this -> add ( $ class ) ; if ( ! $ obj instanceof DB_dsql ) { throw $ this -> exception ( 'Specified class must be descendant of DB_dsql' ) -> addMoreInfo ( 'class' , $ class ) ; } return $ obj ; }
Returns Dynamic Query object which would be compatible with current database connection . If you are connected to MySQL DB_dsql_mysql will be returned .
51,265
public function getOne ( $ query , $ params = array ( ) ) { $ res = $ this -> query ( $ query , $ params ) -> fetch ( ) ; return $ res [ 0 ] ; }
Executes query and returns first column of first row . This is quick and speedy way to get the results of simple queries .
51,266
public function rollBack ( ) { -- $ this -> transaction_depth ; if ( $ this -> transaction_depth < 0 ) { $ this -> transaction_depth = 0 ; } if ( $ this -> transaction_depth == 0 ) { return $ this -> dbh -> rollBack ( ) ; } return false ; }
Rollbacks queries since beginTransaction and resets transaction depth .
51,267
public function render ( ) { $ iter = $ this -> getIterator ( ) ; foreach ( $ iter as $ this -> current_id => $ this -> current_row ) { if ( $ this -> current_row instanceof Model || $ this -> current_row instanceof \ atk4 \ data \ Model ) { $ this -> current_row = $ this -> current_row -> get ( ) ; } elseif ( ! is_array ( $ this -> current_row ) && ! ( $ this -> current_row instanceof ArrayAccess ) ) { $ this -> current = $ this -> current_row ; $ this -> current_row = get_object_vars ( $ this -> current ) ; } $ this -> formatRow ( ) ; $ this -> output ( $ this -> rowRender ( $ this -> template ) ) ; } }
Renders everything .
51,268
public function rowRender ( $ template ) { foreach ( $ this -> current_row as $ key => $ val ) { if ( isset ( $ this -> current_row_html [ $ key ] ) ) { continue ; } if ( $ val instanceof DateTime ) { $ val = $ val -> format ( $ this -> app -> getConfig ( 'locale/datetime' , 'Y-m-d H:i:s' ) ) ; } $ template -> trySet ( $ key , $ val ) ; } $ template -> setHTML ( $ this -> current_row_html ) ; $ template -> trySet ( 'id' , $ this -> current_id ) ; $ o = $ template -> render ( ) ; foreach ( array_keys ( $ this -> current_row ) + array_keys ( $ this -> current_row_html ) as $ k ) { $ template -> tryDel ( $ k ) ; } return $ o ; }
Renders single row .
51,269
public function _unique ( & $ array , $ desired = null ) { $ desired = preg_replace ( '/[^a-zA-Z0-9:]/' , '_' , $ desired ) ; $ desired = parent :: _unique ( $ array , $ desired ) ; return $ desired ; }
{{{ Generic routines
51,270
public function consume ( $ dsql , $ tick = true ) { if ( $ dsql === UNDEFINED ) { return '' ; } if ( $ dsql === null ) { return '' ; } if ( is_object ( $ dsql ) && $ dsql instanceof Field ) { $ dsql = $ dsql -> getExpr ( ) ; } if ( ! is_object ( $ dsql ) || ! $ dsql instanceof self ) { return $ tick ? $ this -> bt ( $ dsql ) : $ dsql ; } $ dsql -> params = & $ this -> params ; $ ret = $ dsql -> _render ( ) ; if ( $ dsql -> mode === 'select' ) { $ ret = '(' . $ ret . ')' ; } unset ( $ dsql -> params ) ; $ dsql -> params = array ( ) ; return $ ret ; }
Recursively renders sub - query or expression combining parameters . If the argument is more likely to be a field use tick = true .
51,271
public function getField ( $ fld ) { if ( $ this -> main_table === false ) { throw $ this -> exception ( 'Cannot use getField() when multiple tables are queried' ) ; } return $ this -> expr ( $ this -> bt ( $ this -> main_table ) . '.' . $ this -> bt ( $ fld ) ) ; }
Return expression containing a properly escaped field . Use make subquery condition reference parent query .
51,272
public function table ( $ table = UNDEFINED , $ alias = UNDEFINED ) { if ( $ table === UNDEFINED ) { return $ this -> main_table ; } if ( is_array ( $ table ) ) { foreach ( $ table as $ alias => $ t ) { if ( is_numeric ( $ alias ) ) { $ alias = UNDEFINED ; } $ this -> table ( $ t , $ alias ) ; } return $ this ; } if ( $ this -> main_table === null ) { $ this -> main_table = $ alias === UNDEFINED || ! $ alias ? $ table : $ alias ; } elseif ( $ this -> main_table ) { $ this -> main_table = false ; } if ( $ table instanceof DB_dsql && ( $ alias === UNDEFINED || ! $ alias ) ) { throw $ this -> exception ( 'If table is passed as DSQL, then table alias is mandatory!' ) ; } $ this -> args [ 'table' ] [ ] = array ( $ table , $ alias ) ; return $ this ; }
Specifies which table to use in this dynamic query . You may specify array to perform operation on multiple tables .
51,273
public function where ( $ field , $ cond = UNDEFINED , $ value = UNDEFINED , $ kind = 'where' ) { if ( is_array ( $ field ) ) { $ or = $ this -> orExpr ( ) ; foreach ( $ field as $ row ) { if ( is_array ( $ row ) ) { $ or -> where ( $ row [ 0 ] , array_key_exists ( 1 , $ row ) ? $ row [ 1 ] : UNDEFINED , array_key_exists ( 2 , $ row ) ? $ row [ 2 ] : UNDEFINED ) ; } elseif ( is_object ( $ row ) ) { $ or -> where ( $ row ) ; } else { $ or -> where ( $ or -> expr ( $ row ) ) ; } } $ field = $ or ; } if ( is_string ( $ field ) && ! preg_match ( '/^[.a-zA-Z0-9_]*$/' , $ field ) ) { preg_match ( '/^([^ <>!=]*)([><!=]*|( *(not|is|in|like))*) *$/' , $ field , $ matches ) ; $ value = $ cond ; $ cond = $ matches [ 2 ] ; if ( ! $ cond ) { $ matches [ 1 ] = $ this -> expr ( $ field ) ; if ( $ value && $ value !== UNDEFINED ) { $ cond = '=' ; } else { $ cond = UNDEFINED ; } } $ field = $ matches [ 1 ] ; } $ this -> args [ $ kind ] [ ] = array ( $ field , $ cond , $ value ) ; return $ this ; }
Adds condition to your query .
51,274
public function join ( $ foreign_table , $ master_field = null , $ join_kind = null , $ _foreign_alias = null ) { if ( isset ( $ this -> app -> compat ) ) { if ( strpos ( $ foreign_table , ' ' ) ) { list ( $ foreign_table , $ alias ) = explode ( ' ' , $ foreign_table ) ; $ foreign_table = array ( $ alias => $ foreign_table ) ; } if ( strpos ( $ master_field , '=' ) ) { $ master_field = $ this -> expr ( $ master_field ) ; } } if ( is_array ( $ foreign_table ) ) { foreach ( $ foreign_table as $ alias => $ foreign ) { if ( is_numeric ( $ alias ) ) { $ alias = null ; } $ this -> join ( $ foreign , $ master_field , $ join_kind , $ alias ) ; } return $ this ; } $ j = array ( ) ; list ( $ f1 , $ f2 ) = explode ( '.' , $ foreign_table , 2 ) ; if ( is_object ( $ master_field ) ) { $ j [ 'expr' ] = $ master_field ; } else { if ( is_null ( $ master_field ) ) { list ( $ m1 , $ m2 ) = array ( null , null ) ; } else { list ( $ m1 , $ m2 ) = explode ( '.' , $ master_field , 2 ) ; } if ( is_null ( $ m2 ) ) { $ m2 = $ m1 ; $ m1 = null ; } if ( is_null ( $ m1 ) ) { $ m1 = $ this -> main_table ; } if ( is_null ( $ f2 ) && is_null ( $ m2 ) ) { $ m2 = $ f1 . '_id' ; } if ( is_null ( $ m2 ) ) { $ m2 = 'id' ; } $ j [ 'm1' ] = $ m1 ; $ j [ 'm2' ] = $ m2 ; } $ j [ 'f1' ] = $ f1 ; if ( is_null ( $ f2 ) ) { $ f2 = 'id' ; } $ j [ 'f2' ] = $ f2 ; $ j [ 't' ] = $ join_kind ? : 'left' ; $ j [ 'fa' ] = $ _foreign_alias ; $ this -> args [ 'join' ] [ ] = $ j ; return $ this ; }
Joins your query with another table .
51,275
public function order ( $ order , $ desc = null ) { if ( is_string ( $ order ) && strpos ( $ order , ',' ) !== false ) { $ order = explode ( ',' , $ order ) ; } if ( is_array ( $ order ) ) { if ( ! is_null ( $ desc ) ) { throw $ this -> exception ( 'If first argument is array, second argument must not be used' ) ; } foreach ( array_reverse ( $ order ) as $ o ) { $ this -> order ( $ o ) ; } return $ this ; } if ( is_null ( $ desc ) && is_string ( $ order ) && strpos ( $ order , ' ' ) !== false ) { list ( $ order , $ desc ) = array_map ( 'trim' , explode ( ' ' , trim ( $ order ) , 2 ) ) ; } if ( is_string ( $ order ) && strpos ( $ order , '.' ) !== false ) { $ order = implode ( '.' , $ this -> bt ( explode ( '.' , $ order ) ) ) ; } if ( is_bool ( $ desc ) ) { $ desc = $ desc ? 'desc' : '' ; } elseif ( strtolower ( $ desc ) === 'asc' ) { $ desc = '' ; } elseif ( $ desc && strtolower ( $ desc ) != 'desc' ) { throw $ this -> exception ( 'Incorrect ordering keyword' ) -> addMoreInfo ( 'order by' , $ desc ) ; } $ this -> args [ 'order' ] [ ] = array ( $ order , $ desc ) ; return $ this ; }
Orders results by field or Expression . See documentation for full list of possible arguments .
51,276
public function call ( $ fx , $ args = null ) { $ this -> mode = 'call' ; $ this -> args [ 'fx' ] = $ fx ; if ( ! is_null ( $ args ) ) { $ this -> args ( $ args ) ; } $ this -> template = 'call [fx]([args])' ; return $ this ; }
Sets a template for a user - defined method call with specified arguments .
51,277
public function set ( $ field , $ value = UNDEFINED ) { if ( $ value === false ) { throw $ this -> exception ( 'Value "false" is not supported by SQL' ) -> addMoreInfo ( 'field' , $ field ) ; } if ( is_array ( $ field ) ) { foreach ( $ field as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } return $ this ; } if ( $ value === UNDEFINED ) { throw $ this -> exception ( 'Specify value when calling set()' ) ; } $ this -> args [ 'set' ] [ $ field ] = $ value ; return $ this ; }
Sets field value for INSERT or UPDATE statements .
51,278
public function bt ( $ s ) { if ( is_array ( $ s ) ) { $ out = array ( ) ; foreach ( $ s as $ ss ) { $ out [ ] = $ this -> bt ( $ ss ) ; } return $ out ; } if ( ! $ this -> bt || is_object ( $ s ) || $ s === '*' || strpos ( $ s , '.' ) !== false || strpos ( $ s , '(' ) !== false || strpos ( $ s , $ this -> bt ) !== false ) { return $ s ; } return $ this -> bt . $ s . $ this -> bt ; }
Adds backtics around argument . This will allow you to use reserved SQL words as table or field names such as table .
51,279
public function SQLTemplate ( $ mode ) { $ this -> mode = $ mode ; $ this -> template = $ this -> sql_templates [ $ mode ] ; return $ this ; }
Switch template for this query . Determines what would be done on execute .
51,280
public function describe ( $ table = null ) { $ q = clone $ this ; if ( $ table !== null ) { $ q -> table ( $ table ) ; } return $ q -> SQLTemplate ( 'describe' ) ; }
Creates a query for listing tables in databse - specific form Agile Toolkit DSQL does not pretend to know anything about model structure so result parsing is up to you .
51,281
public function execute ( ) { try { $ this -> app -> pr -> start ( 'dsql/execute/render' ) ; $ q = $ this -> render ( ) ; $ this -> app -> pr -> next ( 'dsql/execute/query' ) ; $ this -> stmt = $ this -> owner -> query ( $ q , $ this -> params ) ; $ this -> template = $ this -> mode = null ; $ this -> app -> pr -> stop ( ) ; return $ this ; } catch ( PDOException $ e ) { throw $ this -> exception ( 'Database Query Failed' ) -> addMoreInfo ( 'pdo_error' , $ e -> getMessage ( ) ) -> addMoreInfo ( 'mode' , $ this -> mode ) -> addMoreInfo ( 'params' , $ this -> params ) -> addMoreInfo ( 'query' , $ q ) -> addMoreInfo ( 'template' , $ this -> template ) ; } }
Executes current query .
51,282
public function insert ( ) { $ this -> SQLTemplate ( 'insert' ) -> execute ( ) ; return $ this -> hasInsertOption ( 'ignore' ) ? null : $ this -> owner -> lastID ( ) ; }
Executes insert query . Returns ID of new record .
51,283
public function insertAll ( $ array ) { $ ids = array ( ) ; foreach ( $ array as $ hash ) { $ ids [ ] = $ this -> del ( 'set' ) -> set ( $ hash ) -> insert ( ) ; } return $ ids ; }
Inserts multiple rows of data . Uses ignore option AVOID using this might not be implemented correctly .
51,284
public function get ( ) { if ( ! $ this -> stmt ) { $ this -> execute ( ) ; } $ res = $ this -> stmt -> fetchAll ( PDO :: FETCH_ASSOC ) ; $ this -> rewind ( ) ; $ this -> stmt = null ; return $ res ; }
Will execute DSQL query and return all results inside array of hashes .
51,285
public function getOne ( ) { $ res = $ this -> getRow ( ) ; $ this -> rewind ( ) ; $ this -> stmt = null ; return $ res [ 0 ] ; }
Will execute DSQL query and return first column of a first row .
51,286
public function getDebugQuery ( $ r = null ) { if ( $ r === null ) { $ r = $ this -> _render ( ) ; } $ d = $ r ; $ pp = array ( ) ; $ d = preg_replace ( '/`([^`]*)`/' , '`<font color="black">\1</font>`' , $ d ) ; foreach ( array_reverse ( $ this -> params ) as $ key => $ val ) { if ( is_string ( $ val ) ) { $ d = preg_replace ( '/' . $ key . '([^_]|$)/' , '"<font color="green">' . htmlspecialchars ( addslashes ( $ val ) ) . '</font>"\1' , $ d ) ; } elseif ( is_null ( $ val ) ) { $ d = preg_replace ( '/' . $ key . '([^_]|$)/' , '<font color="black">NULL</font>\1' , $ d ) ; } elseif ( is_numeric ( $ val ) ) { $ d = preg_replace ( '/' . $ key . '([^_]|$)/' , '<font color="red">' . $ val . '</font>\1' , $ d ) ; } else { $ d = preg_replace ( '/' . $ key . '([^_]|$)/' , $ val . '\1' , $ d ) ; } $ pp [ ] = $ key ; } return $ d . " <font color='gray'>[" . implode ( ', ' , $ pp ) . ']</font>' ; }
Return formatted debug output .
51,287
public function render ( ) { $ this -> params = $ this -> extra_params ; $ r = $ this -> _render ( ) ; $ this -> debug ( ( string ) $ this -> getDebugQuery ( $ r ) ) ; return $ r ; }
Converts query into string format . This will contain parametric references .
51,288
public function _removeElement ( $ short_name ) { unset ( $ this -> elements [ $ short_name ] ) ; if ( $ this -> _element_name_counts [ $ short_name ] === 1 ) { unset ( $ this -> _element_name_counts [ $ short_name ] ) ; } return $ this ; }
Actually removes the element .
51,289
public function rename ( $ short_name ) { unset ( $ this -> owner -> elements [ $ this -> short_name ] ) ; $ this -> name = $ this -> name . '_' . $ short_name ; $ this -> short_name = $ short_name ; if ( ! $ this -> auto_track_element ) { $ this -> owner -> elements [ $ short_name ] = true ; } else { $ this -> owner -> elements [ $ short_name ] = $ this ; } return $ this ; }
Names object accordingly . May not work on some objects .
51,290
public function setController ( $ controller , $ name = null ) { $ controller = $ this -> app -> normalizeClassName ( $ controller , 'Controller' ) ; return $ this -> add ( $ controller , $ name ) ; }
Associate controller with the object .
51,291
public function setModel ( $ model ) { if ( $ model instanceof \ atk4 \ data \ Model ) { return $ this -> model = $ model ; } $ model = $ this -> app -> normalizeClassName ( $ model , 'Model' ) ; $ this -> model = $ this -> add ( $ model ) ; return $ this -> model ; }
Associate model with object .
51,292
public function debug ( $ msg = true , $ file = null , $ line = null ) { if ( is_bool ( $ msg ) ) { $ this -> debug = $ msg ; return $ this ; } if ( is_object ( $ msg ) ) { throw $ this -> exception ( 'Do not debug objects' ) ; } if ( ( isset ( $ this -> debug ) && $ this -> debug ) || ( isset ( $ this -> app -> debug ) && $ this -> app -> debug ) ) { $ this -> app -> outputDebug ( $ this , $ msg , $ file ) ; } }
Turns on debug mode for this object . Using first argument as string is obsolete .
51,293
public function upCall ( $ type , $ args = array ( ) ) { if ( method_exists ( $ this , $ type ) ) { return call_user_func_array ( array ( $ this , $ type , ) , $ args ) ; } if ( ! $ this -> owner ) { return false ; } return $ this -> owner -> upCall ( $ type , $ args ) ; }
Call specified method for this class and all parents up to app .
51,294
public function addHook ( $ hook_spot , $ callable , $ arguments = array ( ) , $ priority = 5 ) { if ( ! is_array ( $ arguments ) ) { throw $ this -> exception ( 'Incorrect arguments' ) ; } if ( is_string ( $ hook_spot ) && strpos ( $ hook_spot , ',' ) !== false ) { $ hook_spot = explode ( ',' , $ hook_spot ) ; } if ( is_array ( $ hook_spot ) ) { foreach ( $ hook_spot as $ h ) { $ this -> addHook ( $ h , $ callable , $ arguments , $ priority ) ; } return $ this ; } if ( ! is_callable ( $ callable ) && ( $ callable instanceof self && ! $ callable -> hasMethod ( $ hook_spot ) ) ) { throw $ this -> exception ( 'Hook does not exist' ) ; } if ( is_object ( $ callable ) && ! is_callable ( $ callable ) ) { $ callable = array ( $ callable , $ hook_spot ) ; } $ this -> hooks [ $ hook_spot ] [ $ priority ] [ ] = array ( $ callable , $ arguments ) ; return $ this ; }
If priority is negative then hooks will be executed in reverse order .
51,295
public function tryCall ( $ method , $ arguments ) { if ( $ ret = $ this -> hook ( 'method-' . $ method , $ arguments ) ) { return $ ret ; } array_unshift ( $ arguments , $ this ) ; if ( ( $ ret = $ this -> app -> hook ( 'global-method-' . $ method , $ arguments ) ) ) { return $ ret ; } }
Attempts to call dynamic method . Returns array containing result or false .
51,296
public function logError ( $ error , $ msg = '' ) { if ( is_object ( $ error ) ) { $ error = $ error -> getMessage ( ) ; } $ this -> app -> getLogger ( ) -> logLine ( $ msg . ' ' . $ error . "\n" , null , 'error' ) ; }
Output string into error file .
51,297
public function pack ( $ from , $ to ) { if ( ( $ gzip = gzopen ( $ to , 'wb' ) ) === false ) { throw new Exception ( 'Unable create compressed file.' ) ; } if ( ( $ source = fopen ( $ from , 'rb' ) ) === false ) { throw new Exception ( 'Unable open the compression source file.' ) ; } while ( ! feof ( $ source ) ) { $ content = fread ( $ source , 4096 ) ; gzwrite ( $ gzip , $ content , strlen ( $ content ) ) ; } gzclose ( $ gzip ) ; fclose ( $ source ) ; }
Compresses a file .
51,298
public function unpack ( $ from , $ to ) { if ( ( $ gzip = gzopen ( $ from , 'rb' ) ) === false ) { throw new Exception ( 'Unable to read compressed file.' ) ; } if ( ( $ target = fopen ( $ to , 'w' ) ) === false ) { throw new Exception ( 'Unable to open the target.' ) ; } while ( $ string = gzread ( $ gzip , 4096 ) ) { fwrite ( $ target , $ string , strlen ( $ string ) ) ; } gzclose ( $ gzip ) ; fclose ( $ target ) ; }
Uncompresses a file .
51,299
public function setEmptyText ( $ text = null ) { $ this -> empty_text = $ text === null ? $ this -> default_empty_text : $ text ; return $ this ; }
Sets default text which is displayed on a null - value option .