idx int64 0 241k | question stringlengths 64 6.21k | target stringlengths 5 803 |
|---|---|---|
6,400 | protected function rememberMe ( $ connected ) { $ id = $ this -> toCookie ( $ connected ) ; if ( isset ( $ id ) ) { UCookie :: set ( $ this -> _getUserSessionKey ( ) , $ id ) ; } } | Saves the connected user identifier in a cookie |
6,401 | public static function safeMkdir ( $ dir , $ mode = 0777 , $ recursive = true ) { if ( ! \ is_dir ( $ dir ) ) return \ mkdir ( $ dir , $ mode , $ recursive ) ; return true ; } | Tests the existance and eventually creates a directory |
6,402 | public static function cleanPathname ( $ path ) { if ( UString :: isNotNull ( $ path ) ) { if ( \ DS === "/" ) $ path = \ str_replace ( "\\" , \ DS , $ path ) ; else $ path = \ str_replace ( "/" , \ DS , $ path ) ; $ path = \ str_replace ( \ DS . \ DS , \ DS , $ path ) ; if ( ! UString :: endswith ( $ path , \ DS ) ) { $ path = $ path . \ DS ; } } return $ path ; } | Cleans a directory path by removing double backslashes or slashes and using DIRECTORY_SEPARATOR |
6,403 | public static function cleanFilePathname ( $ path ) { if ( UString :: isNotNull ( $ path ) ) { if ( \ DS === "/" ) $ path = \ str_replace ( "\\" , \ DS , $ path ) ; else $ path = \ str_replace ( "/" , \ DS , $ path ) ; $ path = \ str_replace ( \ DS . \ DS , \ DS , $ path ) ; } return $ path ; } | Cleans a file path by removing double backslashes or slashes and using DIRECTORY_SEPARATOR |
6,404 | public static function getLines ( $ filename , $ reverse = false , $ maxLines = null , $ lineCallback = null ) { if ( file_exists ( $ filename ) ) { if ( $ reverse && isset ( $ maxLines ) ) { $ result = [ ] ; $ fl = fopen ( $ filename , "r" ) ; for ( $ x_pos = 0 , $ ln = 0 , $ lines = [ ] ; fseek ( $ fl , $ x_pos , SEEK_END ) !== - 1 ; $ x_pos -- ) { $ char = fgetc ( $ fl ) ; if ( $ char === "\n" ) { if ( is_callable ( $ lineCallback ) ) { $ lineCallback ( $ result , $ lines [ $ ln ] ) ; } else { $ result [ ] = $ lines [ $ ln ] ; } if ( isset ( $ maxLines ) && sizeof ( $ result ) >= $ maxLines ) { fclose ( $ fl ) ; return $ result ; } $ ln ++ ; continue ; } $ lines [ $ ln ] = $ char . ( ( array_key_exists ( $ ln , $ lines ) ) ? $ lines [ $ ln ] : '' ) ; } fclose ( $ fl ) ; return $ result ; } else { return self :: getLinesByLine ( $ filename , $ reverse , $ maxLines , $ lineCallback ) ; } } return [ ] ; } | Returns the lines of a file in an array |
6,405 | public static function init ( & $ config ) { $ controllers = CacheManager :: getControllers ( ) ; foreach ( $ controllers as $ controller ) { CacheManager :: $ cache -> remove ( self :: getControllerCacheKey ( $ controller ) ) ; $ parser = new DiControllerParser ( ) ; $ parser -> parse ( $ controller , $ config ) ; $ injections = $ parser -> getInjections ( ) ; if ( sizeof ( $ injections ) > 0 ) { self :: store ( $ controller , $ parser -> __toString ( ) ) ; } } } | Initialize dependency injection cache To use in dev only! |
6,406 | public static function save ( $ array , $ filename ) { $ content = "<?php\nreturn " . self :: asPhpArray ( $ array , "array" , 1 , true ) . ";" ; return UFileSystem :: save ( $ filename , $ content ) ; } | Save a php array to the disk . |
6,407 | public static function getRoute ( $ path , $ cachedResponse = true ) { $ path = self :: slashPath ( $ path ) ; if ( isset ( self :: $ routes [ $ path ] ) ) { return self :: getRoute_ ( self :: $ routes [ $ path ] , $ path , [ $ path ] , $ cachedResponse ) ; } foreach ( self :: $ routes as $ routePath => $ routeDetails ) { if ( preg_match ( "@^" . $ routePath . "$@s" , $ path , $ matches ) ) { if ( ( $ r = self :: getRoute_ ( $ routeDetails , $ routePath , $ matches , $ cachedResponse ) ) !== false ) { return $ r ; } } } Logger :: warn ( "Router" , "No route found for {$path}" , "getRoute" ) ; return false ; } | Returns the route corresponding to a path |
6,408 | public static function url ( $ name , $ parameters = [ ] ) { return URequest :: getUrl ( self :: getRouteByName ( $ name , $ parameters , false ) ) ; } | Returns the generated url from a route |
6,409 | public static function slashPath ( $ path ) { if ( UString :: startswith ( $ path , "/" ) === false ) $ path = "/" . $ path ; if ( ! UString :: endswith ( $ path , "/" ) ) $ path = $ path . "/" ; return $ path ; } | Adds a slash before and after a path |
6,410 | public static function validate ( $ instance , $ group = "" ) { $ class = get_class ( $ instance ) ; $ cache = self :: getClassCacheValidators ( $ class , $ group ) ; if ( $ cache !== false ) { return self :: validateFromCache_ ( $ instance , $ cache ) ; } $ members = self :: fetch ( $ class ) ; if ( $ group !== "" ) { $ members = self :: getGroupArrayValidators ( $ members , $ group ) ; } return self :: validate_ ( $ instance , $ members ) ; } | Validates an instance |
6,411 | public static function validateInstances ( $ instances , $ group = "" ) { if ( sizeof ( $ instances ) > 0 ) { $ instance = current ( $ instances ) ; $ class = get_class ( $ instance ) ; $ cache = self :: getClassCacheValidators ( $ class , $ group ) ; if ( $ cache === false ) { $ members = self :: fetch ( $ class ) ; self :: initInstancesValidators ( $ instance , $ members , $ group ) ; $ cache = self :: $ instanceValidators [ $ class ] ; } return self :: validateInstances_ ( $ instances , $ cache ) ; } return [ ] ; } | Validates an array of objects |
6,412 | public static function getModels ( & $ config , $ silent = false ) { $ result = [ ] ; $ files = self :: getModelsFiles ( $ config , $ silent ) ; foreach ( $ files as $ file ) { $ result [ ] = ClassUtils :: getClassFullNameFromFile ( $ file ) ; } return $ result ; } | Returns an array of the models class names |
6,413 | public function refresh_ ( ) { $ model = $ this -> model ; if ( isset ( $ _POST [ "s" ] ) ) { $ instances = $ this -> search ( $ model , $ _POST [ "s" ] ) ; } else { $ page = URequest :: post ( "p" , 1 ) ; $ instances = $ this -> getInstances ( $ totalCount , $ page ) ; } if ( ! isset ( $ totalCount ) ) { $ totalCount = DAO :: count ( $ model , $ this -> _getAdminData ( ) -> _getInstancesFilter ( $ model ) ) ; } $ recordsPerPage = $ this -> _getModelViewer ( ) -> recordsPerPage ( $ model , $ totalCount ) ; $ grpByFields = $ this -> _getModelViewer ( ) -> getGroupByFields ( ) ; if ( isset ( $ recordsPerPage ) ) { if ( ! is_array ( $ grpByFields ) ) { UResponse :: asJSON ( ) ; $ responseFormatter = new ResponseFormatter ( ) ; print_r ( $ responseFormatter -> getJSONDatas ( $ instances ) ) ; } else { $ this -> _renderDataTableForRefresh ( $ instances , $ model , $ totalCount ) ; } } else { $ this -> jquery -> execAtLast ( '$("#search-query-content").html("' . $ _POST [ "s" ] . '");$("#search-query").show();$("#table-details").html("");' ) ; $ this -> _renderDataTableForRefresh ( $ instances , $ model , $ totalCount ) ; } } | Refreshes the area corresponding to the DataTable |
6,414 | public function edit ( $ modal = "no" , $ ids = "" ) { if ( URequest :: isAjax ( ) ) { $ instance = $ this -> getModelInstance ( $ ids , false ) ; $ instance -> _new = false ; $ this -> _edit ( $ instance , $ modal ) ; } else { $ this -> jquery -> execAtLast ( "$('._edit[data-ajax={$ids}]').trigger('click');" ) ; $ this -> index ( ) ; } } | Edits an instance |
6,415 | public function newModel ( $ modal = "no" ) { if ( URequest :: isAjax ( ) ) { $ model = $ this -> model ; $ instance = new $ model ( ) ; $ instance -> _new = true ; $ this -> _edit ( $ instance , $ modal ) ; } else { $ this -> jquery -> execAtLast ( "$('.ui.button._new').trigger('click');" ) ; $ this -> index ( ) ; } } | Adds a new instance and edits it |
6,416 | public function display ( $ modal = "no" , $ ids = "" ) { if ( URequest :: isAjax ( ) ) { $ instance = $ this -> getModelInstance ( $ ids ) ; $ key = OrmUtils :: getFirstKeyValue ( $ instance ) ; $ this -> jquery -> execOn ( "click" , "._close" , '$("#table-details").html("");$("#dataTable").show();' ) ; $ this -> jquery -> getOnClick ( "._edit" , $ this -> _getBaseRoute ( ) . "/edit/" . $ modal . "/" . $ key , "#frm-add-update" ) ; $ this -> jquery -> getOnClick ( "._delete" , $ this -> _getBaseRoute ( ) . "/delete/" . $ key , "#table-messages" ) ; $ this -> _getModelViewer ( ) -> getModelDataElement ( $ instance , $ this -> model , $ modal ) ; $ this -> jquery -> renderView ( $ this -> _getFiles ( ) -> getViewDisplay ( ) , [ "classname" => $ this -> model , "instance" => $ instance , "pk" => $ key ] ) ; } else { $ this -> jquery -> execAtLast ( "$('._display[data-ajax={$ids}]').trigger('click');" ) ; $ this -> index ( ) ; } } | Displays an instance |
6,417 | public function delete ( $ ids ) { if ( URequest :: isAjax ( ) ) { $ instance = $ this -> getModelInstance ( $ ids ) ; $ instanceString = $ this -> getInstanceToString ( $ instance ) ; if ( sizeof ( $ _POST ) > 0 ) { try { if ( DAO :: remove ( $ instance ) ) { $ message = new CRUDMessage ( "Deletion of `<b>" . $ instanceString . "</b>`" , "Deletion" , "info" , "info circle" , 4000 ) ; $ message = $ this -> _getEvents ( ) -> onSuccessDeleteMessage ( $ message , $ instance ) ; $ this -> jquery -> exec ( "$('._element[data-ajax={$ids}]').remove();" , true ) ; } else { $ message = new CRUDMessage ( "Can not delete `" . $ instanceString . "`" , "Deletion" , "warning" , "warning circle" ) ; $ message = $ this -> _getEvents ( ) -> onErrorDeleteMessage ( $ message , $ instance ) ; } } catch ( \ Exception $ e ) { $ message = new CRUDMessage ( "Exception : can not delete `" . $ instanceString . "`" , "Exception" , "warning" , "warning" ) ; $ message = $ this -> _getEvents ( ) -> onErrorDeleteMessage ( $ message , $ instance ) ; } $ message = $ this -> _showSimpleMessage ( $ message ) ; } else { $ message = new CRUDMessage ( "Do you confirm the deletion of `<b>" . $ instanceString . "</b>`?" , "Remove confirmation" , "error" , "question circle" ) ; $ message = $ this -> _getEvents ( ) -> onConfDeleteMessage ( $ message , $ instance ) ; $ message = $ this -> _showConfMessage ( $ message , $ this -> _getBaseRoute ( ) . "/delete/{$ids}" , "#table-messages" , $ ids ) ; } echo $ message ; echo $ this -> jquery -> compile ( $ this -> view ) ; } else { $ this -> jquery -> execAtLast ( "$('._delete[data-ajax={$ids}]').trigger('click');" ) ; $ this -> index ( ) ; } } | Deletes an instance |
6,418 | public function update ( ) { $ message = new CRUDMessage ( "Modifications were successfully saved" , "Updating" ) ; $ instance = $ _SESSION [ "instance" ] ?? null ; if ( isset ( $ instance ) ) { $ isNew = $ instance -> _new ; try { $ updated = CRUDHelper :: update ( $ instance , $ _POST ) ; if ( $ updated ) { $ message -> setType ( "success" ) -> setIcon ( "check circle outline" ) ; $ message = $ this -> _getEvents ( ) -> onSuccessUpdateMessage ( $ message , $ instance ) ; $ this -> refreshInstance ( $ instance , $ isNew ) ; } else { $ message -> setMessage ( "An error has occurred. Can not save changes." ) -> setType ( "error" ) -> setIcon ( "warning circle" ) ; $ message = $ this -> _getEvents ( ) -> onErrorUpdateMessage ( $ message , $ instance ) ; } } catch ( \ Exception $ e ) { $ instanceString = $ this -> getInstanceToString ( $ instance ) ; $ message = new CRUDMessage ( "Exception : can not update `" . $ instanceString . "`" , "Exception" , "warning" , "warning" ) ; $ message = $ this -> _getEvents ( ) -> onErrorUpdateMessage ( $ message , $ instance ) ; } echo $ this -> _showSimpleMessage ( $ message , "updateMsg" ) ; echo $ this -> jquery -> compile ( $ this -> view ) ; return $ instance ; } else { throw new \ Exception ( '$_SESSION["instance"] is null' ) ; } } | Updates an instance from the data posted in a form |
6,419 | public function showDetail ( $ ids ) { if ( URequest :: isAjax ( ) ) { $ instance = $ this -> getModelInstance ( $ ids ) ; $ viewer = $ this -> _getModelViewer ( ) ; $ hasElements = false ; $ model = $ this -> model ; $ fkInstances = CRUDHelper :: getFKIntances ( $ instance , $ model ) ; $ semantic = $ this -> jquery -> semantic ( ) ; $ grid = $ semantic -> htmlGrid ( "detail" ) ; if ( sizeof ( $ fkInstances ) > 0 ) { $ wide = intval ( 16 / sizeof ( $ fkInstances ) ) ; if ( $ wide < 4 ) $ wide = 4 ; foreach ( $ fkInstances as $ member => $ fkInstanceArray ) { $ element = $ viewer -> getFkMemberElementDetails ( $ member , $ fkInstanceArray [ "objectFK" ] , $ fkInstanceArray [ "fkClass" ] , $ fkInstanceArray [ "fkTable" ] ) ; if ( isset ( $ element ) ) { $ grid -> addCol ( $ wide ) -> setContent ( $ element ) ; $ hasElements = true ; } } if ( $ hasElements ) { echo $ grid ; $ url = $ this -> _getFiles ( ) -> getDetailClickURL ( $ this -> model ) ; if ( UString :: isNotNull ( $ url ) ) { $ this -> detailClick ( $ url ) ; } } echo $ this -> jquery -> compile ( $ this -> view ) ; } } else { $ this -> jquery -> execAtLast ( "$('tr[data-ajax={$ids}]').trigger('click');" ) ; $ this -> index ( ) ; } } | Shows associated members with foreign keys |
6,420 | public function getDatas ( $ objects , & $ classname = null ) { $ objects = \ array_map ( function ( $ o ) use ( & $ classname ) { return $ this -> cleanRestObject ( $ o , $ classname ) ; } , $ objects ) ; return \ array_values ( $ objects ) ; } | Returns an array of datas from an array of objects |
6,421 | public static function connect ( $ dbType , $ dbName , $ serverName = '127.0.0.1' , $ port = '3306' , $ user = 'root' , $ password = '' , $ options = [ ] , $ cache = false ) { self :: $ db = new Database ( $ dbType , $ dbName , $ serverName , $ port , $ user , $ password , $ options , $ cache ) ; try { self :: $ db -> connect ( ) ; } catch ( \ Exception $ e ) { Logger :: error ( "DAO" , $ e -> getMessage ( ) ) ; throw new DAOException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e -> getPrevious ( ) ) ; } } | Establishes the connection to the database using the past parameters |
6,422 | public static function isConnected ( ) { return self :: $ db !== null && ( self :: $ db instanceof Database ) && self :: $ db -> isConnected ( ) ; } | Returns true if the connection to the database is established |
6,423 | public static function getNamespaceFromParts ( $ parts ) { $ resultArray = [ ] ; if ( ! \ is_array ( $ parts ) ) { $ parts = [ $ parts ] ; } foreach ( $ parts as $ part ) { $ resultArray = \ array_merge ( $ resultArray , \ explode ( "\\" , $ part ) ) ; } $ resultArray = \ array_diff ( $ resultArray , [ "" ] ) ; return \ implode ( "\\" , $ resultArray ) ; } | Returns a cleanly namespace |
6,424 | public static function getClassNameWithNS ( $ defaultNS , $ name ) { if ( \ strpos ( $ name , "\\" ) === false ) { $ name = $ defaultNS . "\\" . $ name ; } return $ name ; } | Returns the complete name of a class |
6,425 | public static function setContentType ( $ contentType , $ encoding = null ) { $ value = $ contentType ; if ( isset ( $ encoding ) ) $ value .= ' ;charset=' . $ encoding ; self :: header ( 'Content-Type' , $ value ) ; } | Sets header content - type |
6,426 | public static function addOrRemoveValueFromArray ( $ arrayKey , $ value , $ add = null ) { $ array = self :: getArray ( $ arrayKey ) ; $ _SESSION [ $ arrayKey ] = $ array ; $ search = array_search ( $ value , $ array ) ; if ( $ search === FALSE && $ add ) { $ _SESSION [ $ arrayKey ] [ ] = $ value ; return true ; } else if ( $ add !== true ) { unset ( $ _SESSION [ $ arrayKey ] [ $ search ] ) ; $ _SESSION [ $ arrayKey ] = array_values ( $ _SESSION [ $ arrayKey ] ) ; return false ; } } | Adds or removes a value from an array in session |
6,427 | public static function setBoolean ( $ key , $ value ) { $ _SESSION [ $ key ] = UString :: isBooleanTrue ( $ value ) ; return $ _SESSION [ $ key ] ; } | Sets a boolean value at key position in session |
6,428 | public static function getBoolean ( $ key ) { self :: start ( ) ; $ ret = false ; if ( isset ( $ _SESSION [ $ key ] ) ) { $ ret = UString :: isBooleanTrue ( $ _SESSION [ $ key ] ) ; } return $ ret ; } | Returns a boolean stored at the key position in session |
6,429 | public static function inc ( $ key , $ inc = 1 ) { return self :: set ( $ key , self :: get ( $ key , 0 ) + $ inc ) ; } | Increment the value at the key index in session |
6,430 | public static function dec ( $ key , $ dec = 1 ) { return self :: set ( $ key , self :: get ( $ key , 0 ) - $ dec ) ; } | Decrement the value at the key index in session |
6,431 | public static function concat ( $ key , $ str , $ default = NULL ) { return self :: set ( $ key , self :: get ( $ key , $ default ) . $ str ) ; } | Adds a string at the end of the value at the key index in session |
6,432 | public static function apply ( $ key , $ callback , $ default = NULL ) { $ value = self :: get ( $ key , $ default ) ; if ( is_string ( $ callback ) && function_exists ( $ callback ) ) { $ value = call_user_func ( $ callback , $ value ) ; } elseif ( is_callable ( $ callback ) ) { $ value = $ callback ( $ value ) ; } else { return $ value ; } return self :: set ( $ key , $ value ) ; } | Applies a callback function to the value at the key index in session |
6,433 | public static function Walk ( $ callback , $ userData = null ) { self :: start ( ) ; array_walk ( $ _SESSION , $ callback , $ userData ) ; return $ _SESSION ; } | Apply a user supplied function to every member of Session array |
6,434 | public static function start ( $ name = null ) { if ( ! self :: isStarted ( ) ) { if ( isset ( $ name ) && $ name !== "" ) { self :: $ name = $ name ; } if ( isset ( self :: $ name ) ) { \ session_name ( self :: $ name ) ; } \ session_start ( ) ; } } | Start new or resume existing session |
6,435 | public static function init ( $ key , $ value ) { if ( ! isset ( $ _SESSION [ $ key ] ) ) { $ _SESSION [ $ key ] = $ value ; } return $ _SESSION [ $ key ] ; } | Initialize the key in Session if key does not exists |
6,436 | public static function terminate ( ) { if ( ! self :: isStarted ( ) ) return ; self :: start ( ) ; $ _SESSION = array ( ) ; if ( \ ini_get ( "session.use_cookies" ) ) { $ params = \ session_get_cookie_params ( ) ; \ setcookie ( \ session_name ( ) , '' , \ time ( ) - 42000 , $ params [ "path" ] , $ params [ "domain" ] , $ params [ "secure" ] , $ params [ "httponly" ] ) ; } \ session_destroy ( ) ; } | Terminates the active session |
6,437 | protected function addPageLinks ( & $ r , $ classname , $ pages ) { $ pageSize = $ pages [ 'pageSize' ] ; unset ( $ pages [ 'pageSize' ] ) ; foreach ( $ pages as $ page => $ number ) { $ r [ 'links' ] [ $ page ] = $ this -> getLink ( $ this -> pageLink , [ "baseRoute" => $ this -> baseRoute , 'classname' => $ classname , 'pageNumber' => $ number , 'pageSize' => $ pageSize ] ) ; } } | Adds page links |
6,438 | protected function _deleteMultiple ( $ data , $ action , $ target , $ condition ) { if ( URequest :: isPost ( ) ) { if ( is_callable ( $ condition ) ) { $ condition = $ condition ( $ data ) ; } $ rep = DAO :: deleteAll ( $ this -> model , $ condition ) ; if ( $ rep ) { $ message = new CRUDMessage ( "Deleting {count} objects" , "Deletion" , "info" , "info circle" , 4000 ) ; $ message = $ this -> _getEvents ( ) -> onSuccessDeleteMultipleMessage ( $ message , $ rep ) ; $ message -> parseContent ( [ "count" => $ rep ] ) ; } if ( isset ( $ message ) ) { $ this -> _showSimpleMessage ( $ message , "delete-all" ) ; } $ this -> index ( ) ; } else { $ message = new CRUDMessage ( "Do you confirm the deletion of this objects?" , "Remove confirmation" , "error" ) ; $ this -> _getEvents ( ) -> onConfDeleteMultipleMessage ( $ message , $ data ) ; $ message = $ this -> _showConfMessage ( $ message , $ this -> _getBaseRoute ( ) . "/{$action}/{$data}" , $ target , $ data , [ "jqueryDone" => "replaceWith" ] ) ; echo $ message ; echo $ this -> jquery -> compile ( $ this -> view ) ; } } | Helper to delete multiple objects |
6,439 | public static function initModelsValidators ( & $ config ) { $ models = CacheManager :: getModels ( $ config , true ) ; foreach ( $ models as $ model ) { self :: initClassValidators ( $ model ) ; } } | Parses models and save validators in cache to use in dev only |
6,440 | public function getForm ( $ identifier , $ instance ) { $ form = $ this -> jquery -> semantic ( ) -> dataForm ( $ identifier , $ instance ) ; $ form -> setLibraryId ( "frmEdit" ) ; $ className = \ get_class ( $ instance ) ; $ fields = $ this -> controller -> _getAdminData ( ) -> getFormFieldNames ( $ className , $ instance ) ; $ relFields = OrmUtils :: getFieldsInRelations_ ( $ className ) ; $ this -> setFormFields_ ( $ fields , $ relFields ) ; array_unshift ( $ fields , "_message" ) ; $ form -> setFields ( $ fields ) ; $ fieldTypes = OrmUtils :: getFieldTypes ( $ className ) ; $ this -> setFormFieldsComponent ( $ form , $ fieldTypes ) ; $ this -> relationMembersInForm ( $ form , $ instance , $ className , $ fields , $ relFields ) ; OrmUtils :: setFieldToMemberNames ( $ fields , $ relFields ) ; $ form -> setCaptions ( $ this -> getFormCaptions ( $ fields , $ className , $ instance ) ) ; $ message = $ this -> getFormTitle ( $ form , $ instance ) ; $ form -> setCaption ( "_message" , $ message [ "subMessage" ] ) ; $ form -> fieldAsMessage ( "_message" , [ "icon" => $ message [ "icon" ] ] ) ; $ instance -> _message = $ message [ "message" ] ; $ form -> setSubmitParams ( $ this -> controller -> _getBaseRoute ( ) . "/update" , "#frm-add-update" ) ; $ form -> onGenerateField ( [ $ this , 'onGenerateFormField' ] ) ; return $ form ; } | Returns the form for adding or modifying an object |
6,441 | protected function getFormTitle ( $ form , $ instance ) { $ type = ( $ instance -> _new ) ? "new" : "edit" ; $ messageInfos = [ "new" => [ "icon" => HtmlIconGroups :: corner ( "table" , "plus" , "big" ) , "subMessage" => "New object creation" ] , "edit" => [ "icon" => HtmlIconGroups :: corner ( "table" , "edit" , "big" ) , "subMessage" => "Editing an existing object" ] ] ; $ message = $ messageInfos [ $ type ] ; $ message [ "message" ] = \ get_class ( $ instance ) ; return $ message ; } | Returns an associative array defining form message title with keys icon message subMessage |
6,442 | public function getModelDataElement ( $ instance , $ model , $ modal ) { $ semantic = $ this -> jquery -> semantic ( ) ; $ fields = $ this -> controller -> _getAdminData ( ) -> getElementFieldNames ( $ model ) ; $ dataElement = $ semantic -> dataElement ( "de" , $ instance ) ; $ pk = OrmUtils :: getFirstKeyValue ( $ instance ) ; $ dataElement -> getInstanceViewer ( ) -> setIdentifierFunction ( function ( ) use ( $ pk ) { return $ pk ; } ) ; $ dataElement -> setFields ( $ fields ) ; $ dataElement -> setCaptions ( $ this -> getElementCaptions ( $ fields , $ model , $ instance ) ) ; $ fkInstances = CRUDHelper :: getFKIntances ( $ instance , $ model ) ; foreach ( $ fkInstances as $ member => $ fkInstanceArray ) { if ( array_search ( $ member , $ fields ) !== false ) { $ dataElement -> setValueFunction ( $ member , function ( ) use ( $ fkInstanceArray , $ member ) { return $ this -> getFkMemberElement ( $ member , $ fkInstanceArray [ "objectFK" ] , $ fkInstanceArray [ "fkClass" ] , $ fkInstanceArray [ "fkTable" ] ) ; } ) ; } } $ this -> addEditMemberFonctionality ( "dataElement" ) ; return $ dataElement ; } | Returns a DataElement object for displaying the instance Used in the display method of the CrudController in display route |
6,443 | public function getModelDataTable ( $ instances , $ model , $ totalCount , $ page = 1 ) { $ adminRoute = $ this -> controller -> _getBaseRoute ( ) ; $ files = $ this -> controller -> _getFiles ( ) ; $ dataTable = $ this -> getDataTableInstance ( $ instances , $ model , $ totalCount , $ page ) ; $ attributes = $ this -> controller -> _getAdminData ( ) -> getFieldNames ( $ model ) ; $ this -> setDataTableAttributes ( $ dataTable , $ attributes , $ model , $ instances ) ; $ dataTable -> setCaptions ( $ this -> getCaptions ( $ attributes , $ model ) ) ; $ dataTable -> addClass ( "small very compact" ) ; $ lbl = new HtmlLabel ( "search-query" , "<span id='search-query-content'></span>" ) ; $ icon = $ lbl -> addIcon ( "delete" , false ) ; $ lbl -> wrap ( "<span>" , "</span>" ) ; $ lbl -> setProperty ( "style" , "display: none;" ) ; $ icon -> getOnClick ( $ adminRoute . $ files -> getRouteRefreshTable ( ) , "#lv" , [ "jqueryDone" => "replaceWith" , "hasLoader" => "internal" ] ) ; $ dataTable -> addItemInToolbar ( $ lbl ) ; $ dataTable -> addSearchInToolbar ( ) ; $ dataTable -> setToolbarPosition ( PositionInTable :: FOOTER ) ; $ dataTable -> getToolbar ( ) -> setSecondary ( ) ; return $ dataTable ; } | Returns the dataTable responsible for displaying instances of the model |
6,444 | protected function getDataTableInstance ( $ instances , $ model , $ totalCount , $ page = 1 ) : DataTable { $ semantic = $ this -> jquery -> semantic ( ) ; $ recordsPerPage = $ this -> recordsPerPage ( $ model , $ totalCount ) ; if ( is_numeric ( $ recordsPerPage ) ) { $ grpByFields = $ this -> getGroupByFields ( ) ; if ( is_array ( $ grpByFields ) ) { $ dataTable = $ semantic -> dataTable ( "lv" , $ model , $ instances ) ; $ dataTable -> setGroupByFields ( $ grpByFields ) ; } else { $ dataTable = $ semantic -> jsonDataTable ( "lv" , $ model , $ instances ) ; } $ dataTable -> paginate ( $ page , $ totalCount , $ recordsPerPage , 5 ) ; $ dataTable -> onActiveRowChange ( '$("#table-details").html("");' ) ; $ dataTable -> onSearchTerminate ( '$("#search-query-content").html(data);$("#search-query").show();$("#table-details").html("");' ) ; } else { $ dataTable = $ semantic -> dataTable ( "lv" , $ model , $ instances ) ; } return $ dataTable ; } | Returns the dataTable instance for dispaying a list of object |
6,445 | public static function setActiveTheme ( $ activeTheme ) { self :: $ activeTheme = $ activeTheme ?? '' ; $ engineInstance = Startup :: $ templateEngine ; if ( $ engineInstance instanceof Twig ) { $ engineInstance -> setTheme ( $ activeTheme , self :: THEMES_FOLDER ) ; } else { throw new ThemesException ( 'Template engine must be an instance of Twig for themes activation!' ) ; } } | Sets the activeTheme |
6,446 | public static function getAvailableThemes ( ) { $ path = \ ROOT . \ DS . 'views' . \ DS . self :: THEMES_FOLDER . \ DS . '*' ; $ dirs = \ glob ( $ path , GLOB_ONLYDIR | GLOB_NOSORT ) ; $ result = [ ] ; foreach ( $ dirs as $ dir ) { $ result [ ] = basename ( $ dir ) ; } return $ result ; } | Returns the names of available themes . |
6,447 | public static function getDatas ( ) { $ method = \ strtolower ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; switch ( $ method ) { case 'post' : if ( self :: getContentType ( ) == 'application/x-www-form-urlencoded' ) { return $ _POST ; } break ; case 'get' : return $ _GET ; default : return self :: getInput ( ) ; } return self :: getInput ( ) ; } | Returns the query data regardless of the method |
6,448 | public static function getBoolean ( $ key ) { $ ret = false ; if ( isset ( $ _REQUEST [ $ key ] ) ) { $ ret = UString :: isBooleanTrue ( $ _REQUEST [ $ key ] ) ; } return $ ret ; } | Returns a boolean at the key position in request |
6,449 | public static function getOrigin ( ) { $ headers = getallheaders ( ) ; if ( isset ( $ headers [ 'Origin' ] ) ) { return $ headers [ 'Origin' ] ; } if ( isset ( $ _SERVER [ 'HTTP_ORIGIN' ] ) ) { return $ _SERVER [ 'HTTP_ORIGIN' ] ; } else if ( isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ) { return $ _SERVER [ 'HTTP_REFERER' ] ; } else { return $ _SERVER [ 'REMOTE_ADDR' ] ; } } | Returns the request origin |
6,450 | public function fetch ( $ key ) { $ result = $ this -> cacheInstance -> getItem ( $ this -> getRealKey ( $ key ) ) -> get ( ) ; return eval ( $ result ) ; } | Fetches data stored for the given key . |
6,451 | public static function set ( $ name , $ value , $ duration = 60 * 60 * 24 , $ path = "/" , $ secure = false , $ httpOnly = false ) { \ setcookie ( $ name , $ value , \ time ( ) + $ duration , $ path , $ secure , $ httpOnly ) ; } | Sends a cookie |
6,452 | public static function deleteAll ( $ path = "/" ) { foreach ( $ _COOKIE as $ name => $ value ) { self :: delete ( $ name , $ path ) ; } } | Deletes all cookies |
6,453 | public static function setRaw ( $ name , $ value , $ duration = 60 * 60 * 24 , $ path = "/" , $ secure = false , $ httpOnly = false ) { return \ setrawcookie ( $ name , $ value , \ time ( ) + $ duration , $ path , $ secure , $ httpOnly ) ; } | Sends a raw cookie without urlencoding the cookie value |
6,454 | public static function pluralize ( $ count , $ zero , $ one , $ other ) { $ result = $ other ; if ( $ count === 0 ) { $ result = $ zero ; } elseif ( $ count === 1 ) { $ result = $ one ; } return \ str_replace ( '{count}' , $ count , $ result ) ; } | Pluralize an expression |
6,455 | public function get ( $ url , array $ params = [ ] ) { $ queryString = '?' . http_build_query ( $ params ) ; $ url = $ url . $ queryString ; $ request = new Request ( $ url , 'GET' ) ; return $ this -> send ( $ request ) ; } | Takes a URL and a key = > value array to generate a GET PSR - 7 request object |
6,456 | public function check ( $ code , $ ip = null ) { try { $ this -> useClient ( ) -> check ( $ this , $ code , $ ip ) ; return true ; } catch ( RequestException $ e ) { if ( $ e -> getCode ( ) == 16 || $ e -> getCode ( ) == 17 ) { return false ; } throw $ e ; } } | Check if the code is correct . Unlike the method it proxies an invalid code does not throw an exception . |
6,457 | public function getChecks ( ) { $ checks = $ this -> proxyArrayAccess ( 'checks' ) ; if ( ! $ checks ) { return [ ] ; } foreach ( $ checks as $ i => $ check ) { $ checks [ $ i ] = new Check ( $ check ) ; } return $ checks ; } | Get an array of verification checks if available . Will return an empty array if no check have been made or if the data is not available . |
6,458 | protected function lazyLoad ( ) { if ( ! empty ( $ this -> data ) ) { return true ; } if ( isset ( $ this -> id ) ) { $ this -> get ( $ this ) ; return true ; } return false ; } | Returns true if the resource data is loaded . |
6,459 | public function getShards ( ) : array { $ shards = [ ] ; foreach ( $ this -> _data [ 'shards' ] as $ shardNumber => $ shard ) { $ shards [ ] = new Shard ( $ shardNumber , $ shard ) ; } return $ shards ; } | Gets the health of the shards in this index . |
6,460 | public function addFunction ( string $ functionType , $ functionParams , AbstractQuery $ filter = null , float $ weight = null ) : self { $ function = [ $ functionType => $ functionParams , ] ; if ( null !== $ filter ) { $ function [ 'filter' ] = $ filter ; } if ( null !== $ weight ) { $ function [ 'weight' ] = $ weight ; } $ this -> _functions [ ] = $ function ; return $ this ; } | Add a function to the function_score query . |
6,461 | public function addScriptScoreFunction ( AbstractScript $ script , AbstractQuery $ filter = null , float $ weight = null ) { return $ this -> addFunction ( 'script_score' , $ script , $ filter , $ weight ) ; } | Add a script_score function to the query . |
6,462 | public function addDecayFunction ( string $ function , string $ field , string $ origin , string $ scale , string $ offset = null , float $ decay = null , float $ weight = null , AbstractQuery $ filter = null , string $ multiValueMode = null ) { $ functionParams = [ $ field => [ 'origin' => $ origin , 'scale' => $ scale , ] , ] ; if ( null !== $ offset ) { $ functionParams [ $ field ] [ 'offset' ] = $ offset ; } if ( null !== $ decay ) { $ functionParams [ $ field ] [ 'decay' ] = $ decay ; } if ( null !== $ multiValueMode ) { $ functionParams [ 'multi_value_mode' ] = $ multiValueMode ; } return $ this -> addFunction ( $ function , $ functionParams , $ filter , $ weight ) ; } | Add a decay function to the query . |
6,463 | public function addRandomScoreFunction ( int $ seed , AbstractQuery $ filter = null , float $ weight = null , string $ field = null ) : self { $ functionParams = [ 'seed' => $ seed , ] ; if ( null !== $ field ) { $ functionParams [ 'field' ] = $ field ; } return $ this -> addFunction ( 'random_score' , $ functionParams , $ filter , $ weight ) ; } | Add a random_score function to the query . |
6,464 | public function setRandomScore ( int $ seed = null ) : self { $ seedParam = new \ stdClass ( ) ; if ( null !== $ seed ) { $ seedParam -> seed = $ seed ; } return $ this -> setParam ( 'random_score' , $ seedParam ) ; } | If set this query will return results in random order . |
6,465 | public function setHighlight ( string $ preTag , string $ postTag ) : Phrase { return $ this -> setParam ( 'highlight' , [ 'pre_tag' => $ preTag , 'post_tag' => $ postTag , ] ) ; } | Set suggestion highlighting . |
6,466 | public function next ( ) { if ( $ this -> currentPage < $ this -> totalPages ) { $ this -> _saveOptions ( ) ; $ this -> _search -> setOption ( Search :: OPTION_SCROLL , $ this -> expiryTime ) ; $ this -> _search -> setOption ( Search :: OPTION_SCROLL_ID , $ this -> _nextScrollId ) ; $ this -> _setScrollId ( $ this -> _search -> search ( ) ) ; $ this -> _revertOptions ( ) ; } else { $ this -> clear ( ) ; } } | Next scroll search . |
6,467 | public function rewind ( ) { $ this -> _options = [ null , null ] ; $ this -> currentPage = 0 ; $ this -> _saveOptions ( ) ; $ this -> _search -> setOption ( Search :: OPTION_SCROLL , $ this -> expiryTime ) ; $ this -> _search -> setOption ( Search :: OPTION_SCROLL_ID , null ) ; $ this -> _setScrollId ( $ this -> _search -> search ( ) ) ; $ this -> _revertOptions ( ) ; } | Initial scroll search . |
6,468 | public function clear ( ) { if ( null !== $ this -> _nextScrollId ) { $ this -> _search -> getClient ( ) -> request ( '_search/scroll' , Request :: DELETE , [ Search :: OPTION_SCROLL_ID => [ $ this -> _nextScrollId ] ] ) ; $ this -> _nextScrollId = null ; $ this -> _currentResultSet = null ; } } | Cleares the search context on ES and marks this Scroll instance as finished . |
6,469 | protected function _setScrollId ( ResultSet $ resultSet ) { if ( 0 === $ this -> currentPage ) { $ this -> totalPages = $ resultSet -> count ( ) > 0 ? \ ceil ( $ resultSet -> getTotalHits ( ) / $ resultSet -> count ( ) ) : 0 ; } $ this -> _currentResultSet = $ resultSet ; ++ $ this -> currentPage ; $ this -> _nextScrollId = $ resultSet -> getResponse ( ) -> isOk ( ) && $ resultSet -> count ( ) > 0 ? $ resultSet -> getResponse ( ) -> getScrollId ( ) : null ; } | Prepares Scroll for next request . |
6,470 | protected function _saveOptions ( ) { if ( $ this -> _search -> hasOption ( Search :: OPTION_SCROLL ) ) { $ this -> _options [ 0 ] = $ this -> _search -> getOption ( Search :: OPTION_SCROLL ) ; } if ( $ this -> _search -> hasOption ( Search :: OPTION_SCROLL_ID ) ) { $ this -> _options [ 1 ] = $ this -> _search -> getOption ( Search :: OPTION_SCROLL_ID ) ; } } | Save all search options manipulated by Scroll . |
6,471 | protected function _revertOptions ( ) { $ this -> _search -> setOption ( Search :: OPTION_SCROLL , $ this -> _options [ 0 ] ) ; $ this -> _search -> setOption ( Search :: OPTION_SCROLL_ID , $ this -> _options [ 1 ] ) ; } | Revert search options to previously saved state . |
6,472 | public function addIndex ( $ index ) { if ( $ index instanceof Index ) { $ index = $ index -> getName ( ) ; } if ( ! \ is_scalar ( $ index ) ) { throw new InvalidException ( 'Invalid param type' ) ; } $ this -> _indices [ ] = ( string ) $ index ; return $ this ; } | Adds a index to the list . |
6,473 | public function addType ( $ type ) { if ( $ type instanceof Type ) { $ type = $ type -> getName ( ) ; } if ( ! \ is_string ( $ type ) ) { throw new InvalidException ( 'Invalid type type' ) ; } $ this -> _types [ ] = $ type ; return $ this ; } | Adds a type to the current search . |
6,474 | public function getPath ( ) { if ( isset ( $ this -> _options [ self :: OPTION_SCROLL_ID ] ) ) { return '_search/scroll' ; } $ indices = $ this -> getIndices ( ) ; $ path = '' ; $ types = $ this -> getTypes ( ) ; if ( empty ( $ indices ) ) { if ( ! empty ( $ types ) ) { $ path .= '_all' ; } } else { $ path .= \ implode ( ',' , $ indices ) ; } if ( ! empty ( $ types ) ) { $ path .= '/' . \ implode ( ',' , $ types ) ; } return $ path . '/_search' ; } | Combines indices and types to the search request path . |
6,475 | public function search ( $ query = '' , $ options = null ) { $ this -> setOptionsAndQuery ( $ options , $ query ) ; $ query = $ this -> getQuery ( ) ; $ path = $ this -> getPath ( ) ; $ params = $ this -> getOptions ( ) ; if ( '_search/scroll' == $ path ) { $ data = [ self :: OPTION_SCROLL_ID => $ params [ self :: OPTION_SCROLL_ID ] ] ; unset ( $ params [ self :: OPTION_SCROLL_ID ] ) ; } else { $ data = $ query -> toArray ( ) ; } $ response = $ this -> getClient ( ) -> request ( $ path , Request :: GET , $ data , $ params ) ; return $ this -> _builder -> buildResultSet ( $ response , $ query ) ; } | Search in the set indices types . |
6,476 | public function setIds ( $ ids ) : self { if ( \ is_array ( $ ids ) ) { $ this -> _params [ 'values' ] = $ ids ; } else { $ this -> _params [ 'values' ] = [ $ ids ] ; } return $ this ; } | Sets the ids to filter . |
6,477 | public function getIndicesWithAlias ( $ alias ) { $ endpoint = new Get ( ) ; $ endpoint -> setName ( $ alias ) ; $ response = null ; try { $ response = $ this -> _client -> requestEndpoint ( $ endpoint ) ; } catch ( ResponseException $ e ) { if ( 404 === $ e -> getResponse ( ) -> getStatus ( ) ) { return [ ] ; } throw $ e ; } $ indices = [ ] ; foreach ( $ response -> getData ( ) as $ name => $ unused ) { $ indices [ ] = new Index ( $ this -> _client , $ name ) ; } return $ indices ; } | Returns an array with all indices that the given alias name points to . |
6,478 | public function getElasticsearchException ( ) : ElasticsearchException { $ response = $ this -> getResponse ( ) ; return new ElasticsearchException ( $ response -> getStatus ( ) , $ response -> getErrorMessage ( ) ) ; } | Returns elasticsearch exception . |
6,479 | public function create ( bool $ recreate = false ) { $ this -> getIndex ( ) -> create ( $ this -> _indexParams , $ recreate ) ; $ mapping = new Mapping ( $ this -> getType ( ) ) ; $ mapping -> setProperties ( $ this -> _mapping ) ; $ mapping -> setSource ( [ 'enabled' => $ this -> _source ] ) ; $ mapping -> send ( ) ; } | Creates the index and sets the mapping for this type . |
6,480 | public function search ( $ query = '' , $ options = null ) : ResultSet { return $ this -> getType ( ) -> search ( $ query , $ options = null ) ; } | Search on the type . |
6,481 | public function setHdr ( string $ key , float $ value ) : self { $ compression = [ $ key => $ value ] ; return $ this -> setParam ( 'hdr' , $ compression ) ; } | Set hdr parameter . |
6,482 | public function setTerm ( string $ key , $ value , float $ boost = 1.0 ) : self { return $ this -> setRawTerm ( [ $ key => [ 'value' => $ value , 'boost' => $ boost ] ] ) ; } | Adds a term to the term query . |
6,483 | public function getAggregation ( $ name ) { $ data = $ this -> _response -> getData ( ) ; if ( isset ( $ data [ 'aggregations' ] ) && isset ( $ data [ 'aggregations' ] [ $ name ] ) ) { return $ data [ 'aggregations' ] [ $ name ] ; } throw new InvalidException ( "This result set does not contain an aggregation named {$name}." ) ; } | Retrieve a specific aggregation from this result set . |
6,484 | public function setPrefix ( string $ key , $ value , float $ boost = 1.0 ) : self { return $ this -> setRawPrefix ( [ $ key => [ 'value' => $ value , 'boost' => $ boost ] ] ) ; } | Adds a prefix to the prefix query . |
6,485 | public function sum_bucket ( string $ name , string $ bucketsPath = null ) : SumBucket { return new SumBucket ( $ name , $ bucketsPath ) ; } | sum bucket aggregation . |
6,486 | public function avg_bucket ( string $ name , string $ bucketsPath = null ) : AvgBucket { return new AvgBucket ( $ name , $ bucketsPath ) ; } | avg bucket aggregation . |
6,487 | public function percentiles ( string $ name , string $ field = null ) : Percentiles { return new Percentiles ( $ name , $ field ) ; } | percentiles aggregation . |
6,488 | public function scripted_metric ( string $ name , string $ initScript = null , string $ mapScript = null , string $ combineScript = null , string $ reduceScript = null ) : ScriptedMetric { return new ScriptedMetric ( $ name , $ initScript , $ mapScript , $ combineScript , $ reduceScript ) ; } | scripted metric aggregation . |
6,489 | public function filter ( string $ name , AbstractQuery $ filter = null ) : Filter { return new Filter ( $ name , $ filter ) ; } | filter aggregation . |
6,490 | public function reverse_nested ( string $ name , string $ path = null ) : ReverseNested { return new ReverseNested ( $ name , $ path ) ; } | reverse nested aggregation . |
6,491 | public function histogram ( string $ name , string $ field , $ interval ) : Histogram { return new Histogram ( $ name , $ field , $ interval ) ; } | histogram aggregation . |
6,492 | public function date_histogram ( string $ name , string $ field , $ interval ) : DateHistogram { return new DateHistogram ( $ name , $ field , $ interval ) ; } | date histogram aggregation . |
6,493 | public function geo_distance ( string $ name , string $ field , $ origin ) : GeoDistance { return new GeoDistance ( $ name , $ field , $ origin ) ; } | geo distance aggregation . |
6,494 | public function bucket_script ( string $ name , array $ bucketsPath = null , string $ script = null ) : BucketScript { return new BucketScript ( $ name , $ bucketsPath , $ script ) ; } | bucket script aggregation . |
6,495 | public function serial_diff ( string $ name , string $ bucketsPath = null ) : SerialDiff { return new SerialDiff ( $ name , $ bucketsPath ) ; } | serial diff aggregation . |
6,496 | public function setAnalyzer ( string $ analyzer ) : self { $ analyzer = \ trim ( $ analyzer ) ; return $ this -> setParam ( 'analyzer' , $ analyzer ) ; } | Set analyzer . |
6,497 | protected function _setupCurl ( $ curlConnection ) { if ( $ this -> getConnection ( ) -> hasConfig ( 'curl' ) ) { foreach ( $ this -> getConnection ( ) -> getConfig ( 'curl' ) as $ key => $ param ) { \ curl_setopt ( $ curlConnection , $ key , $ param ) ; } } } | Called to add additional curl params . |
6,498 | protected function _getConnection ( bool $ persistent = true ) { if ( ! $ persistent || ! self :: $ _curlConnection ) { self :: $ _curlConnection = \ curl_init ( ) ; } return self :: $ _curlConnection ; } | Return Curl resource . |
6,499 | public function refresh ( array $ options = [ ] ) { $ endpoint = new \ Elasticsearch \ Endpoints \ Tasks \ Get ( ) ; $ endpoint -> setTaskId ( $ this -> _id ) ; $ endpoint -> setParams ( $ options ) ; $ this -> _response = $ this -> _client -> requestEndpoint ( $ endpoint ) ; $ this -> _data = $ this -> getResponse ( ) -> getData ( ) ; } | Refresh task status . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.