idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
23,300
public function importArticleFiles ( $ article , $ oldId , $ slug ) { $ fileIdsSql = "SELECT DISTINCT file_id FROM article_files WHERE article_id = :id" ; $ fileIdsStatement = $ this -> dbalConnection -> prepare ( $ fileIdsSql ) ; $ fileIdsStatement -> bindValue ( 'id' , $ oldId ) ; $ fileIdsStatement -> execute ( ) ; $ fileIds = $ fileIdsStatement -> fetchAll ( ) ; $ articleFiles = array ( ) ; foreach ( $ fileIds as $ fileId ) { $ articleFileSql = "SELECT file_id, file_type, original_file_name, revision FROM article_files" . " WHERE article_id = :id AND file_id = :fileId ORDER BY revision DESC LIMIT 1" ; $ articleFileStatement = $ this -> dbalConnection -> prepare ( $ articleFileSql ) ; $ articleFileStatement -> bindValue ( 'fileId' , $ fileId [ 'file_id' ] ) ; $ articleFileStatement -> bindValue ( 'id' , $ oldId ) ; $ articleFileStatement -> execute ( ) ; $ articleFiles [ ] = $ articleFileStatement -> fetch ( ) ; } foreach ( $ articleFiles as $ articleFile ) { $ this -> importArticleFile ( $ articleFile , $ oldId , $ article , $ slug ) ; } }
Imports files of the given article
23,301
public function importArticleFile ( $ pkpArticleFile , $ oldArticleId , $ article , $ slug ) { $ this -> consoleOutput -> writeln ( "Reading article file #" . $ pkpArticleFile [ 'file_id' ] . "... " , true ) ; $ galleysSql = "SELECT galley_id, article_id, locale, label FROM article_galleys " . "WHERE article_id = :article_id AND file_id = :id" ; $ galleysStatement = $ this -> dbalConnection -> prepare ( $ galleysSql ) ; $ galleysStatement -> bindValue ( 'article_id' , $ oldArticleId ) ; $ galleysStatement -> bindValue ( 'id' , $ pkpArticleFile [ 'file_id' ] ) ; $ galleysStatement -> execute ( ) ; $ pkpGalleys = $ galleysStatement -> fetchAll ( ) ; foreach ( $ pkpGalleys as $ galley ) { $ locale = ! empty ( $ galley [ 'locale' ] ) ? mb_substr ( $ galley [ 'locale' ] , 0 , 2 , 'UTF-8' ) : 'en' ; $ label = ! empty ( $ galley [ 'label' ] ) ? $ galley [ 'label' ] : '-' ; $ version = ! empty ( $ pkpArticleFile [ 'revision' ] ) ? $ pkpArticleFile [ 'revision' ] : 0 ; $ filename = sprintf ( 'imported/%s/%s.%s' , $ galley [ 'article_id' ] , $ galley [ 'galley_id' ] , FileHelper :: $ mimeToExtMap [ $ pkpArticleFile [ 'file_type' ] ] ) ; $ articleFile = new ArticleFile ( ) ; $ articleFile -> setFile ( $ filename ) ; $ articleFile -> setArticle ( $ article ) ; $ articleFile -> setVersion ( $ version ) ; $ articleFile -> setTitle ( $ label ) ; $ articleFile -> setLangCode ( $ locale ) ; $ articleFile -> setDescription ( '-' ) ; $ articleFile -> setType ( ArticleFileParams :: FULL_TEXT ) ; $ history = $ this -> em -> getRepository ( FileHistory :: class ) -> findOneBy ( [ 'fileName' => $ filename ] ) ; if ( ! $ history ) { $ history = new FileHistory ( ) ; $ history -> setFileName ( $ filename ) ; $ history -> setOriginalName ( $ pkpArticleFile [ 'original_file_name' ] ) ; $ history -> setType ( 'articlefiles' ) ; $ this -> em -> persist ( $ history ) ; } $ source = sprintf ( '%s/article/download/%s/%s' , $ slug , $ galley [ 'article_id' ] , $ galley [ 'galley_id' ] ) ; $ target = sprintf ( '/../web/uploads/articlefiles/imported/%s/%s.%s' , $ galley [ 'article_id' ] , $ galley [ 'galley_id' ] , FileHelper :: $ mimeToExtMap [ $ pkpArticleFile [ 'file_type' ] ] ) ; $ pendingDownload = new PendingDownload ( ) ; $ pendingDownload -> setSource ( $ source ) ; $ pendingDownload -> setTarget ( $ target ) ; $ this -> em -> persist ( $ pendingDownload ) ; $ this -> em -> persist ( $ articleFile ) ; } }
Imports the given article file
23,302
public function contains ( $ key ) { if ( $ key instanceof Interfaces \ SeedLike ) { $ key = $ key -> getId ( ) ; } return Utility \ Option :: contains ( $ this -> _bag , $ key ) ; }
Checks to see if a key is in the bag .
23,303
private function header ( ) { $ fields = collect ( $ this -> entity -> fields ) -> unique ( 'type' ) -> all ( ) ; $ codeArray = [ ] ; foreach ( $ fields as $ name => $ options ) { $ type = ucwords ( $ options [ 'type' ] ) ; $ className = 'Jaimeeee\\Panel\\Fields\\' . $ type . '\\' . $ type . 'Field' ; if ( method_exists ( $ className , 'header' ) ) { $ codeArray [ ] = ' ' . $ className :: header ( ) ; } } return implode ( chr ( 10 ) , $ codeArray ) ; }
Return each fields header code .
23,304
public function view ( ) { $ code = $ this -> code ( ) ; $ imageList = [ ] ; if ( isset ( $ this -> entity -> images [ 'class' ] ) && $ imageClass = $ this -> entity -> images [ 'class' ] ) { $ images = $ imageClass :: orderBy ( isset ( $ this -> entity -> images [ 'field' ] ) ? $ this -> entity -> images [ 'field' ] : 'created_at' , isset ( $ this -> entity -> images [ 'order' ] ) ? $ this -> entity -> images [ 'order' ] : 'desc' ) -> get ( ) ; foreach ( $ images as $ image ) { $ value = isset ( $ this -> entity -> images [ 'value' ] ) ? $ image -> $ this -> entity -> images [ 'value' ] : $ image -> image_name ; $ imageList [ ] = [ 'title' => ( isset ( $ this -> entity -> images [ 'title' ] ) ? $ image -> $ this -> entity -> images [ 'title' ] : $ image -> description ) ? : $ value , 'value' => asset ( rtrim ( $ this -> entity -> images [ 'path' ] , '/' ) . '/' . $ value ) , ] ; } } return view ( 'panel::form' , [ 'entity' => $ this -> entity , 'header' => $ this -> header ( ) , 'record' => $ this -> record , 'title' => $ this -> entity -> title , 'panel' => $ this -> record ? trans ( 'panel::global.edit_entity' , [ 'entity' => $ this -> entity -> name ( ) ] ) : trans ( 'panel::global.save_entity' , [ 'entity' => $ this -> entity -> name ( ) ] ) , 'footer' => $ this -> footer ( ) , 'formCode' => $ code , 'imageList' => $ imageList , ] ) ; }
Return the form view .
23,305
public function setting ( $ key = null ) : Storage { $ this -> getStorage ( ) -> clearKey ( ) ; $ storage = $ this -> getStorage ( ) -> addKey ( self :: SETTING ) ; if ( $ key === null ) { return $ this -> getStorage ( ) -> get ( ) ; } return $ storage -> addKey ( $ key ) ; }
Get a settings of key .
23,306
public function application ( bool $ null = true ) : array { $ config = $ this -> appConfig ; if ( $ null ) { $ this -> appConfig = [ ] ; } return $ config ; }
Get a configurations of launch app .
23,307
public function getStorage ( $ clone = false ) : Storage { if ( $ this -> storage === null ) { $ this -> storage = new Storage ( $ this -> getCache ( ) ) ; } return $ clone ? clone $ this -> storage : $ this -> storage ; }
Get storage interface
23,308
public function load ( array $ files ) : void { $ this -> appConfig = $ this -> getCache ( ) -> getOrSet ( $ this -> env , function ( ) use ( $ files ) { $ config = $ this -> loadBaseConfig ( $ files ) ; return $ this -> loadInstalledComponentsConfig ( $ config ) ; } ) ; }
Load a configuration of app .
23,309
protected function loadInstalledComponentsConfig ( array $ config = [ ] ) : array { $ env = $ this -> env === self :: WEB ? 'web' : 'console' ; $ config = FileHelper :: loadExtensionsFiles ( 'config/main.php' , $ config ) ; $ config = FileHelper :: loadExtensionsFiles ( "config/{$env}.php" , $ config ) ; return $ config ; }
Load a configuration of installed components .
23,310
public function getCache ( ) : FileCache { if ( ! $ this -> cache ) { $ this -> cache = Yii :: createObject ( [ 'class' => FileCache :: className ( ) , 'cachePath' => Yii :: getAlias ( $ this -> cachePath ) ] ) ; } return $ this -> cache ; }
Get a cache object .
23,311
public function getValue ( ) { $ value = sprintf ( "%02d:%02d" , $ this -> hours , $ this -> minutes ) ; if ( isset ( $ this -> seconds ) ) $ value .= sprintf ( ":%02d" , $ this -> seconds ) ; if ( isset ( $ this -> microtime ) ) $ value .= substr ( $ this -> microtime , 1 ) ; return $ value ; }
Get the value of this Time as an ISO string
23,312
public function setTime ( $ hours , $ minutes , $ seconds ) { self :: validateTime ( $ hours , $ minutes , $ seconds ) ; $ this -> hours = ( int ) $ hours ; $ this -> minutes = ( int ) $ minutes ; $ this -> seconds = ( int ) $ seconds ; if ( is_float ( $ seconds ) ) $ this -> microtime = fmod ( $ seconds , floor ( $ seconds ) ) ; }
Set the time represented by this Time
23,313
static public function validate ( $ time ) { if ( is_string ( $ time ) && strlen ( trim ( $ time ) ) > 0 ) return false ; if ( ! preg_match ( '/^' . self :: PATTERN . '$/' , $ time , $ matches ) ) return false ; if ( count ( $ matches ) == 5 ) list ( $ original , $ hours , $ minutes , $ seconds , $ microtime ) = $ matches ; else list ( $ original , $ hours , $ minutes , $ seconds ) = $ matches ; if ( isset ( $ microtime ) ) $ seconds += $ microtime ; if ( ! self :: validateTime ( $ hours , $ minutes , $ seconds ) ) return false ; return true ; }
Validate if a string is a time
23,314
public function getCommitUrl ( Repo $ repo , $ commitSHA ) { return $ this -> helper -> getCommitUrl ( $ repo -> getSlug ( ) , $ commitSHA ) ; }
Get Repo commit url
23,315
private function find ( $ key ) { if ( $ this -> exists ( $ key ) ) { $ data = Query :: from ( $ this -> table ) -> where ( 'name' , '=' , $ key ) -> first ( ) ; if ( $ data -> lifetime >= time ( ) ) { return [ 'name' => $ key , 'value' => $ this -> unpacking ( $ data -> value ) , 'lifetime' => $ data -> lifetime ] ; } else { $ this -> remove ( $ key ) ; } } }
Find item in cache .
23,316
private function createTable ( ) { Schema :: create ( $ this -> table , function ( $ tab ) { $ tab -> inc ( 'id' ) ; $ tab -> string ( 'name' ) ; $ tab -> string ( 'value' ) ; $ tab -> long ( 'lifetime' ) ; $ tab -> unique ( 'cacheunique' , [ 'name' ] ) ; } ) ; }
Create database cache table .
23,317
public function put ( $ name , $ value , $ lifetime = null , $ timestamp = false ) { if ( is_null ( $ lifetime ) ) { $ lifetime = confg ( 'cache.lifetime' ) ; } if ( ! $ timestamp ) { $ lifetime = time ( ) + $ lifetime ; } $ value = $ this -> packing ( $ value ) ; $ this -> save ( $ name , $ value , $ lifetime ) ; }
Create new item cache .
23,318
protected function add ( $ name , $ value , $ lifetime ) { return Query :: into ( $ this -> table ) -> column ( 'name' , 'value' , 'lifetime' ) -> value ( $ name , $ value , $ lifetime ) -> insert ( ) ; }
Add data to cache database table .
23,319
protected function edit ( $ name , $ value , $ lifetime ) { return Query :: into ( $ this -> table ) -> set ( 'name' , $ name ) -> set ( 'value' , $ value ) -> set ( 'lifetime' , $ lifetime ) -> where ( 'name' , '=' , $ name ) -> update ( ) ; }
Update data in cache database table .
23,320
protected function save ( $ name , $ value , $ lifetime ) { if ( $ this -> exists ( $ name ) ) { return $ this -> edit ( $ name , $ value , $ lifetime ) ; } return $ this -> add ( $ name , $ value , $ lifetime ) ; }
Save the data cache .
23,321
private function exists ( $ key ) { $ data = Query :: from ( $ this -> table ) -> where ( 'name' , '=' , $ key ) -> get ( ) ; return count ( $ data ) > 0 ; }
Check if cache key exists in database .
23,322
public function get ( $ name , $ default = null ) { if ( $ this -> exists ( $ name ) ) { $ data = Query :: from ( $ this -> table ) -> where ( 'name' , '=' , $ name ) -> first ( ) ; if ( $ data -> lifetime >= time ( ) ) { return $ this -> unpacking ( $ data -> value ) ; } else { $ this -> remove ( $ name ) ; return $ default ; } } return $ default ; }
Get a cache key .
23,323
public function expiration ( $ key ) { if ( $ this -> exists ( $ name ) ) { $ data = Query :: from ( $ this -> table ) -> where ( 'name' , '=' , $ name ) -> first ( ) ; if ( $ data -> lifetime >= time ( ) ) { return $ data -> lifetime ; } } }
Get Expiration time of a key .
23,324
public function prolong ( $ key , $ lifetime ) { $ item = $ this -> find ( $ key ) ; if ( ! is_null ( $ item ) ) { $ lifetime = $ item [ 'lifetime' ] + $ lifetime ; $ this -> put ( $ key , $ item [ 'value' ] , $ lifetime , true ) ; } }
Prolong a lifetime of cache item .
23,325
public function append ( $ resource ) { parent :: append ( $ resource ) ; if ( $ this -> totalCount !== null ) { $ this -> setTotalCount ( $ this -> totalCount ) ; } }
Append a Resource and possibly increase totalCount if needed .
23,326
public function jsonLDSerialize ( string $ context = self :: DEFAULT_CONTEXT , bool $ types = NULL ) { return array_map ( function ( $ m ) use ( $ context , $ types ) { return $ m -> jsonLDSerialize ( $ context , $ types ?? true ) ; } , $ this -> members ) ; }
Serialize with type and context fields for each member .
23,327
public function repeater ( string $ key = 'structured_data' ) { return Group :: full ( 'Structured Data' ) -> repeater ( $ key ) -> addGroup ( Group :: full ( 'Person' ) -> key ( 'structureddata.person' ) -> addField ( Field :: string ( 'name' , 'Name' ) , Field :: string ( 'jobTitle' , 'Job Title' ) , Field :: string ( 'telephone' , 'Telephone' ) , Field :: string ( 'url' , 'Website URL' ) , Field :: string ( 'email' , 'Email Address' ) , Field :: date ( 'birthDate' , 'Birth Date' ) , Field :: string ( 'streetAddress' , 'Street Address' ) , Field :: string ( 'addressLocality' , 'City' ) , Field :: string ( 'addressRegion' , 'County' ) , Field :: string ( 'postalCode' , 'Post Code' ) , Field :: string ( 'addressCountry' , 'Country' ) , Field :: select ( 'sameAs' , 'Social Network URLs' ) -> tags ( ) ) , Group :: full ( 'Organization' ) -> key ( 'structureddata.organization' ) -> addField ( Field :: string ( 'name' , 'Name' ) , Field :: string ( 'url' , 'Website URL' ) , Field :: select ( 'contactType' , 'Contact Point' ) -> dropdown ( ) -> single ( ) -> addOptions ( [ 'Customer service' ] ) , Field :: string ( 'telephone' , 'Contact Telephone' ) , Field :: string ( 'email' , 'Contact Email' ) , Field :: string ( 'streetAddress' , 'Street Address' ) , Field :: string ( 'addressLocality' , 'City' ) , Field :: string ( 'addressRegion' , 'County' ) , Field :: string ( 'postalCode' , 'Post Code' ) , Field :: string ( 'addressCountry' , 'Country' ) , Field :: select ( 'sameAs' , 'Social Network URLs' ) -> tags ( ) ) ) ; }
Returns the Agencms repeater configuration for Structured Data blocks
23,328
final public function hasUTF ( ) { $ verParts = explode ( '.' , $ this -> getVersion ( ) ) ; return ( $ verParts [ 0 ] == 5 || ( $ verParts [ 0 ] == 4 && $ verParts [ 1 ] == 1 && ( int ) $ verParts [ 2 ] >= 2 ) ) ; }
Determines UTF support
23,329
final public function getEscaped ( $ text , $ extra = false ) { $ result = mysqli_real_escape_string ( $ this -> resourceId , $ text ) ; if ( $ extra ) { $ result = addcslashes ( $ result , '%_' ) ; } return $ result ; }
Get a database escaped string
23,330
public function startTransaction ( ) { if ( ! is_a ( $ this -> resourceId , "mysqli" ) ) { throw new QueryException ( "No valid db resource Id found. This is required to start a transaction" ) ; return false ; } $ this -> resourceId -> autocommit ( FALSE ) ; }
Begins a database transaction
23,331
public function query ( $ sql , $ execute = FALSE ) { $ query = ( empty ( $ sql ) ) ? $ this -> query : $ sql ; $ this -> transactions [ ] = $ this -> replacePrefix ( $ query ) ; if ( $ execute ) { $ this -> exec ( $ query ) ; } return true ; }
This method is intended for use in transsactions
23,332
public function commitTransaction ( ) { if ( empty ( $ this -> transactions ) || ! is_array ( $ this -> transactions ) ) { throw new QueryException ( t ( "No transaction queries found" ) ) ; $ this -> transactions = array ( ) ; $ this -> resourceId -> autocommit ( TRUE ) ; return false ; } foreach ( $ this -> transactions as $ query ) { if ( ! $ this -> exec ( $ query ) ) { $ this -> resourceId -> rollback ( ) ; $ this -> transactions = array ( ) ; $ this -> resourceId -> autocommit ( TRUE ) ; return false ; } } if ( ! $ this -> resourceId -> commit ( ) ) { throw new QueryException ( t ( "The transaction could not be committed" ) ) ; $ this -> transactions = array ( ) ; $ this -> resourceId -> autocommit ( TRUE ) ; return false ; } $ this -> transactions = array ( ) ; $ this -> resourceId -> autocommit ( TRUE ) ; return true ; }
Commits a transaction or rollbacks on error
23,333
public static function is_array ( $ possibleArray , $ _ = null ) { foreach ( func_get_args ( ) as $ _argument ) { if ( ! is_array ( $ _argument ) ) { return false ; } } return true ; }
Multi - argument is_array helper
23,334
public static function array_prepend ( $ array , $ string , $ deep = false ) { if ( empty ( $ array ) || empty ( $ string ) ) { return $ array ; } foreach ( $ array as $ key => $ element ) { if ( is_array ( $ element ) ) { if ( $ deep ) { $ array [ $ key ] = self :: array_prepend ( $ element , $ string , $ deep ) ; } else { trigger_error ( 'array_prepend: array element' , E_USER_WARNING ) ; } } else { $ array [ $ key ] = $ string . $ element ; } } return $ array ; }
Prepend an array
23,335
public static function argsToArray ( ) { $ _array = array ( ) ; foreach ( func_get_args ( ) as $ _key => $ _argument ) { $ _array [ $ _key ] = $ _argument ; } return $ _array ; }
Takes a list of things and returns them in an array as the values . Keys are maintained .
23,336
public static function in ( ) { $ _haystack = func_get_args ( ) ; if ( ! empty ( $ _haystack ) && count ( $ _haystack ) > 1 ) { $ _needle = array_shift ( $ _haystack ) ; return in_array ( $ _needle , $ _haystack ) ; } return false ; }
Convenience in_array method . Takes variable args .
23,337
public static function contains ( $ needle , $ haystack , $ strict = false ) { foreach ( $ haystack as $ _index => $ _value ) { if ( is_string ( $ _value ) ) { if ( 0 === strcasecmp ( $ needle , $ _value ) ) { return true ; } } else if ( in_array ( $ needle , $ _value , $ strict ) ) { return true ; } } return false ; }
A case - insensitive in_array for all intents and purposes . Works with objects too!
23,338
public static function arraySort ( & $ arrayToSort , $ columnsToSort = array ( ) ) { if ( ! empty ( $ columnsToSort ) && ! is_array ( $ columnsToSort ) ) { $ columnsToSort = array ( $ columnsToSort ) ; } if ( ! empty ( $ columnsToSort ) ) { return usort ( $ arrayToSort , function ( $ a , $ b ) use ( $ columnsToSort ) { $ _result = null ; foreach ( $ columnsToSort as $ _column => $ _order ) { $ _order = trim ( strtolower ( $ _order ) ) ; if ( is_numeric ( $ _column ) && ! static :: in ( $ _order , 'asc' , 'desc' ) ) { $ _column = $ _order ; $ _order = null ; } if ( 'desc' == strtolower ( $ _order ) ) { return strnatcmp ( $ b [ $ _column ] , $ a [ $ _column ] ) ; } return strnatcmp ( $ a [ $ _column ] , $ b [ $ _column ] ) ; } } ) ; } return false ; }
Generic array sorter
23,339
public static function array_multisort_column ( & $ sourceArray , $ column , $ sortDirection = SORT_ASC ) { $ _sortColumn = array ( ) ; foreach ( $ sourceArray as $ _key => $ _row ) { $ _sortColumn [ $ _key ] = ( isset ( $ _row [ $ column ] ) ? $ _row [ $ column ] : null ) ; } return \ array_multisort ( $ _sortColumn , $ sortDirection , $ sourceArray ) ; }
Sorts an array by a single column
23,340
public static function strlen ( $ string ) { if ( false === ( $ _encoding = static :: mbSupported ( $ string ) ) ) { return strlen ( $ string ) ; } return mb_strwidth ( $ string , $ _encoding ) ; }
Multibyte - aware strlen Originally swiped from Symfony2 Console Application class private functions . Modified for Kisma use .
23,341
public static function mbSupported ( $ string = null ) { $ _encoding = false ; if ( ! function_exists ( 'mb_strwidth' ) || ( $ string && false === ( $ _encoding = mb_detect_encoding ( $ string ) ) ) ) { return false ; } return $ _encoding ; }
Checks if multi - byte is available and returns encoding of optional string . False otherwise .
23,342
public function parse ( PhpClass $ phpClass , SplFileInfo $ fileInfo ) { try { $ this -> nodeVisitor -> setPhpClass ( $ phpClass ) ; $ this -> traverse ( $ fileInfo -> getContents ( ) , [ $ this -> nodeVisitor ] ) ; $ phpClass -> setFile ( $ fileInfo ) ; $ phpClass -> setLastModified ( ( new \ DateTime ( ) ) -> setTimestamp ( $ fileInfo -> getMTime ( ) ) ) ; } catch ( \ Exception $ e ) { return false ; } if ( $ phpClass -> isValid ( ) ) { return $ phpClass ; } return false ; }
Builds the cache
23,343
protected function traverse ( $ content , array $ nodeVisitors = [ ] ) { $ nodes = $ this -> phpParser -> parse ( $ content ) ; $ traverser = new NodeTraverser ; $ traverser -> addVisitor ( new NameResolver ( ) ) ; foreach ( $ nodeVisitors as $ nodeVisitor ) { $ traverser -> addVisitor ( $ nodeVisitor ) ; } $ traverser -> traverse ( $ nodes ) ; }
Traverse the parser nodes so we can extract the information
23,344
protected function correctSavedData ( $ insert ) { if ( $ insert ) { $ tzShiftSec = intval ( date ( 'Z' ) ) ; if ( ! empty ( $ tzShiftSec ) ) { $ now = new Expression ( "DATE_SUB(NOW(), INTERVAL {$tzShiftSec} SECOND)" ) ; } else { $ now = new Expression ( 'NOW()' ) ; } $ this -> create_time = $ now ; if ( empty ( $ this -> show_from_time ) ) $ this -> show_from_time = $ now ; $ this -> owner_id = Yii :: $ app -> user -> identity -> id ; } else { } }
Data correction immediatly before save . Datetime fields will convert into Expression - class .
23,345
public static function prepareI18nModels ( $ model ) { $ moduleClass = static :: moduleClass ( ) ; if ( ! $ moduleClass ) $ moduleClass = Module :: className ( ) ; $ module = UniModule :: getModuleByClassname ( $ moduleClass ) ; $ langHelper = $ module -> langHelper ; $ editAllLanguages = empty ( $ module -> params [ 'editAllLanguages' ] ) ? false : $ module -> params [ 'editAllLanguages' ] ; $ languages = $ langHelper :: activeLanguages ( $ editAllLanguages ) ; $ mI18n = $ model -> i18n ; $ modelsI18n = [ ] ; foreach ( $ mI18n as $ modelI18n ) { $ modelsI18n [ $ modelI18n -> lang_code ] = $ modelI18n ; } $ modelsI18n = static :: correctI18nBodies ( $ modelsI18n ) ; foreach ( $ languages as $ langCode => $ lang ) { if ( empty ( $ modelsI18n [ $ langCode ] ) ) { $ newNewsI18n = $ module :: model ( 'NewsI18n' ) ; $ modelsI18n [ $ langCode ] = $ newNewsI18n -> loadDefaultValues ( ) ; $ modelsI18n [ $ langCode ] -> lang_code = $ langCode ; } } return $ modelsI18n ; }
Prepare multilang models array .
23,346
public static function correctI18nBodies ( $ modelsI18n ) { $ module = Module :: getModuleByClassname ( Module :: className ( ) ) ; $ contentHelperClass = $ module -> contentHelper ; foreach ( $ modelsI18n as $ modelI18n ) { $ modelI18n -> body = $ contentHelperClass :: afterSelectBody ( $ modelI18n -> body ) ; } return $ modelsI18n ; }
Use ContentHelper to correct texts after visual editor . Need as independent method to repeat run after unsuccessful validation .
23,347
protected function deleteFiles ( $ id ) { $ subdir = static :: getImageSubdir ( $ id ) ; if ( ! empty ( $ this -> module -> params [ 'uploadsNewsDir' ] ) ) { $ uploadsDir = Yii :: getAlias ( $ this -> module -> params [ 'uploadsNewsDir' ] ) . '/' . $ subdir ; rename ( $ uploadsDir , $ uploadsDir . '~remove~' . date ( 'ymd~His' ) . '~' ) ; } if ( array_key_exists ( '@webfilespath' , Yii :: $ aliases ) && ! empty ( $ this -> module -> params [ 'filesSubpath' ] ) ) { $ webfilesDir = Yii :: getAlias ( '@webfilespath' ) . '/' . $ this -> module -> params [ 'filesSubpath' ] . '/' . $ subdir ; @ FileHelper :: removeDirectory ( $ webfilesDir ) ; } }
Delete uploaded files connected with the model .
23,348
protected function _write_redis ( $ session_id , $ payload ) { $ this -> redis -> set ( $ session_id , $ payload ) ; $ this -> redis -> expire ( $ session_id , $ this -> config [ 'expiration_time' ] ) ; }
Writes the redis entry
23,349
public function describe ( $ label , $ block ) { return $ this -> _tests [ ] = new Context ( $ label , $ block , $ this -> _indent . ' ' , $ this ) ; }
Creates a new subcontext .
23,350
public function it ( $ label , $ block ) { return $ this -> _tests [ ] = new Example ( $ label , $ block , $ this -> _indent . ' ' , $ this ) ; }
Creates a new example .
23,351
public function run ( ) { if ( $ this -> _expector -> output && $ this -> _expector -> output -> isVerbose ( ) ) { $ this -> _expector -> output -> writeln ( $ this -> _indent . $ this -> _label ) ; } foreach ( $ this -> _tests as $ test ) { $ test -> run ( ) ; } }
Runs all the tests in this scope .
23,352
public static function C2ixys ( $ x , $ y , $ s , array & $ rc2i ) { $ r2 ; $ e ; $ d ; $ r2 = $ x * $ x + $ y * $ y ; $ e = ( $ r2 > 0.0 ) ? atan2 ( $ y , $ x ) : 0.0 ; $ d = atan ( sqrt ( $ r2 / ( 1.0 - $ r2 ) ) ) ; IAU :: Ir ( $ rc2i ) ; IAU :: Rz ( $ e , $ rc2i ) ; IAU :: Ry ( $ d , $ rc2i ) ; IAU :: Rz ( - ( $ e + $ s ) , $ rc2i ) ; return ; }
- - - - - - - - - - i a u C 2 i x y s - - - - - - - - - -
23,353
public static function generate ( $ length = 16 ) { if ( function_exists ( 'random_bytes' ) ) { return bin2hex ( random_bytes ( $ length ) ) ; } elseif ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { return bin2hex ( openssl_random_pseudo_bytes ( $ length ) ) ; } else { $ id = uniqid ( ) ; $ hash = '' ; $ str_len = strlen ( $ id ) ; $ limit = floor ( $ length * 2 / $ str_len ) ; for ( $ i = 0 ; $ i < $ limit ; $ i ++ ) { $ hash .= $ id ; } $ remainder = strlen ( $ id ) / ( $ length * 2 ) ; if ( $ remainder ) { $ hash .= substr ( $ id , 0 , $ remainder ) ; } return $ hash ; } }
Generate unique ID
23,354
public function string ( int $ length = 8 ) { $ list = 'abcdefghijklmnopqrstuvwxyz' ; $ return = '' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ return .= $ list [ rand ( 0 , strlen ( $ list ) - 1 ) ] ; } return $ return ; }
Return a simple random string .
23,355
public function integer ( int $ min , int $ max ) { if ( $ max < $ min ) { throw new ResponseCode ( 'max must be greater than min' , 422 ) ; } return rand ( $ min , $ max ) ; }
Return a random integer .
23,356
public function float ( float $ min , float $ max ) { if ( $ max < $ min ) { throw new ResponseCode ( 'max must be greater than min' , 422 ) ; } return rand ( ( int ) $ min * 100 , ( int ) $ max * 100 ) / 100 ; }
Return a random float .
23,357
public function object ( float $ min , float $ max ) { $ populate = function ( bool $ extended = false ) use ( $ min , $ max ) { $ class = 'Cawa\\SwaggerServer\\ExamplesService\\' . ( $ extended ? 'ObjectExtended' : 'Object' ) ; $ object = new $ class ( ) ; $ object -> string = $ this -> String ( ( int ) $ max ) ; if ( $ extended ) { $ object -> extendString = $ this -> String ( ( int ) $ max ) ; } $ object -> integer = $ this -> Integer ( ( int ) $ min , ( int ) $ max ) ; $ object -> float = $ this -> Float ( ( int ) $ min , ( int ) $ max ) ; $ object -> boolean = $ this -> Boolean ( ) ; $ object -> integerMap = [ $ this -> String ( ( int ) $ max ) => $ this -> Integer ( ( int ) $ min , ( int ) $ max ) , $ this -> String ( ( int ) $ max ) => $ this -> Integer ( ( int ) $ min , ( int ) $ max ) , $ this -> String ( ( int ) $ max ) => $ this -> Integer ( ( int ) $ min , ( int ) $ max ) , ] ; $ object -> stringMap = [ $ this -> String ( ( int ) $ max ) => $ this -> String ( ( int ) $ max ) , $ this -> String ( ( int ) $ max ) => $ this -> String ( ( int ) $ max ) , $ this -> String ( ( int ) $ max ) => $ this -> String ( ( int ) $ max ) , ] ; $ object -> datetime = $ this -> Date ( new DateTime ( ) ) ; return $ object ; } ; $ return = $ populate ( ) ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ object = $ populate ( true ) ; $ return -> objects [ ] = $ object ; } return $ return ; }
Return a random object .
23,358
public static function trim_stripslashes_deep ( $ value ) { if ( is_array ( $ value ) ) { $ value = array_map ( array ( get_called_class ( ) , 'trim_stripslashes_deep' ) , $ value ) ; } elseif ( is_object ( $ value ) ) { $ vars = get_object_vars ( $ value ) ; foreach ( $ vars as $ key => $ data ) { $ value -> { $ key } = self :: trim_stripslashes_deep ( $ data ) ; } } elseif ( is_string ( $ value ) ) { $ value = trim ( stripslashes ( $ value ) ) ; } return $ value ; }
Provides a replacement for WP s native stripslashes_deep function which frustratingly doesn t trim
23,359
private function checkMysqlConnection ( ) { $ this -> connection = new \ mysqli ( $ this -> config -> get ( 'backup::config' ) [ 'BACKUP_MYSQL_HOST' ] , $ this -> config -> get ( 'backup::config' ) [ 'BACKUP_MYSQL_USER' ] , $ this -> config -> get ( 'backup::config' ) [ 'BACKUP_MYSQL_PASSWORD' ] ) ; if ( $ this -> connection -> connect_errno ) { $ this -> event -> fire ( 'MonasheeBackupError' , 'No database connection' ) ; throw new \ Exception ( 'Error connecting to MySQL' ) ; } echo 'Connected: ' . $ this -> connection -> host_info . "\n" ; echo 'Server info: ' . $ this -> connection -> get_server_info ( ) . "\n" ; return true ; }
Check MySQL Connection
23,360
protected function view ( $ view , $ data = [ ] , $ auto_filter = null ) { return \ View :: forge ( $ view , $ data , $ auto_filter ) ; }
Creates a new View object
23,361
public function editAction ( ) { $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ id = $ params -> fromRoute ( 'id' ) ; $ rootId = is_numeric ( $ id ) ? ( int ) $ id : null ; $ model = $ locator -> get ( 'Grid\Customize\Model\Sheet\Model' ) ; $ form = $ locator -> get ( 'Form' ) -> get ( 'Grid\Customize\Css' ) ; $ sheet = $ model -> find ( $ rootId ) ; $ form -> setHydrator ( $ model -> getMapper ( ) ) -> bind ( $ sheet ) ; if ( $ request -> isPost ( ) ) { $ form -> setData ( $ request -> getPost ( ) ) ; if ( $ form -> isValid ( ) && $ sheet -> save ( ) ) { $ this -> messenger ( ) -> add ( 'customize.form.success' , 'customize' , Message :: LEVEL_INFO ) ; $ cssPreview = $ locator -> get ( 'Grid\Customize\Service\CssPreview' ) ; if ( $ cssPreview -> hasPreviewById ( $ rootId ) ) { @ unlink ( 'public' . $ cssPreview -> getPreviewById ( $ rootId ) ) ; $ cssPreview -> unsetPreviewById ( $ rootId ) ; } return $ this -> redirect ( ) -> toRoute ( 'Grid\Customize\CssAdmin\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } else { $ this -> messenger ( ) -> add ( 'customize.form.failed' , 'customize' , Message :: LEVEL_ERROR ) ; } } return array ( 'form' => $ form , 'sheet' => $ sheet , ) ; }
Edit a css
23,362
public function previewAction ( ) { $ params = $ this -> params ( ) ; $ request = $ this -> getRequest ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ id = $ params -> fromRoute ( 'id' ) ; $ rootId = is_numeric ( $ id ) ? ( int ) $ id : null ; $ model = $ locator -> get ( 'Grid\Customize\Model\Sheet\Model' ) ; $ form = $ locator -> get ( 'Form' ) -> get ( 'Grid\Customize\Css' ) ; $ sheet = $ model -> createEmpty ( $ rootId ) ; $ form -> setHydrator ( $ model -> getMapper ( ) ) -> bind ( $ sheet ) ; if ( $ request -> isPost ( ) ) { $ form -> setData ( $ request -> getPost ( ) ) ; if ( $ form -> isValid ( ) ) { $ this -> messenger ( ) -> add ( 'customize.preview.success' , 'customize' , Message :: LEVEL_INFO ) ; $ id = $ rootId === null ? 'global' : $ rootId ; $ prefix = 'public' ; $ file = sprintf ( static :: PREVIEW_FILE , $ id ) . '.' ; do { $ suffix = new DateTime ; } while ( file_exists ( $ prefix . $ file . $ suffix -> toHash ( ) . static :: PREVIEW_EXTENSION ) ) ; $ url = $ file . $ suffix -> toHash ( ) . static :: PREVIEW_EXTENSION ; $ path = $ prefix . $ url ; $ sheet -> render ( $ path ) ; $ locator -> get ( 'Grid\Customize\Service\CssPreview' ) -> setPreviewById ( $ rootId , $ url ) ; if ( null === $ rootId ) { return $ this -> redirect ( ) -> toUrl ( '/' ) ; } else { return $ this -> redirect ( ) -> toRoute ( 'Grid\Paragraph\Render\Paragraph' , array ( 'locale' => ( string ) $ this -> locale ( ) , 'paragraphId' => $ rootId , ) ) ; } } else { $ this -> messenger ( ) -> add ( 'customize.preview.failed' , 'customize' , Message :: LEVEL_ERROR ) ; return $ this -> redirect ( ) -> toRoute ( 'Grid\Customize\CssAdmin\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; } } }
Preview a css
23,363
public function cancelAction ( ) { $ params = $ this -> params ( ) ; $ locator = $ this -> getServiceLocator ( ) ; $ cssPreview = $ locator -> get ( 'Grid\Customize\Service\CssPreview' ) ; $ id = $ params -> fromRoute ( 'id' ) ; $ rootId = is_numeric ( $ id ) ? ( int ) $ id : null ; if ( $ cssPreview -> hasPreviewById ( $ rootId ) ) { @ unlink ( 'public' . $ cssPreview -> getPreviewById ( $ rootId ) ) ; $ cssPreview -> unsetPreviewById ( $ rootId ) ; } return $ this -> redirect ( ) -> toRoute ( 'Grid\Customize\CssAdmin\List' , array ( 'locale' => ( string ) $ this -> locale ( ) , ) ) ; }
Cancel an edit of a css
23,364
public function resetPreviewsAction ( ) { $ cssPreview = $ this -> getServiceLocator ( ) -> get ( 'Grid\Customize\Service\CssPreview' ) ; foreach ( $ cssPreview -> getPreviews ( ) as $ url ) { @ unlink ( 'public' . $ url ) ; } $ cssPreview -> unsetPreviews ( ) ; $ this -> messenger ( ) -> add ( 'customize.preview.reset' , 'customize' , Message :: LEVEL_INFO ) ; return $ this -> redirect ( ) -> toUrl ( '/' ) ; }
Reset all previews
23,365
public static function handleException ( $ exception ) { $ message = get_class ( $ exception ) . " " . $ exception -> getCode ( ) . ":\n\n" . $ exception -> getMessage ( ) . "\n" . self :: exception_get_dev_message ( $ exception ) . " in " . $ exception -> getFile ( ) . " on line " . $ exception -> getLine ( ) . ".\n\n Backtrace: " . $ exception -> getTraceAsString ( ) ; $ currentPreviousException = $ exception ; while ( $ currentPreviousException = $ currentPreviousException -> getPrevious ( ) ) { $ message .= "\nPrevious: " . get_class ( $ currentPreviousException ) . " " . $ currentPreviousException -> getMessage ( ) . "\n" . self :: exception_get_dev_message ( $ currentPreviousException ) . "\n in " . $ currentPreviousException -> getFile ( ) . " on line " . $ currentPreviousException -> getLine ( ) . ".\n" . $ currentPreviousException -> getTraceAsString ( ) ; } if ( self :: isDeveloperPresentable ( $ exception ) ) { $ uri = isset ( $ _SERVER [ "REQUEST_URI" ] ) ? $ _SERVER [ "REQUEST_URI" ] : ( isset ( $ _SERVER [ "argv" ] ) ? implode ( " " , $ _SERVER [ "argv" ] ) : null ) ; Logger :: log ( $ message , Logger :: LOG_LEVEL_ERROR ) ; $ debugMsg = $ message . "\n\n\n" . "URL: " . $ uri . " \nPOST: " . print_r ( $ _POST , true ) . "GET: " . print_r ( $ _GET , true ) . "SERVER: " . print_r ( $ _SERVER , true ) . "HTTP: " . print_r ( getallheaders ( ) , true ) . "\nComposer: " . print_r ( GomaENV :: getProjectLevelComposerArray ( ) , true ) . " Installed: " . print_r ( GomaENV :: getProjectLevelInstalledComposerArray ( ) , true ) . "\n\n" ; Logger :: log ( $ debugMsg , Logger :: LOG_LEVEL_DEBUG ) ; } else { Logger :: log ( $ message , Logger :: LOG_LEVEL_LOG ) ; } }
At this point exceptions can be handled . Return true if exception was handled and default handling or handling by others should be stopped .
23,366
protected function startProvidersPlugin ( $ app ) { switch ( $ this -> registerProvidersOn ) { case 'register' : $ this -> onRegister ( 'providers' , function ( ) { $ this -> handleProviders ( ) ; } ) ; break ; case 'booting' : $ this -> app -> booting ( function ( ) { $ this -> handleProviders ( ) ; } ) ; break ; case 'boot' : $ this -> onBoot ( 'providers' , function ( ) { $ this -> handleProviders ( ) ; } ) ; break ; case 'booted' : $ this -> app -> booted ( function ( ) { $ this -> handleProviders ( ) ; } ) ; break ; default : throw new \ LogicException ( 'registerProvidersOn not valid' ) ; break ; } }
startProvidersPlugin method .
23,367
protected function handleProviders ( ) { foreach ( $ this -> deferredProviders as $ provider ) { $ this -> app -> registerDeferredProvider ( $ provider ) ; } if ( $ this -> registerProvidersMethod === 'register' ) { $ this -> registerProviders ( ) ; } elseif ( $ this -> registerProvidersMethod === 'resolve' ) { $ this -> resolveProviders ( ) ; } else { throw new \ LogicException ( 'registerProvidersMethod not valid' ) ; } }
handleProviders method .
23,368
protected function resolveProviders ( ) { foreach ( $ this -> providers as $ provider ) { $ resolved = $ this -> resolveProvider ( $ registered [ ] = $ provider ) ; $ resolved -> register ( ) ; if ( $ this -> registerProvidersOn === 'boot' ) { $ this -> app -> call ( [ $ provider , 'boot' ] ) ; } } }
resolveProviders method .
23,369
public function getByCode ( $ code ) { return $ this -> languages -> filter ( function ( $ language ) use ( $ code ) { return $ language -> code == $ code ; } ) -> first ( ) ; }
Get lang by lang code
23,370
public function create ( ) { $ blog_dir = getcwd ( ) . '/' . $ this -> name . '/' ; $ this -> createBlogDirectory ( $ blog_dir ) ; $ this -> createConfigFile ( $ blog_dir ) ; $ this -> createTemplateFile ( $ blog_dir ) ; }
Create blog app with all its mandatory folder
23,371
public function createBlogDirectory ( $ blog_dir ) { @ mkdir ( $ blog_dir , 0777 , true ) ; $ this -> config = $ this -> configContent ( $ blog_dir ) ; @ mkdir ( $ this -> config [ 'dir' ] [ 'post' ] , 0777 , true ) ; @ mkdir ( $ this -> config [ 'dir' ] [ 'page' ] , 0777 , true ) ; @ mkdir ( $ this -> config [ 'dir' ] [ 'site' ] , 0777 , true ) ; @ mkdir ( $ this -> config [ 'dir' ] [ 'asset' ] , 0777 , true ) ; @ mkdir ( $ this -> config [ 'dir' ] [ 'layout' ] , 0777 , true ) ; }
Create Blog App Directories
23,372
public function createTemplateFile ( ) { if ( ! is_dir ( $ this -> config [ 'dir' ] [ 'asset' ] . '/css' ) ) { mkdir ( $ this -> config [ 'dir' ] [ 'asset' ] . '/css' ) ; } if ( ! is_dir ( $ this -> config [ 'dir' ] [ 'asset' ] . '/js' ) ) { mkdir ( $ this -> config [ 'dir' ] [ 'asset' ] . '/js' ) ; } file_put_contents ( $ this -> config [ 'dir' ] [ 'asset' ] . '/css/bootstrap.min.css' , file_get_contents ( __DIR__ . '/tpl/css/bootstrap.min.css' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'asset' ] . '/css/bootstrap-theme.min.css' , file_get_contents ( __DIR__ . '/tpl/css/bootstrap-theme.min.css' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'asset' ] . '/js/jquery.js' , file_get_contents ( __DIR__ . '/tpl/js/jquery.js' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'asset' ] . '/js/bootstrap.min.js' , file_get_contents ( __DIR__ . '/tpl/js/bootstrap.min.js' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/index.html.tpl' , file_get_contents ( __DIR__ . '/tpl/index.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/post.html.tpl' , file_get_contents ( __DIR__ . '/tpl/post.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/page.html.tpl' , file_get_contents ( __DIR__ . '/tpl/page.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/category.html.tpl' , file_get_contents ( __DIR__ . '/tpl/category.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/author.html.tpl' , file_get_contents ( __DIR__ . '/tpl/author.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/sidebar.html.tpl' , file_get_contents ( __DIR__ . '/tpl/sidebar.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/header.html.tpl' , file_get_contents ( __DIR__ . '/tpl/header.html.tpl' ) ) ; file_put_contents ( $ this -> config [ 'dir' ] [ 'layout' ] . '/layout.html.tpl' , file_get_contents ( __DIR__ . '/tpl/layout.html.tpl' ) ) ; }
Creating template file . Template will be used for view
23,373
public function configContent ( $ blog_dir ) { $ base_blog = basename ( $ blog_dir ) ; return $ array = array ( "config" => array ( "name" => $ this -> name , "url" => '/' , "title" => "Your Site Title" , "tagline" => "Your Site Tagline" , "pagination" => 10 ) , "dir" => array ( "post" => $ base_blog . "/_posts" , "page" => $ base_blog . "/_pages" , "site" => $ base_blog . "/_sites" , "asset" => $ base_blog . "/_assets" , "layout" => $ base_blog . "/_layouts" , ) , "authors" => array ( 'tolkien' => array ( 'name' => 'John Ronald Reuel Tolkien' , 'email' => 'tolkien@kodetalk.com' , 'facebook' => 'Tolkien' , 'twitter' => '@tolkien' , 'github' => 'Tolkien' , 'signature' => 'Creator of LoTR Trilogy' ) ) ) ; }
Content of config . yml
23,374
public function block ( $ model ) { $ deletedAtLeastOne = false ; if ( $ this -> friends -> count ( ) ) { foreach ( $ this -> friends as $ friend ) { if ( $ friend -> getKey ( ) == $ model -> id ) { $ friend -> pivot -> delete ( ) ; $ this -> resetFriends ( ) ; $ deletedAtLeastOne = true ; } } } return $ deletedAtLeastOne ; }
Remove the connection between these two models . AKA block user .
23,375
public function approve ( $ model ) { $ approvedAtLeastOne = false ; if ( $ model -> friends -> count ( ) ) { foreach ( $ model -> friends as $ friend ) { if ( ( int ) $ friend -> getKey ( ) === ( int ) $ this -> getKey ( ) ) { $ friend -> pivot -> approved_at = new \ Carbon \ Carbon ; $ friend -> pivot -> save ( ) ; $ this -> resetFriends ( ) ; $ approvedAtLeastOne = true ; } } } return $ approvedAtLeastOne ; }
Approve an incoming connection request . AKA approve request
23,376
public function getCurrentFriendsAttribute ( ) { return $ this -> friends -> filter ( function ( $ item ) { $ now = new \ Carbon \ Carbon ; if ( ! $ item -> pivot -> approved_at ) { return false ; } switch ( true ) { case ! $ item -> pivot -> end && ! $ item -> pivot -> start : case ! $ item -> pivot -> end && $ item -> pivot -> start && $ item -> pivot -> start < $ now : case ! $ item -> pivot -> start && $ item -> pivot -> end && $ item -> pivot -> end > $ now : case $ item -> pivot -> start && $ item -> pivot -> start < $ now && $ item -> pivot -> end && $ item -> pivot -> end > $ now : return true ; break ; } return false ; } ) ; }
Filters the primary connections by ones that are currently active .
23,377
protected function mergeMineAndRequestedFriends ( ) { $ all = $ this -> sentRequests ; if ( $ more = $ this -> receivedApprovedRequests -> all ( ) ) { foreach ( $ more as $ m ) { $ all -> add ( $ m ) ; } } return $ all ; }
Merge the result of two relationships .
23,378
public function assembleResult ( EarthIT_CMIPREST_ActionResult $ result , TOGoS_Action $ action = null , $ ctx = null ) { $ rootRc = $ result -> getRootResourceClass ( ) ; $ columnHeaders = array ( ) ; foreach ( $ rootRc -> getFields ( ) as $ fn => $ field ) { $ columnHeaders [ ] = $ fn ; } $ itemCollections = $ result -> getItemCollections ( ) ; $ rows = array ( $ columnHeaders ) ; foreach ( $ itemCollections [ 'root' ] as $ item ) { $ row = array ( ) ; foreach ( $ columnHeaders as $ c ) { $ row [ $ c ] = $ item [ $ c ] ; } $ rows [ ] = $ row ; } return $ rows ; }
Assemble a StorageResult into whatever format the thing that s going to take the results needs . Normally this will be an array .
23,379
public function assembledResultToHttpResponse ( $ assembled , TOGoS_Action $ action = null , $ ctx = null ) { return Nife_Util :: httpResponse ( 200 , new EarthIT_CMIPREST_CSVBlob ( $ assembled ) , array ( 'content-type' => 'text/csv' ) ) ; }
Take the result returned by assembleResult and encode it as a Nife_HTTP_Response
23,380
public function exceptionToHttpResponse ( Exception $ e , TOGoS_Action $ action = null , $ ctx = null ) { $ userIsAuthenticated = ( $ ctx and method_exists ( $ ctx , 'userIsAuthenticated' ) ) ? $ ctx -> userIsAuthenticated ( ) : false ; return EarthIT_CMIPREST_Util :: exceptionalNormalJsonHttpResponse ( $ e , $ userIsAuthenticated , array ( EarthIT_CMIPREST_Util :: BASIC_WWW_AUTHENTICATION_REALM => $ this -> basicWwwAuthenticationRealm ) ) ; }
Encode the fact that an exception occurred as a Nife_HTTP_Response .
23,381
private function getClassCandidates ( $ class ) { if ( ! is_array ( $ functions = spl_autoload_functions ( ) ) ) { return array ( ) ; } $ classes = array ( ) ; foreach ( $ functions as $ function ) { if ( ! is_array ( $ function ) ) { continue ; } if ( $ function [ 0 ] instanceof DebugClassLoader ) { $ function = $ function [ 0 ] -> getClassLoader ( ) ; if ( ! is_array ( $ function ) ) { continue ; } } if ( $ function [ 0 ] instanceof ComposerClassLoader || $ function [ 0 ] instanceof SymfonyClassLoader ) { foreach ( $ function [ 0 ] -> getPrefixes ( ) as $ prefix => $ paths ) { foreach ( $ paths as $ path ) { $ classes = array_merge ( $ classes , $ this -> findClassInPath ( $ path , $ class , $ prefix ) ) ; } } } if ( $ function [ 0 ] instanceof ComposerClassLoader ) { foreach ( $ function [ 0 ] -> getPrefixesPsr4 ( ) as $ prefix => $ paths ) { foreach ( $ paths as $ path ) { $ classes = array_merge ( $ classes , $ this -> findClassInPath ( $ path , $ class , $ prefix ) ) ; } } } } return array_unique ( $ classes ) ; }
Tries to guess the full namespace for a given class name .
23,382
final private function isSameObjectAs ( Type $ type , int $ flags = null ) : bool { if ( $ flags & TypeEquality :: IGNORE_OBJECT_IDENTITY ) { return true ; } return ( spl_object_hash ( $ this ) === spl_object_hash ( $ type ) ) ? true : false ; }
Check against an objects ID
23,383
public function afterSave ( Event $ event , Setting $ entity , ArrayObject $ options ) { Cache :: delete ( 'settings' , 'wasabi/core/longterm' ) ; $ this -> eventManager ( ) -> dispatch ( new Event ( 'Wasabi.Settings.changed' ) ) ; }
Called after an entity is saved .
23,384
public function map ( callable $ callback ) { $ keys = array_keys ( $ this -> members ) ; $ members = array_map ( $ callback , $ this -> members , $ keys ) ; return new static ( array_combine ( $ keys , $ members ) ) ; }
Run a map over each of the members .
23,385
public function random ( $ num = 1 ) { if ( $ num == 1 ) return $ this -> members [ array_rand ( $ this -> members ) ] ; $ keys = array_rand ( $ this -> members , $ num ) ; return new static ( array_intersect_key ( $ this -> members , array_flip ( $ keys ) ) ) ; }
Get one or more random members from the collection .
23,386
public function filter ( callable $ callback = null ) { return new static ( $ callback ? array_filter ( $ this -> members , $ callback ) : array_filter ( $ this -> members ) ) ; }
Run a filter over each of the members .
23,387
public static function median ( $ arr ) { $ vals = array_values ( $ arr ) ; sort ( $ vals ) ; $ num_vals = count ( $ vals ) ; return ( $ num_vals % 2 ) ? ( $ vals [ $ num_vals / 2 ] + $ vals [ ( $ num_vals / 2 ) + 1 ] ) / 2 : $ vals [ ( $ num_vals + 1 ) / 2 ] ; }
Get the median
23,388
public static function mode ( $ arr ) { $ vals = array_count_values ( $ arr ) ; asort ( $ vals ) ; return end ( array_keys ( $ vals ) ) ; }
Get the mode
23,389
public static function withKeys ( $ records , $ keys ) { if ( ! self :: iterable ( $ records ) ) { return array ( ) ; } $ out = array ( ) ; foreach ( $ records as $ n => $ record ) { if ( ! self :: iterable ( $ record ) ) { $ out [ $ n ] = $ record ; continue ; } $ out [ $ n ] = array ( ) ; foreach ( $ record as $ k => $ v ) { if ( ! in_array ( $ k , $ keys ) ) { continue ; } $ out [ $ n ] [ $ k ] = $ v ; } } return $ out ; }
Get the data only with specific keys
23,390
public static function apportion ( $ arr , $ num_groups = 2 , $ strict_group_count = false , $ backload = false ) { if ( ! self :: iterable ( $ arr ) ) { return array ( ) ; } if ( $ backload ) { $ arr = array_reverse ( $ arr , true ) ; } $ apportioned = array ( ) ; $ per_group = ceil ( count ( $ arr ) / $ num_groups ) ; if ( $ strict_group_count ) { $ apportioned = array_chunk ( $ arr , $ per_group , true ) ; } else { $ shortage = ( $ per_group * $ num_groups ) - count ( $ arr ) ; if ( $ shortage > 1 ) { $ keys = array_keys ( $ arr ) ; $ first_keys = array_splice ( $ keys , 0 , $ per_group ) ; $ first_group = array_splice ( $ arr , 0 , $ per_group ) ; $ first_group = array_combine ( $ first_keys , $ first_group ) ; $ arr = array_combine ( $ keys , $ arr ) ; $ remainders = self :: apportion ( $ arr , $ num_groups - 1 ) ; $ apportioned = array_merge ( array ( $ first_group ) , $ remainders ) ; } else { $ apportioned = array_chunk ( $ arr , $ per_group , true ) ; } } if ( $ backload ) { foreach ( $ apportioned as & $ group ) { $ group = array_reverse ( $ group , true ) ; } $ apportioned = array_reverse ( $ apportioned , true ) ; } return $ apportioned ; }
Split array into groups with nearly equal number of elements
23,391
public static function logout ( ) { $ _SESSION = [ ] ; session_destroy ( ) ; session_unset ( ) ; self :: $ isGuest = true ; self :: $ user = user :: guest ( ) ; }
logout the current user
23,392
public function getPath ( $ asArray = true ) { $ raw = $ this -> owner -> { $ this -> pathAttribute } ; return $ asArray ? $ this -> convertPathFromPgToPhp ( $ raw ) : $ raw ; }
Returns path of self node .
23,393
public function getParentPath ( $ asArray = true ) { if ( $ this -> owner -> isRoot ( ) ) { return null ; } $ path = $ this -> owner -> getPath ( ) ; array_pop ( $ path ) ; return $ asArray ? $ path : $ this -> convertPathFromPhpToPg ( $ path ) ; }
Returns path from root to parent node .
23,394
public function getParents ( $ depth = null ) { $ query = $ this -> owner -> find ( ) ; return $ query -> parentsOf ( $ this -> owner , $ depth ) ; }
Returns list of parents from root to self node .
23,395
public function getRoot ( ) { $ path = $ this -> owner -> getPath ( ) ; $ path = array_shift ( $ path ) ; $ query = $ this -> owner -> find ( ) ; $ query -> andWhere ( [ $ this -> keyColumn => $ path ] ) -> limit ( 1 ) ; $ query -> multiple = false ; return $ query ; }
Returns root node in self node s subtree .
23,396
public function getDescendants ( $ depth = null , $ andSelf = false ) { $ query = $ this -> owner -> find ( ) ; return $ query -> descendantsOf ( $ this -> owner , $ depth , $ andSelf ) ; }
Returns descendants as plain list .
23,397
public function populateTree ( $ depth = null ) { $ nodes = $ this -> getDescendants ( $ depth ) -> indexBy ( $ this -> keyAttribute ) -> all ( ) ; $ relates = [ ] ; foreach ( $ nodes as $ key => $ node ) { $ parentKey = $ node -> getParentKey ( ) ; if ( ! isset ( $ relates [ $ parentKey ] ) ) { $ relates [ $ parentKey ] = [ ] ; } $ relates [ $ parentKey ] [ ] = $ node ; } $ nodes [ $ this -> owner -> { $ this -> keyAttribute } ] = $ this -> owner ; foreach ( $ relates as $ key => $ children ) { $ nodes [ $ key ] -> populateRelation ( 'children' , $ children ) ; } return $ this -> owner ; }
Returns descendants nodes as tree with self node in the root .
23,398
public function getParentKey ( ) { if ( $ this -> owner -> isRoot ( ) ) { return null ; } $ path = $ this -> getPath ( ) ; return array_pop ( $ path ) ; }
Returns key of parent .
23,399
public function as_array ( $ key = null , $ value = null ) { $ results = array ( ) ; if ( $ key === null and $ value === null ) { foreach ( $ this as $ row ) { $ results [ ] = $ row ; } } elseif ( $ key === null ) { if ( $ this -> _as_object ) { foreach ( $ this as $ row ) { $ results [ ] = $ row -> $ value ; } } else { foreach ( $ this as $ row ) { $ results [ ] = $ row [ $ value ] ; } } } elseif ( $ value === null ) { if ( $ this -> _as_object ) { foreach ( $ this as $ row ) { $ results [ $ row -> $ key ] = $ row ; } } else { foreach ( $ this as $ row ) { $ results [ $ row [ $ key ] ] = $ row ; } } } else { if ( $ this -> _as_object ) { foreach ( $ this as $ row ) { $ results [ $ row -> $ key ] = $ row -> $ value ; } } else { foreach ( $ this as $ row ) { $ results [ $ row [ $ key ] ] = $ row [ $ value ] ; } } } $ this -> rewind ( ) ; return $ results ; }
Return all of the rows in the result as an array .