idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
57,700
|
public function getParamsArray ( ) { $ result = [ ] ; foreach ( $ this -> params as $ param ) { $ result [ ] = $ param -> toArray ( ) ; } return $ result ; }
|
Return the array representation of the params
|
57,701
|
protected function stackIsReady ( ) { $ stacks = $ this -> describeMainStack ( ) ; if ( null === $ stacks ) { return false ; } switch ( $ stacks [ 0 ] [ 'StackStatus' ] ) { case 'CREATE_COMPLETE' : case 'UPDATE_COMPLETE' : case 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS' : return true ; case 'UPDATE_IN_PROGRESS' : case 'CREATE_IN_PROGRESS' : $ this -> logRecentEvents ( ) ; case '' : return false ; default : sleep ( 3 ) ; $ this -> logRecentEvents ( ) ; throw new \ BuildException ( 'Failed to run stack ' . $ this -> getName ( ) . ' (' . $ stacks [ 0 ] [ 'StackStatus' ] . ') !' ) ; } }
|
Log the main stack events Return true when the cloudformation is complete
|
57,702
|
private function describeMainStack ( CloudFormationException & $ cloudFormationException = null ) { $ cloudFormation = $ this -> getService ( ) ; try { $ stack = $ cloudFormation -> describeStacks ( [ 'StackName' => $ this -> getName ( ) , ] ) ; return $ stack [ 'Stacks' ] ; } catch ( CloudFormationException $ e ) { $ cloudFormationException = $ e ; $ message = $ e -> getMessage ( ) ; } if ( 1 === preg_match ( '/AccessDenied|403 Forbidden/i' , $ message ) ) { throw new \ BuildException ( 'You are not authorized to perform describeStacks on [' . $ this -> getName ( ) . ']. Check the credentials and AWS policy' ) ; } if ( 1 === preg_match ( '/Could not resolve host/i' , $ message ) ) { throw new \ BuildException ( "Could not resolve AWS host, thanks to check the AWS_REGION settings or connectivity" ) ; } return null ; }
|
Return the Main Stack result or null if cannot be found
|
57,703
|
private function creationStacks ( ) { $ cloudFormation = $ this -> getService ( ) ; if ( true !== $ this -> getUpdateOnConflict ( ) ) { throw new \ BuildException ( 'Stack ' . $ this -> getName ( ) . ' not exist. Creation stack was skip due to property updateOnConflict set to false' ) ; } try { $ this -> log ( 'Create stacks...' ) ; $ cloudFormation -> createStack ( $ this -> stackProperties ( ) ) ; } catch ( CloudFormationException $ e ) { if ( $ e -> getAwsErrorCode ( ) !== 'AlreadyExistsException' ) { throw $ e ; } else { $ this -> log ( 'stack [' . $ this -> getName ( ) . '] creation already in progress.' ) ; } } }
|
Create stacks in cloudformation
|
57,704
|
private function updateStacks ( ) { $ cloudFormation = $ this -> getService ( ) ; try { $ this -> log ( 'Update stacks...' ) ; $ cloudFormation -> updateStack ( $ this -> stackProperties ( ) ) ; } catch ( CloudFormationException $ e ) { if ( 1 === preg_match ( '/No updates are to be performed/i' , $ e -> getMessage ( ) ) ) { $ this -> log ( 'No updates are to be performed.' ) ; return ; } throw new \ BuildException ( "AwsErrorCode [{$e->getAwsErrorCode()}] Message : " . $ e -> getMessage ( ) ) ; } }
|
Update stacks in cloudformation
|
57,705
|
private function logRecentEvents ( ) { $ events = $ this -> getService ( ) -> describeStackEvents ( [ 'StackName' => $ this -> getName ( ) ] ) ; $ events = array_column ( array_reverse ( $ events [ 'StackEvents' ] ) , null , 'EventId' ) ; foreach ( array_diff_assoc ( $ events , $ this -> events ) as $ event ) { $ timestamp = $ event [ 'Timestamp' ] ; if ( $ timestamp < $ this -> datetimeTaskStart ) { continue ; } $ this -> log ( $ timestamp . ': ' . $ event [ 'ResourceType' ] . ' > ' . $ event [ 'LogicalResourceId' ] . ' (' . $ event [ 'ResourceStatus' ] . ')' ) ; if ( $ event [ 'ResourceStatusReason' ] ) { $ this -> log ( $ event [ 'ResourceStatusReason' ] ) ; } } $ this -> events = $ events ; }
|
Log the recent stack events
|
57,706
|
public function addChild ( TreeNodeInterface $ node ) { $ this -> children [ ] = $ node ; $ node -> setParent ( $ this ) ; return $ this ; }
|
Add a child node to this node
|
57,707
|
private static function _execute ( $ pCmd , array $ pArgs ) { $ result = array ( ) ; exec ( 'php agl ' . $ pCmd . ' ' . implode ( ' ' , $ pArgs ) , $ result ) ; return $ result ; }
|
Execute the requested command with passed arguments .
|
57,708
|
public static function postPackageInstall ( PackageEvent $ pEvent ) { if ( $ pEvent -> getOperation ( ) instanceof \ Composer \ DependencyResolver \ Operation \ InstallOperation ) { $ packageName = $ pEvent -> getOperation ( ) -> getPackage ( ) -> getName ( ) ; } else if ( $ pEvent -> getOperation ( ) instanceof \ Composer \ DependencyResolver \ Operation \ UpdateOperation ) { $ packageName = $ pEvent -> getOperation ( ) -> getInitialPackage ( ) -> getName ( ) ; } else { throw new Exception ( "Event is not supported." ) ; } $ appPath = realpath ( '.' ) . DIRECTORY_SEPARATOR ; $ path = realpath ( '.' . DIRECTORY_SEPARATOR . $ pEvent -> getComposer ( ) -> getConfig ( ) -> get ( 'vendor-dir' ) . DIRECTORY_SEPARATOR . $ packageName . DIRECTORY_SEPARATOR . self :: SETUP_DIR . DIRECTORY_SEPARATOR . self :: CLI_FILE ) ; if ( $ path and is_readable ( $ path ) ) { $ config = require ( $ path ) ; if ( is_array ( $ config ) ) { foreach ( $ config as $ cmd => $ args ) { if ( ! is_array ( $ args ) ) { continue ; } else if ( count ( $ args ) == count ( $ args , COUNT_RECURSIVE ) ) { self :: _execute ( $ cmd , $ args ) ; } else { foreach ( $ args as $ cmdArgs ) { self :: _execute ( $ cmd , $ cmdArgs ) ; } } } } } return true ; }
|
Post package install event fired by Composer . Create config directories and files in application if required by package .
|
57,709
|
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ names = $ input -> getArgument ( 'module' ) ; $ module = BASE_PATH . '/modules' ; if ( is_dir ( $ module ) && ! is_writable ( $ module ) ) { $ output -> writeln ( 'The "%s" directory is not writable' ) ; return ; } if ( is_dir ( $ module ) ) { if ( mkdir ( $ module . "/" . strtolower ( $ names ) , 0755 , true ) ) { $ this -> createModuleClass ( $ module , $ names , $ output ) ; $ this -> createTable ( $ input , $ output ) ; $ this -> createModel ( $ input , $ output ) ; $ this -> createView ( $ input , $ output ) ; $ this -> createController ( $ input , $ output ) ; $ this -> createRoute ( $ input , $ output ) ; $ this -> createConfig ( $ names ) ; $ this -> createAsset ( ) ; } else { $ output -> writeln ( "Failed create Module" ) ; } } else { $ output -> writeln ( "Directory Module not Exsist" ) ; } }
|
Excecute console command
|
57,710
|
public function createModuleClass ( $ module , $ names , OutputInterface $ output ) { $ source = realpath ( __DIR__ . '/../src/module.txt' ) ; $ file = file_get_contents ( $ source ) ; $ file = str_replace ( "!module" , ucfirst ( $ names ) , $ file ) ; $ file = str_replace ( "!date" , date ( 'd/m/Y' ) , $ file ) ; $ file = str_replace ( "!time" , date ( 'HH:mm:ss' ) , $ file ) ; if ( ! file_exists ( $ module . "/" . $ names . "/Modules.php" ) ) { $ fh = fopen ( $ module . "/" . $ names . "/Modules.php" , "w" ) ; fwrite ( $ fh , $ file ) ; fclose ( $ fh ) ; $ className = ucfirst ( $ names ) . ".php" ; return $ output -> writeln ( "Created config $className in modules" ) ; } else { return $ output -> writeln ( "Class modules already Exists!" ) ; } }
|
Generate Module config
|
57,711
|
public function createTable ( InputInterface $ input , OutputInterface $ output ) { $ databse = $ this -> getApplication ( ) -> find ( 'create:table' ) ; $ databse_arguments = array ( 'command' => 'create:table' , 'table' => $ input -> getArgument ( 'table' ) , 'column' => $ input -> getArgument ( 'column' ) ) ; $ input_db = new ArrayInput ( $ databse_arguments ) ; $ return_db = $ databse -> run ( $ input_db , $ output ) ; return $ output -> writeln ( $ return_db ) ; }
|
Generate Table Database
|
57,712
|
public function createConfig ( $ names ) { $ config = include APP_PATH . "/config/modules.php" ; array_push ( $ config , $ names ) ; file_put_contents ( APP_PATH . "/config/modules.php" , '<?php return [' . "'" . implode ( "','" , $ config ) . "'" . '];' ) ; }
|
Add on module config array
|
57,713
|
public function createAsset ( ) { $ css = BASE_PATH . "/public/css/" ; $ js = BASE_PATH . "/public/js/" ; $ source = realpath ( __DIR__ . '/../assets/' ) ; $ css_file = file_get_contents ( $ source . "/jquery.bootgrid.css" ) ; $ js_file = file_get_contents ( $ source . "/jquery.bootgrid.js" ) ; $ fajs_file = file_get_contents ( $ source . "/jquery.bootgrid.fa.js" ) ; $ fc = fopen ( $ css . "jquery.bootgrid.css" , "w" ) ; fwrite ( $ fc , $ css_file ) ; fclose ( $ fc ) ; $ fj = fopen ( $ js . "jquery.bootgrid.js" , "w" ) ; fwrite ( $ fj , $ js_file ) ; fclose ( $ fj ) ; $ fa = fopen ( $ js . "jquery.bootgrid.fa.js" , "w" ) ; fwrite ( $ fa , $ fajs_file ) ; fclose ( $ fa ) ; }
|
Create jquery bootgrid Asset file
|
57,714
|
public function __ ( $ column , $ enumName = null , $ locale = null ) { $ enumName = $ enumName ? : $ column ; $ value = app ( 'enum' ) -> value ( $ this -> attribute ( $ column ) , $ enumName ) ; $ key = implode ( '.' , [ 'enums' , $ column , $ value ] ) ; if ( app ( 'translator' ) -> has ( $ key ) ) { return app ( 'translator' ) -> trans ( $ key , [ ] , $ locale ) ; } return $ value ; }
|
translate model enum name .
|
57,715
|
public function getVersions ( ) { $ versions = array ( ) ; $ log = $ this -> getResourceLog ( ) ; foreach ( $ log as $ entry ) { $ versions [ ] = ( string ) $ entry -> version ; } return $ versions ; }
|
Get available versions
|
57,716
|
public function compareVersions ( $ version1 , $ version2 ) { if ( version_compare ( $ version1 , $ version2 , 'eq' ) === true ) { return 0 ; } elseif ( version_compare ( $ version1 , $ version2 , 'gt' ) === true ) { return 1 ; } return - 1 ; }
|
Compare two version strings
|
57,717
|
public function getLogEntry ( $ version ) { $ log = $ this -> getResourceLog ( ) ; if ( ! isset ( $ log [ $ version ] ) ) { throw new \ UnexpectedValueException ( "Invalid log entry $version for {$this->path}." ) ; } return $ log [ $ version ] ; }
|
Get revision log entry
|
57,718
|
protected function wrapInNode ( $ nodeType , $ callback ) { assert ( is_string ( $ nodeType ) ) ; assert ( is_callable ( $ callback ) ) ; $ this -> startElement ( $ nodeType ) ; $ result = $ callback ( ) ; $ this -> endElement ( ) ; return $ result ; }
|
Wrap callable block in node
|
57,719
|
public function join ( $ type = null , $ table = null , array $ joinOn = null ) : Select { if ( ! \ is_string ( $ type ) || ! \ preg_match ( '/left|right|inner|full/i' , $ type ) ) { throw new InvalidArgumentException ( '$type has to be left|right|inner|full' ) ; } if ( ! \ is_string ( $ table ) && ! \ is_array ( $ table ) ) { throw new InvalidArgumentException ( '$table has to be an array or a string' ) ; } if ( ! \ is_array ( $ joinOn ) ) { throw new InvalidArgumentException ( '$on has to be an array' ) ; } $ this -> join [ ] = \ sprintf ( ' %s JOIN %s ON %s' , \ strtoupper ( $ type ) , \ implode ( ', ' , $ this -> namesClass -> parse ( $ table , true ) ) , ( new Condition ( $ this -> namesClass -> getAliases ( ) ) ) -> parse ( $ joinOn ) ) ; return $ this ; }
|
Adds single join to select
|
57,720
|
public function where ( array $ condition = null ) : Select { if ( ! \ is_array ( $ condition ) ) { throw new InvalidArgumentException ( '$condition has to be an array' ) ; } $ this -> where = ( new Condition ( $ this -> namesClass -> getAliases ( ) ) ) -> parse ( $ condition ) ; return $ this ; }
|
Adds condition to select
|
57,721
|
public function groupby ( $ groupBy = null ) : Select { if ( ! \ is_string ( $ groupBy ) && ! \ is_array ( $ groupBy ) ) { throw new InvalidArgumentException ( '$groupBy has to be an array or a string' ) ; } $ this -> groupBy = $ this -> namesClass -> parse ( $ groupBy ) ; return $ this ; }
|
Adds group by to select
|
57,722
|
public function offset ( int $ offset = 0 ) : Select { if ( ! \ is_int ( $ offset ) || $ offset < 0 ) { throw new InvalidArgumentException ( '$offset have to be a positive integer or a zero' ) ; } $ this -> offset = $ offset ; return $ this ; }
|
Adds offset to select
|
57,723
|
function render ( ) { $ return = $ this -> renderHeaders ( ) ; $ body = $ this -> getBody ( ) ; if ( $ body instanceof iStreamable ) { if ( $ body -> resource ( ) -> isSeekable ( ) ) $ body -> rewind ( ) ; while ( ! $ body -> isEOF ( ) ) $ return .= $ body -> read ( 24400 ) ; } else { $ return .= $ body ; } return $ return ; }
|
Render Http Message To String
|
57,724
|
function setHeaders ( $ headers ) { if ( $ headers instanceof iHeaders ) { $ tHeaders = array ( ) ; foreach ( $ headers as $ h ) $ tHeaders [ ] = $ h ; $ headers = $ tHeaders ; } if ( ! is_array ( $ headers ) ) throw new \ InvalidArgumentException ; foreach ( $ headers as $ label => $ h ) { if ( ! $ h instanceof iHeader ) { if ( is_int ( $ label ) && is_string ( $ h ) ) $ valuable = $ h ; else $ valuable = array ( $ label => $ h ) ; $ h = FactoryHttpHeader :: of ( $ valuable ) ; } $ this -> headers ( ) -> insert ( $ h ) ; } return $ this ; }
|
Set message headers or headers collection
|
57,725
|
function setBody ( $ content ) { if ( ! $ content instanceof iStreamable ) $ content = ( string ) $ content ; $ this -> body = $ content ; return $ this ; }
|
Set Message Body Content
|
57,726
|
public function transformObjectResponse ( ActionViewEvent $ event ) { $ data = $ event -> getData ( ) ; if ( $ data instanceof ObjectResponse ) { $ response = $ this -> doTransformObjectResponse ( $ data ) ; $ event -> setResponse ( $ response ) ; } }
|
Transform object response
|
57,727
|
public function transformObject ( ActionViewEvent $ event ) { $ data = $ event -> getData ( ) ; if ( is_array ( $ data ) ) { $ data = new \ ArrayObject ( $ data ) ; } if ( $ this -> normalizerManager -> supports ( $ data ) && ! $ this -> transformerManager -> supports ( $ data ) ) { $ objectResponse = new ObjectResponse ( $ data ) ; $ objectResponse -> removeActionTransform ( ) ; $ response = $ this -> doTransformObjectResponse ( $ objectResponse ) ; $ event -> setResponse ( $ response ) ; } if ( $ this -> transformerManager -> supports ( $ data ) ) { $ objectResponse = new ObjectResponse ( $ data ) ; $ response = $ this -> doTransformObjectResponse ( $ objectResponse ) ; $ event -> setResponse ( $ response ) ; } }
|
Transform object . Try create a object response via object in response .
|
57,728
|
private function doTransformObjectResponse ( ObjectResponse $ objectResponse ) { $ responseData = $ objectResponse ; if ( $ objectResponse -> isActionTransform ( ) ) { try { $ responseData = $ this -> transformerManager -> transform ( $ responseData -> getObject ( ) , $ objectResponse -> getTransformerContext ( ) ) ; if ( ! is_object ( $ responseData ) ) { throw UnexpectedTypeException :: create ( $ responseData , 'object' ) ; } } catch ( TransformerUnsupportedObjectException $ e ) { throw new \ RuntimeException ( sprintf ( 'Can not transform object with class "%s".' , get_class ( $ objectResponse ) ) , 0 , $ e ) ; } } try { $ responseData = $ this -> normalizerManager -> normalize ( $ responseData instanceof ObjectResponse ? $ responseData -> getObject ( ) : $ responseData , $ objectResponse -> getNormalizerContext ( ) ) ; if ( ! is_array ( $ responseData ) ) { throw UnexpectedTypeException :: create ( $ responseData , 'array' ) ; } } catch ( NormalizerUnsupportedObjectException $ e ) { throw new \ RuntimeException ( sprintf ( 'Can not normalize object with class "%s".' , get_class ( $ responseData ) ) , 0 , $ e ) ; } if ( $ objectResponse -> isEmptyResponse ( ) ) { $ response = new EmptyResponse ( $ responseData , $ objectResponse -> getHttpStatusCode ( ) ) ; } else { $ response = new Response ( $ responseData , $ objectResponse -> getHttpStatusCode ( ) ) ; } return $ response ; }
|
Process transform object response
|
57,729
|
public function addRemote ( $ url , $ name = 'origin' ) { $ this -> getRunnerWithDirectory ( ) -> run ( $ this -> getResettedCommandBuilder ( ) -> addSubcommand ( 'remote' ) -> addSubcommand ( 'add' ) -> addParam ( $ name ) -> addParam ( $ url ) ) ; return $ this ; }
|
Adds a new remote repository to the local repository
|
57,730
|
public function add ( $ all = true , $ refspec = '' , $ force = false ) { $ command = $ this -> getResettedCommandBuilder ( ) -> addSubcommand ( 'add' ) -> addParam ( $ refspec ) ; if ( $ all ) { $ command -> addArgument ( 'all' ) ; } if ( $ force ) { $ command -> addArgument ( 'force' ) ; } $ this -> getRunnerWithDirectory ( ) -> run ( $ command ) ; return $ this ; }
|
Adds files to the repository
|
57,731
|
public function commit ( $ message ) { $ this -> getRunnerWithDirectory ( ) -> run ( $ this -> getResettedCommandBuilder ( ) -> addSubcommand ( 'commit' ) -> addFlag ( 'm' , $ message ) ) ; return $ this ; }
|
Commits all changes from modified files that are already added to the repository
|
57,732
|
public function push ( $ repository = 'origin' , $ ref = 'HEAD' , $ setUpstream = false ) { $ command = $ this -> getResettedCommandBuilder ( ) -> addSubcommand ( 'push' ) -> addParam ( $ repository ) -> addParam ( $ ref ) ; if ( $ setUpstream ) { $ command -> addFlag ( 'u' ) ; } $ this -> getRunnerWithDirectory ( ) -> run ( $ command ) ; return $ this ; }
|
Pushes all staged commits to the upstream
|
57,733
|
private function loadConfig ( string $ config ) : void { if ( ! file_exists ( $ config ) ) { throw new NotfoundException ; } $ ext = substr ( $ config , strrpos ( $ config , '.' ) + 1 ) ; switch ( $ ext ) { case 'json' : $ settings = json_decode ( file_get_contents ( $ config ) , true ) ; if ( is_null ( $ settings ) ) { throw new InvalidException ; } break ; case 'yml' : case 'yaml' : try { $ settings = Yaml :: parse ( file_get_contents ( $ config ) ) ; } catch ( \ Exception $ e ) { throw new InvalidException ; } break ; case 'ini' : $ settings = parse_ini_file ( $ config , true ) ; if ( $ settings === false ) { throw new InvalidException ; } break ; case 'xml' : $ xml = simplexml_load_file ( $ config ) ; if ( $ xml === false ) { throw new InvalidException ; } $ settings = json_decode ( json_encode ( $ xml ) , true ) ; break ; case 'php' : $ settings = include $ config ; if ( ! is_array ( $ settings ) ) { throw new InvalidException ; } break ; default : throw new UnknownFormatException ; } $ new = ( array ) $ this + $ settings ; foreach ( $ new as $ key => $ value ) { $ this [ $ key ] = $ value ; } }
|
Private helper method to load a single config file .
|
57,734
|
private function getItemsAndGroupsPrice ( GroupsAndItemsContainerInterface $ groupsAndItemsContainer ) { $ price = 0 ; foreach ( $ groupsAndItemsContainer -> getItems ( ) as $ item ) { $ price += $ item -> getItemIncludingTaxTotalPrice ( ) ; } foreach ( $ groupsAndItemsContainer -> getGroups ( ) as $ groupOfItems ) { $ price += $ this -> getItemsAndGroupsPrice ( $ groupOfItems ) ; } return $ price ; }
|
Compute recursively the price for all the items and all the groups .
|
57,735
|
public function forget ( $ key ) { $ filename = $ this -> _hash ( array ( $ key ) ) ; return ( bool ) $ this -> _delete ( $ filename ) ; }
|
Delete a value by its key
|
57,736
|
public function exists ( $ filename , $ directory = null ) { $ cache_path = $ this -> config -> get ( 'cache_path' ) ; if ( is_null ( $ directory ) ) { $ path = $ cache_path . $ this -> config -> get ( 'object_dir' ) . $ filename . '.cache' ; } else { $ path = $ cache_path . $ directory . $ filename . '.cache' ; } return ( bool ) file_exists ( $ path ) ; }
|
Does a cache object exist?
|
57,737
|
private function _delete ( $ filename , $ directory = null ) { $ cache_path = $ this -> config -> get ( 'cache_path' ) ; if ( is_null ( $ directory ) ) { $ path = $ cache_path . $ this -> config -> get ( 'object_dir' ) . $ filename . '.cache' ; } else { $ path = $ cache_path . $ directory . $ filename . '.cache' ; } if ( ! file_exists ( $ path ) ) return true ; return ( bool ) unlink ( $ path ) ; }
|
Delete the cache file
|
57,738
|
private function _delete_dir ( $ path = '' ) { $ cache_path = $ this -> config -> get ( 'cache_path' ) ; if ( strpos ( $ path , $ cache_path ) === false ) return ; if ( is_file ( $ path ) ) { return ( bool ) unlink ( $ path ) ; } elseif ( is_dir ( $ path ) ) { $ scan = glob ( rtrim ( $ path , '/' ) . '/*' ) ; foreach ( $ scan as $ item ) { $ this -> _delete_dir ( $ item ) ; } return rmdir ( $ path ) ; } }
|
Delete the cache directory
|
57,739
|
public function CommentQuery ( $ FireEvent = TRUE , $ Join = TRUE ) { $ this -> SQL -> Select ( 'c.*' ) -> From ( 'Comment c' ) ; if ( $ Join ) { $ this -> SQL -> Select ( 'iu.Name' , '' , 'InsertName' ) -> Select ( 'iu.Photo' , '' , 'InsertPhoto' ) -> Select ( 'iu.Email' , '' , 'InsertEmail' ) -> Join ( 'User iu' , 'c.InsertUserID = iu.UserID' , 'left' ) -> Select ( 'uu.Name' , '' , 'UpdateName' ) -> Select ( 'uu.Photo' , '' , 'UpdatePhoto' ) -> Select ( 'uu.Email' , '' , 'UpdateEmail' ) -> Join ( 'User uu' , 'c.UpdateUserID = uu.UserID' , 'left' ) ; } if ( $ FireEvent ) $ this -> FireEvent ( 'AfterCommentQuery' ) ; }
|
Select the data for a single comment .
|
57,740
|
public function Get ( $ DiscussionID , $ Limit , $ Offset = 0 ) { $ this -> CommentQuery ( TRUE , FALSE ) ; $ this -> EventArguments [ 'DiscussionID' ] = & $ DiscussionID ; $ this -> EventArguments [ 'Limit' ] = & $ Limit ; $ this -> EventArguments [ 'Offset' ] = & $ Offset ; $ this -> FireEvent ( 'BeforeGet' ) ; $ Page = PageNumber ( $ Offset , $ Limit ) ; $ PageWhere = $ this -> PageWhere ( $ DiscussionID , $ Page , $ Limit ) ; if ( $ PageWhere ) { $ this -> SQL -> Where ( 'c.DiscussionID' , $ DiscussionID ) ; $ this -> SQL -> Where ( $ PageWhere ) -> Limit ( $ Limit + 10 ) ; $ this -> OrderBy ( $ this -> SQL ) ; } else { $ Sql2 = clone $ this -> SQL ; $ Sql2 -> Reset ( ) ; $ Sql2 -> Select ( 'CommentID' ) -> From ( 'Comment c' ) -> Where ( 'c.DiscussionID' , $ DiscussionID , TRUE , FALSE ) -> Limit ( $ Limit , $ Offset ) ; $ this -> OrderBy ( $ Sql2 ) ; $ Select = $ Sql2 -> GetSelect ( ) ; $ Px = $ this -> SQL -> Database -> DatabasePrefix ; $ this -> SQL -> Database -> DatabasePrefix = '' ; $ this -> SQL -> Join ( "($Select) c2" , "c.CommentID = c2.CommentID" ) ; $ this -> SQL -> Database -> DatabasePrefix = $ Px ; } $ this -> Where ( $ this -> SQL ) ; $ Result = $ this -> SQL -> Get ( ) ; Gdn :: UserModel ( ) -> JoinUsers ( $ Result , array ( 'InsertUserID' , 'UpdateUserID' ) ) ; $ this -> SetCalculatedFields ( $ Result ) ; $ this -> EventArguments [ 'Comments' ] = & $ Result ; $ this -> FireEvent ( 'AfterGet' ) ; $ this -> CachePageWhere ( $ Result -> Result ( ) , $ PageWhere , $ DiscussionID , $ Page , $ Limit ) ; return $ Result ; }
|
Get comments for a discussion .
|
57,741
|
public function GetByUser ( $ UserID , $ Limit , $ Offset = 0 ) { $ Perms = DiscussionModel :: CategoryPermissions ( ) ; $ this -> CommentQuery ( TRUE , FALSE ) ; $ this -> FireEvent ( 'BeforeGet' ) ; $ this -> SQL -> Select ( 'd.Name' , '' , 'DiscussionName' ) -> Join ( 'Discussion d' , 'c.DiscussionID = d.DiscussionID' ) -> Where ( 'c.InsertUserID' , $ UserID ) -> OrderBy ( 'c.CommentID' , 'desc' ) -> Limit ( $ Limit , $ Offset ) ; if ( $ Perms !== TRUE ) { $ this -> SQL -> Join ( 'Category ca' , 'd.CategoryID = ca.CategoryID' , 'left' ) -> WhereIn ( 'd.CategoryID' , $ Perms ) ; } $ Data = $ this -> SQL -> Get ( ) ; Gdn :: UserModel ( ) -> JoinUsers ( $ Data , array ( 'InsertUserID' , 'UpdateUserID' ) ) ; return $ Data ; }
|
Get comments for a user .
|
57,742
|
public function OrderBy ( $ Value = NULL ) { if ( $ Value === NULL ) return $ this -> _OrderBy ; if ( is_string ( $ Value ) ) $ Value = array ( $ Value ) ; if ( is_array ( $ Value ) ) { $ OrderBy = array ( ) ; foreach ( $ Value as $ Part ) { if ( StringEndsWith ( $ Part , ' desc' , TRUE ) ) $ OrderBy [ ] = array ( substr ( $ Part , 0 , - 5 ) , 'desc' ) ; elseif ( StringEndsWith ( $ Part , ' asc' , TRUE ) ) $ OrderBy [ ] = array ( substr ( $ Part , 0 , - 4 ) , 'asc' ) ; else $ OrderBy [ ] = array ( $ Part , 'asc' ) ; } $ this -> _OrderBy = $ OrderBy ; } elseif ( is_a ( $ Value , 'Gdn_SQLDriver' ) ) { foreach ( $ this -> _OrderBy as $ Parts ) { $ Value -> OrderBy ( $ Parts [ 0 ] , $ Parts [ 1 ] ) ; } } }
|
Set the order of the comments or return current order .
|
57,743
|
public function GetUserScore ( $ CommentID , $ UserID ) { $ Data = $ this -> SQL -> Select ( 'Score' ) -> From ( 'UserComment' ) -> Where ( 'CommentID' , $ CommentID ) -> Where ( 'UserID' , $ UserID ) -> Get ( ) -> FirstRow ( ) ; return $ Data ? $ Data -> Score : 0 ; }
|
Gets the UserComment Score value for the specified user .
|
57,744
|
public function SetWatch ( $ Discussion , $ Limit , $ Offset , $ TotalComments ) { $ NewComments = FALSE ; $ Session = Gdn :: Session ( ) ; if ( $ Session -> UserID > 0 ) { $ CountWatch = $ Limit * ( $ Offset + 1 ) ; if ( $ CountWatch > $ TotalComments ) $ CountWatch = $ TotalComments ; if ( is_numeric ( $ Discussion -> CountCommentWatch ) ) { if ( isset ( $ Discussion -> DateLastViewed ) ) $ NewComments |= Gdn_Format :: ToTimestamp ( $ Discussion -> DateLastComment ) > Gdn_Format :: ToTimestamp ( $ Discussion -> DateLastViewed ) ; if ( $ TotalComments > $ Discussion -> CountCommentWatch ) $ NewComments |= TRUE ; if ( $ NewComments ) { $ this -> SQL -> Put ( 'UserDiscussion' , array ( 'CountComments' => $ CountWatch , 'DateLastViewed' => Gdn_Format :: ToDateTime ( ) ) , array ( 'UserID' => $ Session -> UserID , 'DiscussionID' => $ Discussion -> DiscussionID ) ) ; } } else { $ ArchiveDate = C ( 'Vanilla.Archive.Date' , FALSE ) ; if ( ! $ ArchiveDate || ( Gdn_Format :: ToTimestamp ( $ Discussion -> DateLastComment ) > Gdn_Format :: ToTimestamp ( $ ArchiveDate ) ) ) { $ NewComments = TRUE ; $ this -> SQL -> Options ( 'Ignore' , TRUE ) ; $ this -> SQL -> Insert ( 'UserDiscussion' , array ( 'UserID' => $ Session -> UserID , 'DiscussionID' => $ Discussion -> DiscussionID , 'CountComments' => $ CountWatch , 'DateLastViewed' => Gdn_Format :: ToDateTime ( ) ) ) ; } } $ CategoryID = GetValue ( 'CategoryID' , $ Discussion ) ; if ( $ CategoryID ) { $ Category = CategoryModel :: Categories ( $ CategoryID ) ; if ( $ Category ) { $ DateMarkedRead = GetValue ( 'DateMarkedRead' , $ Category ) ; if ( $ DateMarkedRead ) { $ LookBackCount = C ( 'Vanilla.Discussions.PerPage' , 50 ) * 2 ; $ DiscussionModel = new DiscussionModel ( ) ; $ Discussions = $ DiscussionModel -> Get ( 0 , 101 , array ( 'CategoryID' => $ CategoryID , 'DateLastComment>' => $ DateMarkedRead ) ) ; unset ( $ DiscussionModel ) ; $ NumDiscussions = $ Discussions -> NumRows ( ) ; if ( $ NumDiscussions <= $ LookBackCount ) { $ MarkAsRead = TRUE ; while ( $ Discussion = $ Discussions -> NextRow ( DATASET_TYPE_ARRAY ) ) { if ( $ Discussion [ 'Read' ] ) continue ; $ MarkAsRead = FALSE ; break ; } if ( $ MarkAsRead ) { $ CategoryModel = new CategoryModel ( ) ; $ CategoryModel -> SaveUserTree ( $ CategoryID , array ( 'DateMarkedRead' => Gdn_Format :: ToDateTime ( ) ) ) ; unset ( $ CategoryModel ) ; } } } } } } }
|
Record the user s watch data .
|
57,745
|
public function GetCount ( $ DiscussionID ) { $ this -> FireEvent ( 'BeforeGetCount' ) ; if ( ! empty ( $ this -> _Where ) ) { return FALSE ; } return $ this -> SQL -> Select ( 'CommentID' , 'count' , 'CountComments' ) -> From ( 'Comment' ) -> Where ( 'DiscussionID' , $ DiscussionID ) -> Get ( ) -> FirstRow ( ) -> CountComments ; }
|
Count total comments in a discussion specified by ID .
|
57,746
|
public function GetID ( $ CommentID , $ ResultType = DATASET_TYPE_OBJECT ) { $ this -> CommentQuery ( FALSE ) ; $ Comment = $ this -> SQL -> Where ( 'c.CommentID' , $ CommentID ) -> Get ( ) -> FirstRow ( $ ResultType ) ; $ this -> Calculate ( $ Comment ) ; return $ Comment ; }
|
Get single comment by ID . Allows you to pick data format of return value .
|
57,747
|
public function GetIDData ( $ CommentID ) { $ this -> FireEvent ( 'BeforeGetIDData' ) ; $ this -> CommentQuery ( FALSE ) ; return $ this -> SQL -> Where ( 'c.CommentID' , $ CommentID ) -> Get ( ) ; }
|
Get single comment by ID as SQL result data .
|
57,748
|
public function GetNew ( $ DiscussionID , $ LastCommentID ) { $ this -> CommentQuery ( ) ; $ this -> FireEvent ( 'BeforeGetNew' ) ; $ this -> OrderBy ( $ this -> SQL ) ; $ Comments = $ this -> SQL -> Where ( 'c.DiscussionID' , $ DiscussionID ) -> Where ( 'c.CommentID >' , $ LastCommentID ) -> Get ( ) ; $ this -> SetCalculatedFields ( $ Comments ) ; return $ Comments ; }
|
Get comments in a discussion since the specified one .
|
57,749
|
public function GetOffset ( $ Comment ) { $ this -> FireEvent ( 'BeforeGetOffset' ) ; if ( is_numeric ( $ Comment ) ) { $ Comment = $ this -> GetID ( $ Comment ) ; } $ this -> SQL -> Select ( 'c.CommentID' , 'count' , 'CountComments' ) -> From ( 'Comment c' ) -> Where ( 'c.DiscussionID' , GetValue ( 'DiscussionID' , $ Comment ) ) ; $ this -> SQL -> BeginWhereGroup ( ) ; foreach ( $ this -> _OrderBy as $ Part ) { list ( $ Expr , $ Value ) = $ this -> _WhereFromOrderBy ( $ Part , $ Comment , '' ) ; if ( ! isset ( $ PrevWhere ) ) { $ this -> SQL -> Where ( $ Expr , $ Value ) ; } else { $ this -> SQL -> BeginWhereGroup ( ) ; $ this -> SQL -> OrWhere ( $ PrevWhere [ 0 ] , $ PrevWhere [ 1 ] ) ; $ this -> SQL -> Where ( $ Expr , $ Value ) ; $ this -> SQL -> EndWhereGroup ( ) ; } $ PrevWhere = $ this -> _WhereFromOrderBy ( $ Part , $ Comment , '==' ) ; } $ this -> SQL -> EndWhereGroup ( ) ; return $ this -> SQL -> Get ( ) -> FirstRow ( ) -> CountComments ; }
|
Gets the offset of the specified comment in its related discussion .
|
57,750
|
protected function _WhereFromOrderBy ( $ Part , $ Comment , $ Op = '' ) { if ( ! $ Op || $ Op == '=' ) $ Op = ( $ Part [ 1 ] == 'desc' ? '>' : '<' ) . $ Op ; elseif ( $ Op == '==' ) $ Op = '=' ; $ Expr = $ Part [ 0 ] . ' ' . $ Op ; if ( preg_match ( '/c\.(\w*\b)/' , $ Part [ 0 ] , $ Matches ) ) $ Field = $ Matches [ 1 ] ; else $ Field = $ Part [ 0 ] ; $ Value = GetValue ( $ Field , $ Comment ) ; if ( ! $ Value ) $ Value = 0 ; return array ( $ Expr , $ Value ) ; }
|
Builds Where statements for GetOffset method .
|
57,751
|
public function UpdateCommentCount ( $ Discussion ) { if ( is_numeric ( $ Discussion ) ) $ Discussion = $ this -> SQL -> GetWhere ( 'Discussion' , array ( 'DiscussionID' => $ Discussion ) ) -> FirstRow ( DATASET_TYPE_ARRAY ) ; $ DiscussionID = $ Discussion [ 'DiscussionID' ] ; $ this -> FireEvent ( 'BeforeUpdateCommentCountQuery' ) ; $ Data = $ this -> SQL -> Select ( 'c.CommentID' , 'min' , 'FirstCommentID' ) -> Select ( 'c.CommentID' , 'max' , 'LastCommentID' ) -> Select ( 'c.DateInserted' , 'max' , 'DateLastComment' ) -> Select ( 'c.CommentID' , 'count' , 'CountComments' ) -> From ( 'Comment c' ) -> Where ( 'c.DiscussionID' , $ DiscussionID ) -> Get ( ) -> FirstRow ( DATASET_TYPE_ARRAY ) ; $ this -> EventArguments [ 'Discussion' ] = & $ Discussion ; $ this -> EventArguments [ 'Counts' ] = & $ Data ; $ this -> FireEvent ( 'BeforeUpdateCommentCount' ) ; if ( $ Discussion ) { if ( $ Data ) { $ this -> SQL -> Update ( 'Discussion' ) ; if ( ! $ Discussion [ 'Sink' ] && $ Data [ 'DateLastComment' ] ) $ this -> SQL -> Set ( 'DateLastComment' , $ Data [ 'DateLastComment' ] ) ; elseif ( ! $ Data [ 'DateLastComment' ] ) $ this -> SQL -> Set ( 'DateLastComment' , $ Discussion [ 'DateInserted' ] ) ; $ this -> SQL -> Set ( 'FirstCommentID' , $ Data [ 'FirstCommentID' ] ) -> Set ( 'LastCommentID' , $ Data [ 'LastCommentID' ] ) -> Set ( 'CountComments' , $ Data [ 'CountComments' ] ) -> Where ( 'DiscussionID' , $ DiscussionID ) -> Put ( ) ; $ this -> SQL -> Update ( 'Discussion d' ) -> Update ( 'Comment c' ) -> Set ( 'd.LastCommentUserID' , 'c.InsertUserID' , FALSE ) -> Where ( 'd.DiscussionID' , $ DiscussionID ) -> Where ( 'c.CommentID' , 'd.LastCommentID' , FALSE , FALSE ) -> Put ( ) ; } else { $ this -> SQL -> Update ( 'Discussion' ) -> Set ( 'CountComments' , 0 ) -> Set ( 'FirstCommentID' , NULL ) -> Set ( 'LastCommentID' , NULL ) -> Set ( 'DateLastComment' , 'DateInserted' , FALSE , FALSE ) -> Set ( 'LastCommentUserID' , NULL ) -> Where ( 'DiscussionID' , $ DiscussionID ) ; } } }
|
Updates the CountComments value on the discussion based on the CommentID being saved .
|
57,752
|
public function UpdateUserCommentCounts ( $ DiscussionID ) { $ Sql = "update " . $ this -> Database -> DatabasePrefix . "UserDiscussion ud set CountComments = ( select count(c.CommentID)+1 from " . $ this -> Database -> DatabasePrefix . "Comment c where c.DateInserted < ud.DateLastViewed ) where DiscussionID = $DiscussionID" ; $ this -> SQL -> Query ( $ Sql ) ; }
|
Update UserDiscussion so users don t have incorrect counts .
|
57,753
|
public function UpdateUser ( $ UserID , $ Inc = FALSE ) { if ( $ Inc ) { $ this -> SQL -> Update ( 'User' ) -> Set ( 'CountComments' , 'CountComments + 1' , FALSE ) -> Where ( 'UserID' , $ UserID ) -> Put ( ) ; } else { $ CountComments = $ this -> SQL -> Select ( 'c.CommentID' , 'count' , 'CountComments' ) -> From ( 'Comment c' ) -> Where ( 'c.InsertUserID' , $ UserID ) -> Get ( ) -> FirstRow ( ) -> CountComments ; Gdn :: UserModel ( ) -> SetField ( $ UserID , 'CountComments' , $ CountComments ) ; } }
|
Update user s total comment count .
|
57,754
|
public function SetCalculatedFields ( & $ Data ) { $ Result = & $ Data -> Result ( ) ; foreach ( $ Result as & $ Comment ) { $ this -> Calculate ( $ Comment ) ; } }
|
Modifies comment data before it is returned .
|
57,755
|
public static function register ( $ config ) { if ( $ config [ 'send_errors' ] ) { unset ( $ config [ 'send_errors' ] ) ; $ logger = new self ( TDebugger :: $ logDirectory ) ; $ logger -> email = & TDebugger :: $ email ; TDebugger :: setLogger ( $ logger ) ; \ Errbit :: instance ( ) -> configure ( $ config ) ; } }
|
Register logger to \ Tracy \ Debugger
|
57,756
|
public function log ( $ message , $ priority = null ) { foreach ( self :: $ ignoredMessages as $ ignoredMessage ) { if ( strpos ( $ message [ 1 ] , $ ignoredMessage ) !== false ) { return true ; } } $ response = parent :: log ( $ message , $ priority ) ; if ( in_array ( $ priority , self :: $ priorities ) ) { if ( $ message instanceof \ Exception ) { \ Errbit :: instance ( ) -> notify ( $ message ) ; } else { \ Errbit :: instance ( ) -> notify ( new \ Exception ( $ priority . ' ' . $ message ) ) ; } } return $ response ; }
|
Wrapper for log function
|
57,757
|
protected function render ( $ template , $ parameters ) { $ twig = new \ Twig_Environment ( new \ Twig_Loader_Filesystem ( $ this -> getSkeletonDir ( ) ) , array ( 'debug' => true , 'cache' => false , 'strict_variables' => true , 'autoescape' => false , ) ) ; $ twig -> addExtension ( new VinceTBaseExtension ( ) ) ; return $ twig -> render ( $ template , $ parameters ) ; }
|
render a twig template .
|
57,758
|
protected function renderFile ( $ template , $ target , $ parameters ) { if ( is_file ( $ target ) ) { return sprintf ( '<comment>%s already exists</comment>' , $ this -> getRelativeFilePath ( $ target ) ) ; } if ( ! is_dir ( dirname ( $ target ) ) ) { mkdir ( dirname ( $ target ) , 0777 , true ) ; } if ( file_put_contents ( $ target , $ this -> render ( $ template , $ parameters ) ) !== false ) { return sprintf ( '<info>Create %s</info>' , $ this -> getRelativeFilePath ( $ target ) ) ; } return null ; }
|
render a file .
|
57,759
|
public static function arrayToJson ( $ array = false , $ pretty = false ) { if ( $ array && Validate :: isArray ( $ array ) ) { if ( $ pretty === true ) { return json_encode ( $ array , JSON_PRETTY_PRINT ) ; } return json_encode ( $ array ) ; } return false ; }
|
Format array into json .
|
57,760
|
public static function jsonToArray ( $ json = false ) { if ( $ json && Validate :: isJson ( $ json ) ) { $ object = json_decode ( $ json ) ; return self :: objectToArray ( $ object ) ; } return false ; }
|
Format json into array .
|
57,761
|
public static function stringToArray ( $ string = false , $ delimiter = ' ' , $ limit = false ) { if ( $ string && Validate :: isString ( $ string ) ) { if ( $ limit ) { return explode ( $ delimiter , $ string , $ limit ) ; } return explode ( $ delimiter , $ string ) ; } return false ; }
|
Format string into array .
|
57,762
|
public static function toBoolean ( $ input = false ) { if ( $ input ) { $ boolean = ( bool ) $ input ; if ( Validate :: isBoolean ( $ boolean ) ) { return $ boolean ; } } return false ; }
|
Format anything into boolean .
|
57,763
|
public static function toFloat ( $ input = false ) { if ( $ input && Validate :: isNumber ( $ input ) ) { $ float = ( float ) $ input ; if ( Validate :: isFloat ( $ float ) ) { return $ float ; } } return false ; }
|
Format anything into float .
|
57,764
|
public static function toInteger ( $ input = false ) { if ( $ input && Validate :: isNumber ( $ input ) ) { $ integer = ( int ) $ input ; if ( Validate :: isInteger ( $ integer ) ) { return $ integer ; } } return false ; }
|
Format anything into integer .
|
57,765
|
public static function toJson ( $ input = false , $ pretty = false ) { if ( $ input ) { switch ( Data :: type ( $ input ) ) { case 'array' : $ json = self :: arrayToJson ( $ input , $ pretty ) ; break ; case 'object' : $ json = self :: objectToJson ( $ input , $ pretty ) ; break ; default : $ json = false ; break ; } if ( Validate :: isJson ( $ json ) ) { return $ json ; } } return false ; }
|
Format anything into json .
|
57,766
|
public static function toString ( $ input = false ) { if ( $ input ) { $ string = ( string ) $ input ; if ( Validate :: isString ( $ string ) ) { return $ string ; } } return false ; }
|
Format anything into string .
|
57,767
|
public static function objectToArray ( $ object = false ) { if ( $ object && Validate :: isObject ( $ object ) ) { return self :: objectToArrayRecursive ( $ object ) ; } return false ; }
|
Format object into array .
|
57,768
|
private static function objectToArrayRecursive ( $ object ) { if ( is_object ( $ object ) ) $ object = ( array ) $ object ; if ( is_array ( $ object ) ) { $ new = array ( ) ; foreach ( $ object as $ key => $ val ) { $ new [ $ key ] = self :: objectToArrayRecursive ( $ val ) ; } } else $ new = $ object ; return $ new ; }
|
Format object into array recursively .
|
57,769
|
public static function arrayToObject ( $ array = false ) { if ( $ array && Validate :: isArray ( $ array ) ) { $ object = new \ stdClass ( ) ; foreach ( $ array as $ key => $ value ) { $ object -> $ key = $ value ; } return $ object ; } return false ; }
|
Format array into object .
|
57,770
|
public static function objectToJson ( $ object = false , $ pretty = false ) { if ( $ object && Validate :: isObject ( $ object ) ) { $ array = self :: objectToArray ( $ object ) ; return self :: arrayToJson ( $ array , $ pretty ) ; } return false ; }
|
Format object into json .
|
57,771
|
public static function toObject ( $ input = false ) { if ( $ input ) { switch ( Data :: type ( $ input ) ) { case 'array' : $ object = self :: arrayToObject ( $ input ) ; break ; case 'object' : $ object = $ input ; break ; } if ( Validate :: isObject ( $ object ) ) { return $ object ; } } return false ; }
|
Format anything into object .
|
57,772
|
public static function toArray ( $ input = false ) { if ( $ input ) { switch ( Data :: type ( $ input ) ) { case 'array' : $ array = $ input ; break ; case 'object' : $ array = self :: arrayToObject ( $ input ) ; break ; } if ( Validate :: isObject ( $ input ) ) { return $ input ; } } return false ; }
|
Format anything into array .
|
57,773
|
public function xmlToArray ( $ input = false ) { if ( $ input && Validate :: isString ( $ input ) ) { return simplexml_load_string ( $ string ) ; } return false ; }
|
Format XML string into array
|
57,774
|
public function getRelations ( ) { $ bag = $ this -> getParameter ( 'relations' ) ; if ( ! ( $ bag instanceof Bag ) ) { $ bag = new Bag ( ) ; } $ this -> setParameter ( 'relations' , $ bag ) ; return $ bag ; }
|
Get document relations
|
57,775
|
public function addRelation ( $ parameters ) { $ bag = $ this -> getParameter ( 'relations' ) ; if ( ! ( $ bag instanceof Bag ) ) { $ bag = new Bag ( ) ; } $ bag -> add ( new Relation ( $ parameters ) ) ; return $ this -> setParameter ( 'relations' , $ bag ) ; }
|
Add document relation
|
57,776
|
public function setRelations ( $ value ) { if ( is_array ( $ value ) ) { $ bag = new Bag ( ) ; foreach ( $ value as $ itemParameters ) { $ bag -> add ( new Relation ( $ itemParameters ) ) ; } $ value = $ bag ; } return $ this -> setParameter ( 'relations' , $ value ) ; }
|
Set invoice relations
|
57,777
|
public function addTemplatesFolder ( $ name , $ path ) { if ( is_dir ( $ path ) ) { $ this -> templateEngine -> addFolder ( $ name , $ path ) ; } }
|
Add templates folder
|
57,778
|
public static function numberBetween ( $ val , $ min , $ max , $ opt = 'II' ) { switch ( $ opt ) { case 'EE' : return ( $ val > $ min && $ val < $ max ) ; break ; case 'EI' : return ( $ val > $ min && $ val <= $ max ) ; break ; case 'IE' : return ( $ val >= $ min && $ val < $ max ) ; break ; case 'II' : default : return ( $ val >= $ min && $ val <= $ max ) ; } }
|
Compares if a value is between a minimum and maximum value .
|
57,779
|
public static function numberLimit ( $ val , $ min , $ max ) { return ( $ val > $ min ? ( $ val < $ max ? $ val : $ max ) : $ min ) ; }
|
Limits a value to a minimum and maximum boundaries .
|
57,780
|
public static function numberWrap ( $ val , $ min , $ max ) { while ( ! self :: numberBetween ( $ val , $ min , $ max ) ) { if ( $ val < $ min ) { $ val += $ max - $ min + 1 ; } elseif ( $ val > $ max ) { $ val -= $ max - $ min + 1 ; } } return $ val ; }
|
Limits a value to a minimum and maximum boundaries wrapping the overflow .
|
57,781
|
protected static function arrayCallUserFuncEachFirst ( callable $ callback , ... $ arrays ) { $ diffs = [ ] ; foreach ( $ arrays as $ key => $ array ) { $ others = $ arrays ; unset ( $ others [ $ key ] ) ; $ diffs [ ] = call_user_func ( $ callback , $ array , ... $ others ) ; } return array_merge ( ... $ diffs ) ; }
|
Runs a callback in a set of arrays
|
57,782
|
public static function arrayPathGet ( array & $ array , $ path , $ glue = '.' ) { if ( ! is_array ( $ path ) ) { $ path = explode ( $ glue , $ path ) ; } $ ref = & $ array ; foreach ( ( array ) $ path as $ parent ) { if ( is_array ( $ ref ) && array_key_exists ( $ parent , $ ref ) ) { $ ref = & $ ref [ $ parent ] ; } else { return null ; } } return $ ref ; }
|
Gets the value from a nested array following a list of keys
|
57,783
|
public static function arrayPathSet ( array & $ array , $ path , $ value , $ glue = '.' ) { if ( ! is_array ( $ path ) ) { $ path = explode ( $ glue , ( string ) $ path ) ; } $ ref = & $ array ; foreach ( $ path as $ parent ) { if ( isset ( $ ref ) && ! is_array ( $ ref ) ) { $ ref = array ( ) ; } $ ref = & $ ref [ $ parent ] ; } $ ref = $ value ; }
|
Sets the value in a nested array following a list of keys
|
57,784
|
public static function arrayPathUnset ( & $ array , $ path , $ glue = '.' ) { if ( ! is_array ( $ path ) ) { $ path = explode ( $ glue , $ path ) ; } $ key = array_shift ( $ path ) ; if ( empty ( $ path ) ) { unset ( $ array [ $ key ] ) ; } else { self :: arrayPathUnset ( $ array [ $ key ] , $ path ) ; } }
|
Unsets a key value from a nested array following a list of keys
|
57,785
|
public static function recInArray ( $ needle , $ haystack , $ strict = false ) { foreach ( $ haystack as $ item ) { if ( ( $ strict ? $ item === $ needle : $ item == $ needle ) || ( is_array ( $ item ) && self :: recInArray ( $ needle , $ item , $ strict ) ) ) { return true ; } } return false ; }
|
Recursively searches an array for a value .
|
57,786
|
public static function recKsort ( & $ arr , $ flag = SORT_REGULAR ) { if ( ! is_array ( $ arr ) ) { return false ; } ksort ( $ arr , $ flag ) ; foreach ( $ arr as & $ arr1 ) { self :: recKsort ( $ arr1 , $ flag ) ; } return true ; }
|
Recursively sorts the keys of an array .
|
57,787
|
public static function recScandir ( $ directory ) { $ arr = [ ] ; foreach ( scandir ( $ directory ) as $ f ) { if ( $ f == '.' || $ f == '..' ) { continue ; } elseif ( is_dir ( $ directory . '/' . $ f ) ) { $ arr [ $ f ] = self :: recScandir ( $ directory . '/' . $ f ) ; } else { $ arr [ $ f ] = 'file' ; } } return $ arr ; }
|
Recursively lists files and directories inside the specific path .
|
57,788
|
public static function checkOutput ( string $ type = null ) { $ message = "Some data has already been output, can't send " . ( $ type == '' ? 'data' : "$type file" ) ; if ( PHP_SAPI != 'cli' && headers_sent ( $ file , $ line ) ) { throw new \ Exception ( $ message . " (output started at $file:$line)" ) ; } if ( ob_get_length ( ) ) { if ( preg_match ( '/^(\xEF\xBB\xBF)?\s*$/' , ob_get_contents ( ) ) ) { ob_clean ( ) ; } else { throw new \ Exception ( $ message ) ; } } }
|
Checks if data has already been output
|
57,789
|
public static function getBrowserName ( ) { $ user_agent = $ _SERVER [ 'HTTP_USER_AGENT' ] ; if ( strpos ( $ user_agent , 'Opera' ) || strpos ( $ user_agent , 'OPR/' ) ) { return 'Opera' ; } elseif ( strpos ( $ user_agent , 'Edge' ) ) { return 'Edge' ; } elseif ( strpos ( $ user_agent , 'Chrome' ) ) { return 'Chrome' ; } elseif ( strpos ( $ user_agent , 'Safari' ) ) { return 'Safari' ; } elseif ( strpos ( $ user_agent , 'Firefox' ) ) { return 'Firefox' ; } elseif ( strpos ( $ user_agent , 'MSIE' ) || strpos ( $ user_agent , 'Trident/7' ) ) { return 'Internet Explorer' ; } return 'Other' ; }
|
Finds the Browser name inside the user agent .
|
57,790
|
public function appendConfiguration ( ArrayNodeDefinition $ rootNode ) { $ rootNode -> children ( ) -> arrayNode ( 'messages' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> arrayNode ( 'languages' ) -> performNoDeepMerging ( ) -> prototype ( 'scalar' ) -> end ( ) -> defaultValue ( array ( 'nl' , 'en' , 'fr' ) ) -> end ( ) -> booleanNode ( 'overwrite_compatibility' ) -> defaultTrue ( ) -> end ( ) -> scalarNode ( 'yaz_cleanup' ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; }
|
Appends messages configuration options
|
57,791
|
public function define ( $ key , $ value ) { if ( $ this -> isProtected ( $ key ) ) { throw new \ UnexpectedValueException ( "Cannot re-assing protected '$key' item" ) ; } parent :: set ( $ key , $ value ) ; $ this -> protect ( $ key ) ; return $ this ; }
|
Defines a protected value for data
|
57,792
|
public function set ( $ key , $ value ) { if ( $ this -> isProtected ( $ key ) ) { throw new \ UnexpectedValueException ( "Cannot set value in protected '$key' item" ) ; } return parent :: set ( $ key , $ value ) ; }
|
Overwrites delete method . Check if procteded are added
|
57,793
|
public function merge ( array $ items , $ recursive = false ) { foreach ( $ items as $ key => $ value ) { $ this -> set ( $ key , $ value ) ; } return $ this ; }
|
Overwrites merge method . Check if procteded are added
|
57,794
|
protected function checkForProtected ( array $ data ) { foreach ( array_keys ( $ data ) as $ key ) { if ( $ this -> isProtected ( $ key ) ) { throw new \ UnexpectedValueException ( "Cannot set value in protected '$key' index" ) ; } } }
|
Verify if data is protected . If true Exception is throwed
|
57,795
|
public function suggest ( $ title , $ subtitles ) { if ( count ( $ subtitles ) == 1 ) { return 1 ; } $ hdTags = array ( 'HD' , '720p' , '1080p' ) ; $ hd = false ; foreach ( $ hdTags as $ hdTag ) { if ( stripos ( $ title , $ hdTag ) ) { $ hd = true ; } } $ weights = array ( ) ; foreach ( $ subtitles as $ subtitle ) { $ weight = $ subtitle -> hd === true ? 1 : 0 ; $ matches = $ this -> versionMatch ( $ title , $ subtitle -> version ) ; if ( $ matches ) { $ weight += $ matches * 2 ; } $ weights [ $ subtitle -> id ] = $ weight ; } arsort ( $ weights ) ; return key ( $ weights ) ; }
|
Suggest the best subtitle for the file
|
57,796
|
public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( SkillTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ gossi \ trixionary \ model \ Skill ) { $ criteria = $ values -> buildPkeyCriteria ( ) ; } else { $ criteria = new Criteria ( SkillTableMap :: DATABASE_NAME ) ; $ criteria -> add ( SkillTableMap :: COL_ID , ( array ) $ values , Criteria :: IN ) ; } $ query = SkillQuery :: create ( ) -> mergeWith ( $ criteria ) ; if ( $ values instanceof Criteria ) { SkillTableMap :: clearInstancePool ( ) ; } elseif ( ! is_object ( $ values ) ) { foreach ( ( array ) $ values as $ singleval ) { SkillTableMap :: removeInstanceFromPool ( $ singleval ) ; } } return $ query -> delete ( $ con ) ; }
|
Performs a DELETE on the database given a Skill or Criteria object OR a primary key value .
|
57,797
|
protected function processRules ( ) { $ this -> cache = ! YII_DEBUG ; $ this -> rules = $ this -> cache ? Yii :: app ( ) -> cache -> get ( 'CiiMS::Routes' ) : array ( ) ; if ( $ this -> rules == false || empty ( $ this -> rules ) ) { $ this -> rules = array ( ) ; $ this -> rules = $ this -> generateClientRules ( ) ; $ this -> rules = CMap :: mergearray ( $ this -> addRssRules ( ) , $ this -> rules ) ; $ this -> rules = CMap :: mergeArray ( $ this -> addModuleRules ( ) , $ this -> rules ) ; Yii :: app ( ) -> cache -> set ( 'CiiMS::Routes' , $ this -> rules ) ; } $ this -> rules [ '<controller:\w+>/<action:\w+>/<id:\d+>' ] = '<controller>/<action>' ; $ this -> rules [ '<controller:\w+>/<action:\w+>' ] = '<controller>/<action>' ; return parent :: processRules ( ) ; }
|
Overrides processRules allowing us to inject our own ruleset into the URL Manager Takes no parameters
|
57,798
|
private function addRSSRules ( ) { $ categories = Categories :: model ( ) -> findAll ( ) ; foreach ( $ categories as $ category ) $ routes [ $ category -> slug . '.rss' ] = "categories/rss/id/{$category->id}" ; $ routes [ 'blog.rss' ] = '/categories/rss' ; return $ routes ; }
|
Generates RSS rules for categories
|
57,799
|
private function generateClientRules ( ) { $ theme ; $ themeName = Cii :: getConfig ( 'theme' , 'default' ) ; if ( file_exists ( Yii :: getPathOfAlias ( 'base.themes.' ) . DS . $ themeName . DS . 'Theme.php' ) ) { Yii :: import ( 'base.themes.' . $ themeName . '.Theme' ) ; $ theme = new Theme ; } $ rules = CMap :: mergeArray ( $ this -> defaultRules , $ this -> rules ) ; if ( $ theme -> noRouting !== false ) return $ this -> routeAllRulesToRoot ( ) ; else return CMap :: mergeArray ( $ rules , $ this -> generateRules ( ) ) ; }
|
Generates client rules depending on if we want to handle rendering client side or server side
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.