idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
32,400 | protected function _getRootNode ( $ sort = '+' ) { $ search = $ this -> createSearch ( ) ; $ search -> setConditions ( $ search -> compare ( '==' , $ this -> _searchConfig [ 'level' ] [ 'code' ] , 0 ) ) ; $ search -> setSortations ( array ( $ search -> sort ( $ sort , $ this -> _searchConfig [ 'left' ] [ 'code' ] ) ) ) ; $ nodes = $ this -> searchNodes ( $ search ) ; if ( ( $ node = reset ( $ nodes ) ) !== false ) { return $ node ; } return null ; } | Returns the first tree root node depending on the sorting direction . |
32,401 | protected function _getSizeFitted ( $ srcWidth , $ srcHeight , $ destWidth , $ destHeight ) { $ destWidth = ( $ destWidth === null ? $ srcWidth : $ destWidth ) ; $ destHeight = ( $ destHeight === null ? $ srcHeight : $ destHeight ) ; $ wRatio = $ srcWidth / $ destWidth ; $ hRatio = $ srcHeight / $ destHeight ; if ( $ wRatio > $ hRatio ) { $ destHeight = round ( $ srcHeight / $ wRatio ) ; } else { $ destWidth = round ( $ srcWidth / $ hRatio ) ; } return array ( $ destWidth , $ destHeight ) ; } | Returns the fitted width and height . |
32,402 | protected function _createItem ( array $ entry ) { $ item = $ this -> _manager -> createItem ( ) ; foreach ( $ entry as $ name => $ value ) { switch ( $ name ) { case 'job.id' : $ item -> setId ( $ value ) ; break ; case 'job.label' : $ item -> setLabel ( $ value ) ; break ; case 'job.method' : $ item -> setMethod ( $ value ) ; break ; case 'job.status' : $ item -> setStatus ( $ value ) ; break ; case 'job.parameter' : if ( is_string ( $ value ) ) { $ item -> setParameter ( json_decode ( $ value , true ) ) ; } else { $ item -> setParameter ( ( array ) $ value ) ; } break ; case 'job.result' : if ( is_string ( $ value ) ) { $ item -> setResult ( json_decode ( $ value , true ) ) ; } else { $ item -> setResult ( ( array ) $ value ) ; } break ; } } return $ item ; } | Creates a new job item and sets the properties from the given array . |
32,403 | protected function removeHiddenAttributes ( $ instance , $ data ) { $ hidden = $ instance -> getHidden ( ) ; return array_diff_key ( $ data , array_flip ( $ hidden ) ) ; } | Remove model s hidden attributes . |
32,404 | protected function before ( $ key = null ) { if ( ! $ this -> before ) { $ this -> before = $ this -> parseData ( $ this -> activity -> before ) ; } if ( ! $ key ) { return array_keys ( $ this -> before ) ; } if ( ! isset ( $ this -> before [ $ key ] ) || $ this -> before [ $ key ] === '' ) { return null ; } return $ this -> before [ $ key ] ; } | Get the data before the activity . |
32,405 | protected function after ( $ key = null ) { if ( ! $ this -> after ) { $ this -> after = $ this -> parseData ( $ this -> activity -> after ) ; } if ( ! $ key ) { return array_keys ( $ this -> after ) ; } if ( ! isset ( $ this -> after [ $ key ] ) || $ this -> after [ $ key ] === '' ) { return null ; } return $ this -> after [ $ key ] ; } | Get the data after the activity . |
32,406 | protected function keys ( ) { if ( count ( $ this -> before ( ) ) > count ( $ this -> after ( ) ) ) { return $ this -> before ( ) ; } return $ this -> after ( ) ; } | Get diff keys . |
32,407 | public function diff ( ) { $ result = [ ] ; foreach ( $ this -> keys ( ) as $ key ) { if ( $ diff = $ this -> equal ( $ key ) ) { $ result [ ] = $ diff ; continue ; } if ( $ diff = $ this -> delete ( $ key ) ) { $ result [ ] = $ diff ; } if ( $ diff = $ this -> insert ( $ key ) ) { $ result [ ] = $ diff ; } } return $ result ; } | Get the diff for the model . |
32,408 | protected function equal ( $ key ) { if ( $ this -> before ( $ key ) !== $ this -> after ( $ key ) ) { return false ; } $ diff = [ 'key' => $ key , 'value' => $ this -> before ( $ key ) , 'type' => 'equal' , ] ; return ( object ) $ diff ; } | Get equal attribute object . |
32,409 | protected function delete ( $ key ) { if ( $ this -> before ( $ key ) === null || $ this -> before ( $ key ) === '' ) { return false ; } $ this -> differ -> setRenderer ( new Renderers \ Delete ) ; $ value = $ this -> after ( $ key ) ? $ this -> differ -> render ( $ this -> before ( $ key ) , $ this -> after ( $ key ) ) : $ this -> before ( $ key ) ; $ diff = [ 'key' => $ key , 'value' => $ value , 'type' => 'delete' , ] ; return ( object ) $ diff ; } | Get delete attribute object . |
32,410 | protected function insert ( $ key ) { if ( $ this -> after ( $ key ) === null || $ this -> after ( $ key ) === '' ) { return false ; } $ this -> differ -> setRenderer ( new Renderers \ Insert ) ; $ value = $ this -> before ( $ key ) ? $ this -> differ -> render ( $ this -> before ( $ key ) , $ this -> after ( $ key ) ) : $ this -> after ( $ key ) ; $ diff = [ 'key' => $ key , 'value' => $ value , 'type' => 'insert' , ] ; return ( object ) $ diff ; } | Get insert attribute object . |
32,411 | protected function granularity ( ) { $ granularity = $ this -> config ( 'diff.granularity' , $ this -> activity -> model_type ) ; switch ( $ granularity ) { case 'character' : return new \ cogpowered \ FineDiff \ Granularity \ Character ; case 'word' : return new \ cogpowered \ FineDiff \ Granularity \ Word ; case 'sentence' : return new \ cogpowered \ FineDiff \ Granularity \ Sentence ; case 'paragraph' : return new \ cogpowered \ FineDiff \ Granularity \ Paragraph ; } throw new InvalidArgumentException ( "The '$granularity' granularity is not valid." ) ; } | Get the granularity . |
32,412 | protected function _execute ( $ sql , $ name = 'db' ) { $ this -> _getConnection ( $ name ) -> create ( $ sql ) -> execute ( ) -> finish ( ) ; } | Executes a given SQL statement . |
32,413 | protected function _executeList ( array $ list , $ name = 'db' ) { $ conn = $ this -> _getConnection ( $ name ) ; foreach ( $ list as $ sql ) { $ conn -> create ( $ sql ) -> execute ( ) -> finish ( ) ; } } | Executes a list of given SQL statements . |
32,414 | protected function _getValue ( $ sql , $ column , $ name = 'db' ) { $ result = $ this -> _getConnection ( $ name ) -> create ( $ sql ) -> execute ( ) ; if ( ( $ row = $ result -> fetch ( ) ) === false ) { throw new MW_Setup_Exception ( sprintf ( 'No rows found: %1$s' , $ sql ) ) ; } if ( array_key_exists ( $ column , $ row ) === false ) { throw new MW_Setup_Exception ( sprintf ( 'No column "%1$s" found: %2$s' , $ column , $ sql ) ) ; } $ result -> finish ( ) ; return $ row [ $ column ] ; } | Executes a given SQL statement and returns the value of the named column and first row . |
32,415 | protected function _getConnection ( $ name ) { if ( ! isset ( $ this -> _connections [ $ name ] ) ) { return $ this -> _conn ; } return $ this -> _connections [ $ name ] ; } | Returns the connection specified by the given resource name . |
32,416 | protected function _getSchema ( $ name ) { if ( ! isset ( $ this -> _schemas [ $ name ] ) ) { return $ this -> _schema ; } return $ this -> _schemas [ $ name ] ; } | Returns the schemas specified by the given resource name . |
32,417 | protected function _msg ( $ msg , $ level = 0 ) { $ pre = '' ; for ( $ i = 0 ; $ i < 2 * $ level ; $ i ++ ) { $ pre .= ' ' ; } echo str_pad ( $ pre . $ msg , 70 ) ; } | Prints the message for the current test . |
32,418 | protected function _getTableDefinitions ( $ content ) { $ defs = array ( ) ; $ matches = array ( ) ; $ regex = '/CREATE TABLE \"?([a-zA-Z0-9_]+)\"? .*(\n\n|$)/sU' ; if ( preg_match_all ( $ regex , $ content , $ matches , PREG_SET_ORDER ) === false ) { throw new MW_Setup_Exception ( 'Unable to get table definitions' ) ; } foreach ( $ matches as $ match ) { $ defs [ $ match [ 1 ] ] = $ match [ 0 ] ; } return $ defs ; } | Extracts the table definitions from the given content . |
32,419 | protected function _getIndexDefinitions ( $ content ) { $ defs = array ( ) ; $ matches = array ( ) ; if ( preg_match_all ( '/CREATE [a-zA-Z]* ?INDEX \"?([a-zA-Z0-9_]+)\"? ON \"?([a-zA-Z0-9_]+)\"? .+(\n\n|$)/sU' , $ content , $ matches , PREG_SET_ORDER ) === false ) { throw new MW_Setup_Exception ( 'Unable to get index definitions' ) ; } foreach ( $ matches as $ match ) { $ name = $ match [ 2 ] . '.' . $ match [ 1 ] ; $ defs [ $ name ] = $ match [ 0 ] ; } return $ defs ; } | Extracts the index definitions from the given content . |
32,420 | public function fetchRow ( $ mode = null ) { $ spec = $ this -> getResult ( ) ; if ( $ mode === null ) { $ mode = $ this -> getResultMode ( ) ; } $ data = null ; switch ( $ mode ) { case self :: FETCH_ASSOC : $ data = $ spec -> fetch_assoc ( ) ; break ; case self :: FETCH_COLUMN : if ( ( $ row = $ spec -> fetch_row ( ) ) && is_array ( $ row ) ) { $ data = current ( $ row ) ; } else { $ data = null ; } break ; case self :: FETCH_NUM : $ data = $ spec -> fetch_row ( ) ; break ; case self :: FETCH_OBJECT : if ( null !== $ this -> resultClass ) { if ( null !== $ this -> resultParams ) { $ data = $ spec -> fetch_object ( $ this -> resultClass , $ this -> resultParams ) ; } else { $ data = $ spec -> fetch_object ( $ this -> resultClass ) ; } } else { $ data = $ spec -> fetch_object ( ) ; } break ; } $ this -> free ( ) ; return $ data ; } | Fetches a single result row |
32,421 | public function fetchColumn ( ) { $ spec = $ this -> getResult ( ) ; $ data = $ spec -> fetch_row ( ) ; if ( is_array ( $ data ) ) { $ data = current ( $ data ) ; } $ this -> free ( ) ; return $ data ; } | Returns a single value from the first result row . |
32,422 | public function getWhere ( $ key ) { foreach ( $ this -> where as $ w ) { if ( $ w [ 0 ] === $ key ) { return $ w [ 1 ] ; } } return null ; } | Get the specified where |
32,423 | protected function pushLimit ( ) { if ( null !== $ this -> limit ) { if ( null !== $ this -> offset ) { $ this -> parts [ ] = 'LIMIT ?, ?' ; $ this -> params [ ] = $ this -> offset ; $ this -> params [ ] = $ this -> limit ; } else { $ this -> parts [ ] = 'LIMIT ?' ; $ this -> params [ ] = $ this -> limit ; } } } | Push limit clause onto parts |
32,424 | protected function pushGroup ( ) { if ( $ this -> group ) { $ this -> parts [ ] = 'GROUP BY' ; $ this -> parts [ ] = $ this -> quoteIdentifierIfNotExpression ( $ this -> group ) ; } } | Push group by clause onto parts |
32,425 | protected function pushOrder ( ) { if ( $ this -> order ) { $ this -> parts [ ] = 'ORDER BY' ; $ this -> parts [ ] = $ this -> quoteIdentifierIfNotExpression ( $ this -> order ) ; $ this -> parts [ ] = $ this -> direction == self :: DESC ? self :: DESC : self :: ASC ; } } | Push order by clause onto parts |
32,426 | protected function pushWhere ( ) { if ( empty ( $ this -> where ) ) { return ; } $ this -> parts [ ] = 'WHERE' ; foreach ( $ this -> where as $ w ) { $ where = $ w [ 0 ] ; $ value = isset ( $ w [ 1 ] ) ? $ w [ 1 ] : null ; $ type = isset ( $ w [ 2 ] ) ? $ w [ 2 ] : null ; if ( $ where instanceof Expression ) { $ this -> parts [ ] = ( string ) $ where ; } else if ( count ( $ w ) == 3 ) { $ this -> parts [ ] = $ this -> quoteIdentifierIfNotExpression ( $ where ) ; $ this -> parts [ ] = $ type ; $ tmp = '' ; foreach ( $ value as $ val ) { $ tmp .= '?, ' ; $ this -> params [ ] = $ val ; } $ this -> parts [ ] = '(' . substr ( $ tmp , 0 , - 2 ) . ')' ; } else if ( false !== strpos ( $ where , '?' ) ) { $ this -> parts [ ] = $ where ; $ this -> params [ ] = $ value ; } else { $ this -> parts [ ] = $ this -> quoteIdentifierIfNotExpression ( $ where ) ; $ this -> parts [ ] = '=' ; if ( $ value instanceof Expression ) { $ this -> parts [ ] = ( string ) $ value ; } else { $ this -> parts [ ] = '?' ; $ this -> params [ ] = $ value ; } } $ this -> parts [ ] = '&&' ; } array_pop ( $ this -> parts ) ; } | Push where clause onto parts |
32,427 | public function whereIn ( $ where , $ value ) { if ( ! is_array ( $ value ) ) { $ value = ( array ) $ value ; } if ( count ( $ value ) <= 0 ) { $ this -> where [ ] = array ( new Expression ( 'FALSE' ) ) ; } else { $ this -> where [ ] = array ( $ where , $ value , 'IN' ) ; } return $ this ; } | Set where in |
32,428 | public function whereNotIn ( $ where , $ value ) { if ( ! is_array ( $ value ) ) { $ value = ( array ) $ value ; } if ( count ( $ value ) <= 0 ) { $ this -> where [ ] = array ( new Expression ( 'TRUE' ) ) ; } else { $ this -> where [ ] = array ( $ where , $ value , 'NOT IN' ) ; } return $ this ; } | Set where not in |
32,429 | public function store ( MShop_Order_Item_Base_Interface $ basket ) { $ context = $ this -> _getContext ( ) ; $ orderManager = MShop_Factory :: createManager ( $ context , 'order' ) ; $ orderBaseManager = MShop_Factory :: createManager ( $ context , 'order/base' ) ; $ orderBaseManager -> begin ( ) ; $ orderBaseManager -> store ( $ basket ) ; $ orderBaseManager -> commit ( ) ; $ orderItem = $ orderManager -> createItem ( ) ; $ orderItem -> setBaseId ( $ basket -> getId ( ) ) ; $ orderItem -> setType ( MShop_Order_Item_Abstract :: TYPE_WEB ) ; $ orderManager -> saveItem ( $ orderItem ) ; return $ orderItem ; } | Creates a new order from the given basket . |
32,430 | public function getHeader ( $ key = null ) { if ( is_null ( $ key ) ) { return $ this -> header ; } return isset ( $ this -> header [ $ key ] ) ? $ this -> header [ $ key ] : null ; } | Returns a specific header key |
32,431 | public function getPayload ( $ key = null ) { if ( is_null ( $ key ) ) { return $ this -> payload ; } return isset ( $ this -> payload [ $ key ] ) ? $ this -> payload [ $ key ] : null ; } | Returns a specific key |
32,432 | protected function _addPluginData ( MShop_Common_Manager_Interface $ pluginManager , array $ data ) { $ this -> _msg ( 'Adding data for MShop plugins' , 1 ) ; $ types = array ( ) ; $ manager = $ pluginManager -> getSubManager ( 'type' ) ; foreach ( $ manager -> searchItems ( $ manager -> createSearch ( ) ) as $ item ) { $ types [ 'plugin/' . $ item -> getCode ( ) ] = $ item ; } $ num = $ total = 0 ; $ item = $ pluginManager -> createItem ( ) ; foreach ( $ data as $ key => $ dataset ) { $ total ++ ; if ( ! isset ( $ types [ $ dataset [ 'typeid' ] ] ) ) { throw new Exception ( sprintf ( 'No plugin type "%1$s" found' , $ dataset [ 'typeid' ] ) ) ; } $ item -> setId ( null ) ; $ item -> setTypeId ( $ types [ $ dataset [ 'typeid' ] ] -> getId ( ) ) ; $ item -> setProvider ( $ dataset [ 'provider' ] ) ; $ item -> setLabel ( $ dataset [ 'label' ] ) ; $ item -> setConfig ( $ dataset [ 'config' ] ) ; $ item -> setStatus ( $ dataset [ 'status' ] ) ; if ( isset ( $ dataset [ 'position' ] ) ) { $ item -> setPosition ( $ dataset [ 'position' ] ) ; } try { $ pluginManager -> saveItem ( $ item ) ; $ num ++ ; } catch ( Exception $ e ) { ; } } $ this -> _status ( $ num > 0 ? $ num . '/' . $ total : 'OK' ) ; } | Adds plugin data . |
32,433 | public function compare ( $ operator , $ name , $ value ) { return new MW_Common_Criteria_Expression_Compare_SQL ( $ this -> _conn , $ operator , $ name , $ value ) ; } | Creates a new compare expression . |
32,434 | public function setConditions ( MW_Common_Criteria_Expression_Interface $ conditions ) { if ( $ conditions instanceof MW_Common_Criteria_Expression_Sort_Interface ) { throw new MW_Common_Exception ( 'Sortation objects are not allowed' ) ; } $ this -> _conditions = $ conditions ; return $ this ; } | Sets the expression objects . |
32,435 | public function setSlice ( $ start , $ size = 100 ) { $ this -> _sliceStart = ( int ) $ start ; $ this -> _sliceSize = ( int ) $ size ; return $ this ; } | Sets the start number and the size of the requested data slice . |
32,436 | protected function _addAttributes ( $ parentid , array $ data , $ domain ) { $ context = $ this -> _getContext ( ) ; $ attrManager = MShop_Factory :: createManager ( $ context , 'attribute' ) ; $ listManager = MShop_Factory :: createManager ( $ context , $ domain . '/list' ) ; $ item = $ attrManager -> createItem ( ) ; $ item -> setDomain ( $ domain ) ; $ listItem = $ listManager -> createItem ( ) ; $ listItem -> setParentId ( $ parentid ) ; $ listItem -> setDomain ( 'attribute' ) ; foreach ( $ data as $ entry ) { $ item -> setId ( null ) ; $ item -> setTypeId ( $ this -> _getTypeId ( 'attribute/type' , $ domain , $ entry [ 'type' ] ) ) ; $ item -> setCode ( $ entry [ 'code' ] ) ; $ item -> setLabel ( $ entry [ 'label' ] ) ; $ item -> setPosition ( $ entry [ 'position' ] ) ; $ item -> setStatus ( $ entry [ 'status' ] ) ; $ attrManager -> saveItem ( $ item ) ; $ listItem -> setId ( null ) ; $ listItem -> setTypeId ( $ this -> _getTypeId ( $ domain . '/list/type' , 'attribute' , $ entry [ 'list-type' ] ) ) ; $ listItem -> setDateStart ( $ entry [ 'list-start' ] ) ; $ listItem -> setDateEnd ( $ entry [ 'list-end' ] ) ; $ listItem -> setConfig ( $ entry [ 'list-config' ] ) ; $ listItem -> setPosition ( $ entry [ 'list-position' ] ) ; $ listItem -> setStatus ( $ entry [ 'list-status' ] ) ; $ listItem -> setRefId ( $ item -> getId ( ) ) ; $ listManager -> saveItem ( $ listItem , false ) ; if ( isset ( $ entry [ 'attribute' ] ) ) { $ this -> _addAttributes ( $ item -> getId ( ) , $ entry [ 'attribute' ] , 'attribute' ) ; } if ( isset ( $ entry [ 'media' ] ) ) { $ this -> _addMedia ( $ item -> getId ( ) , $ entry [ 'media' ] , 'attribute' ) ; } if ( isset ( $ entry [ 'price' ] ) ) { $ this -> _addPrices ( $ item -> getId ( ) , $ entry [ 'price' ] , 'attribute' ) ; } if ( isset ( $ entry [ 'text' ] ) ) { $ this -> _addTexts ( $ item -> getId ( ) , $ entry [ 'text' ] , 'attribute' ) ; } } } | Adds the attributes to the given parent in the database . |
32,437 | protected function _addPrices ( $ parentid , array $ data , $ domain ) { $ context = $ this -> _getContext ( ) ; $ mediaManager = MShop_Factory :: createManager ( $ context , 'price' ) ; $ listManager = MShop_Factory :: createManager ( $ context , $ domain . '/list' ) ; $ item = $ mediaManager -> createItem ( ) ; $ item -> setDomain ( $ domain ) ; $ listItem = $ listManager -> createItem ( ) ; $ listItem -> setParentId ( $ parentid ) ; $ listItem -> setDomain ( 'price' ) ; foreach ( $ data as $ entry ) { $ item -> setId ( null ) ; $ item -> setTypeId ( $ this -> _getTypeId ( 'price/type' , $ domain , $ entry [ 'type' ] ) ) ; $ item -> setCurrencyId ( $ entry [ 'currencyid' ] ) ; $ item -> setQuantity ( $ entry [ 'quantity' ] ) ; $ item -> setValue ( $ entry [ 'value' ] ) ; $ item -> setCosts ( $ entry [ 'costs' ] ) ; $ item -> setRebate ( $ entry [ 'rebate' ] ) ; $ item -> setTaxRate ( $ entry [ 'taxrate' ] ) ; $ item -> setStatus ( $ entry [ 'status' ] ) ; $ mediaManager -> saveItem ( $ item ) ; $ listItem -> setId ( null ) ; $ listItem -> setTypeId ( $ this -> _getTypeId ( $ domain . '/list/type' , 'price' , $ entry [ 'list-type' ] ) ) ; $ listItem -> setDateStart ( $ entry [ 'list-start' ] ) ; $ listItem -> setDateEnd ( $ entry [ 'list-end' ] ) ; $ listItem -> setConfig ( $ entry [ 'list-config' ] ) ; $ listItem -> setPosition ( $ entry [ 'list-position' ] ) ; $ listItem -> setStatus ( $ entry [ 'list-status' ] ) ; $ listItem -> setRefId ( $ item -> getId ( ) ) ; $ listManager -> saveItem ( $ listItem , false ) ; if ( isset ( $ entry [ 'attribute' ] ) ) { $ this -> _addAttributes ( $ item -> getId ( ) , $ entry [ 'attribute' ] , 'price' ) ; } if ( isset ( $ entry [ 'media' ] ) ) { $ this -> _addMedia ( $ item -> getId ( ) , $ entry [ 'media' ] , 'price' ) ; } if ( isset ( $ entry [ 'price' ] ) ) { $ this -> _addPrices ( $ item -> getId ( ) , $ entry [ 'price' ] , 'price' ) ; } if ( isset ( $ entry [ 'text' ] ) ) { $ this -> _addTexts ( $ item -> getId ( ) , $ entry [ 'text' ] , 'price' ) ; } } } | Adds the prices to the given parent in the database . |
32,438 | protected function _addProducts ( $ parentid , array $ data , $ domain ) { $ context = $ this -> _getContext ( ) ; $ productManager = MShop_Factory :: createManager ( $ context , 'product' ) ; $ listManager = MShop_Factory :: createManager ( $ context , $ domain . '/list' ) ; $ listItem = $ listManager -> createItem ( ) ; $ listItem -> setParentId ( $ parentid ) ; $ listItem -> setDomain ( 'product' ) ; $ codes = array ( ) ; foreach ( $ data as $ entry ) { $ codes [ $ entry [ 'code' ] ] = null ; } $ search = $ productManager -> createSearch ( ) ; $ search -> setConditions ( $ search -> compare ( '==' , 'product.code' , array_keys ( $ codes ) ) ) ; $ products = $ productManager -> searchItems ( $ search ) ; foreach ( $ products as $ product ) { $ codes [ $ product -> getCode ( ) ] = $ product -> getId ( ) ; } foreach ( $ data as $ entry ) { if ( ! isset ( $ codes [ $ entry [ 'code' ] ] ) ) { throw new Exception ( sprintf ( 'No product for code "%1$s" found' , $ entry [ 'code' ] ) ) ; } $ listItem -> setId ( null ) ; $ listItem -> setTypeId ( $ this -> _getTypeId ( $ domain . '/list/type' , 'product' , $ entry [ 'list-type' ] ) ) ; $ listItem -> setDateStart ( $ entry [ 'list-start' ] ) ; $ listItem -> setDateEnd ( $ entry [ 'list-end' ] ) ; $ listItem -> setConfig ( $ entry [ 'list-config' ] ) ; $ listItem -> setPosition ( $ entry [ 'list-position' ] ) ; $ listItem -> setStatus ( $ entry [ 'list-status' ] ) ; $ listItem -> setRefId ( $ codes [ $ entry [ 'code' ] ] ) ; $ listManager -> saveItem ( $ listItem , false ) ; } } | Adds the products to the given parent in the database . |
32,439 | protected function _addProductStock ( $ productid , array $ data ) { $ manager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'product/stock/warehouse' ) ; $ warehouses = array ( ) ; foreach ( $ manager -> searchItems ( $ manager -> createSearch ( ) ) as $ id => $ item ) { $ warehouses [ $ item -> getCode ( ) ] = $ id ; } $ manager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'product/stock' ) ; $ item = $ manager -> createItem ( ) ; $ item -> setProductId ( $ productid ) ; foreach ( $ data as $ entry ) { $ item -> setId ( null ) ; $ item -> setDateBack ( $ entry [ 'dateback' ] ) ; $ item -> setStockLevel ( $ entry [ 'stocklevel' ] ) ; $ item -> setWarehouseId ( $ warehouses [ $ entry [ 'warehouse' ] ] ) ; $ manager -> saveItem ( $ item , false ) ; } } | Adds stock levels to the given product in the database . |
32,440 | protected function _getTypeId ( $ name , $ domain , $ type ) { $ key = str_replace ( '/' , '.' , $ name ) ; $ manager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , $ name ) ; $ search = $ manager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , $ key . '.domain' , $ domain ) , $ search -> compare ( '==' , $ key . '.code' , $ type ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ result = $ manager -> searchItems ( $ search ) ; if ( ( $ item = reset ( $ result ) ) === false ) { throw new Exception ( sprintf ( 'No type item found for "%1$s/%2$s" using "%3$s"' , $ domain , $ type , $ name ) ) ; } return $ item -> getId ( ) ; } | Returns the type ID for the given type and domain found by the manager |
32,441 | protected function _removeItems ( $ parentid , $ name , $ domain , $ refdomain ) { $ context = $ this -> _getContext ( ) ; $ key = str_replace ( '/' , '.' , $ name ) ; $ manager = MShop_Factory :: createManager ( $ context , $ refdomain ) ; $ listManager = MShop_Factory :: createManager ( $ context , $ name ) ; $ search = $ manager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , $ refdomain . '.domain' , $ domain ) , $ search -> compare ( '=~' , $ refdomain . '.label' , 'Demo' ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ ids = array_keys ( $ manager -> searchItems ( $ search ) ) ; $ manager -> deleteItems ( $ ids ) ; $ search = $ listManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , $ key . '.parentid' , $ parentid ) , $ search -> compare ( '==' , $ key . '.domain' , $ refdomain ) , $ search -> compare ( '==' , $ key . '.refid' , $ ids ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ listIds = array_keys ( $ listManager -> searchItems ( $ search ) ) ; $ listManager -> deleteItems ( $ listIds ) ; } | Deletes the demo items from the given parent ID in the database . |
32,442 | protected function _removeListItems ( $ parentid , $ name , $ refdomain ) { $ start = 0 ; $ context = $ this -> _getContext ( ) ; $ key = str_replace ( '/' , '.' , $ name ) ; $ manager = MShop_Factory :: createManager ( $ context , $ refdomain ) ; $ listManager = MShop_Factory :: createManager ( $ context , $ name ) ; $ search = $ listManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , $ key . '.parentid' , $ parentid ) , $ search -> compare ( '==' , $ key . '.domain' , $ refdomain ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; do { $ refIds = $ listIds = $ map = array ( ) ; $ result = $ listManager -> searchItems ( $ search ) ; foreach ( $ result as $ id => $ listItem ) { $ refIds [ ] = $ listItem -> getRefId ( ) ; $ map [ $ listItem -> getRefId ( ) ] [ ] = $ id ; } $ search = $ manager -> createSearch ( ) ; $ search -> setConditions ( $ search -> compare ( '==' , $ refdomain . '.id' , $ refIds ) ) ; $ ids = array_keys ( $ manager -> searchItems ( $ search ) ) ; foreach ( array_diff ( $ refIds , $ ids ) as $ refId ) { $ listIds = array_merge ( $ listIds , $ map [ $ refId ] ) ; } $ listManager -> deleteItems ( $ listIds ) ; $ count = count ( $ result ) ; $ start += $ count ; $ search -> setSlice ( $ start ) ; } while ( $ count == $ search -> getSliceSize ( ) ) ; $ search = $ manager -> createSearch ( ) ; $ search -> setConditions ( $ search -> compare ( '=~' , $ refdomain . '.label' , 'Demo' ) ) ; $ ids = array_keys ( $ manager -> searchItems ( $ search ) ) ; $ search = $ listManager -> createSearch ( ) ; $ expr = array ( $ search -> compare ( '==' , $ key . '.parentid' , $ parentid ) , $ search -> compare ( '==' , $ key . '.refid' , $ ids ) , $ search -> compare ( '==' , $ key . '.domain' , $ refdomain ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ listManager -> deleteItems ( array_keys ( $ listManager -> searchItems ( $ search ) ) ) ; } | Deletes the references to non - existent or demo items in the database . |
32,443 | public function searchItems ( MW_Common_Criteria_Interface $ search , array $ ref = array ( ) , & $ total = null ) { $ dbm = $ this -> _getContext ( ) -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; $ items = array ( ) ; try { $ required = array ( 'coupon' ) ; $ level = MShop_Locale_Manager_Abstract :: SITE_PATH ; $ cfgPathSearch = 'mshop/coupon/manager/default/item/search' ; $ cfgPathCount = 'mshop/coupon/manager/default/item/count' ; $ results = $ this -> _searchItems ( $ conn , $ search , $ cfgPathSearch , $ cfgPathCount , $ required , $ total , $ level ) ; try { while ( ( $ row = $ results -> fetch ( ) ) !== false ) { $ config = $ row [ 'config' ] ; if ( ( $ row [ 'config' ] = json_decode ( $ row [ 'config' ] , true ) ) === null ) { $ msg = sprintf ( 'Invalid JSON as result of search for ID "%2$s" in "%1$s": %3$s' , 'mshop_locale.config' , $ row [ 'id' ] , $ config ) ; $ this -> _getContext ( ) -> getLogger ( ) -> log ( $ msg , MW_Logger_Abstract :: WARN ) ; } $ items [ $ row [ 'id' ] ] = $ this -> _createItem ( $ row ) ; } } catch ( Exception $ e ) { $ results -> finish ( ) ; throw $ e ; } $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } return $ items ; } | Searchs for coupon items based on the given criteria . |
32,444 | public function getProvider ( MShop_Coupon_Item_Interface $ item , $ code ) { $ names = explode ( ',' , $ item -> getProvider ( ) ) ; if ( ( $ providername = array_shift ( $ names ) ) === null ) { throw new MShop_Coupon_Exception ( sprintf ( 'Provider in "%1$s" not available' , $ item -> getProvider ( ) ) ) ; } if ( ctype_alnum ( $ providername ) === false ) { throw new MShop_Coupon_Exception ( sprintf ( 'Invalid characters in provider name "%1$s"' , $ providername ) ) ; } $ interface = 'MShop_Coupon_Provider_Factory_Interface' ; $ classname = 'MShop_Coupon_Provider_' . $ providername ; if ( class_exists ( $ classname ) === false ) { throw new MShop_Coupon_Exception ( sprintf ( 'Class "%1$s" not available' , $ classname ) ) ; } $ context = $ this -> _getContext ( ) ; $ provider = new $ classname ( $ context , $ item , $ code ) ; if ( ( $ provider instanceof $ interface ) === false ) { $ msg = sprintf ( 'Class "%1$s" does not implement interface "%2$s"' , $ classname , $ interface ) ; throw new MShop_Coupon_Exception ( $ msg ) ; } $ decorators = $ context -> getConfig ( ) -> get ( 'mshop/coupon/provider/decorators' , array ( ) ) ; $ object = $ this -> _addCouponDecorators ( $ item , $ code , $ provider , $ names ) ; $ object = $ this -> _addCouponDecorators ( $ item , $ code , $ object , $ decorators ) ; $ object -> setObject ( $ object ) ; return $ object ; } | Returns the coupon model which belongs to the given code . |
32,445 | public function getWord ( $ number ) { if ( is_numeric ( $ number ) ) { $ number = strval ( $ number ) ; } if ( strlen ( $ number ) > 39 ) { throw new InvalidArgumentException ( 'Number max lenght 36 digit' ) ; } $ formated = $ this -> number_format ( strval ( $ number ) , 0 , '.' , ',' ) ; $ groups = explode ( ',' , $ formated ) ; $ steps = count ( $ groups ) ; $ parts = array ( ) ; foreach ( $ groups as $ step => $ group ) { $ group_words = $ this -> groupToWords ( $ group ) ; if ( $ group_words ) { $ part = implode ( ' ' . $ this -> number_word [ 'and' ] . ' ' , $ group_words ) ; if ( isset ( $ this -> number_word [ 'step' ] [ $ steps - $ step - 1 ] ) ) { $ part .= ' ' . $ this -> number_word [ 'step' ] [ $ steps - $ step - 1 ] ; } $ parts [ ] = $ part ; } } return implode ( ' ' . $ this -> number_word [ 'and' ] . ' ' , $ parts ) ; } | return string of number |
32,446 | private function number_format ( $ number , $ decimal_precision = 0 , $ decimals_separator = '.' , $ thousands_separator = ',' ) { $ number = explode ( '.' , str_replace ( ' ' , '' , $ number ) ) ; $ number [ 0 ] = str_split ( strrev ( $ number [ 0 ] ) , 3 ) ; $ total_segments = count ( $ number [ 0 ] ) ; for ( $ i = 0 ; $ i < $ total_segments ; $ i ++ ) { $ number [ 0 ] [ $ i ] = strrev ( $ number [ 0 ] [ $ i ] ) ; } $ number [ 0 ] = implode ( $ thousands_separator , array_reverse ( $ number [ 0 ] ) ) ; if ( ! empty ( $ number [ 1 ] ) ) { $ number [ 1 ] = round ( $ number [ 1 ] , $ decimal_precision ) ; } return implode ( $ decimals_separator , $ number ) ; } | format number for change to word |
32,447 | protected function groupToWords ( $ group ) { $ d3 = floor ( $ group / 100 ) ; $ d2 = floor ( ( $ group - $ d3 * 100 ) / 10 ) ; $ d1 = $ group - $ d3 * 100 - $ d2 * 10 ; $ group_array = array ( ) ; if ( $ d3 != 0 ) { $ group_array [ ] = $ this -> number_word [ 'd3' ] [ $ d3 ] ; } if ( $ d2 == 1 && $ d1 != 0 ) { $ group_array [ ] = $ this -> number_word [ 'd2-1' ] [ $ d1 ] ; } else if ( $ d2 != 0 && $ d1 == 0 ) { $ group_array [ ] = $ this -> number_word [ 'd2-2' ] [ $ d2 ] ; } else if ( $ d2 == 0 && $ d1 == 0 ) { } else if ( $ d2 == 0 && $ d1 != 0 ) { $ group_array [ ] = $ this -> number_word [ 'd1' ] [ $ d1 ] ; } else { $ group_array [ ] = $ this -> number_word [ 'd2-2' ] [ $ d2 ] ; $ group_array [ ] = $ this -> number_word [ 'd1' ] [ $ d1 ] ; } if ( ! count ( $ group_array ) ) { return FALSE ; } return $ group_array ; } | group number to word |
32,448 | private function loadLang ( $ lang ) { $ locale = preg_replace_callback ( '/\b([a-z]{2})[-_](?:([a-z]{4})[-_])?([a-z]{2})\b/' , function ( $ matches ) { return $ matches [ 1 ] . '_' . ( ! empty ( $ matches [ 2 ] ) ? ucfirst ( $ matches [ 2 ] ) . '_' : '' ) . strtoupper ( $ matches [ 3 ] ) ; } , strtolower ( $ lang ) ) ; if ( file_exists ( $ filename = __DIR__ . '/Lang/' . $ locale . '.php' ) ) { $ this -> lang = $ locale ; $ this -> number_word = include __DIR__ . '/Lang/' . $ locale . '.php' ; $ this -> currency = $ this -> number_word [ 'currency' ] ; return true ; } throw new InvalidArgumentException ( 'Unknown language (' . $ lang . ')' ) ; } | fetch language file |
32,449 | public function currency ( $ currency = null ) { $ currency = $ currency == null ? $ this -> currency : $ currency ; return $ this -> getWord ( $ this -> number ) . ' ' . $ currency ; } | return currency string of number |
32,450 | public function setReceiver ( Receiver $ receiver ) { $ this -> pk = $ receiver -> getPrimaryKey ( ) ; $ this -> class = get_class ( $ receiver ) ; } | Wraps the ActiveRecord Receiver object into the ReceiverWrapper . |
32,451 | public function createItem ( ) { try { return $ this -> _createItem ( array ( 'siteid' => $ this -> _getContext ( ) -> getLocale ( ) -> getSiteId ( ) ) ) ; } catch ( Exception $ e ) { return $ this -> _createItem ( ) ; } } | Creates a new locale item object . |
32,452 | private function _bootstrapMatch ( $ siteId , $ lang , $ currency , $ active , MShop_Locale_Item_Site_Interface $ siteItem , array $ sitePath , array $ siteSubTree ) { $ search = $ this -> createSearch ( $ active ) ; $ expr = array ( $ search -> compare ( '==' , 'locale.siteid' , $ sitePath ) ) ; if ( ! empty ( $ lang ) ) { $ expr [ ] = $ search -> compare ( '==' , 'locale.languageid' , $ lang ) ; } if ( ! empty ( $ currency ) ) { $ expr [ ] = $ search -> compare ( '==' , 'locale.currencyid' , $ currency ) ; } $ expr [ ] = $ search -> getConditions ( ) ; if ( $ active === true ) { $ expr [ ] = $ search -> compare ( '>' , 'locale.currency.status' , 0 ) ; $ expr [ ] = $ search -> compare ( '>' , 'locale.language.status' , 0 ) ; $ expr [ ] = $ search -> compare ( '>' , 'locale.site.status' , 0 ) ; } $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ result = $ this -> _search ( $ search ) ; foreach ( $ result as $ row ) { if ( $ row [ 'siteid' ] == $ siteId ) { return $ this -> _createItem ( $ row , $ siteItem , $ sitePath , $ siteSubTree ) ; } } if ( ( $ row = reset ( $ result ) ) !== false ) { $ row [ 'siteid' ] = $ siteId ; return $ this -> _createItem ( $ row , $ siteItem , $ sitePath , $ siteSubTree ) ; } return false ; } | Returns the matching locale item for the given site code language code and currency code . |
32,453 | protected function _createItem ( array $ values = array ( ) , MShop_Locale_Item_Site_Interface $ site = null , array $ sitePath = array ( ) , array $ siteSubTree = array ( ) ) { return new MShop_Locale_Item_Default ( $ values , $ site , $ sitePath , $ siteSubTree ) ; } | Instances a new locale item object . |
32,454 | public function sendRequest ( $ url , $ params , $ method ) { try { if ( ! empty ( $ params [ 'html' ] ) ) { $ commandName = 'GenerateFromHTML' ; } else if ( ! empty ( $ params [ 'url' ] ) ) { $ commandName = 'GenerateFromURL' ; } else if ( ! empty ( $ params [ 'file' ] ) && $ url == 'pdf' ) { $ commandName = 'GenerateFromFile' ; } else { $ operations = $ this -> getDescription ( ) -> getOperations ( ) ; foreach ( $ operations as $ operation ) { if ( $ operation -> getUri ( ) == $ url && $ operation -> getHttpMethod ( ) == $ method ) { $ commandName = $ operation -> getName ( ) ; } } } $ command = $ this -> getCommand ( $ commandName , $ params ) ; $ ret = $ this -> execute ( $ command ) ; if ( $ commandName == 'GetAssetList' || $ commandName == 'UploadAsset' ) { return json_encode ( $ ret ) ; } return $ ret -> getBody ( true ) ; } catch ( ClientErrorResponseException $ exception ) { throw new \ Exception ( $ exception -> getResponse ( ) -> getBody ( true ) , $ exception -> getResponse ( ) -> getStatusCode ( ) ) ; } } | Sends the request via Guzzle Client |
32,455 | public function setId ( $ id ) { if ( ( $ this -> _values [ 'id' ] = MShop_Common_Item_Abstract :: checkId ( $ this -> getId ( ) , $ id ) ) === null ) { $ this -> _modified = true ; } else { $ this -> _modified = false ; } } | Sets the id of the order base object . |
32,456 | public function setComment ( $ comment ) { if ( $ comment == $ this -> getComment ( ) ) { return ; } $ this -> _values [ 'comment' ] = ( string ) $ comment ; $ this -> _modified = true ; } | Sets the comment field of the order item |
32,457 | public function setCustomerId ( $ customerid ) { if ( $ customerid === $ this -> getCustomerId ( ) ) { return ; } $ this -> _notifyListeners ( 'setCustomerId.before' , $ customerid ) ; $ this -> _values [ 'customerid' ] = ( string ) $ customerid ; $ this -> _modified = true ; $ this -> _notifyListeners ( 'setCustomerId.after' , $ customerid ) ; } | Sets the customer ID of the customer who has ordered . |
32,458 | public function setLocale ( MShop_Locale_Item_Interface $ locale ) { $ this -> _notifyListeners ( 'setLocale.before' , $ locale ) ; $ this -> _locale = clone $ locale ; $ this -> _modified = true ; $ this -> _notifyListeners ( 'setLocale.after' , $ locale ) ; } | Sets the locales for the basic order item . |
32,459 | public function getAddress ( $ domain = MShop_Order_Item_Base_Address_Abstract :: TYPE_PAYMENT ) { if ( ! isset ( $ this -> _addresses [ $ domain ] ) ) { throw new MShop_Order_Exception ( sprintf ( 'Address for domain "%1$s" not available' , $ domain ) ) ; } return $ this -> _addresses [ $ domain ] ; } | Returns the billing or delivery address depending on the given domain . |
32,460 | public function setAddress ( MShop_Order_Item_Base_Address_Interface $ address , $ domain = MShop_Order_Item_Base_Address_Abstract :: TYPE_PAYMENT ) { if ( isset ( $ this -> _addresses [ $ domain ] ) && $ this -> _addresses [ $ domain ] === $ address ) { return ; } $ this -> _notifyListeners ( 'setAddress.before' , $ address ) ; $ address -> setType ( $ domain ) ; $ this -> _addresses [ $ domain ] = clone $ address ; $ this -> _modified = true ; $ this -> _notifyListeners ( 'setAddress.after' , $ address ) ; return $ this -> _addresses [ $ domain ] ; } | Sets a customer address as billing or delivery address for an order . |
32,461 | public function deleteAddress ( $ domain = MShop_Order_Item_Base_Address_Abstract :: TYPE_DELIVERY ) { $ this -> _notifyListeners ( 'deleteAddress.before' , $ domain ) ; if ( isset ( $ this -> _addresses [ $ domain ] ) ) { unset ( $ this -> _addresses [ $ domain ] ) ; $ this -> _modified = true ; } $ this -> _notifyListeners ( 'deleteAddress.after' , $ domain ) ; } | Deleted a customer address for billing or delivery of an order . |
32,462 | public function getService ( $ type ) { if ( ! isset ( $ this -> _services [ $ type ] ) ) { throw new MShop_Order_Exception ( sprintf ( 'Service of type "%1$s" not available' , $ type ) ) ; } return $ this -> _services [ $ type ] ; } | Returns the delivery or payment service depending on the given type . |
32,463 | public function setService ( MShop_Order_Item_Base_Service_Interface $ service , $ type ) { $ this -> _checkPrice ( $ service -> getPrice ( ) ) ; $ this -> _notifyListeners ( 'setService.before' , $ service ) ; $ service -> setType ( $ type ) ; $ this -> _services [ $ type ] = clone $ service ; $ this -> _modified = true ; $ this -> _notifyListeners ( 'setService.after' , $ service ) ; return $ this -> _services [ $ type ] ; } | Sets a service as delivery or payment service for an order . |
32,464 | public function deleteService ( $ type ) { $ this -> _notifyListeners ( 'deleteService.before' , $ type ) ; if ( isset ( $ this -> _services [ $ type ] ) ) { unset ( $ this -> _services [ $ type ] ) ; $ this -> _modified = true ; } $ this -> _notifyListeners ( 'deleteService.after' , $ type ) ; } | Deletes the delivery or payment service from the basket . |
32,465 | public function addCoupon ( $ code , array $ products = array ( ) ) { if ( isset ( $ this -> _coupons [ $ code ] ) ) { throw new MShop_Order_Exception ( sprintf ( 'Duplicate coupon code "%1$s"' , $ code ) ) ; } foreach ( $ products as $ product ) { $ this -> _checkProduct ( $ product ) ; $ this -> _checkPrice ( $ product -> getPrice ( ) ) ; } $ this -> _notifyListeners ( 'addCoupon.before' , $ products ) ; $ this -> _coupons [ $ code ] = $ products ; foreach ( $ products as $ product ) { $ this -> _products [ ] = $ product ; } $ this -> _modified = true ; $ this -> _notifyListeners ( 'addCoupon.after' , $ code ) ; } | Adds a coupon code entered by the customer and the given product item to the basket . |
32,466 | public function deleteCoupon ( $ code , $ removecode = false ) { $ products = array ( ) ; if ( isset ( $ this -> _coupons [ $ code ] ) ) { $ this -> _notifyListeners ( 'deleteCoupon.before' , $ code ) ; $ products = $ this -> _coupons [ $ code ] ; foreach ( $ products as $ product ) { if ( ( $ key = array_search ( $ product , $ this -> _products , true ) ) !== false ) { unset ( $ this -> _products [ $ key ] ) ; } } if ( $ removecode === true ) { unset ( $ this -> _coupons [ $ code ] ) ; } else { $ this -> _coupons [ $ code ] = array ( ) ; } $ this -> _modified = true ; $ this -> _notifyListeners ( 'deleteCoupon.after' ) ; } return $ products ; } | Removes a coupon and the related product items from the basket . |
32,467 | public function check ( $ what = MShop_Order_Item_Base_Abstract :: PARTS_ALL ) { $ this -> _checkParts ( $ what ) ; $ this -> _notifyListeners ( 'check.before' , $ what ) ; if ( ( $ what & MShop_Order_Item_Base_Abstract :: PARTS_PRODUCT ) && ( count ( $ this -> _products ) < 1 ) ) { throw new MShop_Order_Exception ( sprintf ( 'Basket empty' ) ) ; } $ this -> _notifyListeners ( 'check.after' , $ what ) ; } | Tests if all necessary items are available to create the order . |
32,468 | public function getPrice ( ) { if ( $ this -> _modified !== false ) { $ this -> _price -> setValue ( '0.00' ) ; $ this -> _price -> setCosts ( '0.00' ) ; $ this -> _price -> setRebate ( '0.00' ) ; $ this -> _price -> setTaxRate ( '0.00' ) ; foreach ( $ this -> getServices ( ) as $ service ) { $ this -> _price -> addItem ( $ service -> getPrice ( ) ) ; } foreach ( $ this -> getProducts ( ) as $ product ) { $ this -> _price -> addItem ( $ product -> getPrice ( ) , $ product -> getQuantity ( ) ) ; } } return $ this -> _price ; } | Returns a price item with amounts calculated for the products costs etc . |
32,469 | protected function _getSameProduct ( MShop_Order_Item_Base_Product_Interface $ item ) { $ attributeMap = array ( ) ; foreach ( $ item -> getAttributes ( ) as $ attributeItem ) { $ attributeMap [ $ attributeItem -> getCode ( ) ] = $ attributeItem ; } foreach ( $ this -> _products as $ position => $ product ) { if ( $ product -> compare ( $ item ) === false ) { continue ; } $ prodAttributes = $ product -> getAttributes ( ) ; if ( count ( $ prodAttributes ) !== count ( $ attributeMap ) ) { continue ; } foreach ( $ prodAttributes as $ attribute ) { if ( array_key_exists ( $ attribute -> getCode ( ) , $ attributeMap ) === false || $ attributeMap [ $ attribute -> getCode ( ) ] -> getValue ( ) != $ attribute -> getValue ( ) ) { continue 2 ; } } return $ position ; } return false ; } | Tests if the given product is similar to an existing one . Similarity is described by the equality of properties so the quantity of the existing product can be updated . |
32,470 | public function setProductId ( $ prodid ) { if ( $ prodid == $ this -> getProductId ( ) ) { return ; } $ this -> _values [ 'prodid' ] = ( int ) $ prodid ; $ this -> setModified ( ) ; } | Sets the Product Id . |
32,471 | public function setWarehouseId ( $ warehouseid ) { if ( $ warehouseid === $ this -> getWarehouseId ( ) ) { return ; } if ( $ warehouseid !== null ) { $ warehouseid = ( int ) $ warehouseid ; } $ this -> _values [ 'warehouseid' ] = $ warehouseid ; $ this -> setModified ( ) ; } | Sets the warehouse Id . |
32,472 | public function setStocklevel ( $ stocklevel ) { if ( $ stocklevel === $ this -> getStocklevel ( ) ) { return ; } if ( $ stocklevel !== null ) { $ stocklevel = ( int ) $ stocklevel ; } $ this -> _values [ 'stocklevel' ] = $ stocklevel ; $ this -> setModified ( ) ; } | Sets the stock level . |
32,473 | public function setDateBack ( $ backdate ) { if ( $ backdate === $ this -> getDateBack ( ) ) { return ; } $ this -> _checkDateFormat ( $ backdate ) ; if ( $ backdate !== null ) { $ backdate = ( string ) $ backdate ; } $ this -> _values [ 'backdate' ] = $ backdate ; $ this -> setModified ( ) ; } | Sets the product back in stock date . |
32,474 | public function deleteItem ( $ id ) { $ siteid = $ this -> _getContext ( ) -> getLocale ( ) -> getSiteId ( ) ; $ this -> begin ( ) ; try { $ this -> _createTreeManager ( $ siteid ) -> deleteNode ( $ id ) ; $ this -> commit ( ) ; } catch ( Exception $ e ) { $ this -> rollback ( ) ; throw $ e ; } } | Deletes the item specified by its ID . |
32,475 | public function saveItem ( MShop_Common_Item_Interface $ item , $ fetch = true ) { $ iface = 'MShop_Catalog_Item_Interface' ; if ( ! ( $ item instanceof $ iface ) ) { throw new MShop_Catalog_Exception ( sprintf ( 'Object is not of required type "%1$s"' , $ iface ) ) ; } $ siteid = $ this -> _getContext ( ) -> getLocale ( ) -> getSiteId ( ) ; $ node = $ item -> getNode ( ) ; $ this -> begin ( ) ; try { $ this -> _createTreeManager ( $ siteid ) -> saveNode ( $ node ) ; $ this -> _updateUsage ( $ node -> getId ( ) , $ item ) ; $ this -> commit ( ) ; } catch ( Exception $ e ) { $ this -> rollback ( ) ; throw $ e ; } } | Updates an item object . |
32,476 | public function getPath ( $ id , array $ ref = array ( ) ) { $ sitePath = array_reverse ( $ this -> _getContext ( ) -> getLocale ( ) -> getSitePath ( ) ) ; foreach ( $ sitePath as $ siteId ) { try { $ path = $ this -> _createTreeManager ( $ siteId ) -> getPath ( $ id ) ; } catch ( Exception $ e ) { continue ; } if ( ! empty ( $ path ) ) { $ itemMap = array ( ) ; foreach ( $ path as $ node ) { $ itemMap [ $ node -> getId ( ) ] = $ node ; } return $ this -> _buildItems ( $ itemMap , $ ref , 'catalog' ) ; } } throw new MShop_Catalog_Exception ( sprintf ( 'Catalog path for ID "%1$s" not found' , $ id ) ) ; } | Returns a list if item IDs that are in the path of given item ID . |
32,477 | protected function _createItem ( array $ values = array ( ) , array $ listItems = array ( ) , array $ refItems = array ( ) , array $ children = array ( ) , MW_Tree_Node_Interface $ node = null ) { if ( $ node === null ) { if ( ! isset ( $ values [ 'siteid' ] ) ) { throw new MShop_Catalog_Exception ( 'No site ID available for creating a catalog item' ) ; } $ node = $ this -> _createTreeManager ( $ values [ 'siteid' ] ) -> createNode ( ) ; $ node -> siteid = $ values [ 'siteid' ] ; } if ( isset ( $ node -> config ) && ( $ result = json_decode ( $ node -> config , true ) ) !== null ) { $ node -> config = $ result ; } return new MShop_Catalog_Item_Default ( $ node , $ children , $ listItems , $ refItems ) ; } | Creates a new catalog item . |
32,478 | protected function _createTree ( MW_Tree_Node_Interface $ node , MShop_Catalog_Item_Interface $ item , array $ listItemMap , array $ refItemMap ) { foreach ( $ node -> getChildren ( ) as $ child ) { $ listItems = array ( ) ; if ( array_key_exists ( $ child -> getId ( ) , $ listItemMap ) ) { $ listItems = $ listItemMap [ $ child -> getId ( ) ] ; } $ refItems = array ( ) ; if ( array_key_exists ( $ child -> getId ( ) , $ refItemMap ) ) { $ refItems = $ refItemMap [ $ child -> getId ( ) ] ; } $ newItem = $ this -> _createItem ( array ( ) , $ listItems , $ refItems , array ( ) , $ child ) ; $ item -> addChild ( $ newItem ) ; $ this -> _createTree ( $ child , $ newItem , $ listItemMap , $ refItemMap ) ; } } | Builds the tree of catalog items . |
32,479 | protected function _createTreeManager ( $ siteid ) { if ( ! isset ( $ this -> _treeManagers [ $ siteid ] ) ) { $ context = $ this -> _getContext ( ) ; $ config = $ context -> getConfig ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ treeConfig = array ( 'search' => $ this -> _searchConfig , 'dbname' => $ this -> _getResourceName ( ) , 'sql' => array ( 'delete' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/delete' ) ) , 'get' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/get' ) ) , 'insert' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/insert' ) ) , 'move-left' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/move-left' ) ) , 'move-right' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/move-right' ) ) , 'search' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/search' ) ) , 'update' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/update' ) ) , 'update-parentid' => str_replace ( ':siteid' , $ siteid , $ config -> get ( 'mshop/catalog/manager/default/item/update-parentid' ) ) , 'newid' => $ config -> get ( 'mshop/catalog/manager/default/item/newid' ) , ) , ) ; $ this -> _treeManagers [ $ siteid ] = MW_Tree_Factory :: createManager ( 'DBNestedSet' , $ treeConfig , $ dbm ) ; } return $ this -> _treeManagers [ $ siteid ] ; } | Creates an object for managing the nested set . |
32,480 | protected function _getNodeMap ( MW_Tree_Node_Interface $ node ) { $ map = array ( ) ; $ map [ ( string ) $ node -> getId ( ) ] = $ node ; foreach ( $ node -> getChildren ( ) as $ child ) { $ map += $ this -> _getNodeMap ( $ child ) ; } return $ map ; } | Creates a flat list node items . |
32,481 | private function _updateUsage ( $ id , MShop_Catalog_Item_Interface $ item , $ case = false ) { $ date = date ( 'Y-m-d H:i:s' ) ; $ context = $ this -> _getContext ( ) ; $ dbm = $ context -> getDatabaseManager ( ) ; $ dbname = $ this -> _getResourceName ( ) ; $ conn = $ dbm -> acquire ( $ dbname ) ; try { $ siteid = $ context -> getLocale ( ) -> getSiteId ( ) ; if ( $ case !== true ) { $ path = 'mshop/catalog/manager/default/item/usage/update' ; } else { $ path = 'mshop/catalog/manager/default/item/usage/add' ; } $ stmt = $ conn -> create ( $ context -> getConfig ( ) -> get ( $ path , $ path ) ) ; $ stmt -> bind ( 1 , json_encode ( $ item -> getConfig ( ) ) ) ; $ stmt -> bind ( 2 , $ date ) ; $ stmt -> bind ( 3 , $ context -> getEditor ( ) ) ; if ( $ case !== true ) { $ stmt -> bind ( 4 , $ siteid , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 5 , $ id , MW_DB_Statement_Abstract :: PARAM_INT ) ; } else { $ stmt -> bind ( 4 , $ date ) ; $ stmt -> bind ( 5 , $ siteid , MW_DB_Statement_Abstract :: PARAM_INT ) ; $ stmt -> bind ( 6 , $ id , MW_DB_Statement_Abstract :: PARAM_INT ) ; } $ stmt -> execute ( ) -> finish ( ) ; $ dbm -> release ( $ conn , $ dbname ) ; } catch ( Exception $ e ) { $ dbm -> release ( $ conn , $ dbname ) ; throw $ e ; } } | Updates the usage information of a node . |
32,482 | protected function _getTypeItem ( ) { if ( ! isset ( $ this -> _typeItem ) ) { $ typeManager = MShop_Factory :: createManager ( $ this -> _getContext ( ) , 'customer/list/type' ) ; $ search = $ typeManager -> createSearch ( true ) ; $ expr = array ( $ search -> compare ( '==' , 'customer.list.type.code' , 'watch' ) , $ search -> getConditions ( ) , ) ; $ search -> setConditions ( $ search -> combine ( '&&' , $ expr ) ) ; $ types = $ typeManager -> searchItems ( $ search ) ; if ( ( $ typeItem = reset ( $ types ) ) === false ) { throw new Client_Html_Exception ( sprintf ( 'List type "%1$s" is not available' , 'watch' ) ) ; } $ this -> _typeItem = $ typeItem ; } return $ this -> _typeItem ; } | Returns the customer list type item for the watch type . |
32,483 | public function get_variables ( $ key ) { if ( ! empty ( $ this -> variables [ $ key ] ) ) { return $ this -> variables [ $ key ] ; } else { return null ; } } | Get variables for the senario . |
32,484 | public function login ( $ user , $ password ) { $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/wp-login.php' ) ) ; $ this -> wait_the_element ( "#loginform" ) ; $ element = $ this -> getSession ( ) -> getPage ( ) ; $ element -> fillField ( "user_login" , $ user ) ; $ element -> fillField ( "user_pass" , $ password ) ; $ submit = $ element -> findButton ( "wp-submit" ) ; $ submit -> click ( ) ; for ( $ i = 0 ; $ i < $ this -> timeout ; $ i ++ ) { try { if ( $ this -> is_current_url ( '/wp-login.php' ) ) { if ( $ this -> getSession ( ) -> getPage ( ) -> find ( 'css' , '#login_error' ) ) { return false ; } else { } } else { return true ; } } catch ( \ Exception $ e ) { } sleep ( 1 ) ; } throw new \ Exception ( 'Login timeout' ) ; } | Log in into the WordPress . |
32,485 | public function logout ( ) { if ( ! $ this -> is_logged_in ( ) ) { return false ; } $ page = $ this -> getSession ( ) -> getPage ( ) ; $ logout = $ page -> find ( "css" , "#wp-admin-bar-logout a" ) ; if ( ! empty ( $ logout ) ) { $ this -> getSession ( ) -> visit ( $ this -> locatePath ( $ logout -> getAttribute ( "href" ) ) ) ; for ( $ i = 0 ; $ i < $ this -> timeout ; $ i ++ ) { try { $ url = $ this -> getSession ( ) -> getCurrentUrl ( ) ; if ( strpos ( $ url , "loggedout=true" ) ) { return true ; } } catch ( \ Exception $ e ) { } sleep ( 1 ) ; } throw new \ Exception ( 'Logout timeout' ) ; } } | Log out from WordPress . |
32,486 | public function is_logged_in ( ) { $ page = $ this -> getSession ( ) -> getPage ( ) ; if ( $ page -> find ( "css" , ".logged-in" ) ) { return true ; } elseif ( $ page -> find ( "css" , ".wp-admin" ) ) { return true ; } return false ; } | Determine if the a user is already logged in . |
32,487 | public function is_plugin_activated ( $ slug ) { $ element = $ this -> search_plugin ( $ slug ) ; if ( ! $ element ) { throw new \ Exception ( sprintf ( "The %s plugin is not installed." , $ slug ) ) ; } $ classes = preg_split ( '/\s+/' , trim ( $ element -> getAttribute ( "class" ) ) ) ; if ( in_array ( 'active' , $ classes ) ) { return true ; } else { return false ; } } | Check the plugin is activated . |
32,488 | public function is_plugin_installed ( $ slug ) { $ element = $ this -> search_plugin ( $ slug ) ; if ( count ( $ element ) ) { return true ; } else { return false ; } } | Check the plugin is installed . |
32,489 | public function deactivate_plugin ( $ slug ) { $ element = $ this -> search_plugin ( $ slug ) ; if ( ! $ element ) { throw new \ Exception ( sprintf ( "The %s plugin is not installed." , $ slug ) ) ; } $ edit = $ element -> find ( 'css' , '.deactivate a' ) ; $ edit -> click ( ) ; sleep ( 1 ) ; } | Deactivate the plugin . |
32,490 | public function search_plugin ( $ slug ) { $ session = $ this -> getSession ( ) ; $ path = $ this -> get_admin_url ( ) . '/plugins.php?s=' . urlencode ( $ slug ) ; $ session -> visit ( $ this -> locatePath ( $ path ) ) ; return $ session -> getPage ( ) -> find ( 'css' , 'tr[data-slug="' . $ slug . '"]' ) ; } | Search plugin in the plugins . php |
32,491 | protected function get_current_theme ( ) { if ( ! $ this -> is_logged_in ( ) ) { throw new \ Exception ( "You are not logged in" ) ; } $ this -> getSession ( ) -> visit ( $ this -> locatePath ( $ this -> get_admin_url ( ) . '/themes.php' ) ) ; $ page = $ this -> getSession ( ) -> getPage ( ) ; $ e = $ page -> find ( 'css' , ".theme.active" ) ; if ( $ e ) { $ classes = preg_split ( "/\s+/" , trim ( $ e -> getAttribute ( "aria-describedby" ) ) ) ; $ theme = preg_replace ( "/\-(name|action)$/" , "" , $ classes [ 0 ] ) ; if ( $ theme ) { return $ theme ; } } throw new \ Exception ( "Maybe you don't have permission to get the current theme." ) ; } | Get the current theme |
32,492 | protected function get_wp_version ( ) { $ this -> getSession ( ) -> visit ( $ this -> locatePath ( '/' ) ) ; $ page = $ this -> getSession ( ) -> getPage ( ) ; $ meta = $ page -> find ( 'css' , "meta[name=generator]" ) ; if ( $ meta ) { $ version = $ meta -> getAttribute ( "content" ) ; if ( $ version ) { return str_replace ( "WordPress " , "" , $ version ) ; } } throw new \ Exception ( "No version number found" ) ; } | Get the WordPress version from meta . |
32,493 | public function replace_variables ( $ str ) { if ( preg_match ( "/^\{([A-Z0-9_]+)\}$/" , $ str , $ matches ) ) { $ key = $ matches [ 1 ] ; if ( $ this -> get_variables ( $ key ) ) { return $ this -> get_variables ( $ key ) ; } } return $ str ; } | Replace with variables |
32,494 | protected function getRegex ( ) { if ( $ this -> regex === null ) { $ this -> regex = $ this -> buildRegex ( $ this -> getTokens ( ) , $ this -> constraints ) ; } return $ this -> regex ; } | Gets regex for matching . |
32,495 | protected function getTokens ( ) { if ( $ this -> tokens === null ) { $ this -> tokens = $ this -> parsePattern ( $ this -> pattern ) ; } return $ this -> tokens ; } | Gets parsed tokens . |
32,496 | protected function parsePattern ( $ pattern ) { $ currentPos = 0 ; $ length = strlen ( $ pattern ) ; $ tokens = [ ] ; $ level = 0 ; $ quotedDelimiter = preg_quote ( $ this -> delimiter ) ; while ( $ currentPos < $ length ) { preg_match ( '(\G(?P<literal>[^:{\[\]]*)(?P<token>[:\[\]]|$))' , $ pattern , $ matches , 0 , $ currentPos ) ; $ currentPos += strlen ( $ matches [ 0 ] ) ; if ( ! empty ( $ matches [ 'literal' ] ) ) { $ tokens [ ] = [ 'literal' , $ matches [ 'literal' ] ] ; } if ( $ matches [ 'token' ] === ':' ) { if ( ! preg_match ( '(\G(?P<name>[^:' . $ quotedDelimiter . '{\[\]]+)(?:{(?P<delimiters>[^}]+)})?:?)' , $ pattern , $ matches , 0 , $ currentPos ) ) { throw new Exception \ RuntimeException ( 'Found empty parameter name' ) ; } $ tokens [ ] = [ 'parameter' , $ matches [ 'name' ] , isset ( $ matches [ 'delimiters' ] ) ? $ matches [ 'delimiters' ] : null ] ; $ currentPos += strlen ( $ matches [ 0 ] ) ; } elseif ( $ matches [ 'token' ] === '[' ) { $ tokens [ ] = [ 'optional-start' ] ; $ level ++ ; } elseif ( $ matches [ 'token' ] === ']' ) { $ tokens [ ] = [ 'optional-end' ] ; $ level -- ; if ( $ level < 0 ) { throw new Exception \ RuntimeException ( 'Found closing bracket without matching opening bracket' ) ; } } else { break ; } } if ( $ level > 0 ) { throw new Exception \ RuntimeException ( 'Found unbalanced brackets' ) ; } return $ tokens ; } | Parses a pattern . |
32,497 | protected function buildRegex ( array $ tokens , array $ constraints ) { $ groupIndex = 1 ; $ regex = '' ; $ quotedDelimiter = preg_quote ( $ this -> delimiter ) ; foreach ( $ tokens as $ token ) { switch ( $ token [ static :: TYPE ] ) { case 'literal' : $ regex .= preg_quote ( $ token [ static :: LITERAL ] ) ; break ; case 'parameter' : $ groupName = '?P<param' . $ groupIndex . '>' ; if ( isset ( $ constraints [ $ token [ static :: NAME ] ] ) ) { $ regex .= '(' . $ groupName . $ constraints [ $ token [ static :: NAME ] ] . ')' ; } elseif ( $ token [ static :: DELIMITERS ] === null ) { $ regex .= '(' . $ groupName . '[^' . $ quotedDelimiter . ']+)' ; } else { $ regex .= '(' . $ groupName . '[^' . $ token [ static :: DELIMITERS ] . ']+)' ; } $ this -> paramMap [ 'param' . $ groupIndex ] = $ token [ static :: NAME ] ; ++ $ groupIndex ; break ; case 'optional-start' : $ regex .= '(?:' ; break ; case 'optional-end' : $ regex .= ')?' ; break ; } } return $ regex ; } | Builds the matching regex from parsed tokens . |
32,498 | protected function buildString ( array $ parts , array $ mergedParams , array $ defaults ) { $ stack = [ ] ; $ current = [ 'is_optional' => false , 'skip' => true , 'skippable' => false , 'path' => '' , ] ; foreach ( $ parts as $ part ) { switch ( $ part [ static :: TYPE ] ) { case 'literal' : $ current [ 'path' ] .= $ part [ static :: LITERAL ] ; break ; case 'parameter' : $ current [ 'skippable' ] = true ; if ( ! isset ( $ mergedParams [ $ part [ static :: NAME ] ] ) ) { if ( ! $ current [ 'is_optional' ] ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Missing parameter "%s"' , $ part [ static :: NAME ] ) ) ; } continue ; } elseif ( ! $ current [ 'is_optional' ] || ! isset ( $ defaults [ $ part [ static :: NAME ] ] ) || $ defaults [ $ part [ static :: NAME ] ] !== $ mergedParams [ $ part [ static :: NAME ] ] ) { $ current [ 'skip' ] = false ; } $ current [ 'path' ] .= $ mergedParams [ $ part [ static :: NAME ] ] ; break ; case 'optional-start' : $ stack [ ] = $ current ; $ current = [ 'is_optional' => true , 'skip' => true , 'skippable' => false , 'path' => '' , ] ; break ; case 'optional-end' : $ parent = array_pop ( $ stack ) ; if ( ! ( $ current [ 'path' ] !== '' && $ current [ 'is_optional' ] && $ current [ 'skippable' ] && $ current [ 'skip' ] ) ) { $ parent [ 'path' ] .= $ current [ 'path' ] ; $ parent [ 'skip' ] = false ; } $ current = $ parent ; break ; } } return $ current [ 'path' ] ; } | Builds a string from parts . |
32,499 | protected function _getSubManager ( $ domain , $ manager , $ name ) { $ domain = strtolower ( $ domain ) ; $ manager = strtolower ( $ manager ) ; $ config = $ this -> _getContext ( ) -> getConfig ( ) ; if ( empty ( $ domain ) || ctype_alnum ( $ domain ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Invalid characters in domain name "%1$s"' , $ domain ) ) ; } if ( $ name === null ) { $ name = $ config -> get ( 'classes/' . $ domain . '/manager/' . $ manager . '/name' , 'Default' ) ; } if ( empty ( $ name ) || ctype_alnum ( $ name ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Invalid characters in manager name "%1$s"' , $ name ) ) ; } $ domainname = ucfirst ( $ domain ) ; $ subnames = $ this -> _createSubNames ( $ manager ) ; $ classname = 'MAdmin_' . $ domainname . '_Manager_' . $ subnames . '_' . $ name ; $ interface = 'MAdmin_' . $ domainname . '_Manager_' . $ subnames . '_Interface' ; if ( class_exists ( $ classname ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Class "%1$s" not available' , $ classname ) ) ; } $ subManager = new $ classname ( $ this -> _getContext ( ) ) ; if ( ( $ subManager instanceof $ interface ) === false ) { throw new MAdmin_Exception ( sprintf ( 'Class "%1$s" does not implement interface "%2$s"' , $ classname , $ interface ) ) ; } return $ subManager ; } | Returns a new manager the given extension name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.