idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
41,200 | protected function getListItems ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , array $ custIds ) { $ listManager = \ Aimeos \ MShop :: create ( $ context , 'customer/lists' ) ; $ search = $ listManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , 'customer.lists.domain' , 'product' ) , $ search -> compare ( '==' , 'customer.lists.parentid' , $ custIds ) , $ search -> compare ( '==' , 'customer.lists.type' , 'watch' ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ search -> setSlice ( 0 , 0x7fffffff ) ; return $ listManager -> searchItems ( $ search ) ; } | Returns the list items for the given customer IDs and list type ID |
41,201 | protected function getProductList ( array $ products , array $ listItems ) { $ result = [ ] ; $ priceManager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'price' ) ; foreach ( $ listItems as $ id => $ listItem ) { try { $ refId = $ listItem -> getRefId ( ) ; $ config = $ listItem -> getConfig ( ) ; if ( isset ( $ products [ $ refId ] ) ) { $ prices = $ products [ $ refId ] -> getRefItems ( 'price' , 'default' , 'default' ) ; $ currencyId = ( isset ( $ config [ 'currency' ] ) ? $ config [ 'currency' ] : null ) ; $ price = $ priceManager -> getLowestPrice ( $ prices , 1 , $ currencyId ) ; if ( isset ( $ config [ 'stock' ] ) && $ config [ 'stock' ] == 1 || isset ( $ config [ 'price' ] ) && $ config [ 'price' ] == 1 && isset ( $ config [ 'pricevalue' ] ) && $ config [ 'pricevalue' ] > $ price -> getValue ( ) ) { $ result [ $ id ] [ 'item' ] = $ products [ $ refId ] ; $ result [ $ id ] [ 'currencyId' ] = $ currencyId ; $ result [ $ id ] [ 'price' ] = $ price ; } } } catch ( \ Exception $ e ) { ; } } return $ result ; } | Returns a filtered list of products for which a notification should be sent |
41,202 | protected function getProducts ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , array $ prodIds , $ stockType ) { $ productCodes = $ stockMap = [ ] ; $ productItems = $ this -> getProductItems ( $ context , $ prodIds ) ; foreach ( $ productItems as $ productItem ) { $ productCodes [ ] = $ productItem -> getCode ( ) ; } foreach ( $ this -> getStockItems ( $ context , $ productCodes , $ stockType ) as $ stockItem ) { $ stockMap [ $ stockItem -> getProductCode ( ) ] = true ; } foreach ( $ productItems as $ productId => $ productItem ) { if ( ! isset ( $ stockMap [ $ productItem -> getCode ( ) ] ) ) { unset ( $ productItems [ $ productId ] ) ; } } return $ productItems ; } | Returns the products for the given IDs which are in stock |
41,203 | protected function getProductItems ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , array $ prodIds ) { $ productManager = \ Aimeos \ MShop :: create ( $ context , 'product' ) ; $ search = $ productManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'product.id' , $ prodIds ) , $ search -> getConditions ( ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ search -> setSlice ( 0 , count ( $ prodIds ) ) ; return $ productManager -> searchItems ( $ search , array ( 'text' , 'price' , 'media' ) ) ; } | Returns the product items for the given product IDs |
41,204 | protected function getStockItems ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , array $ prodCodes , $ stockType ) { $ stockManager = \ Aimeos \ MShop :: create ( $ context , 'stock' ) ; $ search = $ stockManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'stock.productcode' , $ prodCodes ) , $ search -> compare ( '==' , 'stock.type' , $ stockType ) , $ search -> combine ( '||' , array ( $ search -> compare ( '==' , 'stock.stocklevel' , null ) , $ search -> compare ( '>' , 'stock.stocklevel' , 0 ) , ) ) , $ search -> getConditions ( ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ search -> setSlice ( 0 , 100000 ) ; return $ stockManager -> searchItems ( $ search ) ; } | Returns the stock items for the given product codes |
41,205 | protected function sendMail ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , \ Aimeos \ MShop \ Common \ Item \ Address \ Iface $ address , array $ products ) { $ view = $ context -> getView ( ) ; $ view -> extProducts = $ products ; $ view -> extAddressItem = $ address ; $ params = [ 'locale' => $ context -> getLocale ( ) -> getLanguageId ( ) , 'site' => $ context -> getLocale ( ) -> getSite ( ) -> getCode ( ) , ] ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Param \ Standard ( $ view , $ params ) ; $ view -> addHelper ( 'param' , $ helper ) ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Translate \ Standard ( $ view , $ context -> getI18n ( $ address -> getLanguageId ( ) ) ) ; $ view -> addHelper ( 'translate' , $ helper ) ; $ mailer = $ context -> getMail ( ) ; $ message = $ mailer -> createMessage ( ) ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Mail \ Standard ( $ view , $ message ) ; $ view -> addHelper ( 'mail' , $ helper ) ; $ client = $ this -> getClient ( $ context ) ; $ client -> setView ( $ view ) ; $ client -> getHeader ( ) ; $ client -> getBody ( ) ; $ mailer -> send ( $ message ) ; } | Sends the notification e - mail for the given customer address and products |
41,206 | protected function process ( \ Aimeos \ Client \ Html \ Iface $ client , array $ items , $ status ) { $ context = $ this -> getContext ( ) ; $ orderBaseManager = \ Aimeos \ MShop :: create ( $ context , 'order/base' ) ; foreach ( $ items as $ id => $ item ) { try { $ orderBaseItem = $ orderBaseManager -> load ( $ item -> getBaseId ( ) ) ; $ addr = $ this -> getAddressItem ( $ orderBaseItem ) ; $ this -> processItem ( $ client , $ item , $ orderBaseItem , $ addr ) ; $ this -> addOrderStatus ( $ id , $ status ) ; $ str = sprintf ( 'Sent order payment e-mail for status "%1$s" to "%2$s"' , $ status , $ addr -> getEmail ( ) ) ; $ context -> getLogger ( ) -> log ( $ str , \ Aimeos \ MW \ Logger \ Base :: INFO ) ; } catch ( \ Exception $ e ) { $ str = 'Error while trying to send payment e-mail for order ID "%1$s" and status "%2$s": %3$s' ; $ msg = sprintf ( $ str , $ item -> getId ( ) , $ item -> getPaymentStatus ( ) , $ e -> getMessage ( ) ) ; $ context -> getLogger ( ) -> log ( $ msg ) ; } } } | Sends the payment e - mail for the given orders |
41,207 | protected function processItem ( \ Aimeos \ Client \ Html \ Iface $ client , \ Aimeos \ MShop \ Order \ Item \ Iface $ orderItem , \ Aimeos \ MShop \ Order \ Item \ Base \ Iface $ orderBaseItem , \ Aimeos \ MShop \ Order \ Item \ Base \ Address \ Iface $ addrItem ) { $ context = $ this -> getContext ( ) ; $ langId = ( $ addrItem -> getLanguageId ( ) ? : $ orderBaseItem -> getLocale ( ) -> getLanguageId ( ) ) ; $ view = $ this -> getView ( $ context , $ orderBaseItem , $ langId ) ; $ view -> extAddressItem = $ addrItem ; $ view -> extOrderBaseItem = $ orderBaseItem ; $ view -> extOrderItem = $ orderItem ; $ client -> setView ( $ view ) ; $ client -> getHeader ( ) ; $ client -> getBody ( ) ; $ context -> getMail ( ) -> send ( $ view -> mail ( ) ) ; } | Sends the payment related e - mail for a single order |
41,208 | protected function sendEmail ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , \ Aimeos \ MShop \ Customer \ Item \ Iface $ item , $ password ) { $ address = $ item -> getPaymentAddress ( ) ; $ view = $ context -> getView ( ) ; $ view -> extAddressItem = $ address ; $ view -> extAccountCode = $ item -> getCode ( ) ; $ view -> extAccountPassword = $ password ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Translate \ Standard ( $ view , $ context -> getI18n ( $ address -> getLanguageId ( ) ) ) ; $ view -> addHelper ( 'translate' , $ helper ) ; $ mailer = $ context -> getMail ( ) ; $ message = $ mailer -> createMessage ( ) ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Mail \ Standard ( $ view , $ message ) ; $ view -> addHelper ( 'mail' , $ helper ) ; $ client = $ this -> getClient ( $ context ) ; $ client -> setView ( $ view ) ; $ client -> getHeader ( ) ; $ client -> getBody ( ) ; $ mailer -> send ( $ message ) ; } | Sends the account creation e - mail to the e - mail address of the customer |
41,209 | protected function counts ( \ Aimeos \ MShop \ Catalog \ Item \ Iface $ node ) { $ list = [ $ node -> getId ( ) => $ node -> count ] ; foreach ( $ node -> getChildren ( ) as $ child ) { $ list += $ this -> counts ( $ child ) ; } return $ list ; } | Returns the product counts per node |
41,210 | protected function traverse ( \ Aimeos \ MShop \ Catalog \ Item \ Iface $ node , array $ counts ) { $ count = ( isset ( $ counts [ $ node -> getId ( ) ] ) ? $ counts [ $ node -> getId ( ) ] : 0 ) ; foreach ( $ node -> getChildren ( ) as $ child ) { $ count += $ this -> traverse ( $ child , $ counts ) -> count ; } $ node -> count = $ count ; return $ node ; } | Traverses the tree and adds the aggregated product counts to each node |
41,211 | public static function create ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , $ name = null ) { if ( $ name === null ) { $ name = $ context -> getConfig ( ) -> get ( 'client/html/catalog/attribute/name' , 'Standard' ) ; } if ( ctype_alnum ( $ name ) === false ) { $ classname = is_string ( $ name ) ? '\\Aimeos\\Client\\Html\\Catalog\\Attribute\\' . $ name : '<not a string>' ; throw new \ Aimeos \ Client \ Html \ Exception ( sprintf ( 'Invalid characters in class name "%1$s"' , $ classname ) ) ; } $ iface = '\\Aimeos\\Client\\Html\\Iface' ; $ classname = '\\Aimeos\\Client\\Html\\Catalog\\Attribute\\' . $ name ; $ client = self :: createClient ( $ context , $ classname , $ iface ) ; $ client = self :: addClientDecorators ( $ context , $ client , 'catalog/attribute' ) ; return $ client -> setObject ( $ client ) ; } | Creates a attribute client object . |
41,212 | protected function addCoupon ( \ Aimeos \ MW \ View \ Iface $ view ) { if ( ( $ coupon = $ view -> param ( 'b_coupon' ) ) != '' ) { \ Aimeos \ Controller \ Frontend :: create ( $ this -> getContext ( ) , 'basket' ) -> addCoupon ( $ coupon ) ; $ this -> clearCached ( ) ; } } | Adds the coupon specified by the view parameters from the basket . |
41,213 | protected function getStockUrl ( \ Aimeos \ MW \ View \ Iface $ view , array $ products ) { $ target = $ view -> config ( 'client/html/catalog/stock/url/target' ) ; $ cntl = $ view -> config ( 'client/html/catalog/stock/url/controller' , 'catalog' ) ; $ action = $ view -> config ( 'client/html/catalog/stock/url/action' , 'stock' ) ; $ config = $ view -> config ( 'client/html/catalog/stock/url/config' , [ ] ) ; $ max = $ view -> config ( 'client/html/catalog/stock/url/max-items' , 100 ) ; $ codes = [ ] ; foreach ( $ products as $ product ) { $ codes [ ] = $ product -> getCode ( ) ; } sort ( $ codes ) ; $ urls = [ ] ; while ( ( $ list = array_splice ( $ codes , - $ max ) ) !== [ ] ) { $ urls [ ] = $ view -> url ( $ target , $ cntl , $ action , array ( "s_prodcode" => $ list ) , [ ] , $ config ) ; } return array_reverse ( $ urls ) ; } | Returns the URL for retrieving the stock levels |
41,214 | protected function addNavigationUrls ( \ Aimeos \ MW \ View \ Iface $ view , array $ steps , $ activeStep ) { $ cTarget = $ view -> config ( 'client/html/checkout/standard/url/target' ) ; $ cCntl = $ view -> config ( 'client/html/checkout/standard/url/controller' , 'checkout' ) ; $ cAction = $ view -> config ( 'client/html/checkout/standard/url/action' , 'index' ) ; $ cConfig = $ view -> config ( 'client/html/checkout/standard/url/config' , [ ] ) ; $ bTarget = $ view -> config ( 'client/html/basket/standard/url/target' ) ; $ bCntl = $ view -> config ( 'client/html/basket/standard/url/controller' , 'basket' ) ; $ bAction = $ view -> config ( 'client/html/basket/standard/url/action' , 'index' ) ; $ bConfig = $ view -> config ( 'client/html/basket/standard/url/config' , [ ] ) ; $ step = null ; do { $ lastStep = $ step ; } while ( ( $ step = array_shift ( $ steps ) ) !== null && $ step !== $ activeStep ) ; if ( $ lastStep !== null ) { $ param = array ( 'c_step' => $ lastStep ) ; $ view -> standardUrlBack = $ view -> url ( $ cTarget , $ cCntl , $ cAction , $ param , [ ] , $ cConfig ) ; } else { $ view -> standardUrlBack = $ view -> url ( $ bTarget , $ bCntl , $ bAction , [ ] , [ ] , $ bConfig ) ; } if ( ! isset ( $ view -> standardUrlNext ) && ( $ nextStep = array_shift ( $ steps ) ) !== null ) { $ param = array ( 'c_step' => $ nextStep ) ; $ view -> standardUrlNext = $ view -> url ( $ cTarget , $ cCntl , $ cAction , $ param , [ ] , $ cConfig ) ; } return $ view ; } | Adds the back and next URLs to the view |
41,215 | public function end ( \ Aimeos \ MShop \ Subscription \ Item \ Iface $ subscription ) { $ context = $ this -> getContext ( ) ; $ manager = \ Aimeos \ MShop :: create ( $ context , 'order/base' ) ; $ baseItem = $ manager -> getItem ( $ subscription -> getOrderBaseId ( ) , [ 'order/base/address' , 'order/base/product' ] ) ; $ addrItem = $ baseItem -> getAddress ( \ Aimeos \ MShop \ Order \ Item \ Base \ Address \ Base :: TYPE_PAYMENT , 0 ) ; foreach ( $ baseItem -> getProducts ( ) as $ orderProduct ) { if ( $ orderProduct -> getId ( ) == $ subscription -> getOrderProductId ( ) ) { $ this -> sendMail ( $ context , $ subscription , $ addrItem , $ orderProduct ) ; } } } | Processes the end of the subscription |
41,216 | protected function sendMail ( \ Aimeos \ MShop \ Context \ Item \ Iface $ context , \ Aimeos \ MShop \ Subscription \ Item \ Iface $ subscription , \ Aimeos \ MShop \ Common \ Item \ Address \ Iface $ address , \ Aimeos \ MShop \ Order \ Item \ Base \ Product \ Iface $ product ) { $ view = $ context -> getView ( ) ; $ view -> extAddressItem = $ address ; $ view -> extOrderProductItem = $ product ; $ view -> extSubscriptionItem = $ subscription ; $ params = [ 'locale' => $ context -> getLocale ( ) -> getLanguageId ( ) , 'site' => $ context -> getLocale ( ) -> getSite ( ) -> getCode ( ) , ] ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Param \ Standard ( $ view , $ params ) ; $ view -> addHelper ( 'param' , $ helper ) ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Translate \ Standard ( $ view , $ context -> getI18n ( $ address -> getLanguageId ( ) ) ) ; $ view -> addHelper ( 'translate' , $ helper ) ; $ mailer = $ context -> getMail ( ) ; $ message = $ mailer -> createMessage ( ) ; $ helper = new \ Aimeos \ MW \ View \ Helper \ Mail \ Standard ( $ view , $ message ) ; $ view -> addHelper ( 'mail' , $ helper ) ; $ client = $ this -> getClient ( $ context ) ; $ client -> setView ( $ view ) ; $ client -> getHeader ( ) ; $ client -> getBody ( ) ; $ mailer -> send ( $ message ) ; } | Sends the subscription e - mail for the given customer address and products |
41,217 | protected function addCouponCodes ( array $ map ) { $ couponId = $ this -> getCouponId ( ) ; $ manager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'coupon/code' ) ; foreach ( $ map as $ code => $ ref ) { $ item = $ manager -> createItem ( ) -> setParentId ( $ couponId ) -> setCode ( $ code ) -> setRef ( $ ref ) -> setCount ( null ) ; $ manager -> saveItem ( $ item ) ; } } | Saves the given coupon codes |
41,218 | protected function addOrderStatus ( $ orderId , $ value ) { $ orderStatusManager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'order/status' ) ; $ statusItem = $ orderStatusManager -> createItem ( ) -> setParentId ( $ orderId ) -> setValue ( $ value ) -> setType ( \ Aimeos \ MShop \ Order \ Item \ Status \ Base :: EMAIL_VOUCHER ) ; $ orderStatusManager -> saveItem ( $ statusItem ) ; } | Adds the status of the delivered e - mail for the given order ID |
41,219 | protected function getCouponId ( ) { if ( ! isset ( $ this -> couponId ) ) { $ manager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'coupon' ) ; $ search = $ manager -> createSearch ( ) -> setSlice ( 0 , 1 ) ; $ search -> setConditions ( $ search -> compare ( '=~' , 'coupon.provider' , 'Voucher' ) ) ; $ items = $ manager -> searchItems ( $ search ) ; if ( ( $ item = reset ( $ items ) ) === false ) { throw new \ Aimeos \ Controller \ Jobs \ Exception ( 'No coupon provider "Voucher" available' ) ; } $ this -> couponId = $ item -> getId ( ) ; } return $ this -> couponId ; } | Returns the coupon ID for the voucher coupon |
41,220 | protected function process ( \ Aimeos \ Client \ Html \ Iface $ client , array $ items , $ status ) { $ context = $ this -> getContext ( ) ; $ orderBaseManager = \ Aimeos \ MShop :: create ( $ context , 'order/base' ) ; foreach ( $ items as $ id => $ item ) { try { $ orderBaseItem = $ orderBaseManager -> load ( $ item -> getBaseId ( ) ) -> off ( ) ; $ orderBaseItem = $ this -> createCoupons ( $ orderBaseItem ) ; $ orderBaseManager -> store ( $ orderBaseItem ) ; $ this -> sendEmails ( $ orderBaseItem , $ client ) ; $ this -> addOrderStatus ( $ id , $ status ) ; $ str = sprintf ( 'Sent voucher e-mails for order ID "%1$s"' , $ item -> getId ( ) ) ; $ context -> getLogger ( ) -> log ( $ str , \ Aimeos \ MW \ Logger \ Base :: INFO ) ; } catch ( \ Exception $ e ) { $ str = 'Error while trying to send voucher e-mails for order ID "%1$s": %2$s' ; $ msg = sprintf ( $ str , $ item -> getId ( ) , $ e -> getMessage ( ) ) ; $ context -> getLogger ( ) -> log ( $ msg ) ; } } } | Sends the voucher e - mail for the given orders |
41,221 | protected function createCoupons ( \ Aimeos \ MShop \ Order \ Item \ Base \ Iface $ orderBaseItem ) { $ map = [ ] ; $ manager = \ Aimeos \ MShop :: create ( $ this -> getContext ( ) , 'order/base/product/attribute' ) ; foreach ( $ orderBaseItem -> getProducts ( ) as $ pos => $ orderProductItem ) { if ( $ orderProductItem -> getType ( ) === 'voucher' && $ orderProductItem -> getAttribute ( 'coupon-code' , 'coupon' ) === null ) { $ codes = [ ] ; for ( $ i = 0 ; $ i < $ orderProductItem -> getQuantity ( ) ; $ i ++ ) { $ str = $ i . getmypid ( ) . microtime ( true ) . $ orderProductItem -> getId ( ) ; $ code = substr ( strtoupper ( sha1 ( $ str ) ) , - 8 ) ; $ map [ $ code ] = $ orderProductItem -> getId ( ) ; $ codes [ ] = $ code ; } $ item = $ manager -> createItem ( ) -> setCode ( 'coupon-code' ) -> setType ( 'coupon' ) -> setValue ( $ codes ) ; $ orderBaseItem -> addProduct ( $ orderProductItem -> setAttributeItem ( $ item ) , $ pos ) ; } } $ this -> addCouponCodes ( $ map ) ; return $ orderBaseItem ; } | Creates coupon codes for the bought vouchers |
41,222 | protected function sendEmails ( \ Aimeos \ MShop \ Order \ Item \ Base \ Iface $ orderBaseItem , \ Aimeos \ Client \ Html \ Iface $ client ) { $ context = $ this -> getContext ( ) ; $ addrItem = $ this -> getAddressItem ( $ orderBaseItem ) ; $ currencyId = $ orderBaseItem -> getPrice ( ) -> getCurrencyId ( ) ; $ langId = ( $ addrItem -> getLanguageId ( ) ? : $ orderBaseItem -> getLocale ( ) -> getLanguageId ( ) ) ; $ view = $ this -> getView ( $ context , $ orderBaseItem -> getSiteCode ( ) , $ currencyId , $ langId ) ; foreach ( $ orderBaseItem -> getProducts ( ) as $ orderProductItem ) { if ( $ orderProductItem -> getType ( ) === 'voucher' && ( $ codes = $ orderProductItem -> getAttribute ( 'coupon-code' , 'coupon' ) ) !== null ) { foreach ( ( array ) $ codes as $ code ) { $ message = $ context -> getMail ( ) -> createMessage ( ) ; $ view -> addHelper ( 'mail' , new \ Aimeos \ MW \ View \ Helper \ Mail \ Standard ( $ view , $ message ) ) ; $ view -> extOrderProductItem = $ orderProductItem ; $ view -> extAddressItem = $ addrItem ; $ view -> extVoucherCode = $ code ; $ client -> setView ( $ view ) ; $ client -> getHeader ( ) ; $ client -> getBody ( ) ; $ context -> getMail ( ) -> send ( $ view -> mail ( ) ) ; } } } } | Sends the voucher related e - mail for a single order |
41,223 | protected function deleteItems ( \ Aimeos \ MW \ View \ Iface $ view , array $ ids ) { $ cntl = \ Aimeos \ Controller \ Frontend :: create ( $ this -> getContext ( ) , 'customer' ) ; $ item = $ cntl -> uses ( [ 'product' => [ 'watch' ] ] ) -> get ( ) ; foreach ( $ ids as $ id ) { if ( ( $ listItem = $ item -> getListItem ( 'product' , 'watch' , $ id ) ) !== null ) { $ cntl -> deleteListItem ( 'product' , $ listItem ) ; } } $ cntl -> store ( ) ; } | Removes the referencing list items from the given item |
41,224 | protected function editItems ( \ Aimeos \ MW \ View \ Iface $ view , array $ ids ) { $ context = $ this -> getContext ( ) ; $ cntl = \ Aimeos \ Controller \ Frontend :: create ( $ context , 'customer' ) ; $ item = $ cntl -> uses ( [ 'product' => [ 'watch' ] ] ) -> get ( ) ; $ config = [ 'timeframe' => $ view -> param ( 'wat_timeframe' , 7 ) , 'pricevalue' => $ view -> param ( 'wat_pricevalue' , '0.00' ) , 'price' => $ view -> param ( 'wat_price' , 0 ) , 'stock' => $ view -> param ( 'wat_stock' , 0 ) , 'currency' => $ context -> getLocale ( ) -> getCurrencyId ( ) , ] ; foreach ( $ ids as $ id ) { if ( ( $ listItem = $ item -> getListItem ( 'product' , 'watch' , $ id ) ) !== null ) { $ time = time ( ) + ( $ config [ 'timeframe' ] + 1 ) * 86400 ; $ listItem = $ listItem -> setDateEnd ( date ( 'Y-m-d 00:00:00' , $ time ) ) -> setConfig ( $ config ) ; $ cntl -> addListItem ( 'product' , $ listItem ) ; } } $ cntl -> store ( ) ; } | Updates the item using the given reference IDs |
41,225 | protected function addFavorites ( array $ ids ) { $ context = $ this -> getContext ( ) ; $ max = $ context -> getConfig ( ) -> get ( 'client/html/account/favorite/standard/maxitems' , 100 ) ; $ cntl = \ Aimeos \ Controller \ Frontend :: create ( $ context , 'customer' ) ; $ item = $ cntl -> uses ( [ 'product' => [ 'favorite' ] ] ) -> get ( ) ; if ( count ( $ item -> getRefItems ( 'product' , null , 'favorite' ) ) + count ( $ ids ) > $ max ) { $ msg = sprintf ( $ context -> getI18n ( ) -> dt ( 'client' , 'You can only save up to %1$s products as favorites' ) , $ max ) ; throw new \ Aimeos \ Client \ Html \ Exception ( $ msg ) ; } foreach ( $ ids as $ id ) { if ( ( $ listItem = $ item -> getListItem ( 'product' , 'favorite' , $ id ) ) === null ) { $ listItem = $ cntl -> createListItem ( ) ; } $ cntl -> addListItem ( 'product' , $ listItem -> setType ( 'favorite' ) -> setRefId ( $ id ) ) ; } $ cntl -> store ( ) ; } | Adds new product favorite references to the given customer |
41,226 | protected function deleteFavorites ( array $ ids ) { $ cntl = \ Aimeos \ Controller \ Frontend :: create ( $ this -> getContext ( ) , 'customer' ) ; $ item = $ cntl -> uses ( [ 'product' => [ 'favorite' ] ] ) -> get ( ) ; foreach ( $ ids as $ id ) { if ( ( $ listItem = $ item -> getListItem ( 'product' , 'favorite' , $ id ) ) !== null ) { $ cntl -> deleteListItem ( 'product' , $ listItem ) ; } } $ cntl -> store ( ) ; } | Removes product favorite references from the customer |
41,227 | protected function getProductListPage ( \ Aimeos \ MW \ View \ Iface $ view ) { $ page = ( int ) $ view -> param ( 'fav_page' , 1 ) ; return ( $ page < 1 ? 1 : $ page ) ; } | Returns the sanitized page from the parameters for the product list . |
41,228 | protected function getStockItems ( array $ productCodes ) { $ context = $ this -> getContext ( ) ; $ sort = $ context -> getConfig ( ) -> get ( 'client/html/catalog/stock/sort' , 'stock.type' ) ; $ type = $ context -> getLocale ( ) -> getSite ( ) -> getConfigValue ( 'stocktype' ) ; return \ Aimeos \ Controller \ Frontend :: create ( $ context , 'stock' ) -> code ( $ productCodes ) -> type ( $ type ) -> sort ( $ sort ) -> slice ( 0 , count ( $ productCodes ) ) -> search ( ) ; } | Returns the list of stock items for the given product codes and the stock type |
41,229 | protected function getUrlConfirm ( \ Aimeos \ MW \ View \ Iface $ view , array $ params , array $ config ) { $ target = $ view -> config ( 'client/html/checkout/confirm/url/target' ) ; $ cntl = $ view -> config ( 'client/html/checkout/confirm/url/controller' , 'checkout' ) ; $ action = $ view -> config ( 'client/html/checkout/confirm/url/action' , 'confirm' ) ; $ config = $ view -> config ( 'client/html/checkout/confirm/url/config' , $ config ) ; return $ view -> url ( $ target , $ cntl , $ action , $ params , [ ] , $ config ) ; } | Returns the URL to the confirm page . |
41,230 | public function preUpdate ( PreUpdateEventArgs $ args ) { $ reflectionClass = new ReflectionClass ( $ args -> getEntity ( ) ) ; $ properties = $ reflectionClass -> getProperties ( ) ; foreach ( $ properties as $ refProperty ) { if ( $ this -> annReader -> getPropertyAnnotation ( $ refProperty , self :: ENCRYPTED_ANN_NAME ) ) { $ propName = $ refProperty -> getName ( ) ; $ args -> setNewValue ( $ propName , $ this -> encryptor -> encrypt ( $ args -> getNewValue ( $ propName ) ) ) ; } } } | Listen a preUpdate lifecycle event . Checking and encrypt entities fields which have |
41,231 | public function postLoad ( LifecycleEventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; if ( ! $ this -> hasInDecodedRegistry ( $ entity , $ args -> getEntityManager ( ) ) ) { if ( $ this -> processFields ( $ entity , false ) ) { $ this -> addToDecodedRegistry ( $ entity , $ args -> getEntityManager ( ) ) ; } } } | Listen a postLoad lifecycle event . Checking and decrypt entities which have |
41,232 | private function encryptorFactory ( $ classFullName , $ secretKey ) { $ refClass = new \ ReflectionClass ( $ classFullName ) ; if ( $ refClass -> implementsInterface ( self :: ENCRYPTOR_INTERFACE_NS ) ) { return new $ classFullName ( $ secretKey ) ; } else { throw new \ RuntimeException ( 'Encryptor must implements interface EncryptorInterface' ) ; } } | Encryptor factory . Checks and create needed encryptor |
41,233 | private function hasInDecodedRegistry ( $ entity , EntityManager $ em ) { $ className = get_class ( $ entity ) ; $ metadata = $ em -> getClassMetadata ( $ className ) ; $ getter = 'get' . self :: capitalize ( $ metadata -> getIdentifier ( ) ) ; return isset ( $ this -> decodedRegistry [ $ className ] [ $ entity -> $ getter ( ) ] ) ; } | Check if we have entity in decoded registry |
41,234 | private function addToDecodedRegistry ( $ entity , EntityManager $ em ) { $ className = get_class ( $ entity ) ; $ metadata = $ em -> getClassMetadata ( $ className ) ; $ getter = 'get' . self :: capitalize ( $ metadata -> getIdentifier ( ) ) ; $ this -> decodedRegistry [ $ className ] [ $ entity -> $ getter ( ) ] = true ; } | Adds entity to decoded registry |
41,235 | public function login ( $ username , $ accessKey ) { if ( $ this -> passChallenge ( $ username ) === false ) { return false ; } $ postdata = [ 'operation' => 'login' , 'username' => $ username , 'accessKey' => md5 ( $ this -> serviceToken . $ accessKey ) ] ; $ result = $ this -> sendHttpRequest ( $ postdata ) ; if ( ! is_array ( $ result ) || empty ( $ result ) ) { return false ; } $ this -> userName = $ username ; $ this -> accessKey = $ accessKey ; $ this -> sessionName = $ result [ 'sessionName' ] ; $ this -> userID = $ result [ 'userId' ] ; $ this -> vtigerApiVersion = $ result [ 'version' ] ; $ this -> vtigerVersion = $ result [ 'vtigerVersion' ] ; return true ; } | Login to the server using username and VTiger access key token |
41,236 | private function passChallenge ( $ username ) { $ getdata = [ 'operation' => 'getchallenge' , 'username' => $ username ] ; $ result = $ this -> sendHttpRequest ( $ getdata , 'GET' ) ; if ( ! is_array ( $ result ) || ! isset ( $ result [ 'token' ] ) ) { return false ; } $ this -> serviceExpireTime = $ result [ 'expireTime' ] ; $ this -> serviceToken = $ result [ 'token' ] ; return true ; } | Gets a challenge token from the server and stores for future requests |
41,237 | public function sendHttpRequest ( array $ requestData , $ method = 'POST' ) { if ( 'getchallenge' !== $ requestData [ 'operation' ] && time ( ) > $ this -> serviceExpireTime ) { $ this -> login ( $ this -> userName , $ this -> accessKey ) ; } $ requestData [ 'sessionName' ] = $ this -> sessionName ; try { switch ( $ method ) { case 'GET' : $ response = $ this -> httpClient -> get ( $ this -> wsBaseURL , [ 'query' => $ requestData , 'timeout' => $ this -> requestTimeout ] ) ; break ; case 'POST' : $ response = $ this -> httpClient -> post ( $ this -> wsBaseURL , [ 'form_params' => $ requestData , 'timeout' => $ this -> requestTimeout ] ) ; break ; default : throw new WSException ( "Unsupported request type {$method}" ) ; } } catch ( RequestException $ ex ) { $ urlFailed = $ this -> httpClient -> getConfig ( 'base_uri' ) . $ this -> wsBaseURL ; throw new WSException ( sprintf ( 'Failed to execute %s call on "%s" URL' , $ method , $ urlFailed ) , 'FAILED_SENDING_REQUEST' , $ ex ) ; } $ jsonRaw = $ response -> getBody ( ) ; $ jsonObj = json_decode ( $ jsonRaw , true ) ; $ result = ( is_array ( $ jsonObj ) && ! self :: checkForError ( $ jsonObj ) ) ? $ jsonObj [ 'result' ] : null ; return $ result ; } | Sends HTTP request to VTiger web service API endpoint |
41,238 | private static function fixVtigerBaseUrl ( $ baseUrl ) { if ( ! preg_match ( '/^https?:\/\//i' , $ baseUrl ) ) { $ baseUrl = sprintf ( 'http://%s' , $ baseUrl ) ; } if ( strripos ( $ baseUrl , '/' ) !== strlen ( $ baseUrl ) - 1 ) { $ baseUrl .= '/' ; } return $ baseUrl ; } | Cleans and fixes vTiger URL |
41,239 | private static function checkForError ( array $ jsonResult ) { if ( isset ( $ jsonResult [ 'success' ] ) && true === ( bool ) $ jsonResult [ 'success' ] ) { return false ; } if ( isset ( $ jsonResult [ 'error' ] ) ) { $ error = $ jsonResult [ 'error' ] ; throw new WSException ( $ error [ 'message' ] , $ error [ 'code' ] ) ; } throw new WSException ( 'Unknown error' ) ; } | Check if server response contains an error therefore the requested operation has failed |
41,240 | public function findOneByID ( $ moduleName , $ entityID , array $ select = [ ] ) { $ entityID = $ this -> wsClient -> modules -> getTypedID ( $ moduleName , $ entityID ) ; $ record = $ this -> wsClient -> invokeOperation ( 'retrieve' , [ 'id' => $ entityID ] , 'GET' ) ; if ( ! is_array ( $ record ) ) { return null ; } return ( empty ( $ select ) ) ? $ record : array_intersect_key ( $ record , array_flip ( $ select ) ) ; } | Retrieves an entity by ID |
41,241 | public function findOne ( $ moduleName , array $ params , array $ select = [ ] ) { $ entityID = $ this -> getID ( $ moduleName , $ params ) ; return ( empty ( $ entityID ) ) ? null : $ this -> findOneByID ( $ moduleName , $ entityID , $ select ) ; } | Retrieve the entity matching a list of constraints |
41,242 | public function getNumericID ( $ moduleName , array $ params ) { $ entityID = $ this -> getID ( $ moduleName , $ params ) ; $ entityIDParts = explode ( 'x' , $ entityID , 2 ) ; return ( is_array ( $ entityIDParts ) && count ( $ entityIDParts ) === 2 ) ? intval ( $ entityIDParts [ 1 ] ) : - 1 ; } | Retrieve a numeric ID of the entity matching a list of constraints |
41,243 | public function createOne ( $ moduleName , array $ params ) { if ( ! is_assoc_array ( $ params ) ) { throw new WSException ( "You have to specify at least one search parameter (prop => value) in order to be able to create an entity" ) ; } if ( ! isset ( $ params [ 'assigned_user_id' ] ) ) { $ currentUser = $ this -> wsClient -> getCurrentUser ( ) ; $ params [ 'assigned_user_id' ] = $ currentUser [ 'id' ] ; } $ requestData = [ 'elementType' => $ moduleName , 'element' => json_encode ( $ params ) ] ; return $ this -> wsClient -> invokeOperation ( 'create' , $ requestData ) ; } | Creates an entity for the giving module |
41,244 | public function deleteOne ( $ moduleName , $ entityID ) { $ entityID = $ this -> wsClient -> modules -> getTypedID ( $ moduleName , $ entityID ) ; return $ this -> wsClient -> invokeOperation ( 'delete' , [ 'id' => $ entityID ] ) ; } | Provides entity removal functionality |
41,245 | public function findMany ( $ moduleName , array $ params , array $ select = [ ] , $ limit = 0 , $ offset = 0 ) { if ( ! is_array ( $ params ) || ( ! empty ( $ params ) && ! is_assoc_array ( $ params ) ) ) { throw new WSException ( "You have to specify at least one search parameter (prop => value) in order to be able to retrieve entity(ies)" ) ; } $ query = self :: getQueryString ( $ moduleName , $ params , $ select , $ limit , $ offset ) ; $ records = $ this -> wsClient -> runQuery ( $ query ) ; if ( false === $ records || ! is_array ( $ records ) || empty ( $ records ) ) { return null ; } return $ records ; } | Retrieves multiple records using module name and a set of constraints |
41,246 | public function sync ( $ modifiedTime = null , $ moduleName = null , $ syncType = null ) { $ modifiedTime = ( empty ( $ modifiedTime ) ) ? strtotime ( 'today midnight' ) : intval ( $ modifiedTime ) ; $ requestData = [ 'modifiedTime' => $ modifiedTime ] ; if ( ! empty ( $ moduleName ) ) { $ requestData [ 'elementType' ] = $ moduleName ; } if ( $ syncType ) { $ requestData [ 'syncType' ] = $ syncType ; } return $ this -> wsClient -> invokeOperation ( 'sync' , $ requestData , 'GET' ) ; } | Sync will return a sync result object containing details of changes after modifiedTime |
41,247 | public static function getQueryString ( $ moduleName , array $ params , array $ select = [ ] , $ limit = 0 , $ offset = 0 ) { $ criteria = array ( ) ; $ select = ( empty ( $ select ) ) ? '*' : implode ( ',' , $ select ) ; $ query = sprintf ( "SELECT %s FROM $moduleName" , $ select ) ; if ( ! empty ( $ params ) ) { foreach ( $ params as $ param => $ value ) { $ criteria [ ] = "{$param} LIKE '{$value}'" ; } $ query .= sprintf ( ' WHERE %s' , implode ( " AND " , $ criteria ) ) ; } if ( intval ( $ limit ) > 0 ) { $ query .= ( intval ( $ offset ) > 0 ) ? sprintf ( " LIMIT %s, %s" , intval ( $ offset ) , intval ( $ limit ) ) : sprintf ( " LIMIT %s" , intval ( $ limit ) ) ; } return $ query ; } | Builds the query using the supplied parameters |
41,248 | public function runQuery ( $ query ) { $ query = ( strripos ( $ query , ';' ) != strlen ( $ query ) - 1 ) ? trim ( $ query .= ';' ) : trim ( $ query ) ; return $ this -> invokeOperation ( 'query' , [ 'query' => $ query ] , 'GET' ) ; } | VTiger provides a simple query language for fetching data . This language is quite similar to select queries in SQL . There are limitations the queries work on a single Module embedded queries are not supported and does not support joins . But this is still a powerful way of getting data from Vtiger . Query always limits its output to 100 records Client application can use limit operator to get different records . |
41,249 | public function getAll ( ) { $ result = $ this -> wsClient -> invokeOperation ( 'listtypes' , [ ] , 'GET' ) ; $ modules = $ result [ 'types' ] ; $ result = array ( ) ; foreach ( $ modules as $ moduleName ) { $ result [ $ moduleName ] = [ 'name' => $ moduleName ] ; } return $ result ; } | Lists all the Vtiger entity types available through the API |
41,250 | private function getAllProperties ( ) { $ allProperties = get_object_vars ( $ this ) ; $ properties = array ( ) ; foreach ( $ allProperties as $ fullName => $ value ) { $ fullNameComponents = explode ( "\0" , $ fullName ) ; $ propertyName = array_pop ( $ fullNameComponents ) ; if ( $ propertyName && isset ( $ value ) ) { $ properties [ $ propertyName ] = $ value ; } } return $ properties ; } | Gets all the properties of the object |
41,251 | private function setVendorConfig ( ) { $ config_key = 'imap' ; $ path = __DIR__ . '/../../config/' . $ config_key . '.php' ; $ vendor_config = require $ path ; $ config = $ this -> app [ 'config' ] -> get ( $ config_key , [ ] ) ; $ this -> app [ 'config' ] -> set ( $ config_key , $ this -> array_merge_recursive_distinct ( $ vendor_config , $ config ) ) ; $ config = $ this -> app [ 'config' ] -> get ( $ config_key ) ; if ( is_array ( $ config ) ) { if ( isset ( $ config [ 'default' ] ) ) { if ( isset ( $ config [ 'accounts' ] ) && $ config [ 'default' ] != false ) { $ default_config = $ vendor_config [ 'accounts' ] [ 'default' ] ; if ( isset ( $ config [ 'accounts' ] [ $ config [ 'default' ] ] ) ) { $ default_config = array_merge ( $ default_config , $ config [ 'accounts' ] [ $ config [ 'default' ] ] ) ; } if ( is_array ( $ config [ 'accounts' ] ) ) { foreach ( $ config [ 'accounts' ] as $ account_key => $ account ) { $ config [ 'accounts' ] [ $ account_key ] = array_merge ( $ default_config , $ account ) ; } } } } } $ this -> app [ 'config' ] -> set ( $ config_key , $ config ) ; } | Merge the vendor settings with the local config |
41,252 | private function array_merge_recursive_distinct ( ) { $ arrays = func_get_args ( ) ; $ base = array_shift ( $ arrays ) ; if ( ! is_array ( $ base ) ) $ base = empty ( $ base ) ? array ( ) : array ( $ base ) ; foreach ( $ arrays as $ append ) { if ( ! is_array ( $ append ) ) $ append = array ( $ append ) ; foreach ( $ append as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ base ) and ! is_numeric ( $ key ) ) { $ base [ $ key ] = $ append [ $ key ] ; continue ; } if ( is_array ( $ value ) or is_array ( $ base [ $ key ] ) ) { $ base [ $ key ] = $ this -> array_merge_recursive_distinct ( $ base [ $ key ] , $ append [ $ key ] ) ; } else if ( is_numeric ( $ key ) ) { if ( ! in_array ( $ value , $ base ) ) $ base [ ] = $ value ; } else { $ base [ $ key ] = $ value ; } } } return $ base ; } | Marge arrays recursively and distinct |
41,253 | public function setConfig ( array $ config ) { $ default_account = config ( 'imap.default' ) ; $ default_config = config ( "imap.accounts.$default_account" ) ; foreach ( $ this -> valid_config_keys as $ key ) { $ this -> $ key = isset ( $ config [ $ key ] ) ? $ config [ $ key ] : $ default_config [ $ key ] ; } return $ this ; } | Set the Client configuration |
41,254 | public function disconnect ( ) { if ( $ this -> isConnected ( ) && $ this -> connection !== false && is_integer ( $ this -> connection ) === false ) { $ this -> errors = array_merge ( $ this -> errors , imap_errors ( ) ? : [ ] ) ; $ this -> connected = ! imap_close ( $ this -> connection , IMAP :: CL_EXPUNGE ) ; } return $ this ; } | Disconnect from server . |
41,255 | public function getFolders ( $ hierarchical = true , $ parent_folder = null ) { $ this -> checkConnection ( ) ; $ folders = FolderCollection :: make ( [ ] ) ; $ pattern = $ parent_folder . ( $ hierarchical ? '%' : '*' ) ; $ items = imap_getmailboxes ( $ this -> connection , $ this -> getAddress ( ) , $ pattern ) ; if ( is_array ( $ items ) ) { foreach ( $ items as $ item ) { $ folder = new Folder ( $ this , $ item ) ; if ( $ hierarchical && $ folder -> hasChildren ( ) ) { $ pattern = $ folder -> full_name . $ folder -> delimiter . '%' ; $ children = $ this -> getFolders ( true , $ pattern ) ; $ folder -> setChildren ( $ children ) ; } $ folders -> push ( $ folder ) ; } return $ folders ; } else { throw new MailboxFetchingException ( $ this -> getLastError ( ) ) ; } } | Get folders list . If hierarchical order is set to true it will make a tree of folders otherwise it will return flat array . |
41,256 | public function openFolder ( $ folder_path , $ attempts = 3 ) { $ this -> checkConnection ( ) ; if ( property_exists ( $ folder_path , 'path' ) ) { $ folder_path = $ folder_path -> path ; } if ( $ this -> active_folder !== $ folder_path ) { $ this -> active_folder = $ folder_path ; imap_reopen ( $ this -> getConnection ( ) , $ folder_path , $ this -> getOptions ( ) , $ attempts ) ; } } | Open folder . |
41,257 | public function getMessages ( Folder $ folder , $ criteria = 'ALL' , $ fetch_options = null , $ fetch_body = true , $ fetch_attachment = true , $ fetch_flags = false ) { return $ folder -> getMessages ( $ criteria , $ fetch_options , $ fetch_body , $ fetch_attachment , $ fetch_flags ) ; } | Get messages from folder . |
41,258 | protected function getAddress ( ) { $ address = "{" . $ this -> host . ":" . $ this -> port . "/" . ( $ this -> protocol ? $ this -> protocol : 'imap' ) ; if ( ! $ this -> validate_cert ) { $ address .= '/novalidate-cert' ; } if ( in_array ( $ this -> encryption , [ 'tls' , 'ssl' ] ) ) { $ address .= '/' . $ this -> encryption ; } $ address .= '}' ; return $ address ; } | Get full address of mailbox . |
41,259 | public function getMessage ( $ uid , $ msglist = null , $ fetch_options = null , $ fetch_body = false , $ fetch_attachment = false , $ fetch_flags = true ) { $ this -> client -> openFolder ( $ this -> path ) ; if ( imap_msgno ( $ this -> getClient ( ) -> getConnection ( ) , $ uid ) > 0 ) { return new Message ( $ uid , $ msglist , $ this -> getClient ( ) , $ fetch_options , $ fetch_body , $ fetch_attachment , $ fetch_flags ) ; } return null ; } | Get a specific message by UID |
41,260 | public function getUnseenMessages ( $ criteria = 'UNSEEN' , $ fetch_options = null , $ fetch_body = true , $ fetch_attachment = true , $ fetch_flags = true , $ limit = null , $ page = 1 , $ charset = "UTF-8" ) { return $ this -> getMessages ( $ criteria , $ fetch_options , $ fetch_body , $ fetch_attachment , $ fetch_flags , $ limit , $ page , $ charset ) ; } | Get all unseen messages |
41,261 | protected function parseAttributes ( $ attributes ) { $ this -> no_inferiors = ( $ attributes & LATT_NOINFERIORS ) ? true : false ; $ this -> no_select = ( $ attributes & LATT_NOSELECT ) ? true : false ; $ this -> marked = ( $ attributes & LATT_MARKED ) ? true : false ; $ this -> referal = ( $ attributes & LATT_REFERRAL ) ? true : false ; $ this -> has_children = ( $ attributes & LATT_HASCHILDREN ) ? true : false ; } | Parse attributes and set it to object properties . |
41,262 | public function move ( $ target_mailbox , $ expunge = true ) { $ status = imap_renamemailbox ( $ this -> client -> getConnection ( ) , $ this -> path , $ target_mailbox ) ; if ( $ expunge ) $ this -> client -> expunge ( ) ; return $ status ; } | Move or Rename the current Mailbox |
41,263 | public function appendMessage ( $ message , $ options = null , $ internal_date = null ) { return imap_append ( $ this -> client -> getConnection ( ) , $ this -> path , $ message , $ options , $ internal_date ) ; } | Append a string message to the current mailbox |
41,264 | public function copy ( $ mailbox , $ options = 0 ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; return imap_mail_copy ( $ this -> client -> getConnection ( ) , $ this -> msglist , $ mailbox , $ options ) ; } | Copy the current Messages to a mailbox |
41,265 | public function move ( $ mailbox , $ options = 0 ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; return imap_mail_move ( $ this -> client -> getConnection ( ) , $ this -> msglist , $ mailbox , $ options ) ; } | Move the current Messages to a mailbox |
41,266 | private function parseHeader ( ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; $ this -> header = $ header = imap_fetchheader ( $ this -> client -> getConnection ( ) , $ this -> uid , IMAP :: FT_UID ) ; $ this -> priority = $ this -> extractPriority ( $ this -> header ) ; if ( $ this -> header ) { $ header = imap_rfc822_parse_headers ( $ this -> header ) ; } if ( property_exists ( $ header , 'subject' ) ) { if ( $ this -> config [ 'decoder' ] [ 'message' ] [ 'subject' ] === 'utf-8' ) { $ this -> subject = imap_utf8 ( $ header -> subject ) ; } else { $ this -> subject = mb_decode_mimeheader ( $ header -> subject ) ; } } foreach ( [ 'from' , 'to' , 'cc' , 'bcc' , 'reply_to' , 'sender' ] as $ part ) { $ this -> extractHeaderAddressPart ( $ header , $ part ) ; } if ( property_exists ( $ header , 'references' ) ) { $ this -> references = $ header -> references ; } if ( property_exists ( $ header , 'in_reply_to' ) ) { $ this -> in_reply_to = str_replace ( [ '<' , '>' ] , '' , $ header -> in_reply_to ) ; } if ( property_exists ( $ header , 'message_id' ) ) { $ this -> message_id = str_replace ( [ '<' , '>' ] , '' , $ header -> message_id ) ; } if ( property_exists ( $ header , 'Msgno' ) ) { $ messageNo = ( int ) trim ( $ header -> Msgno ) ; $ this -> message_no = ( $ this -> fetch_options == IMAP :: FT_UID ) ? $ messageNo : imap_msgno ( $ this -> client -> getConnection ( ) , $ messageNo ) ; } else { $ this -> message_no = imap_msgno ( $ this -> client -> getConnection ( ) , $ this -> getUid ( ) ) ; } $ this -> date = $ this -> parseDate ( $ header ) ; } | Parse all defined headers |
41,267 | private function parseDate ( $ header ) { $ parsed_date = null ; if ( property_exists ( $ header , 'date' ) ) { $ date = $ header -> date ; if ( preg_match ( '/\+0580/' , $ date ) ) { $ date = str_replace ( '+0580' , '+0530' , $ date ) ; } $ date = trim ( rtrim ( $ date ) ) ; try { $ parsed_date = Carbon :: parse ( $ date ) ; } catch ( \ Exception $ e ) { switch ( true ) { case preg_match ( '/([A-Z]{2,3}[\,|\ \,]\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}.*)+$/i' , $ date ) > 0 : case preg_match ( '/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i' , $ date ) > 0 : case preg_match ( '/([A-Z]{2,3}\, \ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i' , $ date ) > 0 : case preg_match ( '/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{2,4}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}\ [A-Z]{2}\ \-[0-9]{2}\:[0-9]{2}\ \([A-Z]{2,3}\ \-[0-9]{2}:[0-9]{2}\))+$/i' , $ date ) > 0 : $ array = explode ( '(' , $ date ) ; $ array = array_reverse ( $ array ) ; $ date = trim ( array_pop ( $ array ) ) ; break ; case preg_match ( '/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ UT)+$/i' , $ date ) > 0 : $ date .= 'C' ; break ; } try { $ parsed_date = Carbon :: parse ( $ date ) ; } catch ( \ Exception $ _e ) { throw new InvalidMessageDateException ( "Invalid message date. ID:" . $ this -> getMessageId ( ) , 1000 , $ e ) ; } } } return $ parsed_date ; } | Exception handling for invalid dates |
41,268 | private function parseFlags ( ) { $ this -> flags = FlagCollection :: make ( [ ] ) ; $ this -> client -> openFolder ( $ this -> folder_path ) ; $ flags = imap_fetch_overview ( $ this -> client -> getConnection ( ) , $ this -> uid , IMAP :: FT_UID ) ; if ( is_array ( $ flags ) && isset ( $ flags [ 0 ] ) ) { foreach ( $ this -> available_flags as $ flag ) { $ this -> parseFlag ( $ flags , $ flag ) ; } } } | Parse additional flags |
41,269 | private function parseFlag ( $ flags , $ flag ) { $ flag = strtolower ( $ flag ) ; if ( property_exists ( $ flags [ 0 ] , strtoupper ( $ flag ) ) ) { $ this -> flags -> put ( $ flag , $ flags [ 0 ] -> { strtoupper ( $ flag ) } ) ; } elseif ( property_exists ( $ flags [ 0 ] , ucfirst ( $ flag ) ) ) { $ this -> flags -> put ( $ flag , $ flags [ 0 ] -> { ucfirst ( $ flag ) } ) ; } elseif ( property_exists ( $ flags [ 0 ] , $ flag ) ) { $ this -> flags -> put ( $ flag , $ flags [ 0 ] -> $ flag ) ; } } | Extract a possible flag information from a given array |
41,270 | public function getHeaderInfo ( ) { if ( $ this -> header_info == null ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; $ this -> header_info = imap_headerinfo ( $ this -> client -> getConnection ( ) , $ this -> getMessageNo ( ) ) ; } return $ this -> header_info ; } | Get the current Message header info |
41,271 | private function extractHeaderAddressPart ( $ header , $ part ) { if ( property_exists ( $ header , $ part ) ) { $ this -> $ part = $ this -> parseAddresses ( $ header -> $ part ) ; } } | Extract a given part as address array from a given header |
41,272 | public function parseBody ( ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; $ this -> structure = imap_fetchstructure ( $ this -> client -> getConnection ( ) , $ this -> uid , IMAP :: FT_UID ) ; if ( property_exists ( $ this -> structure , 'parts' ) ) { $ parts = $ this -> structure -> parts ; foreach ( $ parts as $ part ) { foreach ( $ part -> parameters as $ parameter ) { if ( $ parameter -> attribute == "charset" ) { $ encoding = $ parameter -> value ; $ encoding = preg_replace ( '/Content-Transfer-Encoding/' , '' , $ encoding ) ; $ encoding = preg_replace ( '/iso-8859-8-i/' , 'iso-8859-8' , $ encoding ) ; $ parameter -> value = $ encoding ; } } } } $ this -> fetchStructure ( $ this -> structure ) ; return $ this ; } | Parse the Message body |
41,273 | private function fetchStructure ( $ structure , $ partNumber = null ) { $ this -> client -> openFolder ( $ this -> folder_path ) ; if ( $ structure -> type == IMAP :: MESSAGE_TYPE_TEXT && ( $ structure -> ifdisposition == 0 || ( $ structure -> ifdisposition == 1 && ! isset ( $ structure -> parts ) && $ partNumber == null ) ) ) { if ( $ structure -> subtype == "PLAIN" ) { if ( ! $ partNumber ) { $ partNumber = 1 ; } $ encoding = $ this -> getEncoding ( $ structure ) ; $ content = imap_fetchbody ( $ this -> client -> getConnection ( ) , $ this -> uid , $ partNumber , $ this -> fetch_options | IMAP :: FT_UID ) ; $ content = $ this -> decodeString ( $ content , $ structure -> encoding ) ; if ( $ encoding != 'us-ascii' ) { $ content = $ this -> convertEncoding ( $ content , $ encoding ) ; } $ body = new \ stdClass ; $ body -> type = "text" ; $ body -> content = $ content ; $ this -> bodies [ 'text' ] = $ body ; $ this -> fetchAttachment ( $ structure , $ partNumber ) ; } elseif ( $ structure -> subtype == "HTML" ) { if ( ! $ partNumber ) { $ partNumber = 1 ; } $ encoding = $ this -> getEncoding ( $ structure ) ; $ content = imap_fetchbody ( $ this -> client -> getConnection ( ) , $ this -> uid , $ partNumber , $ this -> fetch_options | IMAP :: FT_UID ) ; $ content = $ this -> decodeString ( $ content , $ structure -> encoding ) ; if ( $ encoding != 'us-ascii' ) { $ content = $ this -> convertEncoding ( $ content , $ encoding ) ; } $ body = new \ stdClass ; $ body -> type = "html" ; $ body -> content = $ content ; $ this -> bodies [ 'html' ] = $ body ; } } elseif ( $ structure -> type == IMAP :: MESSAGE_TYPE_MULTIPART ) { foreach ( $ structure -> parts as $ index => $ subStruct ) { $ prefix = "" ; if ( $ partNumber ) { $ prefix = $ partNumber . "." ; } $ this -> fetchStructure ( $ subStruct , $ prefix . ( $ index + 1 ) ) ; } } else { if ( $ this -> getFetchAttachmentOption ( ) === true ) { $ this -> fetchAttachment ( $ structure , $ partNumber ) ; } } } | Fetch the Message structure |
41,274 | protected function fetchAttachment ( $ structure , $ partNumber ) { $ oAttachment = new Attachment ( $ this , $ structure , $ partNumber ) ; if ( $ oAttachment -> getName ( ) !== null ) { if ( $ oAttachment -> getId ( ) !== null ) { $ this -> attachments -> put ( $ oAttachment -> getId ( ) , $ oAttachment ) ; } else { $ this -> attachments -> push ( $ oAttachment ) ; } } } | Fetch the Message attachment |
41,275 | public function decodeString ( $ string , $ encoding ) { switch ( $ encoding ) { case IMAP :: MESSAGE_ENC_7BIT : return $ string ; case IMAP :: MESSAGE_ENC_8BIT : return quoted_printable_decode ( imap_8bit ( $ string ) ) ; case IMAP :: MESSAGE_ENC_BINARY : return imap_binary ( $ string ) ; case IMAP :: MESSAGE_ENC_BASE64 : return imap_base64 ( $ string ) ; case IMAP :: MESSAGE_ENC_QUOTED_PRINTABLE : return quoted_printable_decode ( $ string ) ; case IMAP :: MESSAGE_ENC_OTHER : return $ string ; default : return $ string ; } } | Decode a given string |
41,276 | public function convertEncoding ( $ str , $ from = "ISO-8859-2" , $ to = "UTF-8" ) { $ from = EncodingAliases :: get ( $ from ) ; $ to = EncodingAliases :: get ( $ to ) ; if ( $ from === $ to ) { return $ str ; } if ( strtolower ( $ from ) == 'us-ascii' && $ to == 'UTF-8' ) { return $ str ; } if ( function_exists ( 'iconv' ) && $ from != 'UTF-7' && $ to != 'UTF-7' ) { return @ iconv ( $ from , $ to . '//IGNORE' , $ str ) ; } else { if ( ! $ from ) { return mb_convert_encoding ( $ str , $ to ) ; } return mb_convert_encoding ( $ str , $ to , $ from ) ; } } | Convert the encoding |
41,277 | public function getEncoding ( $ structure ) { if ( property_exists ( $ structure , 'parameters' ) ) { foreach ( $ structure -> parameters as $ parameter ) { if ( strtolower ( $ parameter -> attribute ) == "charset" ) { return EncodingAliases :: get ( $ parameter -> value ) ; } } } elseif ( is_string ( $ structure ) === true ) { return mb_detect_encoding ( $ structure ) ; } return 'UTF-8' ; } | Get the encoding of a given abject |
41,278 | public function is ( Message $ message = null ) { if ( is_null ( $ message ) ) { return false ; } return $ this -> uid == $ message -> uid && $ this -> message_id == $ message -> message_id && $ this -> subject == $ message -> subject && $ this -> date -> eq ( $ message -> date ) ; } | Does this message match another one? |
41,279 | public function paginate ( $ per_page = 15 , $ page = null , $ page_name = 'page' ) { $ page = $ page ? : Paginator :: resolveCurrentPage ( $ page_name ) ; $ results = ( $ total = $ this -> count ( ) ) ? $ this -> forPage ( $ page , $ per_page ) : $ this -> all ( ) ; return $ this -> paginator ( $ results , $ total , $ per_page , $ page , [ 'path' => Paginator :: resolveCurrentPath ( ) , 'pageName' => $ page_name , ] ) ; } | Paginate the current collection . |
41,280 | public function get ( ) { $ messages = MessageCollection :: make ( [ ] ) ; try { $ this -> generate_query ( ) ; if ( $ this -> getCharset ( ) === null ) { $ available_messages = imap_search ( $ this -> getClient ( ) -> getConnection ( ) , $ this -> getRawQuery ( ) , IMAP :: SE_UID ) ; } else { $ available_messages = imap_search ( $ this -> getClient ( ) -> getConnection ( ) , $ this -> getRawQuery ( ) , IMAP :: SE_UID , $ this -> getCharset ( ) ) ; } if ( $ available_messages !== false ) { $ available_messages = collect ( $ available_messages ) ; $ options = config ( 'imap.options' ) ; if ( strtolower ( $ options [ 'fetch_order' ] ) === 'desc' ) { $ available_messages = $ available_messages -> reverse ( ) ; } $ query = & $ this ; $ available_messages -> forPage ( $ this -> page , $ this -> limit ) -> each ( function ( $ msgno , $ msglist ) use ( & $ messages , $ options , $ query ) { $ oMessage = new Message ( $ msgno , $ msglist , $ query -> getClient ( ) , $ query -> getFetchOptions ( ) , $ query -> getFetchBody ( ) , $ query -> getFetchAttachment ( ) , $ query -> getFetchFlags ( ) ) ; switch ( $ options [ 'message_key' ] ) { case 'number' : $ message_key = $ oMessage -> getMessageNo ( ) ; break ; case 'list' : $ message_key = $ msglist ; break ; default : $ message_key = $ oMessage -> getMessageId ( ) ; break ; } $ messages -> put ( $ message_key , $ oMessage ) ; } ) ; } return $ messages ; } catch ( \ Exception $ e ) { throw new GetMessagesFailedException ( $ e -> getMessage ( ) ) ; } } | Fetch the current query and return all found messages |
41,281 | public function generate_query ( ) { $ query = '' ; $ this -> query -> each ( function ( $ statement ) use ( & $ query ) { if ( count ( $ statement ) == 1 ) { $ query .= $ statement [ 0 ] ; } else { if ( $ statement [ 1 ] === null ) { $ query .= $ statement [ 0 ] ; } else { $ query .= $ statement [ 0 ] . ' "' . $ statement [ 1 ] . '"' ; } } $ query .= ' ' ; } ) ; $ this -> raw_query = trim ( $ query ) ; return $ this -> raw_query ; } | Get the raw IMAP search query |
41,282 | protected function findType ( ) { switch ( $ this -> structure -> type ) { case IMAP :: ATTACHMENT_TYPE_MESSAGE : $ this -> type = 'message' ; break ; case IMAP :: ATTACHMENT_TYPE_APPLICATION : $ this -> type = 'application' ; break ; case IMAP :: ATTACHMENT_TYPE_AUDIO : $ this -> type = 'audio' ; break ; case IMAP :: ATTACHMENT_TYPE_IMAGE : $ this -> type = 'image' ; break ; case IMAP :: ATTACHMENT_TYPE_VIDEO : $ this -> type = 'video' ; break ; case IMAP :: ATTACHMENT_TYPE_MODEL : $ this -> type = 'model' ; break ; case IMAP :: ATTACHMENT_TYPE_TEXT : $ this -> type = 'text' ; break ; case IMAP :: ATTACHMENT_TYPE_MULTIPART : $ this -> type = 'multipart' ; break ; default : $ this -> type = 'other' ; break ; } } | Determine the structure type |
41,283 | protected function fetch ( ) { $ content = imap_fetchbody ( $ this -> oMessage -> getClient ( ) -> getConnection ( ) , $ this -> oMessage -> getUid ( ) , $ this -> part_number , $ this -> oMessage -> getFetchOptions ( ) | FT_UID ) ; $ this -> content_type = $ this -> type . '/' . strtolower ( $ this -> structure -> subtype ) ; $ this -> content = $ this -> oMessage -> decodeString ( $ content , $ this -> structure -> encoding ) ; if ( property_exists ( $ this -> structure , 'id' ) ) { $ this -> id = str_replace ( [ '<' , '>' ] , '' , $ this -> structure -> id ) ; } if ( property_exists ( $ this -> structure , 'dparameters' ) ) { foreach ( $ this -> structure -> dparameters as $ parameter ) { if ( strtolower ( $ parameter -> attribute ) == "filename" ) { $ this -> setName ( $ parameter -> value ) ; $ this -> disposition = property_exists ( $ this -> structure , 'disposition' ) ? $ this -> structure -> disposition : null ; break ; } } } if ( IMAP :: ATTACHMENT_TYPE_MESSAGE == $ this -> structure -> type ) { if ( $ this -> structure -> ifdescription ) { $ this -> setName ( $ this -> structure -> description ) ; } else { $ this -> setName ( $ this -> structure -> subtype ) ; } } if ( ! $ this -> name && property_exists ( $ this -> structure , 'parameters' ) ) { foreach ( $ this -> structure -> parameters as $ parameter ) { if ( strtolower ( $ parameter -> attribute ) == "name" ) { $ this -> setName ( $ parameter -> value ) ; $ this -> disposition = property_exists ( $ this -> structure , 'disposition' ) ? $ this -> structure -> disposition : null ; break ; } } } } | Fetch the given attachment |
41,284 | public function save ( $ path = null , $ filename = null ) { $ path = $ path ? : storage_path ( ) ; $ filename = $ filename ? : $ this -> getName ( ) ; $ path = substr ( $ path , - 1 ) == DIRECTORY_SEPARATOR ? $ path : $ path . DIRECTORY_SEPARATOR ; return File :: put ( $ path . $ filename , $ this -> getContent ( ) ) !== false ; } | Save the attachment content to your filesystem |
41,285 | public function account ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultAccount ( ) ; if ( ! isset ( $ this -> accounts [ $ name ] ) ) { $ this -> accounts [ $ name ] = $ this -> resolve ( $ name ) ; } return $ this -> accounts [ $ name ] ; } | Resolve a account instance . |
41,286 | public function getHtmlBody ( ) { $ bodies = $ this -> parent -> getBodies ( ) ; if ( ! isset ( $ bodies [ 'html' ] ) ) { return null ; } return $ bodies [ 'html' ] -> content ; } | Get the message html body |
41,287 | public function custom_save ( ) { $ path = storage_path ( 'foo' ) ; $ filename = $ this -> token ( ) ; $ path = substr ( $ path , - 1 ) == DIRECTORY_SEPARATOR ? $ path : $ path . DIRECTORY_SEPARATOR ; return \ Illuminate \ Support \ Facades \ File :: put ( $ path . $ filename , $ this -> getContent ( ) ) !== false ; } | Custom attachment saving method |
41,288 | public function getAll ( array $ filters = null ) { $ response = $ this -> mailjet -> get ( Resources :: $ Template , [ 'filters' => $ filters ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "TemplateService :getAll() failed" , $ response ) ; } return $ response -> getData ( ) ; } | List template resources available for this apikey use a GET request . Alternatively you may want to add one or more filters . |
41,289 | public function get ( $ id ) { $ response = $ this -> mailjet -> get ( Resources :: $ Template , [ 'id' => $ id ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "TemplateService:get() failed" , $ response ) ; } return $ response -> getData ( ) ; } | Access a given template resource use a GET request providing the template s ID value |
41,290 | public function update ( $ id , Template $ Template ) { $ response = $ this -> mailjet -> put ( Resources :: $ Template , [ 'id' => $ id , 'body' => $ Template -> format ( ) ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "TemplateService:update() failed" , $ response ) ; } return $ response -> getData ( ) ; } | Update one specific template resource with a PUT request providing the template s ID value |
41,291 | public function getDetailContent ( $ id ) { $ response = $ this -> mailjet -> get ( Resources :: $ TemplateDetailcontent , [ 'id' => $ id ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "TemplateService:getDetailContent failed" , $ response ) ; } return $ response -> getData ( ) ; } | Return the text and html contents of the Template |
41,292 | public function deleteDetailContent ( $ id ) { $ nullContent = null ; $ response = $ this -> mailjet -> post ( Resources :: $ TemplateDetailcontent , [ 'id' => $ id , 'body' => $ nullContent ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "TemplateService:createDetailContent failed" , $ response ) ; } return $ response -> getData ( ) ; } | Deletes the content of a Template |
41,293 | public function getAllLists ( $ filters ) { $ response = $ this -> client -> get ( Resources :: $ Contactslist , [ 'filters' => $ filters ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:getAllLists() failed" , $ response ) ; } return $ response ; } | Get all list on your mailjet account |
41,294 | public function createList ( $ body ) { $ response = $ this -> client -> post ( Resources :: $ Contactslist , [ 'body' => $ body ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:createList() failed" , $ response ) ; } return $ response ; } | Create a new list |
41,295 | public function getListRecipients ( $ filters ) { $ response = $ this -> client -> get ( Resources :: $ Listrecipient , [ 'filters' => $ filters ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:getListRecipients() failed" , $ response ) ; } return $ response ; } | Get all list recipient on your mailjet account |
41,296 | public function getSingleContact ( $ id ) { $ response = $ this -> client -> get ( Resources :: $ Contact , [ 'id' => $ id ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:getSingleContact() failed" , $ response ) ; } return $ response ; } | Get single contact informations . |
41,297 | public function createContact ( $ body ) { $ response = $ this -> client -> post ( Resources :: $ Contact , [ 'body' => $ body ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:createContact() failed" , $ response ) ; } return $ response ; } | create a contact |
41,298 | public function editListrecipient ( $ id , $ body ) { $ response = $ this -> client -> put ( Resources :: $ Listrecipient , [ 'id' => $ id , 'body' => $ body ] ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "MailjetService:editListrecipient() failed" , $ response ) ; } return $ response ; } | edit a list recipient |
41,299 | public function delete ( $ listId , Contact $ contact ) { $ contact -> setAction ( Contact :: ACTION_REMOVE ) ; $ response = $ this -> _exec ( $ listId , $ contact ) ; if ( ! $ response -> success ( ) ) { $ this -> throwError ( "ContactsListService:delete() failed" , $ response ) ; } return $ response -> getData ( ) ; } | Delete a Contact from listId |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.