idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
51,400
public function dbConnect ( $ dsn = null ) { $ this -> db = $ this -> add ( 'DB' ) ; return $ this -> db -> connect ( $ dsn ) ; }
Use database configuration settings from config file to establish default connection .
51,401
public function normalizeName ( $ name , $ separator = '_' ) { if ( strlen ( $ separator ) == 0 ) { return preg_replace ( '|[^a-z0-9]|i' , '' , $ name ) ; } $ s = $ separator [ 0 ] ; $ name = preg_replace ( '|[^a-z0-9\\' . $ s . ']|i' , $ s , $ name ) ; $ name = trim ( $ name , $ s ) ; $ name = preg_replace ( '|\\' . $ s . '{2,}|' , $ s , $ name ) ; return $ name ; }
Normalize field or identifier name . Can also be used in URL normalization . This will replace all non alpha - numeric characters with separator . Multiple separators in a row is replaced with one . Separators in beginning and at the end of name are removed .
51,402
public function normalizeClassName ( $ name , $ prefix = null ) { if ( ! is_string ( $ name ) ) { return $ name ; } $ name = str_replace ( '/' , '\\' , $ name ) ; if ( $ prefix !== null ) { $ class = ltrim ( strrchr ( $ name , '\\' ) , '\\' ) ? : $ name ; $ prefix = ucfirst ( $ prefix ) ; if ( strpos ( $ class , $ prefix ) !== 0 ) { $ name = preg_replace ( '|^(.*\\\)?(.*)$|' , '\1' . $ prefix . '_\2' , $ name ) ; } } return $ name ; }
First normalize class name then add specified prefix to class name if it s passed and not already added . Class name can have namespaces and they are treated prefectly .
51,403
public function encodeHtmlChars ( $ s , $ flags = null , $ encode = null , $ double_encode = false ) { if ( $ flags === null ) { $ flags = ENT_COMPAT ; } if ( $ encode === null ) { $ encode = ini_get ( 'default_charset' ) ? : 'UTF-8' ; } return htmlspecialchars ( $ s , $ flags , $ encode , $ double_encode ) ; }
Encodes HTML special chars . By default does not encode already encoded ones .
51,404
public function migrate ( ) { $ folders = $ this -> app -> pathfinder -> search ( 'dbupdates' , '' , 'path' ) ; foreach ( $ folders as $ dir ) { $ files = scandir ( $ dir ) ; sort ( $ files ) ; foreach ( $ files as $ name ) { if ( strtolower ( substr ( $ name , - 4 ) ) != '.sql' ) { continue ; } $ q = $ this -> db -> dsql ( ) -> table ( '_db_update' ) -> where ( 'name' , strtolower ( $ name ) ) -> field ( 'status' ) ; if ( $ q -> getOne ( ) === 'ok' ) { continue ; } $ migration = file_get_contents ( $ dir . '/' . $ name ) ; $ q -> set ( 'name' , strtolower ( $ name ) ) ; try { $ this -> db -> dbh -> exec ( $ migration ) ; $ q -> set ( 'status' , 'ok' ) -> replace ( ) ; } catch ( Exception $ e ) { $ q -> set ( 'status' , 'fail' ) -> replace ( ) ; if ( ! $ e instanceof BaseException ) { $ e = $ this -> exception ( ) -> addMoreInfo ( 'Original error' , $ e -> getMessage ( ) ) ; } throw $ e -> addMoreInfo ( 'file' , $ name ) ; } } } return $ this ; }
Find migrations and execute them in order .
51,405
public function getStatusModel ( ) { $ m = $ this -> add ( 'SQL_Model' , [ 'table' => '_db_update' ] ) ; $ m -> addField ( 'name' ) ; $ m -> addField ( 'status' ) -> enum ( [ 'ok' , 'fail' ] ) ; $ m -> setSource ( 'SQL' ) ; return $ m ; }
Produces and returns a generic model you can supply to your Grid if you want show migration status .
51,406
public function routePages ( $ prefix , $ ns = null ) { $ this -> namespace_routes [ $ prefix ] = $ this -> normalizeClassName ( $ ns ? : $ prefix ) ; }
Pages with a specified prefix will loaded from a specified namespace .
51,407
protected function loadStaticPage ( $ page ) { $ layout = $ this -> layout ? : $ this ; try { $ t = 'page/' . str_replace ( '_' , '/' , strtolower ( $ page ) ) ; $ this -> template -> findTemplate ( $ t ) ; $ this -> page_object = $ layout -> add ( $ this -> page_class , $ page , 'Content' , array ( $ t ) ) ; } catch ( Exception_PathFinder $ e2 ) { $ t = 'page/' . strtolower ( $ page ) ; $ this -> template -> findTemplate ( $ t ) ; $ this -> page_object = $ layout -> add ( $ this -> page_class , $ page , 'Content' , array ( $ t ) ) ; } return $ this -> page_object ; }
Attempts to load static page . Raises exception if not found .
51,408
protected function hasError ( $ body ) { if ( $ this -> hasAResponseMessage ( $ body ) && $ this -> hasProperty ( $ this -> getFirstMessage ( $ body ) , 'status' ) ) { $ firstMessage = $ this -> getFirstMessage ( $ body ) ; return ( int ) $ firstMessage [ 'status' ] !== 0 ; } return false ; }
Checks if the transaction has an error .
51,409
public function addStaticInclude ( $ file , $ ext = '.js' ) { if ( @ $ this -> included [ 'js-' . $ file . $ ext ] ++ ) { return $ this ; } if ( strpos ( $ file , 'http' ) !== 0 && $ file [ 0 ] != '/' ) { $ url = $ this -> app -> locateURL ( 'js' , $ file . $ ext ) ; } else { $ url = $ file ; } $ this -> app -> template -> appendHTML ( 'js_include' , '<script type="text/javascript" src="' . $ url . '"></script>' . "\n" ) ; return $ this ; }
Adds static includes
51,410
public function addStaticStylesheet ( $ file , $ ext = '.css' , $ locate = 'css' ) { if ( @ $ this -> included [ $ locate . '-' . $ file . $ ext ] ++ ) { return ; } if ( strpos ( $ file , 'http' ) !== 0 && $ file [ 0 ] != '/' ) { $ url = $ this -> app -> locateURL ( $ locate , $ file . $ ext ) ; } else { $ url = $ file ; } $ this -> app -> template -> appendHTML ( 'js_include' , '<link type="text/css" href="' . $ url . '" rel="stylesheet" />' . "\n" ) ; return $ this ; }
Adds static stylesheet
51,411
protected function buildCall ( $ url ) { if ( ! $ this -> callBuilt ) { $ this -> apiBase .= $ url ; $ this -> callBuilt = true ; } }
Builds the API call address .
51,412
protected function buildUrl ( array $ segments = [ ] ) { $ url = $ this -> apiBase . '?' ; if ( isset ( $ this -> apiEnding ) ) { $ segments = array_merge ( $ segments , $ this -> apiEnding ) ; } foreach ( $ segments as $ key => $ value ) { $ url = $ url . "$key=$value&" ; } $ url = substr ( $ url , 0 , - 1 ) ; return $ url ; }
Builds a URL .
51,413
public function buildBody ( $ values , $ key = null ) { if ( is_array ( $ values ) ) { $ this -> body = array_merge ( $ this -> body , $ values ) ; } else { $ this -> body [ $ key ] = $ values ; } }
Builds the body part of the request and adds it to the body array .
51,414
protected function getAuth ( ) { if ( isset ( $ this -> auth [ 'username' ] ) && isset ( $ this -> auth [ 'password' ] ) ) { return [ $ this -> auth [ 'username' ] , $ this -> auth [ 'password' ] ] ; } }
Returns the auth array for requests . If not set will return null .
51,415
public function addTitle ( $ title , $ class = 'Menu_Advanced_Title' ) { $ i = $ this -> add ( $ class , null , null , array_merge ( $ this -> defaultTemplate ( ) , array ( 'Title' ) ) ) ; $ i -> set ( $ title ) ; return $ i ; }
Adds a title to your menu .
51,416
public function getUploadedFiles ( ) { if ( $ c = $ this -> model ) { $ a = explode ( ',' , $ this -> value ) ; $ b = array ( ) ; foreach ( $ a as $ val ) { if ( $ val ) { $ b [ ] = $ val ; } } $ files = implode ( ',' , filter_var_array ( $ b , FILTER_VALIDATE_INT ) ) ; if ( $ files ) { $ c -> addCondition ( 'id' , 'in' , ( $ files ? $ files : 0 ) ) ; $ data = $ c -> getRows ( array ( 'id' , 'url' , 'thumb_url' , $ this -> getOriginalFilenameFieldName ( ) , $ this -> getFilesizeFieldName ( ) ) ) ; } else { $ data = array ( ) ; } return $ this -> formatFiles ( $ data ) ; } }
those can be done in flash thingie as well
51,417
public function getModel ( ) { if ( ! $ this -> model ) { $ this -> model = $ this -> add ( $ this -> model_name ) ; } if ( $ this -> display_field ) { $ this -> model -> title_field = $ this -> display_field ; } if ( $ this -> table_alias ) { $ this -> model -> table_alias = $ this -> table_alias ; } return $ this -> model ; }
Return model of field
51,418
public function refSQL ( ) { $ q = $ this -> ref ( 'model' ) ; $ q -> addCondition ( $ q -> id_field , $ this ) ; return $ q ; }
Return DSQL for field
51,419
public function getDereferenced ( ) { if ( $ this -> dereferenced_field ) { return $ this -> dereferenced_field ; } $ f = preg_replace ( '/_id$/' , '' , $ this -> short_name ) ; if ( $ f != $ this -> short_name ) { return $ f ; } $ f = $ this -> short_name . '_text' ; if ( $ this -> owner -> hasElement ( $ f ) ) { return $ f ; } $ f = $ this -> _unique ( $ this -> owner -> elements , $ f ) ; $ this -> dereferenced_field = $ f ; return $ f ; }
Return name of dereferenced field
51,420
public function destroy ( ) { if ( $ e = $ this -> owner -> hasElement ( $ this -> getDereferenced ( ) ) ) { $ e -> destroy ( ) ; } return parent :: destroy ( ) ; }
Destroy this field and dereferenced field .
51,421
public function importFields ( $ model , $ fields = null ) { $ this -> model = $ model ; if ( $ fields === false ) { return ; } if ( ! $ fields ) { if ( $ model -> only_fields ) { $ fields = $ model -> only_fields ; } else { $ fields = [ ] ; foreach ( $ model -> elements as $ field => $ f_object ) { if ( $ f_object instanceof \ atk4 \ data \ Field ) { $ fields [ ] = $ f_object ; } } } } if ( ! is_array ( $ fields ) ) { $ fields = [ $ fields ] ; } foreach ( $ fields as $ field ) { $ this -> importField ( $ field ) ; } return $ this ; }
Import model fields in view .
51,422
public function sendRawRequest ( $ model , $ url , $ method = 'GET' , $ data = null ) { if ( $ model -> debug ) { echo '<font color="blue">' . htmlspecialchars ( "$method $url (" . json_encode ( $ data ) . ')' ) . '</font>' ; } $ method = strtolower ( $ method ) ; $ pest = $ model -> _table [ $ this -> short_name ] ; if ( $ data ) { return $ pest -> $ method ( $ url , $ data ) ; } else { return $ pest -> $ method ( $ url ) ; } }
Sends request to specified URL with specified method and data .
51,423
public function save ( $ model , $ id , $ data ) { if ( is_null ( $ id ) ) { $ model -> data = $ this -> sendCollectionRequest ( $ model , $ this -> insert_mode , $ data ) ; $ model -> id = $ model -> data ? $ model -> data [ $ model -> id_field ] : null ; } else { $ model -> data = $ this -> sendItemRequest ( $ model , $ id , $ this -> update_mode , $ data ) ; $ model -> id = $ model -> data ? $ model -> data [ $ model -> id_field ] : null ; } return $ model -> id ; }
Saving updating and deleting data
51,424
public function isActive ( $ mode = null ) { if ( $ mode !== null && isset ( $ _GET [ $ this -> name ] ) ) { return $ _GET [ $ this -> name ] == $ mode ; } return isset ( $ _GET [ $ this -> name ] ) ? $ _GET [ $ this -> name ] : false ; }
Returns true if the URL is requesting the page to be shown . If no parameter is passed then return active page mode .
51,425
public function set ( $ method_or_arg , $ method = null ) { $ method = is_callable ( $ method_or_arg ) ? $ method_or_arg : $ method ; $ arg = is_callable ( $ method_or_arg ) ? null : $ method_or_arg ; $ self = $ this ; if ( $ this -> isActive ( $ arg ) ) { $ this -> app -> addHook ( 'post-init' , function ( ) use ( $ method , $ self ) { $ page = $ self -> getPage ( ) ; $ page -> id = $ _GET [ $ self -> name . '_id' ] ; $ self -> app -> stickyGET ( $ self -> name . '_id' ) ; try { call_user_func ( $ method , $ page , $ self ) ; } catch ( Exception $ e ) { if ( $ e instanceof Exception_StopInit ) { return ; } throw $ e ; } } ) ; throw $ this -> exception ( '' , 'StopInit' ) ; } return $ this ; }
Associates code with the page . This code will be executed within a brand new page when called by URL .
51,426
public function getPage ( ) { if ( $ this -> page ) { return $ this -> page ; } $ this -> app -> page_object -> destroy ( false ) ; $ this -> page = $ this -> app -> add ( $ this -> page_class , $ this -> name , null , $ this -> page_template ) ; $ this -> app -> page_object = $ this -> page ; $ this -> app -> stickyGET ( $ this -> name ) ; return $ this -> page ; }
Simply returns a page we can put stuff on . This page would be displayed instead of regular page so beware .
51,427
public function addColumn ( $ name , $ title = null , $ buttontext = null , $ grid = null ) { if ( $ grid === null ) { $ grid = $ this -> owner ; } if ( ! is_array ( $ buttontext ) ) { $ buttontext = array ( 'descr' => $ buttontext ) ; } if ( ! $ buttontext [ 'descr' ] ) { $ buttontext [ 'descr' ] = $ title ? : ucwords ( str_replace ( '_' , ' ' , $ name ) ) ; } $ icon = '' ; if ( $ buttontext [ 'icon' ] ) { if ( $ buttontext [ 'icon' ] [ 0 ] != '<' ) { $ icon .= '<i class="icon-' . $ buttontext [ 'icon' ] . '"></i>' ; } else { $ icon .= $ buttontext [ 'icon' ] ; } $ icon .= '&nbsp;' ; } $ grid -> addColumn ( 'template' , $ name , $ buttontext ? : $ title ) ; $ grid -> setTemplate ( '<button type="button" class="atk-button-small pb_' . $ name . '">' . $ icon . $ this -> app -> encodeHtmlChars ( $ buttontext [ 'descr' ] ) . '</button>' ) ; $ grid -> columns [ $ name ] [ 'thparam' ] .= ' style="width: 40px; text-align: center"' ; $ t = $ this -> type ; $ grid -> js ( 'click' ) -> _selector ( '#' . $ grid -> name . ' .pb_' . $ name ) -> univ ( ) -> $ t ( $ title , array ( $ this -> getURL ( $ name ) , $ this -> name . '_id' => $ grid -> js ( ) -> _selectorThis ( ) -> closest ( 'tr' ) -> attr ( 'data-id' ) , ) , $ this -> frame_options ) ; return $ this ; }
Call this if you are adding this inside a grid .
51,428
public function addButton ( $ label = 'Continue' ) { if ( ! is_array ( $ label ) ) { $ label = array ( $ label , 'icon-r' => 'right-big' ) ; } $ button = $ this -> add ( 'Button' , null , 'Button' ) ; return $ button -> set ( $ label ) ; }
Adds Button on the right side of the box for follow - up action .
51,429
public function addClose ( ) { if ( $ this -> recall ( 'closed' , false ) ) { $ this -> destroy ( ) ; } $ self = $ this ; $ icon = $ this -> add ( 'Icon' , null , 'Button' ) ; $ icon -> addComponents ( array ( 'size' => 'mega' ) ) -> set ( 'cancel-1' ) -> addStyle ( array ( 'cursor' => 'pointer' ) ) -> on ( 'click' , function ( $ js ) use ( $ self ) { $ self -> memorize ( 'closed' , true ) ; return $ self -> js ( ) -> hide ( ) -> execute ( ) ; } ) ; return $ this ; }
View box can be closed by clicking on the cross .
51,430
public function driver ( $ driver ) { $ this -> container [ 'sms.sender' ] = $ this -> container -> share ( function ( $ app ) use ( $ driver ) { return ( new DriverManager ( $ app ) ) -> driver ( $ driver ) ; } ) ; $ this -> driver = $ this -> container [ 'sms.sender' ] ; }
Changes the set SMS driver .
51,431
public function send ( $ view , $ data , $ callback ) { $ data [ 'message' ] = $ message = $ this -> createOutgoingMessage ( ) ; $ message -> view ( $ view ) ; $ message -> data ( $ data ) ; call_user_func ( $ callback , $ message ) ; $ this -> driver -> send ( $ message ) ; return $ message ; }
Send a SMS .
51,432
public function loadCurrent ( $ model ) { $ model -> _table [ $ this -> short_name ] -> next ( ) ; $ model -> data = $ model -> _table [ $ this -> short_name ] -> current ( ) ; $ model -> id = $ model -> data [ $ model -> id_field ] ; }
Provided that rewind was called before load next data entry
51,433
public function reload ( ) { $ f = $ this -> findTemplate ( $ this -> template_file ) ; $ template_source = implode ( '' , file ( $ f ) ) ; $ this -> loadTemplateFromString ( $ template_source ) ; return $ this ; }
Causes the template to be refreshed from it s original source
51,434
public function getTagRef ( $ tag , & $ template ) { if ( $ this -> isTopTag ( $ tag ) ) { $ template = & $ this -> template ; return $ this ; } @ list ( $ tag , $ ref ) = explode ( '#' , $ tag ) ; if ( ! $ ref ) { $ ref = 1 ; } if ( ! isset ( $ this -> tags [ $ tag ] ) ) { throw $ this -> exception ( 'Tag not found in Template' ) -> addMoreInfo ( 'tag' , $ tag ) -> addMoreInfo ( 'tags' , implode ( ', ' , array_keys ( $ this -> tags ) ) ) ; } $ template = reset ( $ this -> tags [ $ tag ] ) ; return $ this ; }
This is a helper method which populates an array pointing to the place in the template referenced by a said tag .
51,435
public function hasTag ( $ tag ) { if ( is_array ( $ tag ) ) { return true ; } @ list ( $ tag , $ ref ) = explode ( '#' , $ tag ) ; return isset ( $ this -> tags [ $ tag ] ) || $ this -> isTopTag ( $ tag ) ; }
Checks if template has defined a specified tag .
51,436
public function findTemplate ( $ template_name ) { if ( ! $ this -> app ) { throw new Exception_InitError ( 'You should use add() to add objects!' ) ; } $ f = $ this -> app -> locatePath ( $ this -> template_type ? : $ this -> settings [ 'template_type' ] , $ template_name . $ this -> settings [ 'extension' ] ) ; return $ this -> origin_filename = $ f ; }
template loading and parsing
51,437
public function _prepend ( $ code ) { if ( is_array ( $ code ) ) { $ code = implode ( ';' , $ code ) ; } $ this -> prepend = $ code . ';' . $ this -> prepend ; return $ this ; }
Execute more JavaScript code before chain . Avoid using .
51,438
public function reload ( $ arg = array ( ) , $ fn = null , $ url = null , $ interval = null ) { if ( $ fn && $ fn instanceof self ) { $ fn -> _enclose ( ) ; } $ obj = $ this -> owner ; if ( $ url === null ) { $ url = $ this -> app -> url ( null , array ( 'cut_object' => $ obj -> name ) ) ; } return $ this -> univ ( ) -> _fn ( 'reload' , array ( $ url , $ arg , $ fn , $ interval ) ) ; }
Reload object .
51,439
public function _enclose ( $ fn = null , $ preventDefault = false ) { if ( $ fn === null ) { $ fn = true ; } $ this -> enclose = $ fn ; $ this -> preventDefault = $ preventDefault ; return $ this ; }
Chain will not be called but will return callable function instead .
51,440
public function _render ( ) { $ ret = $ this -> prepend ; if ( $ this -> library ) { $ ret .= $ this -> library ; } else { if ( $ this -> str ) { $ ret .= "$('#" . $ this -> owner -> getJSID ( ) . "')" ; } } $ ret .= $ this -> str ; if ( $ this -> enclose === true ) { if ( $ this -> preventDefault ) { $ ret = 'function(ev,ui){ev.preventDefault();ev.stopPropagation(); ' . $ ret . '}' ; } else { $ ret = 'function(ev,ui){' . $ ret . '}' ; } } elseif ( $ this -> enclose ) { $ ret = ( $ this -> library ? : "$('#" . $ this -> owner -> getJSID ( ) . "')" ) . ".bind('" . $ this -> enclose . "',function(ev,ui){ev.preventDefault();ev.stopPropagation(); " . $ ret . '})' ; } if ( @ $ this -> debug ) { echo "<font color='blue'>" . htmlspecialchars ( $ ret ) . ';</font><br/>' ; $ this -> debug = false ; } return $ ret ; }
Render and return js chain as string
51,441
public function addField ( $ name , $ alias = null ) { $ field = $ this -> add ( $ this -> field_class , $ name ) ; $ field = $ field -> actual ( $ alias ) ; return $ field ; }
Creates field definition object containing field meta - information such as caption type validation rules default value etc .
51,442
public function set ( $ name , $ value = UNDEFINED ) { if ( is_array ( $ name ) ) { foreach ( $ name as $ key => $ val ) { $ this -> set ( $ key , $ val ) ; } return $ this ; } elseif ( $ value === UNDEFINED ) { throw $ this -> exception ( 'You must define the second argument' ) ; } if ( $ this -> strict_fields && ! $ this -> hasElement ( $ name ) ) { throw $ this -> exception ( 'No such field' , 'Logic' ) -> addMoreInfo ( 'field' , $ name ) ; } if ( ( $ value !== $ this -> data [ $ name ] ) || ( is_null ( $ value ) && ! array_key_exists ( $ name , $ this -> data ) ) ) { $ this -> data [ $ name ] = $ value ; $ this -> setDirty ( $ name ) ; } if ( $ name === $ this -> id_field ) { $ this -> id = $ value ; } return $ this ; }
Set value of fields . If only a single argument is specified and it is a hash will use keys as property names and set values accordingly .
51,443
public function setActualFields ( $ group = UNDEFINED ) { if ( is_array ( $ group ) ) { $ this -> actual_fields = $ group ; return $ this ; } if ( $ group === UNDEFINED ) { $ group = 'all' ; } $ this -> actual_fields = $ this -> getGroupField ( $ group ) ; return $ this ; }
Set the actual fields of this model . You can use an array to set the list of fields or a string to use the grouping .
51,444
public function getActualFields ( ) { if ( $ this -> actual_fields === false ) { $ this -> actual_fields = $ this -> getGroupField ( ) ; } return $ this -> actual_fields ; }
Get the actual fields .
51,445
public function getTitleField ( ) { if ( $ this -> title_field && $ this -> hasElement ( $ this -> title_field ) ) { return $ this -> title_field ; } return $ this -> id_field ; }
Return the title field .
51,446
public function isDirty ( $ name ) { $ field = $ this -> getElement ( $ name ) ; return $ this -> dirty [ $ name ] || ( ! $ this -> loaded ( ) && $ field -> has_default_value ) ; }
Return true if the field is set .
51,447
public function setControllerData ( $ controller ) { if ( is_string ( $ controller ) ) { $ controller = $ this -> app -> normalizeClassName ( $ controller , 'Data' ) ; } elseif ( ! $ controller instanceof Controller_Data ) { throw $ this -> exception ( 'Inappropriate Controller. Must extend Controller_Data' ) ; } $ this -> controller = $ this -> setController ( $ controller ) ; return $ this -> controller ; }
Set the controller data of this model .
51,448
public function supports ( $ feature ) { if ( ! $ this -> controller ) { return false ; } $ s = 'support' . $ feature ; return $ this -> controller -> $ s ; }
Returns if certain feature is supported by model
51,449
public function load ( $ id ) { if ( ! $ this -> controller ) { throw $ this -> exception ( 'Unable to load model, setSource() must be set' ) ; } if ( $ this -> loaded ( ) ) { $ this -> unload ( ) ; } $ this -> hook ( 'beforeLoad' , array ( 'load' , array ( $ id ) ) ) ; $ this -> controller -> loadById ( $ this , $ id ) ; $ this -> endLoad ( ) ; return $ this ; }
Like tryLoad method but if the record not found an exception is thrown .
51,450
public function loadAny ( ) { if ( $ this -> loaded ( ) ) { $ this -> unload ( ) ; } $ this -> hook ( 'beforeLoad' , array ( 'loadAny' , array ( ) ) ) ; $ this -> controller -> loadByConditions ( $ this ) ; $ this -> endLoad ( ) ; return $ this ; }
Like tryLoadAny method but if the record not found an exception is thrown .
51,451
public function loadBy ( $ field , $ cond , $ value = UNDEFINED ) { if ( $ field == $ this -> id_field && $ value === UNDEFINED ) { return $ this -> load ( $ cond ) ; } if ( $ field == $ this -> id_field && cond === '=' ) { return $ this -> load ( $ value ) ; } if ( $ this -> loaded ( ) ) { $ this -> unload ( ) ; } $ this -> hook ( 'beforeLoad' , array ( 'loadBy' , array ( $ field , $ cond , $ value ) ) ) ; $ conditions = $ this -> conditions ; $ this -> addCondition ( $ field , $ cond , $ value ) ; $ this -> controller -> loadByConditions ( $ this ) ; $ this -> conditions = $ conditions ; $ this -> endLoad ( ) ; return $ this ; }
Like tryLoadBy method but if the record not found an exception is thrown .
51,452
public function tryLoadBy ( $ field , $ cond = UNDEFINED , $ value = UNDEFINED ) { try { $ this -> loadBy ( $ field , $ cond , $ value ) ; } catch ( Exception_NotFound $ e ) { } return $ this ; }
Adding temporally condition to the model to retrive the first record The condition specified is removed after the controller data call .
51,453
public function unload ( ) { if ( $ this -> _save_later ) { $ this -> _save_later = false ; $ this -> saveAndUnload ( ) ; } if ( $ this -> loaded ( ) ) { $ this -> hook ( 'beforeUnload' ) ; } $ this -> data = $ this -> dirty = array ( ) ; $ this -> id = null ; $ this -> hook ( 'afterUnload' ) ; return $ this ; }
Forget loaded data .
51,454
public function deleteAll ( ) { if ( $ this -> loaded ( ) ) { $ this -> unload ( ) ; } $ this -> hook ( 'beforeDeleteAll' ) ; $ this -> controller -> deleteAll ( $ this ) ; $ this -> hook ( 'afterDeleteAll' ) ; return $ this ; }
Deletes all records associated with this model .
51,455
public function addCondition ( $ field , $ operator = UNDEFINED , $ value = UNDEFINED ) { if ( ! $ this -> controller ) { throw $ this -> exception ( 'Controller for this model is not set' , 'NotImplemented' ) ; } if ( ! @ $ this -> controller -> supportConditions ) { throw $ this -> exception ( 'The controller doesn\'t support conditions' , 'NotImplemented' ) -> addMoreInfo ( 'controller' , $ this -> controller ) ; } if ( is_array ( $ field ) ) { foreach ( $ field as $ value ) { $ this -> addCondition ( $ value [ 0 ] , $ value [ 1 ] , count ( $ value ) === 2 ? UNDEFINED : $ value [ 2 ] ) ; } return $ this ; } elseif ( ( $ operator === UNDEFINED ) && ( ! is_object ( $ field ) ) ) { throw $ this -> exception ( 'You must define the second argument' ) ; } if ( $ value === UNDEFINED ) { $ value = $ operator ; $ operator = '=' ; } $ supportOperators = $ this -> controller -> supportOperators ; if ( $ supportOperators !== 'all' && ( is_null ( $ supportOperators ) || ( ! isset ( $ supportOperators [ $ operator ] ) ) ) ) { throw $ this -> exception ( 'Unsupport operator' , 'NotImplemented' ) -> addMoreInfo ( 'operator' , $ operator ) ; } $ this -> conditions [ ] = array ( $ field , $ operator , $ value ) ; return $ this ; }
Adds a new condition for this model
51,456
public function count ( $ alias = null ) { if ( $ this -> controller && $ this -> controller -> hasMethod ( 'count' ) ) { return $ this -> controller -> count ( $ this , $ alias ) ; } throw $ this -> exception ( 'The controller doesn\'t support count' , 'NotImplemented' ) -> addMoreInfo ( 'controller' , $ this -> controller ? $ this -> controller -> short_name : 'none' ) ; }
Count records of model .
51,457
public function hasOne ( $ model , $ our_field = UNDEFINED , $ field_class = UNDEFINED ) { if ( $ field_class === UNDEFINED ) { $ field_class = $ this -> defaultHasOneFieldClass ; } if ( $ our_field === UNDEFINED ) { $ tmp = $ this -> app -> normalizeClassName ( $ model , 'Model' ) ; $ tmp = new $ tmp ( ) ; $ refFieldName = ( $ tmp -> table ? : strtolower ( get_class ( $ this ) ) ) . '_id' ; } else { $ refFieldName = $ our_field ; } $ displayFieldName = preg_replace ( '/_id$/' , '' , $ our_field ) ; $ field = $ this -> addField ( $ refFieldName ) ; if ( ! @ $ this -> controller -> supportExpressions ) { $ expr = $ this -> addExpression ( $ displayFieldName , $ model , $ field_class ) -> setModel ( $ model ) -> setForeignFieldName ( $ refFieldName ) ; $ this -> _references [ $ refFieldName ] = $ model ; return $ expr ; } return $ field ; }
{{{ Relational methods
51,458
public function ref ( $ ref1 ) { list ( $ ref , $ rest ) = explode ( '/' , $ ref1 , 2 ) ; if ( ! isset ( $ this -> _references [ $ ref ] ) ) { $ e = $ this -> hasElement ( $ ref ) ; if ( $ e && $ e -> hasMethod ( 'ref' ) ) { return $ e -> ref ( ) ; } else { throw $ this -> exception ( 'Reference is not defined' ) -> addMoreInfo ( 'model' , $ this ) -> addMoreInfo ( 'ref' , $ ref ) ; } } $ class = $ this -> _references [ $ ref ] ; if ( is_array ( $ class ) ) { if ( $ rest ) { throw $ this -> exception ( 'Cannot traverse multiple references' ) ; } $ m = $ this -> _ref ( $ class [ 0 ] , $ class [ 1 ] && $ class [ 1 ] != UNDEFINED ? $ class [ 1 ] : $ this -> table . '_id' , $ class [ 2 ] && $ class [ 2 ] != UNDEFINED ? $ this [ $ class [ 2 ] ] : $ this -> id ) ; } else { $ id = $ this -> get ( $ ref ) ; $ m = $ this -> _ref ( $ class , null , $ id ) ; if ( $ id ) { $ this -> hook ( 'beforeRefLoad' , array ( $ m , $ id ) ) ; $ m -> load ( $ id ) ; } } if ( $ rest ) { $ m = $ m -> ref ( $ rest ) ; } return $ m ; }
Traverses reference of relation .
51,459
public function error ( $ field , $ text = null ) { $ form_field = $ this -> getElement ( $ field ) ; $ form_field -> displayFieldError ( $ text ) ; }
Adds error message to form field .
51,460
public function importFields ( $ model , $ fields = null ) { $ c = $ this -> add ( $ this -> default_controller ) ; $ c -> importFields ( $ model , $ fields ) ; }
Imports model fields in form by using form controller .
51,461
public function init ( ) { parent :: init ( ) ; $ this -> cache = & $ this -> app -> smlite_cache ; $ this -> settings = $ this -> getDefaultSettings ( ) ; $ this -> settings [ 'extension' ] = $ this -> app -> getConfig ( 'smlite/extension' , '.html' ) ; }
Template creation interface functions
51,462
public function get ( $ tag ) { if ( $ this -> isTopTag ( $ tag ) ) { return $ this -> template ; } $ v = $ this -> tags [ $ tag ] [ 0 ] ; if ( is_array ( $ v ) && count ( $ v ) == 1 ) { $ v = array_shift ( $ v ) ; } return $ v ; }
Finds tag and returns contents .
51,463
public function append ( $ tag , $ value , $ encode = true ) { if ( $ value instanceof URL ) { $ value = $ value -> __toString ( ) ; } if ( $ encode && $ value != $ this -> app -> encodeHtmlChars ( $ value , ENT_NOQUOTES ) && $ this -> app -> getConfig ( 'html_injection_debug' , false ) ) { throw $ this -> exception ( 'Attempted to supply html string through append()' ) -> addMoreInfo ( 'val' , var_export ( $ value , true ) ) -> addMoreInfo ( 'enc' , var_export ( $ this -> app -> encodeHtmlChars ( $ value , ENT_NOQUOTES ) , true ) ) ; } if ( $ encode ) { $ value = $ this -> app -> encodeHtmlChars ( $ value , ENT_NOQUOTES ) ; } if ( $ this -> isTopTag ( $ tag ) ) { $ this -> template [ ] = $ value ; return $ this ; } if ( ! isset ( $ this -> tags [ $ tag ] ) || ! is_array ( $ this -> tags [ $ tag ] ) ) { throw $ this -> exception ( "Cannot append to tag $tag" ) -> addMoreInfo ( 'by' , $ this -> owner ) ; } foreach ( $ this -> tags [ $ tag ] as $ key => $ _ ) { if ( ! is_array ( $ this -> tags [ $ tag ] [ $ key ] ) ) { $ this -> tags [ $ tag ] [ $ key ] = array ( $ this -> tags [ $ tag ] [ $ key ] ) ; } $ this -> tags [ $ tag ] [ $ key ] [ ] = $ value ; } return $ this ; }
This appends static content to region refered by a tag . This function is useful when you are adding more rows to a list or table .
51,464
public function setMessage ( $ tag , $ args = array ( ) ) { if ( ! is_array ( $ args ) ) { $ args = array ( $ args ) ; } $ fmt = $ this -> app -> _ ( $ this -> get ( $ tag ) ) ; if ( class_exists ( 'MessageFormatter' , false ) && strpos ( $ fmt , '{' ) !== null ) { $ fmt = new MessageFormatter ( $ this -> app -> locale , $ fmt ) ; $ str = $ fmt -> format ( $ args ) ; } elseif ( strpos ( $ fmt , '%' ) !== null ) { array_unshift ( $ args , $ fmt ) ; $ str = call_user_func_array ( 'sprintf' , $ args ) ; } else { throw $ this -> exception ( 'Unclear how to format this' ) -> addMoreInfo ( 'fmt' , $ fmt ) ; } return $ this -> set ( $ tag , $ str ) ; }
Provided that the HTML tag contains ICU - compatible message format string it will be localized then integrated with passed arguments .
51,465
public function hasTag ( $ tag ) { if ( $ this -> isTopTag ( $ tag ) ) { return true ; } return isset ( $ this -> tags [ $ tag ] ) && is_array ( $ this -> tags [ $ tag ] ) ; }
Check if tag is present inside template
51,466
public function rebuildTags ( ) { $ this -> tags = array ( ) ; $ this -> updated_tag_list = array ( ) ; $ this -> rebuildTagsRegion ( $ this -> template ) ; return $ this ; }
Rebuild tags of existing array structure
51,467
public function get ( ) { if ( $ this -> owner -> loaded ( ) || isset ( $ this -> owner -> data [ $ this -> short_name ] ) ) { return $ this -> owner -> get ( $ this -> short_name ) ; } return $ this -> defaultValue ( ) ; }
Get the value of the field of a loaded model . If model is not loaded will return default value instead .
51,468
public function system ( $ t = UNDEFINED ) { if ( $ t === true ) { $ this -> editable ( false ) -> visible ( false ) ; } return $ this -> setterGetter ( 'system' , $ t ) ; }
Marking field as system will cause it to always be loaded even if it s not requested through Actual Fields . It will also hide the field making it dissapear from Grids and Forms . A good examples of system fields are id or created_dts .
51,469
public function mb_str_to_lower ( $ a ) { return ( $ this -> is_mb ) ? mb_strtolower ( $ a , $ this -> encoding ) : strtolower ( $ a ) ; }
Is the PHP5 multibyte lib available?
51,470
public function search ( $ type , $ filename = '' , $ return = 'relative' ) { $ matches = array ( ) ; foreach ( $ this -> elements as $ location ) { if ( ! ( $ location instanceof PathFinder_Location ) ) { continue ; } $ path = $ location -> locate ( $ type , $ filename , $ return ) ; if ( is_string ( $ path ) ) { $ matches [ ] = $ path ; } } return $ matches ; }
Search is similar to locate but will return array of all matching files .
51,471
public function searchDir ( $ type , $ directory = '' ) { $ dirs = $ this -> search ( $ type , $ directory , 'path' ) ; $ files = array ( ) ; foreach ( $ dirs as $ dir ) { $ this -> _searchDirFiles ( $ dir , $ files ) ; } return $ files ; }
Specify type and directory and it will return array of all files of a matching type inside that directory . This will work even if specified directory exists inside multiple locations .
51,472
public function loadClass ( $ className ) { $ origClassName = str_replace ( '-' , '' , $ className ) ; $ this -> app -> pr -> start ( 'pathfinder/loadClass ' ) ; $ this -> app -> pr -> next ( 'pathfinder/loadClass/convertpath ' ) ; $ className = ltrim ( $ className , '\\' ) ; $ nsPath = '' ; $ namespace = '' ; if ( $ lastNsPos = strripos ( $ className , '\\' ) ) { $ namespace = substr ( $ className , 0 , $ lastNsPos ) ; $ className = substr ( $ className , $ lastNsPos + 1 ) ; $ nsPath = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ namespace ) ; } $ classPath = str_replace ( '_' , DIRECTORY_SEPARATOR , $ className ) . '.php' ; $ this -> app -> pr -> next ( 'pathfinder/loadClass/locate ' ) ; try { if ( $ namespace ) { if ( strpos ( $ className , 'page_' ) === 0 ) { $ path = $ this -> app -> locatePath ( 'addons' , $ nsPath . DIRECTORY_SEPARATOR . $ classPath ) ; } else { $ path = $ this -> app -> locatePath ( 'addons' , $ nsPath . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . $ classPath ) ; } } else { if ( strpos ( $ className , 'page_' ) === 0 ) { $ path = $ this -> app -> locatePath ( 'page' , substr ( $ classPath , 5 ) ) ; } else { $ path = $ this -> app -> locatePath ( 'php' , $ classPath ) ; } } } catch ( Exception_PathFinder $ e ) { $ e -> addMoreInfo ( 'class' , $ className ) -> addMoreInfo ( 'namespace' , $ namespace ) -> addMoreInfo ( 'orig_class' , $ origClassName ) ; throw $ e ; } if ( ! is_readable ( $ path ) ) { throw new Exception_PathFinder ( 'addon' , $ path , $ prefix ) ; } $ this -> app -> pr -> next ( 'pathfinder/loadClass/include ' ) ; $ this -> app -> pr -> start ( 'php parsing' ) ; include_once $ path ; if ( ! class_exists ( $ origClassName , false ) && ! interface_exists ( $ origClassName , false ) ) { throw $ this -> exception ( 'Class is not defined in file or extended class can not be found' ) -> addMoreInfo ( 'file' , $ path ) -> addMoreInfo ( 'namespace' , $ namespace ) -> addMoreInfo ( 'class' , $ className ) ; } $ this -> app -> pr -> stop ( ) ; return $ path ; }
Provided with a class name this will attempt to find and load it .
51,473
public function getURL ( $ file_path = null ) { if ( ! $ this -> base_url ) { throw new BaseException ( 'Unable to determine URL' ) ; } if ( ! $ file_path ) { return $ this -> base_url ; } $ u = $ this -> base_url ; if ( substr ( $ u , - 1 ) != '/' ) { $ u .= '/' ; } return $ u . $ file_path ; }
Returns how this location or file can be accessed through web base url + relative path + file_path .
51,474
public function setParent ( Pathfinder_Location $ parent ) { $ this -> setBasePath ( $ parent -> base_path . '/' . $ this -> _relative_path ) ; $ this -> setBaseURL ( $ parent -> base_url . '/' . $ this -> _relative_path ) ; return $ this ; }
OBSOLETE - Compatiblity
51,475
public function useFields ( $ fields ) { if ( is_string ( $ fields ) ) { $ fields = explode ( ',' , $ fields ) ; } $ this -> fields = $ fields ; return $ this ; }
Set fields on which filtering will be done .
51,476
public function postInit ( ) { parent :: postInit ( ) ; if ( ! ( $ v = trim ( $ this -> get ( 'q' ) ) ) ) { return ; } $ m = $ this -> view -> model ; if ( $ m -> hasMethod ( 'addConditionLike' ) ) { return $ m -> addConditionLike ( $ v , $ this -> fields ) ; } if ( $ m instanceof \ atk4 \ data \ Model ) { if ( ! $ m -> hasMethod ( 'expr' ) ) { return $ m ; } $ expr = [ ] ; foreach ( $ this -> fields as $ k => $ field ) { $ f = $ m -> hasElement ( $ field ) ; if ( ! $ f || $ f -> never_persist ) { unset ( $ this -> fields [ $ k ] ) ; continue ; } $ expr [ ] = 'lower({' . $ field . '}) like lower([])' ; } $ expr = '(' . implode ( ' or ' , $ expr ) . ')' ; $ expr = $ m -> expr ( $ expr , array_fill ( 0 , count ( $ this -> fields ) , '%' . $ v . '%' ) ) ; return $ m -> addCondition ( $ expr ) ; } if ( $ m instanceof SQL_Model ) { $ q = $ m -> _dsql ( ) ; } else { $ q = $ this -> view -> dq ; } $ or = $ q -> orExpr ( ) ; foreach ( $ this -> fields as $ field ) { $ or -> where ( $ field , 'like' , '%' . $ v . '%' ) ; } $ q -> having ( $ or ) ; }
Process received filtering parameters after init phase .
51,477
public function getFieldType ( $ field ) { $ type = $ field -> type ; if ( isset ( $ this -> type_associations [ $ type ] ) ) { $ type = $ this -> type_associations [ $ type ] ; } if ( $ type == 'text' && isset ( $ field -> allowHtml ) && $ field -> allowHtml ) { $ type = 'html' ; } if ( isset ( $ field -> ui [ 'display' ] ) ) { $ tmp = $ field -> ui [ 'display' ] ; if ( isset ( $ tmp [ 'grid' ] ) ) { $ tmp = $ tmp [ 'grid' ] ; } if ( is_string ( $ tmp ) && $ tmp ) { $ type = $ tmp ; } } return $ type ; }
Returns grid column type associated with model field .
51,478
public function collectBasicData ( $ code ) { $ this -> name = get_class ( $ this ) ; $ this -> my_backtrace = debug_backtrace ( ) ; array_shift ( $ this -> my_backtrace ) ; array_shift ( $ this -> my_backtrace ) ; }
Collect basic data of exception .
51,479
public function getHTML ( ) { $ e = $ this ; $ o = '<div class="atk-layout">' ; $ o .= $ this -> getHTMLHeader ( ) ; $ o .= $ this -> getHTMLSolution ( ) ; $ o .= '<div class="atk-layout-row"><div class="atk-wrapper atk-section-small">' ; if ( isset ( $ e -> more_info ) ) { $ o .= '<h3>Additional information:</h3>' ; $ o .= $ this -> print_r ( $ e -> more_info , '<ul>' , '</ul>' , '<li>' , '</li>' , ' ' ) ; } if ( method_exists ( $ e , 'getMyFile' ) ) { $ o .= '<div class="atk-effect-info">' . $ e -> getMyFile ( ) . ':' . $ e -> getMyLine ( ) . '</div>' ; } if ( method_exists ( $ e , 'getMyTrace' ) ) { $ o .= $ this -> backtrace ( 3 , $ e -> getMyTrace ( ) ) ; } else { $ o .= $ this -> backtrace ( @ $ e -> shift , $ e -> getTrace ( ) ) ; } if ( isset ( $ e -> by_exception ) ) { $ o .= '<h3>This error was triggered by the following error:</h3>' ; if ( $ e -> by_exception instanceof self ) { $ o .= $ e -> by_exception -> getHTML ( ) ; } elseif ( $ e -> by_exception instanceof Exception ) { $ o .= $ e -> by_exception -> getMessage ( ) ; } } $ o .= '</div></div>' ; return $ o ; }
Returns HTML representation of the exception .
51,480
public function getDocURL ( $ o ) { if ( ! is_object ( $ o ) ) { return false ; } if ( ! $ o instanceof AbstractObject ) { return false ; } $ url = $ o :: DOC ; if ( substr ( $ url , 0 , 4 ) != 'http' ) { return 'http://book.agiletoolkit.org/' . $ url . '.html' ; } return $ url ; }
Classes define a DOC constant which points to a on - line resource containing documentation for given class . This method will return full URL for the specified object .
51,481
public function getText ( ) { $ more_info = $ this -> print_r ( $ this -> more_info , '[' , ']' , '' , ',' , ' ' ) ; $ text = get_class ( $ this ) . ': ' . $ this -> getMessage ( ) . ' (' . $ more_info . ')' . ' in ' . $ this -> getMyFile ( ) . ':' . $ this -> getMyLine ( ) ; return $ text ; }
Returns Textual representation of the exception .
51,482
public function addPaginator ( $ rows = 25 , $ options = null , $ class = null ) { if ( $ this -> paginator ) { return $ this -> paginator ; } $ this -> paginator = $ this -> add ( $ class ? : $ this -> paginator_class , $ options ) ; $ this -> paginator -> setRowsPerPage ( $ rows ) ; return $ this -> paginator ; }
Adds paginator to the grid .
51,483
public function addQuickSearch ( $ fields , $ options = null , $ class = null , $ spot = null ) { if ( $ this -> quick_search ) { return $ this -> quick_search ; } $ this -> quick_search = $ this -> add ( $ class ? : $ this -> quick_search_class , $ options , $ spot ? : 'quick_search' ) ; $ this -> quick_search -> useWith ( $ this ) -> useFields ( $ fields ) ; return $ this -> quick_search ; }
Adds QuickSearch to the grid .
51,484
public function addSelectable ( $ field ) { $ this -> js_widget = null ; $ this -> js ( true ) -> _load ( 'ui.atk4_checkboxes' ) -> atk4_checkboxes ( array ( 'dst_field' => $ field ) ) ; $ this -> addColumn ( 'checkbox' , 'selected' ) ; $ this -> addOrder ( ) -> useArray ( $ this -> columns ) -> move ( 'selected' , 'first' ) -> now ( ) ; }
Adds column with checkboxes on the basis of Model definition .
51,485
public function makeSortable ( $ db_field = null ) { $ reverse = false ; if ( $ db_field [ 0 ] == '-' ) { $ reverse = true ; $ db_field = substr ( $ db_field , 1 ) ; } if ( ! $ db_field ) { $ db_field = $ this -> last_column ; } switch ( ( string ) $ this -> sortby ) { case $ db_field : $ info = array ( '1' , $ reverse ? 0 : ( '-' . $ db_field ) ) ; $ this -> sortby_db = $ db_field ; break ; case '-' . $ db_field : $ info = array ( '2' , $ reverse ? $ db_field : '0' ) ; $ this -> sortby_db = '-' . $ db_field ; break ; default : $ info = array ( '0' , $ reverse ? ( '-' . $ db_field ) : $ db_field ) ; } $ this -> columns [ $ db_field ] [ 'sortable' ] = $ info ; return $ this ; }
Make sortable .
51,486
public function applySorting ( $ i , $ field , $ desc ) { if ( ! $ field ) { return ; } if ( $ i instanceof DB_dsql ) { $ i -> order ( $ field , $ desc ) ; } elseif ( $ i instanceof \ atk4 \ data \ Model ) { $ i -> setOrder ( $ field , $ desc ) ; } elseif ( $ i instanceof SQL_Model ) { $ i -> setOrder ( $ field , $ desc ) ; } elseif ( $ i instanceof Model ) { $ i -> setOrder ( $ field , $ desc ) ; } }
Apply sorting on particular field .
51,487
public function getCurrentIndex ( $ idfield = 'id' ) { if ( is_array ( $ this -> data ) ) { return array_search ( current ( $ this -> data ) , $ this -> data ) ; } return $ this -> current_row [ $ idfield ] ; }
Returns ID of record .
51,488
public function setTDParam ( $ field , $ path , $ value ) { if ( $ value === null ) { return ; } $ path = explode ( '/' , $ path ) ; $ current_position = & $ this -> tdparam [ $ this -> getCurrentIndex ( ) ] [ $ field ] ; if ( ! is_array ( $ current_position ) ) { $ current_position = array ( ) ; } foreach ( $ path as $ part ) { if ( array_key_exists ( $ part , $ current_position ) ) { $ current_position = & $ current_position [ $ part ] ; } else { $ current_position [ $ part ] = array ( ) ; $ current_position = & $ current_position [ $ part ] ; } } $ current_position = $ value ; }
Sets TD params .
51,489
public function applyTDParams ( $ field , & $ row_template = null ) { if ( ! $ row_template ) { $ row_template = & $ this -> row_t ; } $ tdparam = $ this -> tdparam [ $ this -> getCurrentIndex ( ) ] [ $ field ] ; $ tdparam_str = '' ; if ( is_array ( $ tdparam ) ) { if ( is_array ( $ tdparam [ 'style' ] ) ) { $ tdparam_str .= 'style="' ; foreach ( $ tdparam [ 'style' ] as $ key => $ value ) { $ tdparam_str .= $ key . ':' . $ value . ';' ; } $ tdparam_str .= '" ' ; unset ( $ tdparam [ 'style' ] ) ; } foreach ( $ tdparam as $ id => $ value ) { $ tdparam_str .= $ id . '="' . $ value . '" ' ; } $ row_template -> set ( "tdparam_$field" , trim ( $ tdparam_str ) ) ; } }
Apply TD parameters to appropriate template .
51,490
public function setTotalsTitle ( $ field , $ title = 'Total: %s row%s' ) { $ this -> totals_title_field = $ field ; $ this -> totals_title = $ title ; return $ this ; }
Sets totals title field and text .
51,491
public function init_expander ( $ field ) { $ this -> columns [ $ field ] [ 'thparam' ] .= ' style="width:40px; text-align:center"' ; if ( ! isset ( $ this -> columns [ $ field ] [ 'refid' ] ) ) { if ( $ this -> model ) { $ refid = $ this -> model -> table ; } elseif ( $ this -> dq ) { $ refid = $ this -> dq -> args [ 'table' ] ; } else { $ refid = preg_replace ( '/.*_/' , '' , $ this -> app -> page ) ; } $ this -> columns [ $ field ] [ 'refid' ] = $ refid ; } $ class = $ this -> name . '_' . $ field . '_expander' ; $ this -> js ( true ) -> find ( '.' . $ class ) -> button ( ) ; $ this -> js ( true ) -> _selector ( '.' . $ class ) -> _load ( 'ui.atk4_expander' ) -> atk4_expander ( ) ; }
Initialize expander .
51,492
public function format_expander ( $ field , $ column ) { if ( ! $ this -> current_row [ $ field ] ) { $ this -> current_row [ $ field ] = $ column [ 'descr' ] ; } $ key = $ this -> name . '_' . $ field . '_' ; $ id = $ key . $ this -> app -> normalizeName ( $ this -> model -> id ) ; $ class = $ key . 'expander' ; $ this -> current_row_html [ $ field ] = '<input type="checkbox" ' . 'class="' . $ class . '" ' . 'id="' . $ id . '" ' . 'rel="' . $ this -> app -> url ( $ column [ 'page' ] ? : './' . $ field , array ( 'expander' => $ field , 'expanded' => $ this -> name , 'cut_page' => 1 , $ this -> columns [ $ field ] [ 'refid' ] . '_' . $ this -> model -> id_field => $ this -> model -> id , ) ) . '" ' . '/>' . '<label for="' . $ id . '" style="cursor:pointer;"><a class="atk-button-small">' . $ this -> current_row [ $ field ] . '</a></label>' ; }
Format expander .
51,493
public function format_float ( $ field ) { $ precision = 2 ; $ m = ( float ) $ this -> current_row [ $ field ] ; $ this -> current_row [ $ field ] = is_null ( $ this -> current_row [ $ field ] ) ? '-' : number_format ( $ m , $ precision ) ; $ this -> setTDParam ( $ field , 'align' , 'right' ) ; $ this -> setTDParam ( $ field , 'style/white-space' , 'nowrap' ) ; }
Format field as real number with 2 digit precision .
51,494
public function format_boolean ( $ field ) { $ value = $ this -> current_row [ $ field . '_original' ] ; $ label = $ this -> current_row [ $ field ] ; if ( $ value === true || $ value === 1 || $ value === 'Y' ) { $ this -> current_row_html [ $ field ] = '<div align=center>' . '<i class="icon-check">' . ( $ label !== $ value ? $ label : $ this -> app -> _ ( 'yes' ) ) . '</i>' . '</div>' ; } else { $ this -> current_row_html [ $ field ] = '' ; } }
Format field as boolean .
51,495
public function format_money ( $ field ) { $ this -> format_real ( $ field ) ; if ( $ this -> current_row [ $ field ] < 0 ) { $ this -> setTDParam ( $ field , 'style/color' , 'red' ) ; } else { $ this -> setTDParam ( $ field , 'style/color' , false ) ; } }
Format field as money with 2 digit precision .
51,496
public function format_object ( $ field ) { $ this -> current_row [ $ field ] = ( string ) $ this -> current_row [ $ field ] ; return $ this -> format_shorttext ( $ field ) ; }
Format field as object .
51,497
public function format_json ( $ field ) { if ( ! is_scalar ( $ this -> current_row [ $ field ] ) ) { $ this -> current_row [ $ field ] = json_encode ( $ this -> current_row [ $ field ] ) ; } }
Format field by json encoding it .
51,498
public function format_date ( $ field ) { if ( ! $ this -> current_row [ $ field ] ) { $ this -> current_row [ $ field ] = '-' ; } else { if ( is_object ( $ this -> current_row [ $ field ] ) ) { $ this -> current_row [ $ field ] = $ this -> current_row [ $ field ] -> format ( $ this -> app -> getConfig ( 'locale/date' , 'd/m/Y' ) ) ; } else { $ this -> current_row [ $ field ] = date ( $ this -> app -> getConfig ( 'locale/date' , 'd/m/Y' ) , strtotime ( $ this -> current_row [ $ field ] ) ) ; } } }
Format field as date .
51,499
public function format_time ( $ field ) { $ this -> current_row [ $ field ] = date ( $ this -> app -> getConfig ( 'locale/time' , 'H:i:s' ) , strtotime ( $ this -> current_row [ $ field ] ) ) ; }
Format field as time .