idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
500 | public function visitExpressionNode ( ExpressionNode $ node ) { $ leftValue = $ node -> getLeft ( ) -> accept ( $ this ) ; $ operator = $ node -> getOperator ( ) ; if ( ! $ operator ) return "$leftValue" ; $ right = $ node -> getRight ( ) ; if ( $ right ) { $ rightValue = $ node -> getRight ( ) -> accept ( $ this ) ; r... | Print an ExpressionNode . |
501 | public function visitFunctionNode ( FunctionNode $ node ) { $ functionName = $ node -> getName ( ) ; $ operand = $ node -> getOperand ( ) -> accept ( $ this ) ; return "$functionName($operand)" ; } | Print a FunctionNode . |
502 | public function parse ( array $ tokens ) { $ tokens = $ this -> filterTokens ( $ tokens ) ; if ( static :: allowImplicitMultiplication ( ) ) { $ tokens = $ this -> parseImplicitMultiplication ( $ tokens ) ; } $ this -> tokens = $ tokens ; return $ this -> shuntingYard ( $ tokens ) ; } | Parse list of tokens |
503 | private function shuntingYard ( array $ tokens ) { $ this -> operatorStack = new Stack ( ) ; $ this -> operandStack = new Stack ( ) ; $ lastNode = null ; for ( $ index = 0 ; $ index < count ( $ tokens ) ; $ index ++ ) { $ token = $ tokens [ $ index ] ; if ( $ this -> rationalFactory ) { $ node = Node :: rationalFactory... | Implementation of the shunting yard parsing algorithm |
504 | protected function handleExpression ( $ node ) { if ( $ node instanceof FunctionNode ) throw new ParenthesisMismatchException ( $ node -> getOperator ( ) ) ; if ( $ node instanceof SubExpressionNode ) throw new ParenthesisMismatchException ( $ node -> getOperator ( ) ) ; if ( ! $ this -> simplifyingParser ) return $ th... | Populate node with operands . |
505 | protected function naiveHandleExpression ( $ node ) { if ( $ node -> getOperator ( ) == '~' ) { $ left = $ this -> operandStack -> pop ( ) ; if ( $ left === null ) { throw new SyntaxErrorException ( ) ; } $ node -> setOperator ( '-' ) ; $ node -> setLeft ( $ left ) ; return $ node ; } $ right = $ this -> operandStack -... | Populate node with operands without any simplification . |
506 | protected function filterTokens ( array $ tokens ) { $ filteredTokens = array_filter ( $ tokens , function ( Token $ t ) { return $ t -> getType ( ) !== TokenType :: Whitespace ; } ) ; return array_values ( $ filteredTokens ) ; } | Remove Whitespace from the token list . |
507 | protected function handleSubExpression ( ) { $ clean = false ; while ( $ popped = $ this -> operatorStack -> pop ( ) ) { if ( $ popped instanceof SubExpressionNode ) { $ clean = true ; break ; } $ node = $ this -> handleExpression ( $ popped ) ; $ this -> operandStack -> push ( $ node ) ; } if ( ! $ clean ) { throw new... | Handle a closing parenthesis popping operators off the operator stack until we find a matching opening parenthesis . |
508 | private function numericExponent ( $ leftOperand , $ rightOperand ) { if ( $ this -> isNumeric ( $ leftOperand ) && $ this -> isNumeric ( $ rightOperand ) ) { if ( $ leftOperand -> getValue ( ) == 0 && $ rightOperand -> getValue ( ) == 0 ) throw new DivisionByZeroException ( ) ; } if ( $ rightOperand -> getValue ( ) ==... | Simplify an expression x^y when y is numeric . |
509 | public static function rationalFactory ( Token $ token ) { switch ( $ token -> getType ( ) ) { case TokenType :: PosInt : case TokenType :: Integer : $ x = intval ( $ token -> getValue ( ) ) ; return new IntegerNode ( $ x ) ; case TokenType :: RealNumber : $ x = floatval ( str_replace ( ',' , '.' , $ token -> getValue ... | Node factory creating an appropriate Node from a Token . |
510 | public function complexity ( ) { if ( $ this instanceof IntegerNode || $ this instanceof VariableNode || $ this instanceof ConstantNode ) { return 1 ; } elseif ( $ this instanceof RationalNode || $ this instanceof NumberNode ) { return 2 ; } elseif ( $ this instanceof FunctionNode ) { return 5 + $ this -> getOperand ( ... | Rough estimate of the complexity of the AST . |
511 | public function isTerminal ( ) { if ( $ this instanceof NumberNode ) { return true ; } if ( $ this instanceof IntegerNode ) { return true ; } if ( $ this instanceof RationalNode ) { return true ; } if ( $ this instanceof VariableNode ) { return true ; } if ( $ this instanceof ConstantNode ) { return true ; } return fal... | Returns true if the node is a terminal node i . e . a NumerNode VariableNode or ConstantNode . |
512 | public function match ( $ input ) { $ result = preg_match ( $ this -> pattern , $ input , $ matches , PREG_OFFSET_CAPTURE ) ; if ( $ result === false ) throw new \ Exception ( preg_last_error ( ) ) ; if ( $ result === 0 ) return null ; return $ this -> getTokenFromMatch ( $ matches [ 0 ] ) ; } | Try to match the given input to the current TokenDefinition . |
513 | private function getTokenFromMatch ( $ match ) { $ value = $ match [ 0 ] ; $ offset = $ match [ 1 ] ; if ( $ offset !== 0 ) return null ; if ( $ this -> value ) $ value = $ this -> value ; return new Token ( $ value , $ this -> tokenType , $ match [ 0 ] ) ; } | Convert matching string to an actual Token . |
514 | public function parse ( $ text ) { $ this -> tokens = $ this -> lexer -> tokenize ( $ text ) ; $ this -> tree = $ this -> parser -> parse ( $ this -> tokens ) ; return $ this -> tree ; } | Parse the given mathematical expression into an abstract syntax tree . |
515 | public function makeNode ( $ leftOperand , $ rightOperand ) { if ( $ rightOperand === null ) return $ this -> createUnaryMinusNode ( $ leftOperand ) ; $ leftOperand = $ this -> sanitize ( $ leftOperand ) ; $ rightOperand = $ this -> sanitize ( $ rightOperand ) ; $ node = $ this -> numericTerms ( $ leftOperand , $ right... | Create a Node representing leftOperand - rightOperand |
516 | public function visitExpressionNode ( ExpressionNode $ node ) { $ operator = $ node -> getOperator ( ) ; $ left = $ node -> getLeft ( ) ; $ right = $ node -> getRight ( ) ; switch ( $ operator ) { case '+' : $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return ... | Generate LaTeX code for an ExpressionNode |
517 | private function MultiplicationNeedsCdot ( $ left , $ right ) { if ( $ left instanceof FunctionNode ) { return true ; } if ( $ this -> isNumeric ( $ right ) ) { return true ; } if ( $ right instanceof ExpressionNode && $ this -> isNumeric ( $ right -> getLeft ( ) ) ) { return true ; } return false ; } | Check if a multiplication needs an inserted \ cdot or if it can be safely written with implicit multiplication . |
518 | private function visitFactorialNode ( FunctionNode $ node ) { $ functionName = $ node -> getName ( ) ; $ op = $ node -> getOperand ( ) ; $ operand = $ op -> accept ( $ this ) ; if ( $ this -> isNumeric ( $ op ) ) { if ( $ op -> getValue ( ) < 0 ) { $ operand = "($operand)" ; } } elseif ( $ op instanceof VariableNode ||... | Generate LaTeX code for factorials |
519 | public function visitFunctionNode ( FunctionNode $ node ) { $ functionName = $ node -> getName ( ) ; $ operand = $ node -> getOperand ( ) -> accept ( $ this ) ; switch ( $ functionName ) { case 'sqrt' : return "\\$functionName{" . $ node -> getOperand ( ) -> accept ( $ this ) . '}' ; case 'exp' : $ operand = $ node -> ... | Generate LaTeX code for a FunctionNode |
520 | public function visitExpressionNode ( ExpressionNode $ node ) { $ operator = $ node -> getOperator ( ) ; $ left = $ node -> getLeft ( ) ; $ right = $ node -> getRight ( ) ; switch ( $ operator ) { case '+' : $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return ... | Generate ASCII output code for an ExpressionNode |
521 | public static function canFactorsInImplicitMultiplication ( $ token1 , $ token2 ) { if ( $ token1 === null || $ token2 === null ) return false ; $ check1 = ( $ token1 -> type == TokenType :: PosInt || $ token1 -> type == TokenType :: Integer || $ token1 -> type == TokenType :: RealNumber || $ token1 -> type == TokenTyp... | Helper function determining whether a pair of tokens can form an implicit multiplication . |
522 | private function normalize ( ) { $ gcd = Math :: gcd ( $ this -> p , $ this -> q ) ; if ( $ gcd == 0 ) throw new DivisionByZeroException ( ) ; $ this -> p = $ this -> p / $ gcd ; $ this -> q = $ this -> q / $ gcd ; if ( $ this -> q < 0 ) { $ this -> p = - $ this -> p ; $ this -> q = - $ this -> q ; } } | Normalize i . e . make sure the denominator is positive and that the numerator and denominator have no common factors |
523 | public function signed ( ) { if ( $ this -> q == 1 ) { return sprintf ( "%+d" , $ this -> p ) ; } return sprintf ( "%+d/%d" , $ this -> p , $ this -> q ) ; } | convert rational number to string adding a + if the number is positive |
524 | public function is_nan ( ) { if ( $ this -> q == 0 ) return true ; return is_nan ( $ this -> p ) || is_nan ( $ this -> q ) ; } | test if the rational number is NAN |
525 | public static function fromFloat ( $ float , $ tolerance = 1e-7 ) { if ( is_string ( $ float ) && preg_match ( '~^\-?\d+([,|.]\d+)?$~' , $ float ) ) { $ float = floatval ( str_replace ( ',' , '.' , $ float ) ) ; } if ( $ float == 0.0 ) { return new Rational ( 0 , 1 ) ; } $ negative = ( $ float < 0 ) ; if ( $ negative )... | convert float to Rational |
526 | public function makeNode ( $ leftOperand , $ rightOperand ) { $ leftOperand = $ this -> sanitize ( $ leftOperand ) ; $ rightOperand = $ this -> sanitize ( $ rightOperand ) ; $ node = $ this -> numericTerms ( $ leftOperand , $ rightOperand ) ; if ( $ node ) return $ node ; return new ExpressionNode ( $ leftOperand , '+'... | Create a Node representing leftOperand + rightOperand |
527 | public function fileAction ( $ objectId , $ fileId ) { if ( empty ( $ objectId ) || empty ( $ fileId ) ) { return $ this -> accessDenied ( ) ; } $ contactClient = $ this -> checkContactClientAccess ( $ objectId , 'view' ) ; if ( $ contactClient instanceof Response ) { return $ contactClient ; } $ file = $ this -> check... | Downloads a file securely . |
528 | public function addEvent ( array $ data ) { if ( $ this -> countOnly ) { if ( $ this -> groupUnit && $ this -> chartQuery ) { $ countData = [ [ 'date' => $ data [ 'timestamp' ] , 'count' => 1 , ] , ] ; $ count = $ this -> chartQuery -> completeTimeData ( $ countData ) ; $ this -> addToCounter ( $ data [ 'event' ] , $ c... | Add an event to the container . |
529 | public function addToCounter ( $ eventType , $ count ) { if ( ! isset ( $ this -> totalEvents [ $ eventType ] ) ) { $ this -> totalEvents [ $ eventType ] = 0 ; } if ( is_array ( $ count ) ) { if ( isset ( $ count [ 'total' ] ) ) { $ this -> totalEvents [ $ eventType ] += $ count [ 'total' ] ; } elseif ( $ this -> isEng... | Add to the event counters . |
530 | public function getEvents ( ) { if ( empty ( $ this -> events ) ) { return [ ] ; } $ events = call_user_func_array ( 'array_merge' , $ this -> events ) ; foreach ( $ events as & $ e ) { if ( ! $ e [ 'timestamp' ] instanceof \ DateTime ) { $ dt = new DateTimeHelper ( $ e [ 'timestamp' ] , 'Y-m-d H:i:s' , 'UTC' ) ; $ e [... | Fetch the events . |
531 | public function getEventCounter ( ) { foreach ( $ this -> events as $ type => $ events ) { if ( ! isset ( $ this -> totalEvents [ $ type ] ) ) { $ this -> totalEvents [ $ type ] = count ( $ events ) ; } } $ counter = [ 'total' => array_sum ( $ this -> totalEvents ) , ] ; if ( $ this -> countOnly && $ this -> groupUnit ... | Get total number of events for pagination . |
532 | public function setCountOnly ( \ DateTime $ dateFrom , \ DateTime $ dateTo , $ groupUnit = '' , ChartQuery $ chartQuery = null ) { $ this -> countOnly = true ; $ this -> dateFrom = $ dateFrom ; $ this -> dateTo = $ dateTo ; $ this -> groupUnit = $ groupUnit ; $ this -> chartQuery = $ chartQuery ; } | Calculate engagement counts only . |
533 | public function addSerializerGroup ( $ group ) { if ( is_array ( $ group ) ) { $ this -> serializerGroups = array_merge ( $ this -> serializerGroups , $ group ) ; } else { $ this -> serializerGroups [ $ group ] = $ group ; } } | Add a serializer group for API formatting . |
534 | public function getTokens ( $ string ) { $ tokens = [ ] ; $ scanResults = $ this -> engine -> getTokenizer ( ) -> scan ( $ string ) ; foreach ( $ scanResults as $ scanResult ) { if ( isset ( $ scanResult [ 'type' ] ) && isset ( $ scanResult [ 'name' ] ) && \ Mustache_Tokenizer :: T_ESCAPED === $ scanResult [ 'type' ] )... | Scan a string for tokens using the same engine . |
535 | public function getFormats ( ) { return [ 'date' => $ this -> getDateFormatHelper ( ) -> getFormatsDate ( ) , 'datetime' => $ this -> getDateFormatHelper ( ) -> getFormatsDateTime ( ) , 'time' => $ this -> getDateFormatHelper ( ) -> getFormatsTime ( ) , 'number' => $ this -> formatNumber , 'boolean' => $ this -> format... | Outputs an array of formats by field type for the front - end tokenization . |
536 | private function findPivotDataTokens ( $ string ) { if ( ! $ this -> needsDeviceData && 1 === preg_match ( '/{{\s?device\..*\s?}}/' , $ string ) ) { $ this -> needsDeviceData = true ; } if ( ! $ this -> needsUtmData && 1 === preg_match ( '/{{\s?utm\..*\s?}}/' , $ string ) ) { $ this -> needsUtmData = true ; } if ( ! $ ... | Check for the need for device data to keep queries low later . |
537 | public function addContextEvent ( $ event = [ ] ) { $ contactId = isset ( $ this -> context [ 'id' ] ) ? $ this -> context [ 'id' ] : 0 ; $ this -> context [ 'event' ] [ 'id' ] = ! empty ( $ event [ 'id' ] ) ? ( int ) $ event [ 'id' ] : null ; $ this -> context [ 'event' ] [ 'name' ] = ! empty ( $ event [ 'name' ] ) ? ... | Take an event array and use it to enhance the context for later dispositional callback . Campaign context should be added before this as it is used for the token . |
538 | private function eventTokenEncode ( $ values ) { list ( $ campaignId , $ eventId , $ contactId ) = $ values ; $ campaignIdString = $ this -> baseEncode ( ( int ) $ campaignId ) ; $ eventIdString = $ this -> baseEncode ( ( int ) $ eventId ) ; $ contactIdString = $ this -> baseEncode ( ( int ) $ contactId ) ; return $ ca... | Encode Campaign ID Event ID and Contact ID into a short base62 string . Zeros are used as delimiters reducing the subsequent integers to base61 . |
539 | public function render ( $ template = '' ) { $ result = $ template ; if ( is_array ( $ template ) || is_object ( $ template ) ) { foreach ( $ result as & $ val ) { $ val = $ this -> render ( $ val ) ; } } elseif ( is_string ( $ template ) && strlen ( $ template ) >= self :: TEMPLATE_MIN_LENGTH && false !== strpos ( $ t... | Replace Tokens in a simple string using an array for context . |
540 | public function getContextLabeled ( $ sort = true ) { $ result = [ ] ; $ labels = $ this -> describe ( $ this -> context ) ; $ this -> flattenArray ( $ labels , $ result ) ; $ result [ 'file_count' ] = 'File: Number of contacts in this file' ; $ result [ 'file_test' ] = 'File: Inserts ".test" if testing' ; $ result [ '... | Get the context array labels instead of values for use in token suggestions . |
541 | private function describe ( $ array = [ ] , $ keys = '' , $ sort = true , $ payload = false ) { foreach ( $ array as $ key => & $ value ) { if ( is_array ( $ value ) ) { if ( 0 === count ( $ value ) ) { unset ( $ array [ $ key ] ) ; continue ; } else { $ value = $ this -> describe ( $ value , $ keys . ' ' . $ key , $ s... | Given a token array set the values to the labels for the context if possible . |
542 | private function handleMustacheErrors ( $ errno , $ errstr , $ errfile , $ errline ) { if ( ! empty ( $ this -> lastTemplate ) ) { if ( function_exists ( 'newrelic_add_custom_parameter' ) ) { call_user_func ( 'newrelic_add_custom_parameter' , 'contactclientToken' , $ this -> lastTemplate ) ; } } if ( ! empty ( $ this -... | Capture Mustache warnings to be logged for debugging . |
543 | private function eventTokenDecode ( $ string ) { list ( $ campaignIdString , $ eventIdString , $ contactIdString ) = explode ( '0' , $ string ) ; return [ $ this -> baseDecode ( $ campaignIdString ) , $ this -> baseDecode ( $ eventIdString ) , $ this -> baseDecode ( $ contactIdString ) , ] ; } | Take a string from eventTokenEncode and reverse it to an array . |
544 | private function parse ( $ date , $ timezone = null ) { if ( ! ( $ date instanceof \ DateTime ) ) { if ( false === strtotime ( $ date ) ) { throw new \ Exception ( 'Invalid date not parsed.' ) ; } if ( ! $ timezone ) { $ timezone = $ this -> timezoneSource ; } $ date = new \ DateTime ( $ date , new \ DateTimeZone ( $ t... | Parse a string into a DateTime . |
545 | private function setSettings ( $ settings ) { if ( $ settings ) { foreach ( $ this -> settings as $ key => & $ value ) { if ( ! empty ( $ settings -> { $ key } ) && $ settings -> { $ key } ) { $ value = $ settings -> { $ key } ; } } } } | Retrieve API settings from the payload to override our defaults . |
546 | public function evaluateSchedule ( ) { $ this -> scheduleModel -> reset ( ) -> setContactClient ( $ this -> contactClient ) -> setTimezone ( ) -> evaluateDay ( ) -> evaluateTime ( ) -> evaluateExclusions ( ) ; return new \ DateTime ( ) ; } | Returns the expected send time for limit evaluation . Throws an exception if an open slot is not available . |
547 | public function run ( ) { $ this -> validateOperations ( ) ; $ this -> prepareTransport ( ) ; $ this -> prepareTokenHelper ( ) ; $ this -> preparePayloadAuth ( ) ; try { $ this -> runApiOperations ( ) ; } catch ( \ Exception $ e ) { if ( $ this -> start && $ e instanceof ContactClientException && Stat :: TYPE_AUTH === ... | Step through all operations defined . |
548 | private function prepareTokenHelper ( ) { $ this -> tokenHelper -> newSession ( $ this -> contactClient , $ this -> contact , $ this -> payload , $ this -> campaign , $ this -> event ) ; $ this -> tokenHelper -> addContext ( [ 'api_date' => $ this -> tokenHelper -> getDateFormatHelper ( ) -> format ( new \ DateTime ( )... | Apply our context to create a new tokenhelper session . |
549 | private function preparePayloadAuth ( ) { $ this -> apiPayloadAuth -> reset ( ) -> setTest ( $ this -> test ) -> setContactClient ( $ this -> contactClient ) -> setOperations ( $ this -> payload -> operations ) ; $ this -> start = $ this -> apiPayloadAuth -> getStartOperation ( ) ; if ( $ this -> start ) { $ context = ... | Prepare the APIPayloadAuth model and get the starting operation ID it reccomends . |
550 | private function savePayloadAuthTokens ( $ operationId ) { if ( $ this -> valid && $ this -> apiPayloadAuth -> hasAuthRequest ( $ operationId ) ) { $ fieldSets = $ this -> getAggregateActualResponses ( null , $ operationId ) ; $ this -> apiPayloadAuth -> savePayloadAuthTokens ( $ operationId , $ fieldSets ) ; } } | If we just made a successful run with an auth operation without skipping said operation preserve the applicable auth tokens for future use . |
551 | public function getAggregateActualResponses ( $ key = null , $ operationId = null , $ types = [ 'headers' , 'body' ] ) { if ( $ this -> valid && isset ( $ this -> aggregateActualResponses ) ) { if ( null !== $ key ) { foreach ( $ types as $ type ) { if ( null !== $ operationId ) { if ( isset ( $ this -> aggregateActual... | Get the most recent non - empty response value by field name ignoring validity . Provide key or operationId or both . |
552 | public function applyResponseMap ( $ updateTokens = false ) { $ responseMap = $ this -> getResponseMap ( ) ; if ( count ( $ responseMap ) ) { foreach ( $ responseMap as $ alias => $ value ) { $ oldValue = $ this -> contact -> getFieldValue ( $ alias ) ; if ( $ oldValue !== $ value ) { $ this -> contact -> addUpdatedFie... | Apply the responsemap to update a contact entity . |
553 | private function updatePayload ( ) { if ( $ this -> contactClient ) { $ this -> sortPayloadFields ( ) ; $ jsonHelper = new JSONHelper ( ) ; $ payloadJSON = $ jsonHelper -> encode ( $ this -> payload , 'Payload' ) ; $ this -> contactClient -> setAPIPayload ( $ payloadJSON ) ; } } | Update the payload with the parent ContactClient because we ve updated the response expectation . |
554 | private function sortPayloadFields ( ) { if ( isset ( $ this -> payload -> operations ) ) { foreach ( $ this -> payload -> operations as $ id => $ operation ) { foreach ( [ 'request' , 'response' ] as $ opType ) { if ( isset ( $ operation -> { $ opType } ) ) { foreach ( [ 'headers' , 'body' ] as $ fieldType ) { if ( is... | Sort the fields by keys so that the user doesn t have to . Only applies when AutoUpdate is enabled . |
555 | private function decodeJSON ( $ json ) { $ query = json_decode ( $ json ) ; if ( json_last_error ( ) ) { throw new \ Exception ( 'JSON parsing threw an error: ' . json_last_error_msg ( ) ) ; } if ( ! is_object ( $ query ) ) { throw new \ Exception ( 'The query is not valid JSON' ) ; } return $ query ; } | Decode the given JSON . |
556 | protected function checkRuleCorrect ( $ rule ) { if ( ! isset ( $ rule -> value ) ) { $ rule -> value = null ; } if ( ! isset ( $ rule -> id , $ rule -> field , $ rule -> type , $ rule -> input , $ rule -> operator ) ) { return false ; } if ( ! isset ( $ this -> operators [ $ rule -> operator ] ) ) { return false ; } r... | Check if a given rule is correct . Just before making a query for a rule we want to make sure that the field operator and value are set . |
557 | protected function enforceArrayOrString ( $ requireArray , $ value , $ field ) { $ this -> checkFieldIsAnArray ( $ requireArray , $ value , $ field ) ; if ( ! $ requireArray && is_array ( $ value ) ) { return $ this -> convertArrayToFlatValue ( $ field , $ value ) ; } return $ value ; } | Enforce whether the value for a given field is the correct type . |
558 | protected function isNested ( $ rule ) { if ( isset ( $ rule -> rules ) && is_array ( $ rule -> rules ) && count ( $ rule -> rules ) > 0 ) { return true ; } return false ; } | Determine if we have nested rules to evaluate . |
559 | public function oldestDateAdded ( $ duration , string $ timezone = null , \ DateTime $ dateSend = null ) { if ( ! $ timezone ) { $ timezone = date_default_timezone_get ( ) ; } if ( is_string ( $ timezone ) ) { $ timezone = new \ DateTimeZone ( $ timezone ) ; } if ( $ dateSend ) { $ oldest = clone $ dateSend ; $ oldest ... | Support non - rolling durations when P is not prefixing . |
560 | private function bitwiseIn ( $ max , $ matching ) { $ result = [ ] ; for ( $ i = 1 ; $ i <= $ max ; ++ $ i ) { if ( $ i & $ matching ) { $ result [ ] = $ i ; } } return $ result ; } | Given bitwise operators and the value we want to match against generate a minimal array for an IN query . |
561 | private function addExpiration ( & $ filters = [ ] , \ DateTime $ dateSend = null ) { if ( $ filters ) { $ expiration = $ dateSend ? $ dateSend : new \ DateTime ( ) ; $ expiration = $ expiration -> getTimestamp ( ) ; foreach ( $ filters as & $ filter ) { $ filter [ 'exclusive_expire_date' ] = $ expiration ; } } } | Add Exclusion Expiration date . |
562 | public function reduceExclusivityIndex ( ) { $ q = $ this -> getEntityManager ( ) -> getConnection ( ) -> createQueryBuilder ( ) ; $ q -> update ( MAUTIC_TABLE_PREFIX . $ this -> getTableName ( ) ) ; $ q -> where ( $ q -> expr ( ) -> isNotNull ( 'exclusive_expire_date' ) , $ q -> expr ( ) -> lte ( 'exclusive_expire_dat... | Update exclusivity rows to reduce the index size and thus reduce processing required to check exclusivity . |
563 | public function getEntities ( array $ args = [ ] ) { $ alias = $ this -> getTableAlias ( ) ; $ q = $ this -> _em -> createQueryBuilder ( ) -> select ( $ alias ) -> from ( 'MauticContactClientBundle:ContactClient' , $ alias , $ alias . '.id' ) ; if ( empty ( $ args [ 'iterator_mode' ] ) ) { $ q -> leftJoin ( $ alias . '... | Get a list of entities . |
564 | public function getStats ( $ contactClientId , $ type , $ fromDate = null , $ toDate = null ) { $ q = $ this -> createQueryBuilder ( 's' ) ; $ expr = $ q -> expr ( ) -> andX ( $ q -> expr ( ) -> eq ( 'IDENTITY(s.contactclient)' , ( int ) $ contactClientId ) , $ q -> expr ( ) -> eq ( 's.type' , ':type' ) ) ; if ( $ from... | Fetch the base stat data from the database . |
565 | protected function checkContactClientAccess ( $ contactClientId , $ action , $ isPlugin = false , $ integration = '' ) { if ( ! $ contactClientId instanceof ContactClient ) { $ contactClientModel = $ this -> getModel ( 'contactClient' ) ; $ contactClient = $ contactClientModel -> getEntity ( ( int ) $ contactClientId )... | Determines if the user has access to the contactClient . |
566 | protected function checkContactClientFileAccess ( $ fileId , $ action , $ isPlugin = false , $ integration = '' ) { if ( ! $ fileId instanceof File ) { $ fileRepository = $ this -> getDoctrine ( ) -> getEntityManager ( ) -> getRepository ( 'MauticContactClientBundle:File' ) ; $ file = $ fileRepository -> getEntity ( ( ... | Determines if the user has access to a File . |
567 | protected function checkAllAccess ( $ action , $ limit ) { $ model = $ this -> getModel ( 'contactClient' ) ; $ repo = $ model -> getRepository ( ) ; $ contactClients = $ repo -> getEntities ( [ 'filter' => [ ] , 'oderBy' => 'r.last_active' , 'orderByDir' => 'DESC' , 'limit' => $ limit , 'hydration_mode' => 'HYDRATE_AR... | Returns contactClients the user has access to . |
568 | protected function getUpdateSelectParams ( $ updateSelect , $ entity , $ nameMethod = 'getName' , $ groupMethod = 'getLanguage' ) { $ options = [ 'updateSelect' => $ updateSelect , 'id' => $ entity -> getId ( ) , 'name' => $ entity -> $ nameMethod ( ) , ] ; return $ options ; } | Return array of options update select response . |
569 | public function getStartOperation ( ) { $ id = 0 ; if ( $ this -> hasAuthRequest ( ) ) { foreach ( $ this -> operations as $ id => $ operation ) { if ( $ id == count ( $ this -> operations ) - 1 ) { break ; } if ( ! $ this -> hasAuthRequest ( $ id ) ) { break ; } if ( $ this -> operationUpdatesContact ( $ operation ) )... | Step forward through operations to find the one we MUST start with . |
570 | private function determineOperationRequirements ( ) { if ( null === $ this -> requiredPayloadTokens ) { $ this -> requiredPayloadTokens = [ ] ; $ valueSources = [ 'value' , 'default_value' ] ; if ( $ this -> test ) { $ valueSources = [ 'test_value' , 'value' , 'default_value' ] ; } foreach ( $ this -> operations as $ i... | Discern the tokens that are required by operation ID . |
571 | private function loadPreviousPayloadAuthTokens ( ) { if ( ! $ this -> previousPayloadAuthTokens ) { $ this -> previousPayloadAuthTokens = $ this -> getAuthRepository ( ) -> getPreviousPayloadAuthTokensByContactClient ( $ this -> contactClient -> getId ( ) , null , $ this -> test ) ; } } | Load up the previously stored payload tokens . |
572 | public function addEvent ( ContactClient $ contactClient = null , $ type = null , Contact $ contact = null , $ logs = null , $ message = null , $ integrationEntityId = null ) { $ event = new EventEntity ( ) ; $ event -> setDateAdded ( new \ DateTime ( ) ) ; if ( $ type ) { $ event -> setType ( $ type ) ; } if ( $ conta... | Add transactional log in contactclient_events . |
573 | public function limitQueryToCreator ( QueryBuilder $ q ) { $ q -> join ( 't' , MAUTIC_TABLE_PREFIX . 'contactclient' , 'm' , 'e.id = t.contactclient_id' ) -> andWhere ( 'm.created_by = :userId' ) -> setParameter ( 'userId' , $ this -> userHelper -> getUser ( ) -> getId ( ) ) ; } | Joins the email table and limits created_by to currently logged in user . |
574 | public function run ( ) { if ( empty ( $ this -> request ) ) { $ this -> setLogs ( 'Skipping empty operation: ' . $ this -> name , 'notice' ) ; return true ; } $ this -> setLogs ( $ this -> name , 'name' ) ; $ this -> setLogs ( ( $ this -> test ? 'TEST' : 'PROD' ) , 'mode' ) ; $ apiRequest = new ApiRequest ( $ this -> ... | Run this single API Operation . |
575 | public function getResponseMap ( ) { $ mappedFields = [ ] ; foreach ( [ 'headers' , 'body' ] as $ type ) { if ( isset ( $ this -> responseExpected -> { $ type } ) && isset ( $ this -> responseActual [ $ type ] ) ) { foreach ( $ this -> responseExpected -> { $ type } as $ value ) { if ( ! empty ( $ value -> destination ... | Get filled responses that have Contact destinations defined . |
576 | public function getExternalId ( ) { $ externalIds = array_flip ( $ this -> externalIds ) ; $ id = null ; $ idIndex = null ; foreach ( [ 'headers' , 'body' ] as $ type ) { if ( isset ( $ this -> responseActual [ $ type ] ) && isset ( $ this -> responseActual [ $ type ] ) ) { foreach ( $ this -> responseActual [ $ type ]... | Given the response fields attempt to assume an external ID for future correlation . Find the best possible fit . |
577 | public function findOpening ( $ startDay = 0 , $ endDay = 7 , $ fileRate = 1 , $ all = false , $ startTime = null ) { $ openings = [ ] ; for ( $ day = $ startDay ; $ day <= $ endDay ; ++ $ day ) { if ( 0 === $ day ) { if ( $ startTime && $ startTime instanceof \ DateTime ) { $ date = clone $ startTime ; } else { $ date... | Given the hours of operation timezone and excluded dates of the client ... Find the next appropriate time to send them contacts . |
578 | public function setTimezone ( \ DateTimeZone $ timezone = null ) { if ( ! $ timezone ) { $ timezone = $ this -> contactClient -> getScheduleTimezone ( ) ; if ( ! $ timezone ) { $ timezone = $ this -> coreParametersHelper -> getParameter ( 'default_timezone' ) ; $ timezone = ! empty ( $ timezone ) ? $ timezone : date_de... | Set Client timezone defaulting to Mautic or System as is relevant . |
579 | public function create ( ) { $ entities = [ ] ; $ exclusive = $ this -> getExclusiveRules ( ) ; if ( count ( $ exclusive ) ) { foreach ( $ exclusive as $ rule ) { if ( ! isset ( $ entity ) ) { $ entity = $ this -> createEntity ( ) ; } else { $ entity = clone $ entity ; } $ expireDate = $ this -> getRepository ( ) -> ol... | Create all necessary cache entities for the given Contact and Contact Client . |
580 | public function getExclusiveRules ( ) { $ jsonHelper = new JSONHelper ( ) ; $ exclusive = $ jsonHelper -> decodeObject ( $ this -> contactClient -> getExclusive ( ) , 'Exclusive' ) ; $ this -> excludeIrrelevantRules ( $ exclusive ) ; return $ this -> mergeRules ( $ exclusive ) ; } | Given the Contact and Contact Client discern which exclusivity entries need to be cached . |
581 | public function evaluateExclusive ( ) { if ( ! $ this -> contactClient -> getExclusiveIgnore ( ) ) { $ exclusive = $ this -> getRepository ( ) -> findExclusive ( $ this -> contact , $ this -> contactClient , $ this -> dateSend ) ; if ( $ exclusive ) { throw new ContactClientException ( 'Skipping exclusive Contact.' , C... | Given a contact evaluate exclusivity rules of all cache entries against it . |
582 | public function getLimitRules ( ) { $ jsonHelper = new JSONHelper ( ) ; $ limits = $ jsonHelper -> decodeObject ( $ this -> contactClient -> getLimits ( ) , 'Limits' ) ; $ this -> excludeIrrelevantRules ( $ limits ) ; return $ this -> mergeRules ( $ limits , false ) ; } | Given the Contact and Contact Client get the rules used to evaluate limits . |
583 | public function setAttribution ( $ attribution ) { if ( $ this -> queue ) { $ this -> queue -> setAttribution ( $ attribution ) ; $ this -> getQueueRepository ( ) -> saveEntity ( $ this -> queue ) ; } } | Append the current queue entity with attribution . |
584 | public function reset ( $ exclusions = [ 'contactClientModel' , 'tokenHelper' , 'em' , 'formModel' , 'eventModel' , 'contactModel' , 'pathsHelper' , 'coreParametersHelper' , 'filesystemLocal' , 'mailHelper' , 'scheduleModel' , 'utmSourceHelper' , ] ) { foreach ( array_diff_key ( get_class_vars ( get_class ( $ this ) ) ... | Reset local class variables . |
585 | private function setSettings ( $ settings ) { if ( $ settings ) { foreach ( $ this -> settings as $ key => & $ value ) { if ( ! empty ( $ settings -> { $ key } ) && $ settings -> { $ key } ) { if ( is_object ( $ settings -> { $ key } ) ) { $ value = array_merge ( $ value , json_decode ( json_encode ( $ settings -> { $ ... | Retrieve File settings from the payload to override our defaults . |
586 | public function run ( $ step = 'add' ) { $ this -> setLogs ( $ step , 'step' ) ; switch ( $ step ) { case 'add' : $ this -> getFieldValues ( ) ; $ this -> fileEntitySelect ( true ) ; $ this -> fileEntityRefreshSettings ( ) ; $ this -> addContactToQueue ( ) ; break ; case 'build' : if ( $ this -> test ) { $ this -> getF... | These steps can occur in different sessions . |
587 | private function fileEntityRefreshSettings ( ) { if ( $ this -> file ) { if ( ! empty ( $ this -> settings [ 'name' ] ) && ! $ this -> file -> getLocation ( ) ) { $ this -> file -> setName ( $ this -> settings [ 'name' ] ) ; } if ( ! empty ( $ this -> settings [ 'type' ] ) ) { if ( ! empty ( $ this -> settings [ 'type'... | Update fields on the file entity based on latest data . |
588 | public function evaluateSchedule ( $ prepFile = false ) { if ( ! $ this -> scheduleStart && ! $ this -> test ) { $ rate = max ( 1 , ( int ) $ this -> settings [ 'rate' ] ) ; $ endDay = 30 ; $ this -> scheduleModel -> reset ( ) -> setContactClient ( $ this -> contactClient ) -> setTimezone ( ) ; $ openings = $ this -> s... | Assuming we have a file entity ready to go Throws an exception if an open slot is not available . |
589 | private function fileGenerateTmp ( $ compression = null ) { $ fileTmp = null ; $ compression = 'none' == $ compression ? null : $ compression ; while ( true ) { $ fileTmpName = uniqid ( $ this -> getFileName ( $ compression ) , true ) ; $ fileTmp = sys_get_temp_dir ( ) . '/' . $ fileTmpName ; if ( ! file_exists ( $ fil... | Generates a temporary path for file generation . |
590 | private function getFileName ( $ compression = null ) { $ compression = 'none' == $ compression ? null : $ compression ; $ this -> tokenHelper -> newSession ( $ this -> contactClient , $ this -> contact , $ this -> payload , $ this -> campaign , $ this -> event ) ; $ type = $ this -> file -> getType ( ) ; $ type = str_... | Discern the desired output file name for a new file . |
591 | private function fileEntitySave ( ) { if ( ! $ this -> file ) { return ; } if ( $ this -> file -> isNew ( ) || $ this -> file -> getChanges ( ) ) { if ( $ this -> contactClient -> getId ( ) ) { $ this -> formModel -> saveEntity ( $ this -> file , true ) ; } } } | Save any file changes using the form model . |
592 | private function fileCompress ( ) { if ( $ this -> file && $ this -> file -> getTmp ( ) ) { $ compression = $ this -> file -> getCompression ( ) ; if ( $ compression && in_array ( $ compression , [ 'tar.gz' , 'tar.bz2' , 'zip' ] ) ) { $ target = $ this -> fileGenerateTmp ( $ compression ) ; $ fileName = $ this -> getFi... | Perform compression on the temp file . |
593 | private function fileMove ( $ overwrite = true ) { if ( ! $ this -> file -> getLocation ( ) || $ overwrite ) { $ origin = $ this -> file -> getTmp ( ) ; $ uploadDir = realpath ( $ this -> coreParametersHelper -> getParameter ( 'upload_dir' ) ) ; $ fileName = $ this -> getFileName ( $ this -> file -> getCompression ( ) ... | Moves the file out of temp and locks the hashes . |
594 | private function operationSftp ( $ operation ) { $ config = $ this -> operationFtpConfig ( $ operation ) ; $ adapter = new SftpAdapter ( $ config ) ; $ filesystem = new Filesystem ( $ adapter ) ; $ written = false ; if ( $ stream = fopen ( $ this -> file -> getLocation ( ) , 'r+' ) ) { $ this -> setLogs ( $ this -> fil... | Upload the current client file by sFTP . |
595 | public function getExternalId ( ) { if ( $ this -> file && $ this -> file -> getCrc32 ( ) ) { return $ this -> file -> getName ( ) . ' (' . $ this -> file -> getCrc32 ( ) . ')' ; } return null ; } | Since there is no external ID when sending files we ll include the file name and CRC check at creation . |
596 | public function pushLead ( $ contact , $ event = [ ] ) { $ this -> reset ( ) ; $ this -> getEvent ( $ event ) ; if ( empty ( $ this -> event [ 'config' ] [ 'contactclient' ] ) ) { return false ; } $ clientModel = $ this -> getContactClientModel ( ) ; $ client = $ clientModel -> getEntity ( $ this -> event [ 'config' ] ... | Push a contact to a preconfigured Contact Client . |
597 | public function getEvent ( $ event = [ ] ) { if ( ! $ this -> event ) { $ this -> event = $ event ; if ( isset ( $ event [ 'config' ] ) && ( empty ( $ event [ 'integration' ] ) || ( ! empty ( $ event [ 'integration' ] ) && $ event [ 'integration' ] == $ this -> getName ( ) ) ) ) { $ this -> event [ 'config' ] = array_m... | Merges a config from integration_list with feature settings . |
598 | private function getPayloadModel ( ContactClient $ contactClient = null ) { if ( ! $ this -> payloadModel || $ contactClient ) { $ contactClient = $ contactClient ? $ contactClient : $ this -> contactClient ; $ clientType = $ contactClient -> getType ( ) ; if ( 'api' == $ clientType ) { $ model = $ this -> getApiPayloa... | Get the current Payload model or the model of a particular client . |
599 | private function evaluateDnc ( ) { if ( $ this -> test ) { return $ this ; } $ channels = explode ( ',' , $ this -> contactClient -> getDncChecks ( ) ) ; if ( $ channels ) { foreach ( $ channels as $ channel ) { $ dncRepo = $ this -> getDncRepo ( ) ; $ dncRepo -> setDispatcher ( $ this -> dispatcher ) ; $ dncEntries = ... | Evaluates the DNC entries for the Contact against the Client settings . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.