idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
15,900 | public function getEditionLogOfPageEditionById ( $ pageId ) { $ data = array ( ) ; $ pageEdition = $ this -> getServiceLocator ( ) -> get ( 'MelisEnginePage' ) ; $ dataLogs = $ pageEdition -> getEditionLogsOfPage ( $ pageId ) ; $ data = $ dataLogs ; return $ data ; } | Returns edition log of page edition |
15,901 | public function saveEditionAction ( ) { $ idPage = $ this -> params ( ) -> fromRoute ( 'idPage' , $ this -> params ( ) -> fromQuery ( 'idPage' , '' ) ) ; $ translator = $ this -> serviceLocator -> get ( 'translator' ) ; $ eventDatas = array ( 'idPage' => $ idPage ) ; $ this -> getEventManager ( ) -> trigger ( 'meliscms_page_saveedition_start' , null , $ eventDatas ) ; $ container = new Container ( 'meliscms' ) ; if ( empty ( $ idPage ) ) { $ result = array ( 'success' => 0 , 'errors' => array ( array ( 'empty' => $ translator -> translate ( 'tr_meliscms_form_common_errors_Empty datas' ) ) ) ) ; } else { if ( ! empty ( $ container [ 'content-pages' ] [ $ idPage ] ) ) { $ newXmlContent = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" ; $ newXmlContent .= '<document type="MelisCMS" author="MelisTechnology" version="2.0">' . "\n" ; foreach ( $ container [ 'content-pages' ] [ $ idPage ] as $ namePlugin => $ pluginEntries ) { if ( $ namePlugin != 'private:melisPluginSettings' ) { foreach ( $ pluginEntries as $ idEntry => $ valueEntry ) { $ newXmlContent .= "\t" . $ valueEntry . "\n" ; } } } $ newXmlContent .= '</document>' ; $ melisPageSavedTable = $ this -> getServiceLocator ( ) -> get ( 'MelisEngineTablePageSaved' ) ; $ melisPageSavedTable -> save ( array ( 'page_content' => $ newXmlContent ) , $ idPage ) ; } $ result = array ( 'success' => 1 , 'errors' => array ( ) , ) ; } $ this -> getEventManager ( ) -> trigger ( 'meliscms_page_saveedition_end' , null , $ result ) ; return new JsonModel ( $ result ) ; } | Save Page edition |
15,902 | public function getTinyTemplatesAction ( ) { $ idPage = $ this -> params ( ) -> fromRoute ( 'idPage' , $ this -> params ( ) -> fromQuery ( 'idPage' , '' ) ) ; $ success = 1 ; $ tinyTemplates = array ( ) ; if ( ! empty ( $ idPage ) ) { $ melisPage = $ this -> getServiceLocator ( ) -> get ( 'MelisEnginePage' ) ; $ datasPage = $ melisPage -> getDatasPage ( $ idPage , 'saved' ) ; $ datasTemplate = $ datasPage -> getMelisTemplate ( ) ; if ( ! empty ( $ datasTemplate ) ) { $ folderSite = $ datasTemplate -> tpl_zf2_website_folder ; $ folderSite .= '/public/' . self :: MINI_TEMPLATES_FOLDER ; $ folderSite = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../module/MelisSites/' . $ folderSite ; if ( is_dir ( $ folderSite ) ) { if ( $ handle = opendir ( $ folderSite ) ) { while ( false !== ( $ entry = readdir ( $ handle ) ) ) { if ( is_dir ( $ folderSite . '/' . $ entry ) || $ entry == '.' || $ entry == '..' ) continue ; array_push ( $ tinyTemplates , array ( 'title' => $ entry , 'url' => "/" . $ datasTemplate -> tpl_zf2_website_folder . '/' . self :: MINI_TEMPLATES_FOLDER . '/' . $ entry ) ) ; } closedir ( $ handle ) ; } } } } return new JsonModel ( $ tinyTemplates ) ; } | This method sends back the list of mini - templates for TinyMCE It takes the page id as a parameter determines the website folder in order to list only the mini - templates of the website and not all of them |
15,903 | public static function create ( Node $ object , $ method_name ) { $ node = new static ( ) ; $ node -> addChild ( $ object , 'object' ) ; $ node -> addChild ( Token :: objectOperator ( ) , 'operator' ) ; $ node -> addChild ( Token :: identifier ( $ method_name ) , 'methodName' ) ; $ node -> addChild ( Token :: openParen ( ) , 'openParen' ) ; $ node -> addChild ( new CommaListNode ( ) , 'arguments' ) ; $ node -> addChild ( Token :: closeParen ( ) , 'closeParen' ) ; return $ node ; } | Creates a method call on an object with an empty argument list . |
15,904 | protected function parseFilters ( SimpleXMLElement $ xml ) { if ( false === $ filters = $ xml -> xpath ( '//config:filters/config:filter' ) ) { return ; } try { $ filterConfig = $ this -> container -> getParameter ( "Thelia.parser.filters" ) ; } catch ( ParameterNotFoundException $ e ) { $ filterConfig = array ( ) ; } foreach ( $ filters as $ filter ) { $ filterConfig [ $ this -> getAttributeAsPhp ( $ filter , "name" ) ] = $ this -> getAttributeAsPhp ( $ filter , "class" ) ; } $ this -> container -> setParameter ( "Thelia.parser.filters" , $ filterConfig ) ; } | parse Filters property |
15,905 | protected function parseTemplateDirectives ( SimpleXMLElement $ xml ) { if ( false === $ baseParams = $ xml -> xpath ( '//config:templateDirectives/config:templateDirective' ) ) { return ; } try { $ baseParamConfig = $ this -> container -> getParameter ( "Thelia.parser.templateDirectives" ) ; } catch ( ParameterNotFoundException $ e ) { $ baseParamConfig = array ( ) ; } foreach ( $ baseParams as $ baseParam ) { $ baseParamConfig [ $ this -> getAttributeAsPhp ( $ baseParam , "name" ) ] = $ this -> getAttributeAsPhp ( $ baseParam , "class" ) ; } $ this -> container -> setParameter ( "Thelia.parser.templateDirectives" , $ baseParamConfig ) ; } | parse BaseParams property |
15,906 | protected function parseService ( $ id , $ service , $ file ) { if ( ( string ) $ service [ 'alias' ] ) { $ public = true ; if ( isset ( $ service [ 'public' ] ) ) { $ public = $ this -> getAttributeAsPhp ( $ service , 'public' ) ; } $ this -> container -> setAlias ( $ id , new Alias ( ( string ) $ service [ 'alias' ] , $ public ) ) ; return ; } if ( isset ( $ service [ 'parent' ] ) ) { $ definition = new DefinitionDecorator ( ( string ) $ service [ 'parent' ] ) ; } else { $ definition = new Definition ( ) ; } foreach ( array ( 'class' , 'scope' , 'public' , 'factory-class' , 'factory-method' , 'factory-service' , 'synthetic' , 'abstract' ) as $ key ) { if ( isset ( $ service [ $ key ] ) ) { $ method = 'set' . str_replace ( '-' , '' , $ key ) ; $ definition -> $ method ( ( string ) $ this -> getAttributeAsPhp ( $ service , $ key ) ) ; } } if ( $ service -> file ) { $ definition -> setFile ( ( string ) $ service -> file ) ; } $ definition -> setArguments ( $ this -> getArgumentsAsPhp ( $ service , 'argument' ) ) ; $ definition -> setProperties ( $ this -> getArgumentsAsPhp ( $ service , 'property' ) ) ; if ( isset ( $ service -> configurator ) ) { if ( isset ( $ service -> configurator [ 'function' ] ) ) { $ definition -> setConfigurator ( ( string ) $ service -> configurator [ 'function' ] ) ; } else { if ( isset ( $ service -> configurator [ 'service' ] ) ) { $ class = new Reference ( ( string ) $ service -> configurator [ 'service' ] , ContainerInterface :: EXCEPTION_ON_INVALID_REFERENCE , false ) ; } else { $ class = ( string ) $ service -> configurator [ 'class' ] ; } $ definition -> setConfigurator ( array ( $ class , ( string ) $ service -> configurator [ 'method' ] ) ) ; } } foreach ( $ service -> call as $ call ) { $ definition -> addMethodCall ( ( string ) $ call [ 'method' ] , $ this -> getArgumentsAsPhp ( $ call , 'argument' ) ) ; } foreach ( $ service -> tag as $ tag ) { $ parameters = array ( ) ; foreach ( $ tag -> attributes ( ) as $ name => $ value ) { if ( 'name' === $ name ) { continue ; } $ parameters [ $ name ] = XmlUtils :: phpize ( $ value ) ; } $ definition -> addTag ( ( string ) $ tag [ 'name' ] , $ parameters ) ; } return $ definition ; } | Parses an individual Definition |
15,907 | private function getArgumentsAsPhp ( SimpleXMLElement $ xml , $ name , $ lowercase = true ) { $ arguments = array ( ) ; foreach ( $ xml -> $ name as $ arg ) { if ( isset ( $ arg [ 'name' ] ) ) { $ arg [ 'key' ] = ( string ) $ arg [ 'name' ] ; } $ key = isset ( $ arg [ 'key' ] ) ? ( string ) $ arg [ 'key' ] : ( ! $ arguments ? 0 : max ( array_keys ( $ arguments ) ) + 1 ) ; if ( 'parameter' == $ name && $ lowercase ) { $ key = strtolower ( $ key ) ; } if ( isset ( $ arg [ 'index' ] ) ) { $ key = 'index_' . $ arg [ 'index' ] ; } switch ( $ arg [ 'type' ] ) { case 'service' : $ invalidBehavior = ContainerInterface :: EXCEPTION_ON_INVALID_REFERENCE ; if ( isset ( $ arg [ 'on-invalid' ] ) && 'ignore' == $ arg [ 'on-invalid' ] ) { $ invalidBehavior = ContainerInterface :: IGNORE_ON_INVALID_REFERENCE ; } elseif ( isset ( $ arg [ 'on-invalid' ] ) && 'null' == $ arg [ 'on-invalid' ] ) { $ invalidBehavior = ContainerInterface :: NULL_ON_INVALID_REFERENCE ; } if ( isset ( $ arg [ 'strict' ] ) ) { $ strict = XmlUtils :: phpize ( $ arg [ 'strict' ] ) ; } else { $ strict = true ; } $ arguments [ $ key ] = new Reference ( ( string ) $ arg [ 'id' ] , $ invalidBehavior , $ strict ) ; break ; case 'expression' : $ arguments [ $ key ] = new Expression ( ( string ) $ arg ) ; break ; case 'collection' : $ arguments [ $ key ] = $ this -> getArgumentsAsPhp ( $ arg , $ name , false ) ; break ; case 'string' : $ arguments [ $ key ] = ( string ) $ arg ; break ; case 'constant' : $ arguments [ $ key ] = constant ( ( string ) $ arg ) ; break ; default : $ arguments [ $ key ] = XmlUtils :: phpize ( $ arg ) ; } } return $ arguments ; } | Returns arguments as valid PHP types . |
15,908 | public function create ( ProductCreateEvent $ event ) { $ defaultTaxRuleId = null ; if ( null !== $ defaultTaxRule = TaxRuleQuery :: create ( ) -> findOneByIsDefault ( true ) ) { $ defaultTaxRuleId = $ defaultTaxRule -> getId ( ) ; } $ product = new ProductModel ( ) ; $ product -> setDispatcher ( $ this -> eventDispatcher ) -> setRef ( $ event -> getRef ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setVisible ( $ event -> getVisible ( ) ? 1 : 0 ) -> setVirtual ( $ event -> getVirtual ( ) ? 1 : 0 ) -> setTemplateId ( $ event -> getTemplateId ( ) ) -> create ( $ event -> getDefaultCategory ( ) , $ event -> getBasePrice ( ) , $ event -> getCurrencyId ( ) , $ event -> getTaxRuleId ( ) ? : $ defaultTaxRuleId , $ event -> getBaseWeight ( ) , $ event -> getBaseQuantity ( ) ) ; $ event -> setProduct ( $ product ) ; } | Create a new product entry |
15,909 | public function update ( ProductUpdateEvent $ event ) { if ( null !== $ product = ProductQuery :: create ( ) -> findPk ( $ event -> getProductId ( ) ) ) { $ con = Propel :: getWriteConnection ( ProductTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ prevRef = $ product -> getRef ( ) ; $ product -> setDispatcher ( $ this -> eventDispatcher ) -> setRef ( $ event -> getRef ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setDescription ( $ event -> getDescription ( ) ) -> setChapo ( $ event -> getChapo ( ) ) -> setPostscriptum ( $ event -> getPostscriptum ( ) ) -> setVisible ( $ event -> getVisible ( ) ? 1 : 0 ) -> setVirtual ( $ event -> getVirtual ( ) ? 1 : 0 ) -> setBrandId ( $ event -> getBrandId ( ) <= 0 ? null : $ event -> getBrandId ( ) ) -> save ( $ con ) ; $ defaultPseRefChange = $ prevRef !== $ product -> getRef ( ) && 0 === $ product -> getDefaultSaleElements ( ) -> countAttributeCombinations ( ) ; if ( $ defaultPseRefChange ) { $ defaultPse = $ product -> getDefaultSaleElements ( ) ; $ defaultPse -> setRef ( $ product -> getRef ( ) ) -> save ( ) ; } $ product -> setDefaultCategory ( $ event -> getDefaultCategory ( ) ) ; $ event -> setProduct ( $ product ) ; $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollBack ( ) ; throw $ e ; } } } | Change a product |
15,910 | public function delete ( ProductDeleteEvent $ event ) { if ( null !== $ product = ProductQuery :: create ( ) -> findPk ( $ event -> getProductId ( ) ) ) { $ con = Propel :: getWriteConnection ( ProductTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ fileList = [ 'images' => [ ] , 'documentList' => [ ] ] ; $ fileList [ 'images' ] [ 'list' ] = ProductImageQuery :: create ( ) -> findByProductId ( $ event -> getProductId ( ) ) ; $ fileList [ 'images' ] [ 'type' ] = TheliaEvents :: IMAGE_DELETE ; $ fileList [ 'documentList' ] [ 'list' ] = ProductDocumentQuery :: create ( ) -> findByProductId ( $ event -> getProductId ( ) ) ; $ fileList [ 'documentList' ] [ 'type' ] = TheliaEvents :: DOCUMENT_DELETE ; $ product -> setDispatcher ( $ this -> eventDispatcher ) -> delete ( $ con ) ; $ event -> setProduct ( $ product ) ; foreach ( $ fileList as $ fileTypeList ) { foreach ( $ fileTypeList [ 'list' ] as $ fileToDelete ) { $ fileDeleteEvent = new FileDeleteEvent ( $ fileToDelete ) ; $ this -> eventDispatcher -> dispatch ( $ fileTypeList [ 'type' ] , $ fileDeleteEvent ) ; } } $ con -> commit ( ) ; } catch ( \ Exception $ e ) { $ con -> rollBack ( ) ; throw $ e ; } } } | Delete a product entry |
15,911 | public function toggleVisibility ( ProductToggleVisibilityEvent $ event ) { $ product = $ event -> getProduct ( ) ; $ product -> setDispatcher ( $ this -> eventDispatcher ) -> setVisible ( $ product -> getVisible ( ) ? false : true ) -> save ( ) ; $ event -> setProduct ( $ product ) ; } | Toggle product visibility . No form used here |
15,912 | public function updateAccessoryPosition ( UpdatePositionEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { return $ this -> genericUpdatePosition ( AccessoryQuery :: create ( ) , $ event , $ dispatcher ) ; } | Changes accessry position selecting absolute ou relative change . |
15,913 | public function deleteFeatureProductValue ( FeatureProductDeleteEvent $ event ) { FeatureProductQuery :: create ( ) -> filterByProductId ( $ event -> getProductId ( ) ) -> filterByFeatureId ( $ event -> getFeatureId ( ) ) -> delete ( ) ; } | Delete a product feature value |
15,914 | public function deleteTemplateFeature ( TemplateDeleteFeatureEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ products = ProductQuery :: create ( ) -> filterByTemplateId ( $ event -> getTemplate ( ) -> getId ( ) ) -> find ( ) ; foreach ( $ products as $ product ) { $ dispatcher -> dispatch ( TheliaEvents :: PRODUCT_FEATURE_DELETE_VALUE , new FeatureProductDeleteEvent ( $ product -> getId ( ) , $ event -> getFeatureId ( ) ) ) ; } } | When a feature is removed from a template the products which are using this feature should be updated . |
15,915 | public function deleteTemplateAttribute ( TemplateDeleteAttributeEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ pseToDelete = ProductSaleElementsQuery :: create ( ) -> useProductQuery ( ) -> filterByTemplateId ( $ event -> getTemplate ( ) -> getId ( ) ) -> endUse ( ) -> useAttributeCombinationQuery ( ) -> filterByAttributeId ( $ event -> getAttributeId ( ) ) -> endUse ( ) -> select ( [ ProductSaleElementsTableMap :: COL_ID ] ) -> find ( ) ; $ currencyId = CurrencyModel :: getDefaultCurrency ( ) -> getId ( ) ; foreach ( $ pseToDelete -> getData ( ) as $ pseId ) { $ dispatcher -> dispatch ( TheliaEvents :: PRODUCT_DELETE_PRODUCT_SALE_ELEMENT , new ProductSaleElementDeleteEvent ( $ pseId , $ currencyId ) ) ; } } | When an attribute is removed from a template the conbinations and PSE of products which are using this template should be updated . |
15,916 | public function viewCheck ( ViewCheckEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( $ event -> getView ( ) == 'product' ) { $ product = ProductQuery :: create ( ) -> filterById ( $ event -> getViewId ( ) ) -> filterByVisible ( 1 ) -> count ( ) ; if ( $ product == 0 ) { $ dispatcher -> dispatch ( TheliaEvents :: VIEW_PRODUCT_ID_NOT_VISIBLE , $ event ) ; } } } | Check if is a product view and if product_id is visible |
15,917 | public function checkDuplicateCouponCode ( $ value , ExecutionContextInterface $ context ) { $ exists = CouponQuery :: create ( ) -> filterByCode ( $ value ) -> count ( ) > 0 ; if ( $ exists ) { $ context -> addViolation ( Translator :: getInstance ( ) -> trans ( "The coupon code '%code' already exists. Please choose another coupon code" , [ '%code' => $ value ] ) ) ; } } | Check coupon code unicity |
15,918 | public function checkLocalizedDate ( $ value , ExecutionContextInterface $ context ) { $ format = LangQuery :: create ( ) -> findOneByByDefault ( true ) -> getDatetimeFormat ( ) ; if ( false === \ DateTime :: createFromFormat ( $ format , $ value ) ) { $ context -> addViolation ( Translator :: getInstance ( ) -> trans ( "Date '%date' is invalid, please enter a valid date using %fmt format" , [ '%fmt' => $ format , '%date' => $ value ] ) ) ; } } | Validate a date entered with the default Language date format . |
15,919 | public function getModulesDependOf ( $ active = true ) { $ code = $ this -> getModuleDefinition ( ) -> getCode ( ) ; $ query = ModuleQuery :: create ( ) ; $ dependantModules = [ ] ; if ( true === $ active ) { $ query -> findByActivate ( 1 ) ; } elseif ( false === $ active ) { $ query -> findByActivate ( 0 ) ; } $ modules = $ query -> find ( ) ; foreach ( $ modules as $ module ) { try { $ validator = new ModuleValidator ( $ module -> getAbsoluteBaseDir ( ) ) ; $ definition = $ validator -> getModuleDefinition ( ) ; $ dependencies = $ definition -> getDependencies ( ) ; if ( \ count ( $ dependencies ) > 0 ) { foreach ( $ dependencies as $ dependency ) { if ( $ dependency [ 0 ] == $ code ) { $ dependantModules [ ] = [ 'code' => $ definition -> getCode ( ) , 'version' => $ dependency [ 1 ] ] ; break ; } } } } catch ( \ Exception $ ex ) { ; } } return $ dependantModules ; } | Get an array of modules that depend of the current module |
15,920 | public function getCurrentModuleDependencies ( $ recursive = false ) { if ( empty ( $ this -> moduleDescriptor -> required ) ) { return [ ] ; } $ dependencies = [ ] ; foreach ( $ this -> moduleDescriptor -> required -> module as $ dependency ) { $ dependencyArray = [ "code" => ( string ) $ dependency , "version" => ( string ) $ dependency [ 'version' ] , ] ; if ( ! \ in_array ( $ dependencyArray , $ dependencies ) ) { $ dependencies [ ] = $ dependencyArray ; } if ( $ recursive ) { $ recursiveModuleValidator = new ModuleValidator ( THELIA_MODULE_DIR . '/' . ( string ) $ dependency ) ; array_merge ( $ dependencies , $ recursiveModuleValidator -> getCurrentModuleDependencies ( true ) ) ; } } return $ dependencies ; } | Get the dependencies of this module . |
15,921 | public function sortKey ( ) { if ( $ this instanceof RootNode ) { return spl_object_hash ( $ this ) ; } if ( ! $ this -> parent ) { return '~/' . spl_object_hash ( $ this ) ; } $ path = $ this -> parent -> sortKey ( ) . '/' ; $ position = 0 ; $ previous = $ this -> previous ; while ( $ previous ) { $ position ++ ; $ previous = $ previous -> previous ; } $ path .= $ position ; return $ path ; } | Get a unique key for sorting this node . |
15,922 | public function is ( $ test ) { if ( is_callable ( $ test ) ) { return ( boolean ) $ test ( $ this ) ; } elseif ( is_string ( $ test ) ) { return $ this -> is ( Filter :: isInstanceOf ( $ test ) ) ; } else { throw new \ InvalidArgumentException ( ) ; } } | Tests this node against a condition . |
15,923 | public function isAnyOf ( array $ tests ) { foreach ( $ tests as $ test ) { if ( $ this -> is ( $ test ) ) { return TRUE ; } } return FALSE ; } | Tests if this node matches any the tests in the array . |
15,924 | public function isAllOf ( array $ tests ) { foreach ( $ tests as $ test ) { if ( ! $ this -> is ( $ test ) ) { return FALSE ; } } return TRUE ; } | Tests if this node matches all of the tests in the array . |
15,925 | public static function fromValue ( $ value ) { if ( is_array ( $ value ) ) { $ elements = [ ] ; foreach ( $ value as $ k => $ v ) { $ elements [ ] = ArrayPairNode :: create ( static :: fromValue ( $ k ) , static :: fromValue ( $ v ) ) ; } return ArrayNode :: create ( $ elements ) ; } elseif ( is_string ( $ value ) ) { return StringNode :: create ( var_export ( $ value , TRUE ) ) ; } elseif ( is_integer ( $ value ) ) { return new IntegerNode ( T_LNUMBER , $ value ) ; } elseif ( is_float ( $ value ) ) { return new FloatNode ( T_DNUMBER , $ value ) ; } elseif ( is_bool ( $ value ) ) { return BooleanNode :: create ( $ value ) ; } elseif ( is_null ( $ value ) ) { return NullNode :: create ( 'NULL' ) ; } else { throw new \ InvalidArgumentException ( ) ; } } | Creates a Node from a php value . |
15,926 | protected function init ( ) { $ this -> setLevel ( ConfigQuery :: read ( self :: VAR_LEVEL , self :: DEFAULT_LEVEL ) ) ; $ this -> dir_destinations = array ( __DIR__ . DS . 'Destination' , THELIA_LOCAL_DIR . 'tlog' . DS . 'destinations' ) ; $ this -> setPrefix ( ConfigQuery :: read ( self :: VAR_PREFIXE , self :: DEFAUT_PREFIXE ) ) ; $ this -> setFiles ( ConfigQuery :: read ( self :: VAR_FILES , self :: DEFAUT_FILES ) ) ; $ this -> setIp ( ConfigQuery :: read ( self :: VAR_IP , self :: DEFAUT_IP ) ) ; $ this -> setDestinations ( ConfigQuery :: read ( self :: VAR_DESTINATIONS , self :: DEFAUT_DESTINATIONS ) ) ; $ this -> setShowRedirect ( ConfigQuery :: read ( self :: VAR_SHOW_REDIRECT , self :: DEFAUT_SHOW_REDIRECT ) ) ; register_shutdown_function ( array ( $ this , 'writeOnExit' ) ) ; } | initialize default configuration |
15,927 | protected function listExport ( OutputInterface $ output ) { $ table = new Table ( $ output ) ; foreach ( ( new ExportQuery ) -> find ( ) as $ export ) { $ table -> addRow ( [ $ export -> getRef ( ) , $ export -> getTitle ( ) , $ export -> getDescription ( ) ] ) ; } $ table -> setHeaders ( [ 'Reference' , 'Title' , 'Description' ] ) -> render ( ) ; } | Output available exports |
15,928 | protected function listSerializer ( OutputInterface $ output ) { $ table = new Table ( $ output ) ; $ serializerManager = $ this -> getContainer ( ) -> get ( RegisterSerializerPass :: MANAGER_SERVICE_ID ) ; foreach ( $ serializerManager -> getSerializers ( ) as $ serializer ) { $ table -> addRow ( [ $ serializer -> getId ( ) , $ serializer -> getName ( ) , $ serializer -> getExtension ( ) , $ serializer -> getMimeType ( ) ] ) ; } $ table -> setHeaders ( [ 'Id' , 'Name' , 'Extension' , 'MIME type' ] ) -> render ( ) ; } | Output available serializers |
15,929 | protected function listArchiver ( OutputInterface $ output ) { $ table = new Table ( $ output ) ; $ archiverManager = $ this -> getContainer ( ) -> get ( RegisterArchiverPass :: MANAGER_SERVICE_ID ) ; foreach ( $ archiverManager -> getArchivers ( true ) as $ archiver ) { $ table -> addRow ( [ $ archiver -> getId ( ) , $ archiver -> getName ( ) , $ archiver -> getExtension ( ) , $ archiver -> getMimeType ( ) ] ) ; } $ table -> setHeaders ( [ 'Id' , 'Name' , 'Extension' , 'MIME type' ] ) -> render ( ) ; } | Output available archivers |
15,930 | public function getCurrency ( $ forceDefault = true ) { $ currency = $ this -> get ( "thelia.current.currency" ) ; if ( null === $ currency && $ forceDefault ) { $ currency = Currency :: getDefaultCurrency ( ) ; } return $ currency ; } | Return current currency |
15,931 | public function setSessionCart ( Cart $ cart = null ) { if ( null === $ cart || $ cart -> isNew ( ) ) { self :: $ transientCart = $ cart ; $ this -> remove ( "thelia.cart_id" ) ; } else { self :: $ transientCart = null ; $ this -> set ( "thelia.cart_id" , $ cart -> getId ( ) ) ; } return $ this ; } | Set the cart to store in the current session . |
15,932 | public function getSessionCart ( EventDispatcherInterface $ dispatcher = null ) { $ cart_id = $ this -> get ( "thelia.cart_id" , null ) ; if ( null !== $ cart_id ) { $ cart = CartQuery :: create ( ) -> findPk ( $ cart_id ) ; } else { $ cart = self :: $ transientCart ; } if ( null === $ cart || ! $ this -> isValidCart ( $ cart ) ) { if ( null == $ dispatcher ) { throw new \ InvalidArgumentException ( "In this context (no cart in session), an EventDispatcher should be provided to Session::getSessionCart()." ) ; } $ cartEvent = new CartRestoreEvent ( ) ; if ( null !== $ cart ) { $ cartEvent -> setCart ( $ cart ) ; } $ dispatcher -> dispatch ( TheliaEvents :: CART_RESTORE_CURRENT , $ cartEvent ) ; if ( null === $ cart = $ cartEvent -> getCart ( ) ) { throw new \ LogicException ( "Unable to get a Cart." ) ; } $ this -> setSessionCart ( $ cart ) ; } return $ cart ; } | Return the cart stored in the current session |
15,933 | public function clearSessionCart ( EventDispatcherInterface $ dispatcher ) { $ event = new CartCreateEvent ( ) ; $ dispatcher -> dispatch ( TheliaEvents :: CART_CREATE_NEW , $ event ) ; if ( null === $ cart = $ event -> getCart ( ) ) { throw new \ LogicException ( "Unable to get a new empty Cart." ) ; } $ this -> setSessionCart ( $ cart ) ; } | Clear the current session cart and store a new empty one in the session . |
15,934 | protected function isValidCart ( Cart $ cart ) { $ customer = $ this -> getCustomerUser ( ) ; return ( null !== $ customer && $ cart -> getCustomerId ( ) == $ customer -> getId ( ) ) || ( null === $ customer && $ cart -> getCustomerId ( ) === null ) ; } | A cart is valid if its customer ID is the same as the current logged in user |
15,935 | public function create ( CouponCreateOrUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ coupon = new CouponModel ( ) ; $ this -> createOrUpdate ( $ coupon , $ event , $ dispatcher ) ; } | Occurring when a Coupon is about to be created |
15,936 | public function update ( CouponCreateOrUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ coupon = $ event -> getCouponModel ( ) ; $ this -> createOrUpdate ( $ coupon , $ event , $ dispatcher ) ; } | Occurring when a Coupon is about to be updated |
15,937 | public function updateCondition ( CouponCreateOrUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ modelCoupon = $ event -> getCouponModel ( ) ; $ this -> createOrUpdateCondition ( $ modelCoupon , $ event , $ dispatcher ) ; } | Occurring when a Coupon condition is about to be updated |
15,938 | public function clearAllCoupons ( Event $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ this -> couponManager -> clear ( ) ; $ this -> getSession ( ) -> setConsumedCoupons ( array ( ) ) ; $ this -> updateOrderDiscount ( $ event , $ eventName , $ dispatcher ) ; } | Clear all coupons in session . |
15,939 | public function consume ( CouponConsumeEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ totalDiscount = 0 ; $ isValid = false ; $ coupon = $ this -> couponFactory -> buildCouponFromCode ( $ event -> getCode ( ) ) ; if ( $ coupon ) { $ isValid = $ coupon -> isMatching ( ) ; if ( $ isValid ) { $ this -> couponManager -> pushCouponInSession ( $ event -> getCode ( ) ) ; $ totalDiscount = $ this -> couponManager -> getDiscount ( ) ; $ this -> getSession ( ) -> getSessionCart ( $ dispatcher ) -> setDiscount ( $ totalDiscount ) -> save ( ) ; $ this -> getSession ( ) -> getOrder ( ) -> setDiscount ( $ totalDiscount ) ; } } $ event -> setIsValid ( $ isValid ) ; $ event -> setDiscount ( $ totalDiscount ) ; } | Occurring when a Coupon condition is about to be consumed |
15,940 | public function orderStatusChange ( OrderEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( $ event -> getOrder ( ) -> isCancelled ( ) || $ event -> getOrder ( ) -> isRefunded ( ) ) { $ usedCoupons = OrderCouponQuery :: create ( ) -> filterByUsageCanceled ( false ) -> findByOrderId ( $ event -> getOrder ( ) -> getId ( ) ) ; $ customerId = $ event -> getOrder ( ) -> getCustomerId ( ) ; foreach ( $ usedCoupons as $ usedCoupon ) { if ( null !== $ couponModel = CouponQuery :: create ( ) -> findOneByCode ( $ usedCoupon -> getCode ( ) ) ) { $ this -> couponManager -> incrementQuantity ( $ couponModel , $ customerId ) ; } $ usedCoupon -> setUsageCanceled ( true ) -> save ( ) ; } } else { $ usedCoupons = OrderCouponQuery :: create ( ) -> filterByUsageCanceled ( true ) -> findByOrderId ( $ event -> getOrder ( ) -> getId ( ) ) ; $ customerId = $ event -> getOrder ( ) -> getCustomerId ( ) ; foreach ( $ usedCoupons as $ usedCoupon ) { if ( null !== $ couponModel = CouponQuery :: create ( ) -> findOneByCode ( $ usedCoupon -> getCode ( ) ) ) { $ this -> couponManager -> decrementQuantity ( $ couponModel , $ customerId ) ; } $ usedCoupon -> setUsageCanceled ( false ) -> save ( ) ; } } } | Cancels order coupons usage when order is canceled or refunded or use canceled coupons again if the order is no longer canceled or refunded |
15,941 | protected function updateProductSaleElementsPrices ( $ pseList , $ promoStatus , $ offsetType , Calculator $ taxCalculator , $ saleOffsetByCurrency , ConnectionInterface $ con ) { foreach ( $ pseList as $ pse ) { if ( $ pse -> getPromo ( ) != $ promoStatus ) { $ pse -> setPromo ( $ promoStatus ) -> save ( $ con ) ; } foreach ( $ saleOffsetByCurrency as $ currencyId => $ offset ) { $ productPrice = ProductPriceQuery :: create ( ) -> filterByProductSaleElementsId ( $ pse -> getId ( ) ) -> filterByCurrencyId ( $ currencyId ) -> findOne ( $ con ) ; if ( null !== $ productPrice ) { $ priceWithTax = $ taxCalculator -> getTaxedPrice ( $ productPrice -> getPrice ( ) ) ; switch ( $ offsetType ) { case SaleModel :: OFFSET_TYPE_AMOUNT : $ promoPrice = max ( 0 , $ priceWithTax - $ offset ) ; break ; case SaleModel :: OFFSET_TYPE_PERCENTAGE : $ promoPrice = $ priceWithTax * ( 1 - $ offset / 100 ) ; break ; default : $ promoPrice = $ priceWithTax ; } $ promoPrice = $ taxCalculator -> getUntaxedPrice ( $ promoPrice ) ; $ productPrice -> setPromoPrice ( $ promoPrice ) -> save ( $ con ) ; } } } } | Update PSE for a given product |
15,942 | public function updateProductsSaleStatus ( ProductSaleStatusUpdateEvent $ event ) { $ taxCalculator = new Calculator ( ) ; $ sale = $ event -> getSale ( ) ; if ( null !== $ saleProducts = SaleProductQuery :: create ( ) -> filterBySale ( $ sale ) -> orderByProductId ( ) ) { $ saleOffsetByCurrency = $ sale -> getPriceOffsets ( ) ; $ offsetType = $ sale -> getPriceOffsetType ( ) ; $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { foreach ( $ saleProducts as $ saleProduct ) { ProductSaleElementsQuery :: create ( ) -> filterByProductId ( $ saleProduct -> getProductId ( ) ) -> update ( [ 'Promo' => false ] , $ con ) ; $ taxCalculator -> load ( $ saleProduct -> getProduct ( $ con ) , CountryModel :: getShopLocation ( ) ) ; $ attributeAvId = $ saleProduct -> getAttributeAvId ( ) ; $ pseRequest = ProductSaleElementsQuery :: create ( ) -> filterByProductId ( $ saleProduct -> getProductId ( ) ) ; if ( ! \ is_null ( $ attributeAvId ) ) { $ pseRequest -> useAttributeCombinationQuery ( null , Criteria :: LEFT_JOIN ) -> filterByAttributeAvId ( $ attributeAvId ) -> endUse ( ) ; } $ pseList = $ pseRequest -> find ( ) ; if ( null !== $ pseList ) { $ this -> updateProductSaleElementsPrices ( $ pseList , $ sale -> getActive ( ) , $ offsetType , $ taxCalculator , $ saleOffsetByCurrency , $ con ) ; } } $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } } | Update the promo status of the sale s selected products and combinations |
15,943 | public function create ( SaleCreateEvent $ event ) { $ sale = new SaleModel ( ) ; $ sale -> setLocale ( $ event -> getLocale ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setSaleLabel ( $ event -> getSaleLabel ( ) ) -> save ( ) ; $ event -> setSale ( $ sale ) ; } | Create a new Sale |
15,944 | public function update ( SaleUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( null !== $ sale = SaleQuery :: create ( ) -> findPk ( $ event -> getSaleId ( ) ) ) { $ sale -> setDispatcher ( $ dispatcher ) ; $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ sale -> setActive ( false ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; $ sale -> setActive ( $ event -> getActive ( ) ) -> setStartDate ( $ event -> getStartDate ( ) ) -> setEndDate ( $ event -> getEndDate ( ) ) -> setPriceOffsetType ( $ event -> getPriceOffsetType ( ) ) -> setDisplayInitialPrice ( $ event -> getDisplayInitialPrice ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setSaleLabel ( $ event -> getSaleLabel ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setDescription ( $ event -> getDescription ( ) ) -> setChapo ( $ event -> getChapo ( ) ) -> setPostscriptum ( $ event -> getPostscriptum ( ) ) -> save ( $ con ) ; $ event -> setSale ( $ sale ) ; SaleOffsetCurrencyQuery :: create ( ) -> filterBySaleId ( $ sale -> getId ( ) ) -> delete ( $ con ) ; foreach ( $ event -> getPriceOffsets ( ) as $ currencyId => $ priceOffset ) { $ saleOffset = new SaleOffsetCurrency ( ) ; $ saleOffset -> setCurrencyId ( $ currencyId ) -> setSaleId ( $ sale -> getId ( ) ) -> setPriceOffsetValue ( $ priceOffset ) -> save ( $ con ) ; } SaleProductQuery :: create ( ) -> filterBySaleId ( $ sale -> getId ( ) ) -> delete ( $ con ) ; $ productAttributesArray = $ event -> getProductAttributes ( ) ; foreach ( $ event -> getProducts ( ) as $ productId ) { if ( isset ( $ productAttributesArray [ $ productId ] ) ) { foreach ( $ productAttributesArray [ $ productId ] as $ attributeId ) { $ saleProduct = new SaleProduct ( ) ; $ saleProduct -> setSaleId ( $ sale -> getId ( ) ) -> setProductId ( $ productId ) -> setAttributeAvId ( $ attributeId ) -> save ( $ con ) ; } } else { $ saleProduct = new SaleProduct ( ) ; $ saleProduct -> setSaleId ( $ sale -> getId ( ) ) -> setProductId ( $ productId ) -> setAttributeAvId ( null ) -> save ( $ con ) ; } } if ( $ sale -> getActive ( ) ) { $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; } $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } } | Process update sale |
15,945 | public function toggleActivity ( SaleToggleActivityEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ sale = $ event -> getSale ( ) ; $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ sale -> setDispatcher ( $ dispatcher ) -> setActive ( ! $ sale -> getActive ( ) ) -> save ( $ con ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; $ event -> setSale ( $ sale ) ; $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } | Toggle Sale activity |
15,946 | public function delete ( SaleDeleteEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( null !== $ sale = SaleQuery :: create ( ) -> findPk ( $ event -> getSaleId ( ) ) ) { $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { if ( $ sale -> getActive ( ) ) { $ sale -> setActive ( false ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; } $ sale -> setDispatcher ( $ dispatcher ) -> delete ( $ con ) ; $ event -> setSale ( $ sale ) ; $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } } | Delete a sale |
15,947 | public function clearStatus ( SaleClearStatusEvent $ event ) { $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { SaleQuery :: create ( ) -> filterByActive ( true ) -> update ( [ 'Active' => false ] , $ con ) ; ProductSaleElementsQuery :: create ( ) -> filterByPromo ( true ) -> update ( [ 'Promo' => false ] , $ con ) ; $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } | Clear all sales |
15,948 | public function checkSaleActivation ( SaleActiveStatusCheckEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { $ con = Propel :: getWriteConnection ( SaleTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ now = time ( ) ; if ( null !== $ salesToDisable = SaleQuery :: create ( ) -> filterByActive ( true ) -> filterByEndDate ( $ now , Criteria :: LESS_THAN ) -> find ( ) ) { foreach ( $ salesToDisable as $ sale ) { $ sale -> setActive ( false ) -> save ( ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; } } if ( null !== $ salesToEnable = SaleQuery :: create ( ) -> filterByActive ( false ) -> filterByStartDate ( $ now , Criteria :: LESS_EQUAL ) -> filterByEndDate ( $ now , Criteria :: GREATER_EQUAL ) -> find ( ) ) { foreach ( $ salesToEnable as $ sale ) { $ sale -> setActive ( true ) -> save ( ) ; $ dispatcher -> dispatch ( TheliaEvents :: UPDATE_PRODUCT_SALE_STATUS , new ProductSaleStatusUpdateEvent ( $ sale ) ) ; } } $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollback ( ) ; throw $ e ; } } | This method check the activation and deactivation dates of sales and perform the required action depending on the current date . |
15,949 | public function combine ( array $ schemaDocuments = [ ] , array $ externalSchemaDocuments = [ ] ) { $ globalDatabaseElements = [ ] ; foreach ( $ schemaDocuments as $ sourceSchemaDocument ) { if ( ! $ sourceSchemaDocument instanceof \ DOMDocument ) { throw new \ InvalidArgumentException ( 'Schema file is not a \DOMDocument' ) ; } $ sourceSchemaDocument = clone $ sourceSchemaDocument ; foreach ( $ sourceSchemaDocument -> getElementsByTagName ( 'database' ) as $ sourceDatabaseElement ) { $ this -> filterExternalSchemaElements ( $ sourceDatabaseElement ) ; $ this -> inheritDatabaseAttributes ( $ sourceDatabaseElement ) ; $ this -> applyDatabaseTablePrefix ( $ sourceDatabaseElement ) ; $ this -> mergeDatabaseElement ( $ sourceDatabaseElement ) ; } } foreach ( $ externalSchemaDocuments as $ externalSchemaDocument ) { if ( ! $ externalSchemaDocument instanceof \ DOMDocument ) { throw new \ InvalidArgumentException ( 'Schema file is not a \DOMDocument' ) ; } foreach ( $ externalSchemaDocument -> getElementsByTagName ( 'database' ) as $ externalSchemaDatabaseElement ) { $ this -> includeExternalSchema ( $ externalSchemaDatabaseElement ) ; } } $ globalSchemaDocuments = [ ] ; foreach ( $ globalDatabaseElements as $ database => $ globalDatabaseElement ) { $ globalSchemaDocuments [ $ database ] = $ globalDatabaseElement -> ownerDocument ; } return $ globalSchemaDocuments ; } | Combine multiple schemas into one schema per database . |
15,950 | protected function inheritDatabaseAttributes ( \ DOMElement $ databaseElement ) { $ attributesToInherit = [ ] ; foreach ( static :: $ DATABASE_INHERITABLE_ATTRIBUTES as $ databaseAttribute => $ tableAttribute ) { if ( ! $ databaseElement -> hasAttribute ( $ databaseAttribute ) ) { continue ; } $ attributesToInherit [ $ tableAttribute ] = $ databaseElement -> getAttribute ( $ databaseAttribute ) ; } foreach ( $ databaseElement -> getElementsByTagName ( 'table' ) as $ tableElement ) { foreach ( static :: $ DATABASE_INHERITABLE_ATTRIBUTES as $ databaseAttribute => $ tableAttribute ) { if ( ! isset ( $ attributesToInherit [ $ tableAttribute ] ) ) { continue ; } if ( $ tableElement -> hasAttribute ( $ tableAttribute ) ) { continue ; } $ databaseAttributeInheritanceNoticeComment = $ tableElement -> ownerDocument -> createComment ( "Attribute '{$tableAttribute}'" . " inherited from parent database attribute '{$databaseAttribute}'" ) ; $ tableElement -> insertBefore ( $ databaseAttributeInheritanceNoticeComment , $ tableElement -> firstChild ) ; $ tableElement -> setAttribute ( $ tableAttribute , $ attributesToInherit [ $ tableAttribute ] ) ; } } } | Copy inheritable database attribute to the tables in the database . |
15,951 | protected function applyDatabaseTablePrefix ( \ DOMElement $ databaseElement ) { if ( ! $ databaseElement -> hasAttribute ( 'tablePrefix' ) ) { return ; } $ tablePrefix = $ databaseElement -> getAttribute ( 'tablePrefix' ) ; foreach ( $ databaseElement -> getElementsByTagName ( 'table' ) as $ tableElement ) { if ( ! $ tableElement -> hasAttribute ( 'name' ) ) { continue ; } $ tablePrefixingNoticeComment = $ tableElement -> ownerDocument -> createComment ( "Table name prefixed with parent database 'tablePrefix'" ) ; $ tableElement -> appendChild ( $ tablePrefixingNoticeComment ) ; $ table = $ tableElement -> getAttribute ( 'name' ) ; $ tableElement -> setAttribute ( 'name' , $ tablePrefix . $ table ) ; } } | Prefix table names with the prefix defined on the database . |
15,952 | protected function getDatabaseFromDatabaseElement ( \ DOMElement $ databaseElement ) { $ database = $ databaseElement -> getAttribute ( 'name' ) ; if ( empty ( $ database ) ) { throw new \ LogicException ( 'Unnamed database node.' ) ; } return $ database ; } | Get the database name from a database element . |
15,953 | protected function initGlobalDatabaseElement ( $ database ) { if ( \ in_array ( $ database , $ this -> databases ) ) { return ; } $ databaseDocument = new \ DOMDocument ( static :: $ GLOBAL_SCHEMA_XML_VERSION , static :: $ GLOBAL_SCHEMA_XML_ENCODING ) ; $ databaseElement = $ databaseDocument -> createElement ( 'database' ) ; $ databaseElement -> setAttribute ( 'name' , $ database ) ; $ identifierQuotingNoticeComment = $ databaseElement -> ownerDocument -> createComment ( "Attribute 'identifierQuoting' generated" ) ; $ databaseElement -> appendChild ( $ identifierQuotingNoticeComment ) ; $ databaseElement -> setAttribute ( 'identifierQuoting' , 'true' ) ; $ databaseDocument -> appendChild ( $ databaseElement ) ; $ this -> databases [ ] = $ database ; $ this -> globalDatabaseElements [ $ database ] = $ databaseElement ; $ this -> sourceDatabaseElements [ $ database ] = [ ] ; $ this -> externalSchemaDatabaseElements [ $ database ] = [ ] ; } | Create a global database element in a new document . |
15,954 | protected function mergeDatabaseElement ( \ DOMElement $ sourceDatabaseElement ) { $ database = $ this -> getDatabaseFromDatabaseElement ( $ sourceDatabaseElement ) ; $ this -> initGlobalDatabaseElement ( $ database ) ; $ globalDatabaseElement = $ this -> globalDatabaseElements [ $ database ] ; $ fileStartMarkerComment = $ globalDatabaseElement -> ownerDocument -> createComment ( "Start of schema from '{$sourceDatabaseElement->ownerDocument->baseURI}'" ) ; $ globalDatabaseElement -> appendChild ( $ fileStartMarkerComment ) ; foreach ( $ sourceDatabaseElement -> childNodes as $ childNode ) { $ importedNode = $ globalDatabaseElement -> ownerDocument -> importNode ( $ childNode , true ) ; $ globalDatabaseElement -> appendChild ( $ importedNode ) ; } $ fileEndMarkerComment = $ globalDatabaseElement -> ownerDocument -> createComment ( "End of schema from '{$sourceDatabaseElement->ownerDocument->baseURI}'" ) ; $ globalDatabaseElement -> appendChild ( $ fileEndMarkerComment ) ; $ this -> sourceDatabaseElements [ $ database ] [ ] = $ sourceDatabaseElement ; } | Merge a source database element into the corresponding global database element for this database . |
15,955 | protected function includeExternalSchema ( \ DOMElement $ externalDatabaseElement ) { $ database = $ this -> getDatabaseFromDatabaseElement ( $ externalDatabaseElement ) ; $ this -> initGlobalDatabaseElement ( $ database ) ; $ globalDatabaseElement = $ this -> globalDatabaseElements [ $ database ] ; $ externalSchemaIncludeComment = $ globalDatabaseElement -> ownerDocument -> createComment ( "External schema included in the combining process" ) ; $ globalDatabaseElement -> appendChild ( $ externalSchemaIncludeComment ) ; $ externalSchemaInclude = $ globalDatabaseElement -> ownerDocument -> createElement ( 'external-schema' , $ externalDatabaseElement -> ownerDocument -> baseURI ) ; $ globalDatabaseElement -> appendChild ( $ externalSchemaInclude ) ; $ this -> externalSchemaDatabaseElements [ $ database ] [ ] = $ externalDatabaseElement ; } | Include an external schema into a database element . |
15,956 | public function getImport ( $ importId , $ dispatchException = false ) { $ import = ( new ImportQuery ) -> findPk ( $ importId ) ; if ( $ import === null && $ dispatchException ) { throw new \ ErrorException ( Translator :: getInstance ( ) -> trans ( 'There is no id "%id" in the imports' , [ '%id' => $ importId ] ) ) ; } return $ import ; } | Get import model based on given identifier |
15,957 | public function getImportByRef ( $ importRef , $ dispatchException = false ) { $ import = ( new ImportQuery ) -> findOneByRef ( $ importRef ) ; if ( $ import === null && $ dispatchException ) { throw new \ ErrorException ( Translator :: getInstance ( ) -> trans ( 'There is no id "%ref" in the imports' , [ '%ref' => $ importRef ] ) ) ; } return $ import ; } | Get import model based on given reference |
15,958 | public function getCategory ( $ importCategoryId , $ dispatchException = false ) { $ category = ( new ImportCategoryQuery ) -> findPk ( $ importCategoryId ) ; if ( $ category === null && $ dispatchException ) { throw new \ ErrorException ( Translator :: getInstance ( ) -> trans ( 'There is no id "%id" in the import categories' , [ '%id' => $ importCategoryId ] ) ) ; } return $ category ; } | Get import category model based on given identifier |
15,959 | public function matchArchiverByExtension ( $ fileName ) { foreach ( $ this -> archiverManager -> getArchivers ( true ) as $ archiver ) { if ( stripos ( $ fileName , '.' . $ archiver -> getExtension ( ) ) !== false ) { return $ archiver ; } } return null ; } | Match archiver relative to file name |
15,960 | public function matchSerializerByExtension ( $ fileName ) { foreach ( $ this -> serializerManager -> getSerializers ( ) as $ serializer ) { if ( stripos ( $ fileName , '.' . $ serializer -> getExtension ( ) ) !== false ) { return $ serializer ; } } return null ; } | Match serializer relative to file name |
15,961 | public function dump ( $ glue = '' , $ before = '' , $ after = '' ) { $ ret = '' ; if ( 0 !== \ count ( $ this -> fragments ) ) { $ ret = $ before . implode ( $ glue , $ this -> fragments ) . $ after ; } return $ ret ; } | Concatenates all fragments in a string . |
15,962 | public function buildConnectionNode ( $ rootName , $ isArray ) { $ treeBuilder = new TreeBuilder ( ) ; $ connectionNode = $ treeBuilder -> root ( $ rootName ) ; if ( $ isArray ) { $ connectionNodePrototype = $ connectionNode -> prototype ( 'array' ) ; $ connectionNodeBuilder = $ connectionNodePrototype -> children ( ) ; } else { $ connectionNodeBuilder = $ connectionNode -> children ( ) ; } $ connectionNodeBuilder -> scalarNode ( 'driver' ) -> defaultValue ( 'mysql' ) ; $ connectionNodeBuilder -> scalarNode ( 'user' ) -> defaultValue ( 'root' ) ; $ connectionNodeBuilder -> scalarNode ( 'password' ) -> defaultValue ( '' ) ; $ connectionNodeBuilder -> scalarNode ( 'dsn' ) -> cannotBeEmpty ( ) ; $ connectionNodeBuilder -> scalarNode ( 'classname' ) -> defaultValue ( '\Propel\Runtime\Connection\ConnectionWrapper' ) ; return $ connectionNode ; } | Build a configuration node describing one or more database connection |
15,963 | public function getUseDeclarations ( ) { $ declarations = [ ] ; $ use_blocks = $ this -> children ( Filter :: isInstanceOf ( '\Pharborist\Namespaces\UseDeclarationBlockNode' ) ) ; foreach ( $ use_blocks as $ use_block ) { foreach ( $ use_block -> getDeclarationStatements ( ) as $ use_statement ) { $ declarations = array_merge ( $ declarations , $ use_statement -> getDeclarations ( ) -> toArray ( ) ) ; } } return new NodeCollection ( $ declarations , FALSE ) ; } | Get the use declarations of this statement block . |
15,964 | public function getClassAliases ( ) { $ mappings = array ( ) ; foreach ( $ this -> getUseDeclarations ( ) as $ use_declaration ) { if ( $ use_declaration -> isClass ( ) ) { $ mappings [ $ use_declaration -> getBoundedName ( ) ] = $ use_declaration -> getName ( ) -> getAbsolutePath ( ) ; } } return $ mappings ; } | Return mapping of class names to fully qualified names . |
15,965 | public function appendStatement ( StatementNode $ statementNode ) { if ( ! $ this -> isEmpty ( ) && $ this -> firstToken ( ) -> getType ( ) === '{' ) { $ this -> lastChild ( ) -> before ( $ statementNode ) ; } else { $ this -> appendChild ( $ statementNode ) ; } return $ this ; } | Append statement to block . |
15,966 | public function make ( array $ config ) { Arr :: requires ( $ config , [ 'token' ] ) ; $ client = new Client ( ) ; return new SlackGateway ( $ client , $ config ) ; } | Create a new slack gateway instance . |
15,967 | public static function get ( $ key = null ) { $ configs = self :: $ configs ; if ( $ key ) { $ configs = ! empty ( self :: $ configs [ $ key ] ) ? self :: $ configs [ $ key ] : null ; } else { $ configs = self :: $ configs ; } return $ configs ; } | Get configs or config by key . |
15,968 | public static function any ( $ filters ) { return function ( $ node ) use ( $ filters ) { foreach ( $ filters as $ filter ) { if ( $ filter ( $ node ) ) { return TRUE ; } } return FALSE ; } ; } | Callback returns true if any of the callbacks pass . |
15,969 | public static function all ( $ filters ) { return function ( $ node ) use ( $ filters ) { foreach ( $ filters as $ filter ) { if ( ! $ filter ( $ node ) ) { return FALSE ; } } return TRUE ; } ; } | Callback returns true if all of the callbacks pass . |
15,970 | public static function isInstanceOf ( $ class_name ) { $ classes = func_get_args ( ) ; return function ( $ node ) use ( $ classes ) { foreach ( $ classes as $ class ) { if ( $ node instanceof $ class ) { return TRUE ; } } return FALSE ; } ; } | Callback to filter for nodes of certain types . |
15,971 | public static function isFunction ( $ function_name ) { $ function_names = func_get_args ( ) ; return function ( $ node ) use ( $ function_names ) { if ( $ node instanceof FunctionDeclarationNode ) { return in_array ( $ node -> getName ( ) -> getText ( ) , $ function_names , TRUE ) ; } return FALSE ; } ; } | Callback to filter for specific function declaration . |
15,972 | public static function isFunctionCall ( $ function_name ) { $ function_names = func_get_args ( ) ; return function ( $ node ) use ( $ function_names ) { if ( $ node instanceof FunctionCallNode ) { return in_array ( $ node -> getName ( ) -> getText ( ) , $ function_names , TRUE ) ; } return FALSE ; } ; } | Callback to filter for calls to a function . |
15,973 | public static function isClass ( $ class_name ) { $ class_names = func_get_args ( ) ; return function ( $ node ) use ( $ class_names ) { if ( $ node instanceof ClassNode ) { return in_array ( $ node -> getName ( ) -> getText ( ) , $ class_names , TRUE ) ; } return FALSE ; } ; } | Callback to filter for specific class declaration . |
15,974 | public static function isClassMethodCall ( $ class_name , $ method_name ) { return function ( $ node ) use ( $ class_name , $ method_name ) { if ( $ node instanceof ClassMethodCallNode ) { $ call_class_name_node = $ node -> getClassName ( ) ; $ call_class_name = $ call_class_name_node instanceof NameNode ? $ call_class_name_node -> getAbsolutePath ( ) : $ call_class_name_node -> getText ( ) ; $ class_matches = $ call_class_name === $ class_name ; $ method_matches = $ node -> getMethodName ( ) -> getText ( ) === $ method_name ; return $ class_matches && $ method_matches ; } return FALSE ; } ; } | Callback to filter for calls to a class method . |
15,975 | public static function isComment ( $ include_doc_comment = TRUE ) { if ( $ include_doc_comment ) { return function ( $ node ) { if ( $ node instanceof LineCommentBlockNode ) { return TRUE ; } elseif ( $ node instanceof CommentNode ) { return ! ( $ node -> parent ( ) instanceof LineCommentBlockNode ) ; } else { return FALSE ; } } ; } else { return function ( $ node ) { if ( $ node instanceof LineCommentBlockNode ) { return TRUE ; } elseif ( $ node instanceof DocCommentNode ) { return FALSE ; } elseif ( $ node instanceof CommentNode ) { return ! ( $ node -> parent ( ) instanceof LineCommentBlockNode ) ; } else { return FALSE ; } } ; } } | Callback to filter comments . |
15,976 | public static function isTokenType ( $ type ) { $ types = func_get_args ( ) ; return function ( $ node ) use ( $ types ) { return $ node instanceof TokenNode && in_array ( $ node -> getType ( ) , $ types ) ; } ; } | Callback to test if match to given token type . |
15,977 | public static function isNewline ( ) { static $ callback = NULL ; if ( ! $ callback ) { $ callback = function ( Node $ node ) { return $ node instanceof WhitespaceNode && $ node -> getNewlineCount ( ) > 0 ; } ; } return $ callback ; } | Callback to match whitespace containing newlines . |
15,978 | public static function create ( string $ contents ) { $ contextInst = new ContextFactory ( ) ; $ context = function ( string $ namespace ) use ( $ contents , $ contextInst ) { return $ contextInst -> createForNamespace ( $ namespace , $ contents ) ; } ; $ phpdocInst = DocBlockFactory :: createInstance ( ) ; $ phpdoc = function ( string $ doc , Context $ context ) use ( $ phpdocInst ) { return $ phpdocInst -> create ( $ doc , $ context ) ; } ; return new self ( $ context , $ phpdoc ) ; } | Create a new doc visitor aware of file contents . |
15,979 | public function enterNode ( Node $ node ) { if ( $ node instanceof Namespace_ ) { $ this -> resetContext ( $ node -> name ) ; } $ this -> recordDoc ( $ node -> getAttribute ( 'comments' , [ ] ) ) ; return $ node ; } | Enter the node and record the phpdoc . |
15,980 | protected function recordDoc ( array $ comments ) { $ callable = $ this -> phpdocFactory ; foreach ( $ comments as $ comment ) { if ( $ comment instanceof Doc ) { $ this -> doc [ ] = $ callable ( $ comment -> getText ( ) , $ this -> context ) ; } } } | Reset the visitor context . |
15,981 | protected static function sortUnique ( $ nodes ) { $ sort = [ ] ; $ detached = [ ] ; foreach ( $ nodes as $ node ) { $ key = $ node -> sortKey ( ) ; if ( $ key [ 0 ] === '~' ) { $ detached [ ] = $ node ; } else { $ sort [ $ key ] = $ node ; } } ksort ( $ sort , SORT_NATURAL ) ; return array_merge ( array_values ( $ sort ) , $ detached ) ; } | Sort nodes and remove duplicates |
15,982 | public function slice ( $ start_index , $ end_index = NULL ) { if ( $ start_index < 0 ) { $ start_index = $ this -> count ( ) + $ start_index ; } if ( $ end_index < 0 ) { $ end_index = $ this -> count ( ) + $ end_index ; } $ last_index = $ this -> count ( ) - 1 ; if ( $ start_index > $ last_index ) { $ start_index = $ last_index ; } if ( $ end_index !== NULL ) { if ( $ end_index > $ last_index ) { $ end_index = $ last_index ; } if ( $ start_index > $ end_index ) { $ start_index = $ end_index ; } $ length = $ end_index - $ start_index ; } else { $ length = $ this -> count ( ) - $ start_index ; } return new NodeCollection ( array_slice ( $ this -> nodes , $ start_index , $ length ) ) ; } | Reduce the set of matched nodes to a subset specified by a range . |
15,983 | public function indexOf ( callable $ callback ) { foreach ( $ this -> nodes as $ i => $ node ) { if ( $ callback ( $ node ) ) { return $ i ; } } return - 1 ; } | Index of first element that is matched by callback . |
15,984 | public function is ( callable $ callback ) { foreach ( $ this -> nodes as $ node ) { if ( $ callback ( $ node ) ) { return TRUE ; } } return FALSE ; } | Test is any element in collection matches . |
15,985 | public function closest ( callable $ callback ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { if ( $ match = $ node -> closest ( $ callback ) ) { $ matches [ ] = $ match ; } } return new NodeCollection ( $ matches ) ; } | For each node in the collection get the first node matched by the callback by testing this node and traversing up through its ancestors in the tree . |
15,986 | public function children ( callable $ callback = NULL ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { if ( $ node instanceof ParentNode ) { $ matches = array_merge ( $ matches , $ node -> children ( $ callback ) -> nodes ) ; } } return new NodeCollection ( $ matches ) ; } | Get the immediate children of each node in the set of matched nodes . |
15,987 | public function clear ( ) { foreach ( $ this -> nodes as $ node ) { if ( $ node instanceof ParentNode ) { $ node -> clear ( ) ; } } return $ this ; } | Remove all child nodes of the set of matched elements . |
15,988 | public function previous ( callable $ callback = NULL ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { if ( $ match = $ node -> previous ( $ callback ) ) { $ matches [ ] = $ match ; } } return new NodeCollection ( $ matches ) ; } | Get the immediately preceding sibling of each node in the set of matched nodes . If a callback is provided it retrieves the next sibling only if the callback returns TRUE . |
15,989 | public function previousAll ( callable $ callback = NULL ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { $ matches = array_merge ( $ matches , $ node -> previousAll ( $ callback ) -> nodes ) ; } return new NodeCollection ( $ matches ) ; } | Get all preceding siblings of each node in the set of matched nodes optionally filtered by a callback . |
15,990 | public function previousUntil ( callable $ callback , $ inclusive = FALSE ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { $ matches = array_merge ( $ matches , $ node -> previousUntil ( $ callback , $ inclusive ) -> nodes ) ; } return new NodeCollection ( $ matches ) ; } | Get all preceding siblings of each node up to the node matched by the callback . |
15,991 | public function find ( callable $ callback ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { if ( $ node instanceof ParentNode ) { $ matches = array_merge ( $ matches , $ node -> find ( $ callback ) -> nodes ) ; } } return new NodeCollection ( $ matches ) ; } | Get the descendants of each node in the current set of matched nodes filtered by callback . |
15,992 | public function filter ( callable $ callback ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ index => $ node ) { if ( $ callback ( $ node , $ index ) ) { $ matches [ ] = $ node ; } } return new NodeCollection ( $ matches , FALSE ) ; } | Reduce the set of matched nodes to those that pass the callback filter . |
15,993 | public function has ( callable $ callback ) { $ matches = [ ] ; foreach ( $ this -> nodes as $ node ) { if ( $ node instanceof ParentNode && $ node -> has ( $ callback ) ) { $ matches [ ] = $ node ; } } return new NodeCollection ( $ matches , FALSE ) ; } | Reduce the set of matched nodes to those that have a descendant that match . |
15,994 | public function first ( ) { $ matches = [ ] ; if ( ! empty ( $ this -> nodes ) ) { $ matches [ ] = $ this -> nodes [ 0 ] ; } return new NodeCollection ( $ matches , FALSE ) ; } | Reduce the set of matched nodes to the first in the set . |
15,995 | public function last ( ) { $ matches = [ ] ; if ( ! empty ( $ this -> nodes ) ) { $ matches [ ] = $ this -> nodes [ count ( $ this -> nodes ) - 1 ] ; } return new NodeCollection ( $ matches , FALSE ) ; } | Reduce the set of matched nodes to the last in the set . |
15,996 | public function insertBefore ( $ targets ) { foreach ( $ this -> nodes as $ node ) { $ node -> insertBefore ( $ targets ) ; } return $ this ; } | Insert every node in the set of matched nodes before the targets . |
15,997 | public function before ( $ nodes ) { foreach ( $ this -> nodes as $ i => $ node ) { $ node -> before ( $ i === 0 ? $ nodes : clone $ nodes ) ; } return $ this ; } | Insert nodes before each node in the set of matched nodes . |
15,998 | public function insertAfter ( $ targets ) { foreach ( $ this -> nodes as $ node ) { $ node -> insertAfter ( $ targets ) ; } return $ this ; } | Insert every node in the set of matched nodes after the targets . |
15,999 | public function after ( $ nodes ) { foreach ( $ this -> nodes as $ i => $ node ) { $ node -> after ( $ i === 0 ? $ nodes : clone $ nodes ) ; } return $ this ; } | Insert nodes after each node in the set of matched nodes . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.