idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
7,100
public function setCreditCard ( $ type , $ number , $ expireMonth , $ expireYear , $ cvv , $ firstname , $ lastname ) { $ this -> creditCard = new CreditCard ( ) ; $ this -> creditCard -> setType ( $ type ) -> setNumber ( $ number ) -> setExpireMonth ( $ expireMonth ) -> setExpireYear ( $ expireYear ) -> setCvv2 ( $ cv...
Sets credit card for usage .
7,101
private function getPatternType ( $ cardNumber ) { if ( empty ( $ cardNumber ) ) return ; $ types = [ 'visa' => '(4\d{12}(?:\d{3})?)' , 'amex' => '(3[47]\d{13})' , 'jcb' => '(35[2-8][89]\d\d\d{10})' , 'maestro' => '((?:5020|5038|6304|6579|6761)\d{12}(?:\d\d)?)' , 'solo' => '((?:6334|6767)\d{12}(?:\d\d)?\d?)' , 'masterc...
Returns the credit card type based on a credit card number pattern .
7,102
public function createOrReverse ( Model \ InStore \ Refund $ refund , Model \ InStore \ Reversal $ refundReversal = null , HandlerStack $ stack = null ) { try { return $ this -> create ( $ refund , $ stack ) ; } catch ( ApiException $ refundException ) { if ( $ refundException -> getErrorResponse ( ) -> getErrorCode ( ...
Helper method to automatically attempt to reverse a refund if an error occurs .
7,103
private function setTopicName ( string $ topicFilter ) : self { $ this -> generalRulesCheck ( $ topicFilter ) ; $ this -> topicFilter = $ topicFilter ; return $ this ; }
Will validate and set the topic filter
7,104
public function storeConfiguration ( Configuration $ targetConfiguration , PackageSet $ requiredPackages , Configuration $ newConfiguration ) { $ key = $ this -> getKey ( $ targetConfiguration , $ requiredPackages ) ; $ this -> configurations [ $ key ] = $ newConfiguration ; }
Stores the Composer newConfiguration that resulted from requiring the given set of requiredPackages .
7,105
public function isActive ( ) : bool { if ( ! isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return false ; } $ currentUrl = esc_url_raw ( wp_unslash ( $ _SERVER [ 'REQUEST_URI' ] ) ) ; $ matchUrl = str_replace ( esc_url_raw ( get_site_url ( ) ) , '' , esc_url_raw ( $ this -> getUrl ( ) ) ) ; return 0 === strpos ( $ currentU...
Whether this tab is active i . e . current screen is on this tab .
7,106
public function add ( AdminTab ... $ adminTabs ) { $ this -> adminTabs = array_unique ( array_merge ( $ this -> adminTabs , $ adminTabs ) , SORT_REGULAR ) ; }
Add admin tabs .
7,107
public static function sentence ( $ string ) { $ pieces = explode ( ' ' , $ string ) ; if ( ! preg_match ( '@^[[:upper:]]+$@' , $ pieces [ 0 ] ) ) { $ pieces [ 0 ] = lcfirst ( $ pieces [ 0 ] ) ; } return new StringAssembler ( $ pieces ) ; }
Takes a sentence case string .
7,108
public function productFormAction ( ) { $ userLocale = $ this -> getUser ( ) -> getLocale ( ) ; $ status = $ this -> getStatus ( $ userLocale ) ; $ units = $ this -> getUnits ( $ userLocale ) ; $ deliveryStates = $ this -> getDeliveryStates ( $ userLocale ) ; return $ this -> render ( 'SuluProductBundle:Template:produc...
Returns template for product list .
7,109
public function attributeFormAction ( ) { $ repository = $ this -> getDoctrine ( ) -> getRepository ( 'SuluProductBundle:AttributeType' ) ; $ types = $ repository -> findAll ( ) ; $ attributeTypes = [ ] ; foreach ( $ types as $ type ) { $ attributeTypes [ ] = [ 'id' => $ type -> getId ( ) , 'name' => $ type -> getName ...
Returns template for attribute list .
7,110
public function productPricingAction ( ) { $ userLocale = $ this -> getUser ( ) -> getLocale ( ) ; $ taxClasses = $ this -> get ( 'sulu_product.tax_class_manager' ) -> findAll ( $ userLocale ) ; $ taxClassTitles = [ ] ; foreach ( $ taxClasses as $ taxClass ) { $ taxClassTitles [ ] = [ 'id' => $ taxClass -> getId ( ) , ...
Returns template for product pricing .
7,111
protected function getStatus ( $ locale ) { $ statuses = $ this -> get ( 'sulu_product.status_manager' ) -> findAll ( $ locale ) ; $ statusTitles = [ ] ; foreach ( $ statuses as $ status ) { $ statusTitles [ ] = [ 'id' => $ status -> getId ( ) , 'name' => $ status -> getName ( ) , ] ; } return $ statusTitles ; }
Returns status for products .
7,112
protected function getUnits ( $ locale ) { $ units = $ this -> get ( 'sulu_product.unit_manager' ) -> findAll ( $ locale ) ; $ unitTitles = [ ] ; foreach ( $ units as $ unit ) { $ unitTitles [ ] = [ 'id' => $ unit -> getId ( ) , 'name' => $ unit -> getName ( ) , ] ; } return $ unitTitles ; }
Returns units .
7,113
protected function getCurrencies ( $ locale ) { $ currencies = $ this -> get ( 'sulu_product.currency_manager' ) -> findAll ( $ locale ) ; $ currencyTitles = [ ] ; foreach ( $ currencies as $ currency ) { $ currencyTitles [ ] = [ 'id' => $ currency -> getId ( ) , 'name' => $ currency -> getName ( ) , 'code' => $ curren...
Returns currencies .
7,114
protected function getCategoryUrl ( ) { $ rootKey = $ this -> container -> getParameter ( 'sulu_product.category_root_key' ) ; if ( null !== $ rootKey ) { return $ this -> generateUrl ( 'get_category_children' , [ 'key' => $ rootKey , 'flat' => 'true' , 'sortBy' => 'depth' , 'sortOrder' => 'asc' ] ) ; } return $ this -...
Returns url for fetching categories .
7,115
protected function getDeliveryStates ( $ locale ) { $ states = $ this -> getDeliveryStatusManager ( ) -> findAll ( $ locale ) ; $ deliveryStates = [ ] ; foreach ( $ states as $ state ) { $ deliveryStates [ ] = [ 'id' => $ state -> getId ( ) , 'name' => $ state -> getName ( ) , ] ; } return $ deliveryStates ; }
Returns delivery states .
7,116
public function getTranslation ( $ locale ) { $ translation = null ; if ( count ( $ this -> translations ) > 0 ) { $ translation = $ this -> translations [ 0 ] ; } foreach ( $ this -> translations as $ translationData ) { if ( $ translationData -> getLocale ( ) == $ locale ) { $ translation = $ translationData ; break ...
Returns the translation for the given locale .
7,117
public function deleteAction ( $ productId , $ attributeId ) { $ this -> getVariantAttributeManager ( ) -> removeVariantAttributeRelation ( $ productId , $ attributeId ) ; $ this -> getDoctrine ( ) -> getEntityManager ( ) -> flush ( ) ; $ view = $ this -> view ( null , Response :: HTTP_NO_CONTENT ) ; return $ this -> h...
Deletes attribute from variant .
7,118
private function createVariableHeaderFlags ( ) : string { if ( $ this -> isRedelivery ) { $ this -> specialFlags |= 8 ; $ this -> logger -> debug ( 'Activating redelivery bit' ) ; } if ( $ this -> message -> isRetained ( ) ) { $ this -> specialFlags |= 1 ; $ this -> logger -> debug ( 'Activating retain flag' ) ; } if (...
Sets some common flags and returns the variable header string should there be one
7,119
public function shouldExpectAnswer ( ) : bool { $ shouldExpectAnswer = ! ( $ this -> message -> getQoSLevel ( ) === 0 ) ; $ this -> logger -> debug ( 'Checking whether we should expect an answer or not' , [ 'shouldExpectAnswer' => $ shouldExpectAnswer , ] ) ; return $ shouldExpectAnswer ; }
QoS level 0 does not have to wait for a answer so return false . Any other QoS level returns true
7,120
private function analyzeFirstByte ( int $ firstByte , QoSLevel $ qoSLevel ) : Publish { $ this -> logger -> debug ( 'Analyzing first byte' , [ sprintf ( '%08d' , decbin ( $ firstByte ) ) ] ) ; $ this -> message -> setRetainFlag ( false ) ; if ( ( $ firstByte & 1 ) === 1 ) { $ this -> logger -> debug ( 'Setting retain f...
Sets several bits and pieces from the first byte of the fixed header for the Publish packet
7,121
private function determineIncomingQoSLevel ( int $ bitString ) : QoSLevel { $ shiftedBits = $ bitString >> 1 ; $ incomingQoSLevel = 0 ; if ( ( $ shiftedBits & 1 ) === 1 ) { $ incomingQoSLevel = 1 ; } if ( ( $ shiftedBits & 2 ) === 2 ) { $ incomingQoSLevel = 2 ; } $ this -> logger -> debug ( 'Setting QoS level' , [ 'bit...
Finds out the QoS level in a fixed header for the Publish object
7,122
private function completePossibleIncompleteMessage ( string $ rawMQTTHeaders , ClientInterface $ client ) : string { if ( strlen ( $ rawMQTTHeaders ) < 2 ) { $ rawMQTTHeaders .= $ client -> readBrokerData ( 1 ) ; } $ restOfBytes = $ this -> performRemainingLengthFieldOperations ( $ rawMQTTHeaders , $ client ) ; if ( st...
Gets the full message in case this object needs to
7,123
public function fillObject ( string $ rawMQTTHeaders , ClientInterface $ client ) : ReadableContentInterface { $ fullMessage = $ this -> completePossibleIncompleteMessage ( $ rawMQTTHeaders , $ client ) ; $ firstByte = ord ( $ fullMessage { 0 } ) ; $ topicSize = ord ( $ fullMessage { $ this -> sizeOfRemainingLengthFiel...
Will perform sanity checks and fill in the Readable object with data
7,124
private function composePubRecAnswer ( ) : PubRec { $ this -> checkForValidPacketIdentifier ( ) ; $ pubRec = new PubRec ( $ this -> logger ) ; $ pubRec -> setPacketIdentifier ( $ this -> packetIdentifier ) ; return $ pubRec ; }
Composes a PubRec answer with the same packetIdentifier as what we received
7,125
private function composePubAckAnswer ( ) : PubAck { $ this -> checkForValidPacketIdentifier ( ) ; $ pubAck = new PubAck ( $ this -> logger ) ; $ pubAck -> setPacketIdentifier ( $ this -> packetIdentifier ) ; return $ pubAck ; }
Composes a PubAck answer with the same packetIdentifier as what we received
7,126
private function checkForValidPacketIdentifier ( ) : self { if ( $ this -> packetIdentifier === null ) { $ this -> logger -> critical ( 'No valid packet identifier found at a stage where there MUST be one set' ) ; throw new InvalidRequest ( 'You are trying to send a request without a valid packet identifier' ) ; } retu...
Will check whether the current object has a packet identifier set . If not we are in serious problems!
7,127
public function edit ( Request $ request , $ template ) { $ data = $ this -> getData ( ) ; \ PDFGeneratorAPI :: setWorkspace ( $ this -> userRepository -> getWorkspaceIdentifier ( Auth :: user ( ) ) ) ; return redirect ( ) -> away ( \ PDFGeneratorAPI :: editor ( $ template , $ data ) ) ; }
Redirects to editor to edit the new template
7,128
public function editAsCopy ( Request $ request , $ template ) { $ name = $ request -> get ( 'name' ) ; $ data = $ this -> getData ( ) ; try { \ PDFGeneratorAPI :: setWorkspace ( $ this -> userRepository -> getWorkspaceIdentifier ( Auth :: user ( ) ) ) ; $ newTemplate = \ PDFGeneratorAPI :: copy ( $ template , $ name ) ...
Creates a copy of given template and redirects to editor to edit the new template
7,129
public function setUnit ( \ Sulu \ Bundle \ ProductBundle \ Entity \ Unit $ unit ) { $ this -> unit = $ unit ; return $ this ; }
Set unit .
7,130
private function getAttributeQuery ( $ locale ) { $ queryBuilder = $ this -> createQueryBuilder ( 'attribute' ) -> leftJoin ( 'attribute.translations' , 'translations' , 'WITH' , 'translations.locale = :locale' ) -> leftJoin ( 'attribute.type' , 'type' ) -> setParameter ( 'locale' , $ locale ) ; return $ queryBuilder ;...
Returns the query for attributes .
7,131
public function setClientId ( ClientId $ clientId ) : self { $ this -> clientId = $ clientId ; $ this -> logger -> debug ( 'Set clientId' , [ 'actualClientString' => ( string ) $ clientId ] ) ; if ( $ this -> clientId -> isEmptyClientId ( ) ) { $ this -> logger -> debug ( 'Empty clientId detected, forcing clean session...
Handles everything related to setting the ClientId
7,132
public function getConnectionUrl ( ) : string { return sprintf ( '%s://%s:%d' , $ this -> brokerPort -> getTransmissionProtocol ( ) , $ this -> host , $ this -> brokerPort -> getBrokerPort ( ) ) ; }
Returns the connection string
7,133
public function setKeepAlivePeriod ( int $ keepAlivePeriod ) : self { if ( $ keepAlivePeriod > 65535 || $ keepAlivePeriod < 0 ) { $ this -> logger -> error ( 'Keep alive period must be between 0 and 65535' ) ; throw new \ InvalidArgumentException ( 'Keep alive period must be between 0 and 65535' ) ; } $ this -> keepAli...
Keep alive period is measured in positive seconds . The maximum is 18h 12m and 15s equivalent to 65535 seconds
7,134
public function setCredentials ( string $ username , string $ password ) : self { $ this -> bitFlag &= ~ 64 ; $ this -> bitFlag &= ~ 128 ; if ( $ username !== '' ) { $ this -> logger -> debug ( 'Username set, setting username flag' ) ; $ this -> bitFlag |= 128 ; $ this -> username = $ username ; } if ( $ password !== '...
Sets the 6th and 7th bit of the connect flag
7,135
private function setWillRetainBit ( bool $ willRetain ) : self { $ this -> bitFlag &= ~ 32 ; if ( $ willRetain === true ) { $ this -> logger -> debug ( 'Setting will retain flag' ) ; $ this -> bitFlag |= 32 ; } return $ this ; }
Sets the 5th bit of the connect flag
7,136
private function setWillQoSLevelBit ( int $ QoSLevel ) : self { $ this -> bitFlag &= ~ 8 ; $ this -> bitFlag &= ~ 16 ; if ( $ QoSLevel !== 0 ) { $ this -> logger -> debug ( sprintf ( 'Setting will QoS level %d flag (bit %d)' , $ QoSLevel , $ QoSLevel * 8 ) ) ; $ this -> bitFlag |= ( $ QoSLevel * 8 ) ; } return $ this ;...
Determines and sets the 3rd and 4th bits of the connect flag
7,137
public function setWill ( Message $ message ) : self { $ this -> bitFlag &= ~ 4 ; if ( $ message -> getTopicName ( ) !== '' ) { $ this -> logger -> debug ( 'Setting will flag' ) ; $ this -> bitFlag |= 4 ; } $ this -> will = $ message ; $ this -> setWillRetainBit ( $ message -> isRetained ( ) ) -> setWillQoSLevelBit ( $...
Sets the given will . Will also set the 2nd bit of the connect flags if a message is provided
7,138
public function setCleanSession ( bool $ cleanSession ) : self { $ this -> bitFlag &= ~ 2 ; if ( $ cleanSession === true ) { $ this -> logger -> debug ( 'Clean session flag set' ) ; $ this -> bitFlag |= 2 ; } $ this -> cleanSession = $ cleanSession ; return $ this ; }
Sets the 1st bit of the connect flags
7,139
public function findAllCurrent ( $ limit = 1000 , $ page = 1 ) { try { $ qb = $ this -> getValidSpecialPriceQuery ( ) ; $ adapter = new DoctrineORMAdapter ( $ qb ) ; $ pagerfanta = new Pagerfanta ( $ adapter ) ; $ pagerfanta -> setMaxPerPage ( $ limit ) ; $ pagerfanta -> setCurrentPage ( $ page ) ; return $ pagerfanta ...
Returns the current special prices .
7,140
public function findAllCurrentIds ( $ limit = 1000 ) { try { $ queryBuilder = $ this -> getValidSpecialPriceQuery ( ) -> select ( 'specialPrice.id' ) -> addOrderBy ( 'specialPrice.id' , 'DESC' ) ; $ query = $ queryBuilder -> getQuery ( ) -> useResultCache ( true , 3600 ) ; $ ids = $ query -> getScalarResult ( ) ; retur...
Returns the ids of a specific amount of special prices .
7,141
protected function getValidSpecialPriceQuery ( ) { $ qb = $ this -> createQueryBuilder ( 'specialPrice' ) -> leftJoin ( 'specialPrice.product' , 'product' ) -> leftJoin ( 'product.status' , 'productStatus' ) -> where ( ':now BETWEEN specialPrice.startDate AND specialPrice.endDate' ) -> andWhere ( 'productStatus.id = :p...
Returns special price querybuilder .
7,142
public static function convertNumberToBinaryString ( int $ number ) : string { if ( $ number > 65535 ) { throw new OutOfRangeException ( 'This is an INT16 conversion, so the maximum is 65535' ) ; } return chr ( $ number >> 8 ) . chr ( $ number & 255 ) ; }
Converts a number to a binary string that the MQTT protocol understands
7,143
public static function convertBinaryStringToNumber ( string $ binaryString ) : int { return self :: convertEndianness ( ( ord ( $ binaryString { 1 } ) << 8 ) + ( ord ( $ binaryString { 0 } ) & 255 ) ) ; }
Converts a binary representation of a number to an actual int
7,144
public static function convertRemainingLengthStringToInt ( string $ remainingLengthField ) : int { $ multiplier = 128 ; $ value = 0 ; $ iteration = 0 ; do { $ encodedByte = ord ( $ remainingLengthField { $ iteration } ) ; $ value += ( $ encodedByte & 127 ) * ( $ multiplier ** $ iteration ) ; if ( $ multiplier > 128 ** ...
The remaining length of a message is encoded in this specific way the opposite of formatRemainingLengthOutput
7,145
public function indexAction ( ProductInterface $ product , ProductTranslation $ translation ) { $ apiProduct = $ this -> getProductFactory ( ) -> createApiEntity ( $ product , $ translation -> getLocale ( ) ) ; return $ this -> render ( $ this -> getProductViewTemplate ( ) , [ 'product' => $ apiProduct , 'urls' => $ th...
This action is used for displaying a product via a template . The template that is defined by sulu_product . template parameter is used for displaying the product .
7,146
public function getAllRoutesOfProduct ( ProductInterface $ product ) { $ urls = [ ] ; foreach ( $ product -> getTranslations ( ) as $ productTranslation ) { if ( $ productTranslation -> getRoute ( ) ) { $ urls [ $ productTranslation -> getLocale ( ) ] = $ productTranslation -> getRoute ( ) -> getPath ( ) ; } } return $...
Returns all routes that are defined for given product .
7,147
public function getBasePriceForCurrency ( ProductInterface $ product , $ currency = null ) { $ currency = $ currency ? : $ this -> defaultCurrency ; if ( $ prices = $ product -> getPrices ( ) ) { foreach ( $ prices as $ price ) { if ( $ price -> getCurrency ( ) -> getCode ( ) == $ currency && $ price -> getMinimumQuant...
Returns the base prices for the product by a given currency .
7,148
private function isValidSpecialPrice ( SpecialPrice $ specialPrice ) { $ startDate = $ specialPrice -> getStartDate ( ) ; $ endDate = $ specialPrice -> getEndDate ( ) ; $ now = new \ DateTime ( ) ; if ( ( $ now >= $ startDate && $ now <= $ endDate ) || ( $ now >= $ startDate && empty ( $ endDate ) ) || ( empty ( $ star...
Checks if a special price is still valid by today .
7,149
public function get ( ) { $ handle = fopen ( $ this -> filePath , "rb" ) ; $ fileSize = filesize ( $ this -> filePath ) ; $ hash = array ( 3 => 0 , 2 => 0 , 1 => ( $ fileSize >> 16 ) & 0xFFFF , 0 => $ fileSize & 0xFFFF ) ; for ( $ i = 0 ; $ i < 8192 ; $ i ++ ) { $ tmp = $ this -> readUINT64 ( $ handle ) ; $ hash = $ th...
Hash to send to OpenSubtitles
7,150
public function setTaxClass ( \ Sulu \ Bundle \ ProductBundle \ Entity \ TaxClass $ taxClass = null ) { $ this -> taxClass = $ taxClass ; return $ this ; }
Set taxClass .
7,151
public function getQoSLevel ( ) : int { if ( $ this -> qosLevel === null ) { $ this -> qosLevel = new QoSLevel ( 0 ) ; } return $ this -> qosLevel -> getQoSLevel ( ) ; }
Gets the current QoS level
7,152
public function blameCreator ( $ user ) { if ( is_null ( $ this -> createdBy ) && is_null ( $ this -> updatedBy ) ) { $ this -> createdBy = $ this -> updatedBy = $ user ; } }
Initialise the blamable fields
7,153
public function postPersist ( ProductTranslationEvent $ productTranslationEvent ) { $ this -> productRouteManager -> saveRoute ( $ productTranslationEvent -> getProductTranslation ( ) ) ; $ this -> entityManager -> flush ( ) ; }
Called when product translation has been created and stored to database . Will save a new product route .
7,154
public function performSpecialActions ( ClientInterface $ client , WritableContentInterface $ originalRequest ) : bool { $ this -> controlPacketIdentifiers ( $ originalRequest ) ; $ pubRel = new PubRel ( $ this -> logger ) ; $ pubRel -> setPacketIdentifier ( $ this -> packetIdentifier ) ; $ pubComp = $ client -> proces...
Any class can overwrite the default behaviour
7,155
public function getName ( ) { if ( ! $ this -> entity -> getTranslation ( $ this -> locale ) ) { return null ; } return $ this -> entity -> getTranslation ( $ this -> locale ) -> getName ( ) ; }
The name of the type .
7,156
public function initializeTimestamps ( ) { if ( is_null ( $ this -> createdAt ) && is_null ( $ this -> updatedAt ) ) { $ this -> createdAt = Carbon :: now ( ) ; $ this -> updatedAt = Carbon :: now ( ) ; } }
Initialises the timestamp properties
7,157
private function retrieveProductTypesMap ( ) { $ productTypeMap = [ ] ; LoadProductTypes :: processProductTypesFixtures ( function ( \ DOMElement $ element ) use ( & $ productTypeMap ) { $ productTypeMap [ $ element -> getAttribute ( 'key' ) ] = $ element -> getAttribute ( 'id' ) ; } ) ; return $ productTypeMap ; }
Returns key to id mapping for product - types . Processes product - types fixtures xml .
7,158
protected function fetchBucket ( $ key ) { $ data = $ this -> storage -> get ( $ key ) ; return json_decode ( $ data , TRUE ) ; }
Fetch our bucket data from storage
7,159
protected function save ( $ bucket ) { return $ this -> storage -> set ( $ this -> key , json_encode ( $ bucket -> getData ( ) ) ) ; }
Save our bucket to storage
7,160
private function checkAndReturnAnswer ( WritableContentInterface $ object ) : string { $ returnValue = '' ; if ( $ object -> shouldExpectAnswer ( ) === true ) { $ this -> enableSynchronousTransfer ( true ) ; $ returnValue = $ this -> readBrokerHeader ( ) ; $ this -> enableSynchronousTransfer ( false ) ; } return $ retu...
Checks on the writable object whether we should wait for an answer and either wait or return an empty string
7,161
private function checkForConnectionErrors ( int $ errorCode , string $ errorDescription ) : self { if ( $ errorCode !== 0 || $ this -> socket === null ) { $ this -> logger -> critical ( 'Could not connect to broker' , [ 'errorCode' => $ errorCode , 'errorDescription' => $ errorDescription , ] ) ; throw new NotConnected...
Checks for socket error connections will throw an exception if any is found
7,162
private function setSocketTimeout ( ) : self { $ timeCalculation = $ this -> connectionParameters -> getKeepAlivePeriod ( ) * 1.5 ; $ seconds = ( int ) floor ( $ timeCalculation ) ; stream_set_timeout ( $ this -> socket , $ seconds , ( int ) ( $ timeCalculation - $ seconds ) * 1000 ) ; return $ this ; }
Calculates and sets the timeout on the socket connection according to the MQTT standard
7,163
private function preSocketCommunication ( WritableContentInterface $ object ) : self { $ this -> objectStack [ $ object :: getControlPacketValue ( ) ] = $ object ; if ( $ object instanceof Connect ) { $ this -> generateSocketConnection ( $ object ) ; } return $ this ; }
Stuff that has to happen before we actually begin sending data through our socket
7,164
private function postSocketCommunication ( ReadableContentInterface $ readableContent ) : WritableContentInterface { $ originPacket = null ; $ originPacketIdentifier = $ readableContent -> getOriginControlPacket ( ) ; if ( array_key_exists ( $ originPacketIdentifier , $ this -> objectStack ) ) { $ this -> logger -> deb...
Checks in the object stack whether there is some method that might issue the current ReadableContent
7,165
public function cgetAction ( Request $ request , $ id ) { try { if ( $ request -> get ( 'flat' ) == 'true' ) { $ list = $ this -> getListRepresentation ( $ request , $ id ) ; } else { $ list = new CollectionRepresentation ( $ this -> getManager ( ) -> findAllByAttributeIdAndLocale ( $ this -> getLocale ( $ request ) , ...
Retrieves and shows a attributeValue with the given ID .
7,166
public function postAction ( Request $ request , $ attributeId ) { try { $ attributeValue = $ this -> getManager ( ) -> save ( $ request -> request -> all ( ) , $ this -> getLocale ( $ request ) , $ attributeId ) ; $ view = $ this -> view ( $ attributeValue , 200 ) ; } catch ( AttributeDependencyNotFoundException $ exc...
Creates and stores a new attribute value .
7,167
public function deleteAction ( Request $ request , $ attributeId , $ attributeValueId ) { try { $ this -> getManager ( ) -> delete ( $ attributeValueId , $ this -> getUser ( ) -> getId ( ) ) ; $ view = $ this -> view ( $ attributeValueId , 204 ) ; } catch ( AttributeValueNotFoundException $ exc ) { $ exception = new En...
Delete an product attribute value for the given id .
7,168
private function getProductQuery ( $ locale ) { $ qb = $ this -> createQueryBuilder ( 'product' ) -> addSelect ( 'prices' ) -> addSelect ( 'parent' ) -> addSelect ( 'translations' ) -> addSelect ( 'status' ) -> addSelect ( 'type' ) -> addSelect ( 'currency' ) -> addSelect ( 'media' ) -> leftJoin ( 'product.parent' , 'p...
Returns the query for products .
7,169
public function findByLocaleAndIds ( $ locale , array $ ids = [ ] ) { try { $ qb = $ this -> getProductQuery ( $ locale ) ; $ qb -> where ( 'product.id IN (:ids)' ) ; $ qb -> setParameter ( 'ids' , $ ids ) ; $ query = $ qb -> getQuery ( ) ; return $ query -> getResult ( ) ; } catch ( NoResultException $ ex ) { return n...
Returns all products with the given locale and ids .
7,170
public function retrieveFieldDescriptors ( $ locale ) { $ fieldDescriptors = [ ] ; $ fieldDescriptors [ 'id' ] = new DoctrineFieldDescriptor ( 'id' , 'id' , static :: $ attributeEntityName , null , [ static :: $ attributeEntityName => new DoctrineJoinDescriptor ( static :: $ attributeEntityName , static :: $ productEnt...
Returns all field - descriptors for variant attributes .
7,171
public function createVariantAttributeRelation ( $ productId , array $ requestData ) { $ variant = $ this -> retrieveProductById ( $ productId ) ; $ attribute = $ this -> retrieveAttributeById ( $ this -> getProperty ( $ requestData , 'attributeId' ) ) ; if ( ! $ variant -> getVariantAttributes ( ) -> contains ( $ attr...
Creates a new relation between variant and attribute .
7,172
public function removeVariantAttributeRelation ( $ productId , $ attributeId ) { $ variant = $ this -> retrieveProductById ( $ productId ) ; $ attribute = $ this -> retrieveAttributeById ( $ attributeId ) ; if ( ! $ variant -> getVariantAttributes ( ) -> contains ( $ attribute ) ) { throw new ProductException ( 'Varian...
Removes relation between variant and attribute .
7,173
private function retrieveAttributeById ( $ attributeId ) { $ attribute = $ this -> attributeRepository -> find ( $ attributeId ) ; if ( ! $ attribute ) { throw new AttributeNotFoundException ( $ attributeId ) ; } return $ attribute ; }
Fetches attribute from db . If not found an exception is thrown .
7,174
private function retrieveProductById ( $ productId ) { $ product = $ this -> productRepository -> find ( $ productId ) ; if ( ! $ product ) { throw new ProductNotFoundException ( $ productId ) ; } return $ product ; }
Fetches product from db . If not found an exception is thrown .
7,175
public function getAction ( Request $ request , $ parentId , $ variantId ) { $ locale = $ this -> getLocale ( $ request ) ; $ view = $ this -> responseGetById ( $ variantId , function ( $ id ) use ( $ locale , $ parentId ) { $ product = $ this -> getProductManager ( ) -> findByIdAndLocale ( $ id , $ locale ) ; if ( $ p...
Retrieves and shows the variant with the given ID for the parent product .
7,176
public function cgetAction ( Request $ request , $ parentId ) { if ( $ request -> get ( 'flat' ) == 'true' ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( self :: $ entityName ) ; $ fi...
Returns a list of product variants for the requested product .
7,177
public function postAction ( Request $ request , $ parentId ) { $ requestData = $ request -> request -> all ( ) ; $ userId = $ this -> getUser ( ) -> getId ( ) ; $ locale = $ this -> getLocale ( $ request ) ; $ variant = $ this -> getProductVariantManager ( ) -> createVariant ( $ parentId , $ requestData , $ locale , $...
Adds a new variant to given product .
7,178
public function putAction ( Request $ request , $ parentId , $ variantId ) { $ requestData = $ request -> request -> all ( ) ; $ userId = $ this -> getUser ( ) -> getId ( ) ; $ locale = $ this -> getLocale ( $ request ) ; $ variant = $ this -> getProductVariantManager ( ) -> updateVariant ( $ variantId , $ requestData ...
Updates an existing variant to given product .
7,179
private function mapDataToVariant ( ProductInterface $ variant , array $ variantData , $ locale , $ userId ) { $ productTranslation = $ this -> productManager -> retrieveOrCreateProductTranslationByLocale ( $ variant , $ locale ) ; $ productTranslation -> setName ( $ this -> getProperty ( $ variantData , 'name' ) ) ; $...
Maps all the data to a given variant for the given locale .
7,180
private function processAttributes ( ProductInterface $ variant , array $ variantData , $ locale ) { $ parent = $ variant -> getParent ( ) ; $ sizeOfVariantAttributes = count ( $ this -> getProperty ( $ variantData , 'attributes' ) ) ; $ sizeOfParentAttributes = $ parent -> getVariantAttributes ( ) -> count ( ) ; if ( ...
Adds variant attributes to variant .
7,181
private function processPrices ( ProductInterface $ variant , array $ variantData ) { if ( ! isset ( $ variantData [ 'prices' ] ) || ! is_array ( $ variantData [ 'prices' ] ) ) { return ; } $ currentPrices = iterator_to_array ( $ variant -> getPrices ( ) ) ; foreach ( $ variantData [ 'prices' ] as $ price ) { $ matchin...
Adds or updates price information for a variant .
7,182
private function retrievePriceByCurrency ( array & $ prices , $ currencyId ) { foreach ( $ prices as $ index => $ price ) { if ( $ currencyId === $ price -> getCurrency ( ) -> getId ( ) ) { unset ( $ prices [ $ index ] ) ; return $ price ; } } return null ; }
Returns price by currency id . If found the ProductPrice entity is removed from the prices array .
7,183
public function findByAttributeIdAndProductId ( $ attributeId , $ productId ) { try { $ queryBuilder = $ this -> createQueryBuilder ( 'productAttribute' ) -> leftJoin ( 'productAttribute.attribute' , 'attribute' ) -> leftJoin ( 'productAttribute.product' , 'product' ) -> andWhere ( 'attribute.id = :attributeId' ) -> an...
Returns the productAttribute for the given attribute and product id .
7,184
public static function processProductTypesFixtures ( callable $ elementCallback ) { $ file = dirname ( __FILE__ ) . '/../../product-types.xml' ; $ doc = new \ DOMDocument ( ) ; $ doc -> load ( $ file ) ; $ xpath = new \ DOMXpath ( $ doc ) ; $ elements = $ xpath -> query ( '/product-types/product-type' ) ; if ( ! is_nul...
Function reads the product - types fixtures file and executes the given element callback function for each node . This function is static in order to be able to load product types xml from another function as well .
7,185
public function markAsAuthenticated ( $ username , array $ attrs = null ) { if ( ! $ attrs ) { $ attrs = $ this -> fetchAttrs ( $ username ) ; } $ authResult = new AuthResult ( $ username , $ attrs ) ; return $ this -> _stateMgr -> set ( 'authResult' , $ authResult ) ; }
Mark the user as authenticated and store her in the state manager
7,186
public function findAll ( $ locale ) { $ units = $ this -> unitRepository -> findAllByLocale ( $ locale ) ; array_walk ( $ units , function ( & $ unit ) use ( $ locale ) { $ unit = new Unit ( $ unit , $ locale ) ; } ) ; return $ units ; }
Find all units .
7,187
public function scoreForMonth ( Request $ request ) { $ repos = new ResultsRepository ( ) ; $ title = Carbon :: createFromDate ( ) -> subMonths ( $ request -> input ( 'monthsBack' , 0 ) ) -> format ( 'F' ) ; return view ( 'game-of-tests::results.list' , [ 'title' => $ title , 'months_back' => $ request -> input ( 'mont...
Show rankings of specific month
7,188
public function scoreLastMonths ( Request $ request ) { $ repos = new ResultsRepository ( ) ; return view ( 'game-of-tests::results.list' , [ 'type' => 'from' , 'months_back' => $ request -> input ( 'monthsBack' , 0 ) , 'results' => $ repos -> getScoreLastMonths ( $ request -> input ( 'monthsBack' , 0 ) ) ] ) ; }
Show rankings for last X months
7,189
public function resultForUser ( $ user , Request $ request ) { $ repos = new ResultsRepository ( ) ; $ results = $ repos -> getByUser ( $ user , $ request -> input ( 'monthsBack' , false ) , $ request -> input ( 'fromMonthsBack' , false ) ) ; return view ( 'game-of-tests::results.author' , [ 'results' => $ results ] ) ...
Show result for specific user .
7,190
public function getFilterFieldDescriptors ( ) { $ fieldDescriptors = [ ] ; $ fieldDescriptors [ 'type_id' ] = new DoctrineFieldDescriptor ( 'id' , 'type_id' , self :: $ productTypeEntityName , null , [ self :: $ productTypeEntityName => new DoctrineJoinDescriptor ( self :: $ productTypeEntityName , static :: $ productE...
Returns a list of fieldDescriptors just used for filtering .
7,191
public function createProductMedia ( ApiProductInterface $ product , $ locale ) { $ media = [ ] ; foreach ( $ product -> getEntity ( ) -> getMedia ( ) as $ medium ) { $ media [ ] = $ this -> mediaManager -> getById ( $ medium -> getId ( ) , $ locale ) ; } $ product -> setMedia ( $ media ) ; }
Sets product media for api - product Otherwise api - media will not contain additional info like url ..
7,192
public function findAllByIdsAndLocale ( $ locale , $ ids = '' ) { $ products = $ this -> productRepository -> findByLocaleAndIds ( $ locale , explode ( ',' , $ ids ) ) ; if ( $ products ) { array_walk ( $ products , function ( & $ product ) use ( $ locale ) { $ product = $ this -> productFactory -> createApiEntity ( $ ...
Finds all elements with one of the ids .
7,193
public function findByLocaleAndInternalItemNumber ( $ locale , $ internalItemNumber ) { $ products = $ this -> productRepository -> findByLocaleAndInternalItemNumber ( $ locale , $ internalItemNumber ) ; if ( $ products ) { array_walk ( $ products , function ( & $ product ) use ( $ locale ) { $ product = $ this -> prod...
Returns all simple products in the given locale for the given number .
7,194
protected function fetchProduct ( $ id , $ locale ) { $ product = $ this -> productRepository -> findByIdAndLocale ( $ id , $ locale ) ; if ( ! $ product ) { throw new ProductNotFoundException ( $ id ) ; } return $ this -> productFactory -> createApiEntity ( $ product , $ locale ) ; }
Fetches a product .
7,195
private function checkDateString ( $ dateTimeString ) { if ( empty ( $ dateTimeString ) ) { return null ; } try { $ date = new \ DateTime ( $ dateTimeString ) ; } catch ( Exception $ e ) { return null ; } return $ date ; }
Checks if datetime string is valid .
7,196
public function copyDataFromChangedToActiveProduct ( ProductInterface $ changedProduct , ProductInterface $ activeProduct ) { $ this -> convertProduct ( $ changedProduct , $ activeProduct ) ; $ activeProduct -> setIsDeprecated ( false ) ; }
Copies all data from a changed product to an active one and unsets deprecated state of active product .
7,197
public function parseCommaSeparatedString ( $ string , $ maxLength = self :: MAX_SEARCH_TERMS_LENGTH ) { $ result = null ; if ( strlen ( trim ( $ string ) ) === 0 ) { return null ; } $ string = mb_strtolower ( $ string , 'UTF-8' ) ; $ fields = explode ( ',' , $ string ) ; $ fields = array_map ( [ $ this , 'trimAndValid...
Parses a comma separated string . Trims all values and removes empty strings .
7,198
private function priceHasChanged ( $ data , $ price ) { $ currencyNotChanged = isset ( $ data [ 'currency' ] ) && array_key_exists ( 'name' , $ data [ 'currency' ] ) && $ data [ 'currency' ] [ 'name' ] == $ price -> getCurrency ( ) -> getName ( ) ; $ valueNotChanged = array_key_exists ( 'price' , $ data ) && $ data [ '...
Checks if price of a product has changed .
7,199
protected function getExistingActiveOrInactiveProduct ( $ existingProduct , $ statusId , $ locale ) { if ( ( $ statusId == StatusEntity :: ACTIVE || $ statusId == StatusEntity :: INACTIVE ) && $ existingProduct -> getStatus ( ) -> getId ( ) != $ statusId ) { $ products = $ this -> productRepository -> findByLocaleAndIn...
Checks if a product with the same internal product id as the given product exists in published state and returns it .