php Thelia-Model-CountryQuery类(方法)实例源码

下面列出了php Thelia-Model-CountryQuery 类(方法)源码代码实例,从而了解它的用法。

作者:badela    项目:theli   
public function buildModelCriteria()
 {
     $search = CountryQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search);
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $area = $this->getArea();
     if (null !== $area) {
         $search->filterByAreaId($area, Criteria::IN);
     }
     $withArea = $this->getWith_area();
     if (true === $withArea) {
         $search->filterByAreaId(null, Criteria::ISNOTNULL);
     } elseif (false === $withArea) {
         $search->filterByAreaId(null, Criteria::ISNULL);
     }
     $exclude = $this->getExclude();
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $search->addAscendingOrderByColumn('i18n_TITLE');
     return $search;
 }

作者:marger    项目:theli   
public function buildModelCriteria()
 {
     $search = CountryQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search);
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $area = $this->getArea();
     if (null !== $area) {
         $search->useCountryAreaQuery('with_area')->filterByAreaId($area, Criteria::IN)->endUse();
     }
     $excludeArea = $this->getExcludeArea();
     if (null !== $excludeArea) {
         // FIXME : did not find a way to do this in a single request :(
         // select * from country where id not in (select country_id from country_area where area in (...))
         $countries = CountryAreaQuery::create()->filterByAreaId($excludeArea, Criteria::IN)->select(['country_id'])->find();
         $search->filterById($countries->toArray(), Criteria::NOT_IN);
     }
     $withArea = $this->getWithArea();
     if (true === $withArea) {
         $search->joinCountryArea('with_area', Criteria::LEFT_JOIN)->where('`with_area`.country_id ' . Criteria::ISNOTNULL);
     } elseif (false === $withArea) {
         $search->joinCountryArea('with_area', Criteria::LEFT_JOIN)->where('`with_area`.country_id ' . Criteria::ISNULL);
     }
     $exclude = $this->getExclude();
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $search->addAscendingOrderByColumn('i18n_TITLE');
     return $search;
 }

作者:marger    项目:theli   
/**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $stubDispatcher = $this->getMockBuilder('\\Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $stubDispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($dummy, $cartEvent) {
         $ci = new CartItem();
         $ci->setId(3)->setPrice(123)->setPromo(0)->setProductId($this->freeProduct->getId());
         $cartEvent->setCartItem($ci);
     }));
     $stubFacade->expects($this->any())->method('getDispatcher')->will($this->returnValue($stubDispatcher));
     $stubSession = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Session\\Session')->disableOriginalConstructor()->getMock();
     $stubSession->expects($this->any())->method('get')->will($this->onConsecutiveCalls(-1, 3));
     $stubRequest = $this->getMockBuilder('\\Thelia\\Core\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $stubRequest->expects($this->any())->method('getSession')->will($this->returnValue($stubSession));
     $stubFacade->expects($this->any())->method('getRequest')->will($this->returnValue($stubRequest));
     $country = CountryQuery::create()->findOneByByDefault(1);
     $stubFacade->expects($this->any())->method('getDeliveryCountry')->will($this->returnValue($country));
     return $stubFacade;
 }

作者:zorn-    项目:theli   
public function toggleDefault(CountryToggleDefaultEvent $event)
 {
     if (null !== ($country = CountryQuery::create()->findPk($event->getCountryId()))) {
         $country->toggleDefault();
         $event->setCountry($country);
     }
 }

作者:manuelbc    项目:theli   
public function verifyCountry($value, ExecutionContextInterface $context)
 {
     $address = CountryQuery::create()->findPk($value);
     if (null === $address) {
         $context->addViolation(Translator::getInstance()->trans("Country ID not found"));
     }
 }

作者:GuiminZHO    项目:theli   
public function testFormatAddress()
 {
     // Test for address in France
     $countryFR = CountryQuery::create()->filterByIsoalpha2('FR')->findOne();
     $address = AddressQuery::create()->findOne();
     $address->setCountryId($countryFR->getId())->save();
     $data = $this->renderString('{format_address address=$address locale="fr_FR"}', ['address' => $address->getId()]);
     $title = $address->getCustomerTitle()->setLocale('fr_FR')->getShort();
     $expected = ['<p >', sprintf('<span class="recipient">%s %s %s</span><br>', $title, $address->getLastname(), $address->getFirstname()), sprintf('<span class="address-line1">%s</span><br>', $address->getAddress1()), sprintf('<span class="postal-code">%s</span> <span class="locality">%s</span><br>', $address->getZipcode(), $address->getCity()), '<span class="country">France</span>', '</p>'];
     $this->assertEquals($data, implode("\n", $expected));
     // Test for address in USA
     $stateDC = StateQuery::create()->filterByIsocode('DC')->findOne();
     $countryUS = $stateDC->getCountry();
     $address->setCountryId($countryUS->getId())->setStateId($stateDC->getId())->save();
     $data = $this->renderString('{format_address address=$address locale="en_US"}', ['address' => $address->getId()]);
     $title = $address->getCustomerTitle()->setLocale('en_US')->getShort();
     $expected = ['<p >', sprintf('<span class="recipient">%s %s %s</span><br>', $title, $address->getLastname(), $address->getFirstname()), sprintf('<span class="address-line1">%s</span><br>', $address->getAddress1()), sprintf('<span class="locality">%s</span>, <span class="administrative-area">%s</span> <span class="postal-code">%s</span><br>', $address->getCity(), $stateDC->getIsocode(), $address->getZipcode()), '<span class="country">United States</span>', '</p>'];
     $this->assertEquals($data, implode("\n", $expected));
     // Test html tag
     $data = $this->renderString('{format_address html_tag="address" html_class="a_class" html_id="an_id" address=$address}', ['address' => $address->getId()]);
     $this->assertTrue(strpos($data, '<address class="a_class" id="an_id">') !== false);
     // Test plain text
     $data = $this->renderString('{format_address html="0" address=$address locale="en_US"}', ['address' => $address->getId()]);
     $expected = [sprintf('%s %s %s', $title, $address->getLastname(), $address->getFirstname()), sprintf('%s', $address->getAddress1()), sprintf('%s, %s %s', $address->getCity(), $stateDC->getIsocode(), $address->getZipcode()), 'United States'];
     $this->assertEquals($data, implode("\n", $expected));
 }

作者:ThomasArnau    项目:LocalPicku   
public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_localpickup')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_localpickup'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $store = ConfigQuery::create();
                 $country = CountryQuery::create()->findPk($store->read("store_country"));
                 $country = CountryI18nQuery::create()->filterById($country->getId())->findOneByLocale($order->getLang()->getLocale())->getTitle();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('store_name', $store->read("store_name"));
                 $this->parser->assign('store_address1', $store->read("store_address1"));
                 $this->parser->assign('store_address2', $store->read("store_address2"));
                 $this->parser->assign('store_address3', $store->read("store_address3"));
                 $this->parser->assign('store_zipcode', $store->read("store_zipcode"));
                 $this->parser->assign('store_city', $store->read("store_city"));
                 $this->parser->assign('store_country', $country);
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }

作者:zorn-    项目:theli   
public function migrateSystemAction()
 {
     $response = $this->checkAuth(AdminResources::COUNTRY, array(), AccessManager::UPDATE);
     if (null !== $response) {
         return $response;
     }
     // load country not migrated
     $dataForm = [];
     $migratedCountries = json_decode(ConfigQuery::read('thelia_country_state_migration', '[]'), true);
     $countries = CountryQuery::create()->filterByHasStates(1);
     /** @var Country $country */
     foreach ($countries as $country) {
         $oldCountries = CountryQuery::create()->filterByHasStates(0)->filterByIsocode($country->getIsoCode())->find();
         /** @var Country $oldCountry */
         foreach ($oldCountries as $oldCountry) {
             if (!isset($migratedCountries[$oldCountry->getId()])) {
                 $dataForm[] = ['migrate' => false, 'country' => $oldCountry->getId(), 'new_country' => $country->getId(), 'new_state' => null];
             }
         }
     }
     // prepare form
     $form = $this->createForm('thelia.admin.country.state.migration', 'form', ['migrations' => $dataForm]);
     $this->getParserContext()->addForm($form);
     return $this->render('countries-migrate', ['countriesMigrated' => $migratedCountries, 'showForm' => count($dataForm) != 0]);
 }

作者:badela    项目:theli   
public function removeCountry(AreaRemoveCountryEvent $event)
 {
     if (null !== ($country = CountryQuery::create()->findPk($event->getCountryId()))) {
         $event->setArea($country->getArea());
         $country->setDispatcher($event->getDispatcher());
         $country->setAreaId(null)->save();
     }
 }

作者:alex6353    项目:theli   
protected function buildForm()
 {
     $countryList = array();
     foreach (CountryQuery::create()->find() as $country) {
         $countryList[$country->getId()] = $country->getId();
     }
     $this->formBuilder->add("id", "hidden", array("required" => true, "constraints" => array(new Constraints\NotBlank(), new Constraints\Callback(array("methods" => array(array($this, "verifyTaxRuleId")))))))->add("tax_list", "hidden", array("required" => true, "attr" => array("id" => 'tax_list'), "constraints" => array(new Constraints\Callback(array("methods" => array(array($this, "verifyTaxList")))))))->add("country_list", "choice", array("choices" => $countryList, "required" => true, "multiple" => true, "constraints" => array(new Constraints\NotBlank())));
 }

作者:lopes-vincen    项目:Predic   
/**
  * @return array|mixed|\Thelia\Model\Country
  * @throws \UnexpectedValueException
  */
 public function getDeliveryOrderCountry()
 {
     $country_id = $this->getDeliveryOrderAddress()->getCountryId();
     $country = CountryQuery::create()->findPK($country_id);
     if ($country === null) {
         throw new \UnexpectedValueException("The country doesn't exist");
     }
     return $country;
 }

作者:vigourouxjulie    项目:theli   
/**
  * @param AreaModel $area
  * @depends testAddCountry
  * @return AreaModel
  */
 public function testRemoveCountry(AreaModel $area)
 {
     $country = CountryQuery::create()->filterByArea($area)->find()->getFirst();
     $event = new AreaRemoveCountryEvent($area->getId(), $country->getId());
     $areaAction = new Area();
     $areaAction->removeCountry($event);
     $updatedCountry = CountryAreaQuery::create()->filterByCountryId($country->getId())->filterByStateId(null)->filterByAreaId($area->getId())->findOne();
     $updatedArea = $event->getArea();
     $this->assertInstanceOf('Thelia\\Model\\Area', $updatedArea);
     $this->assertNull($updatedCountry);
     return $event->getArea();
 }

作者:ThomasArnau    项目:SoColissim   
public function socolissimoDeliveryPrice($params, $smarty)
 {
     $deliveryMode = $params["delivery-mode"];
     $country = CountryQuery::create()->findOneById($params["country"]);
     $cartWeight = $this->request->getSession()->getSessionCart($this->dispatcher)->getWeight();
     $cartAmount = $this->request->getSession()->getSessionCart($this->dispatcher)->getTaxedAmount($country);
     try {
         $price = SoColissimo::getPostageAmount($country->getAreaId(), $cartWeight, $cartAmount, $deliveryMode);
     } catch (DeliveryException $ex) {
         $smarty->assign('isValidMode', false);
     }
     $smarty->assign('deliveryModePrice', $price);
 }

作者:badela    项目:theli   
/**
  * @param AreaModel $area
  * @depends testAddCountry
  */
 public function testRemoveCountry(AreaModel $area)
 {
     $country = CountryQuery::create()->filterByArea($area)->find()->getFirst();
     $event = new AreaRemoveCountryEvent($area->getId(), $country->getId());
     $event->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $areaAction = new Area();
     $areaAction->removeCountry($event);
     $updatedCountry = CountryQuery::create()->findPk($country->getId());
     $updatedArea = $event->getArea();
     $this->assertInstanceOf('Thelia\\Model\\Area', $updatedArea);
     $this->assertNull($updatedCountry->getAreaId());
     return $event->getArea();
 }

作者:alex6353    项目:theli   
/**
  * @inheritdoc
  */
 public function getSummary()
 {
     $i18nOperator = Operators::getI18n($this->translator, $this->operators[self::COUNTRIES_LIST]);
     $cntryStrList = '';
     $cntryIds = $this->values[self::COUNTRIES_LIST];
     if (null !== ($cntryList = CountryQuery::create()->findPks($cntryIds))) {
         /** @var Country $cntry */
         foreach ($cntryList as $cntry) {
             $cntryStrList .= $cntry->getTitle() . ', ';
         }
         $cntryStrList = rtrim($cntryStrList, ', ');
     }
     return $this->getSummaryLabel($cntryStrList, $i18nOperator);
 }

作者:shiron    项目:theli   
public function testLoad()
 {
     $productQuery = ProductQuery::create()->findOne();
     $countryQuery = CountryQuery::create()->findOneById(64);
     $calculator = new Calculator();
     $taxRuleQuery = $this->getMock('\\Thelia\\Model\\TaxRuleQuery', array('getTaxCalculatorCollection'));
     $taxRuleQuery->expects($this->once())->method('getTaxCalculatorCollection')->with($productQuery->getTaxRule(), $countryQuery)->will($this->returnValue('foo'));
     $rewritingUrlQuery = $this->getProperty('taxRuleQuery');
     $rewritingUrlQuery->setValue($calculator, $taxRuleQuery);
     $calculator->load($productQuery, $countryQuery);
     $this->assertEquals($productQuery, $this->getProperty('product')->getValue($calculator));
     $this->assertEquals($countryQuery, $this->getProperty('country')->getValue($calculator));
     $this->assertEquals('foo', $this->getProperty('taxRulesCollection')->getValue($calculator));
 }

作者:zorn-    项目:theli   
public function verifyState($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (null !== ($country = CountryQuery::create()->findPk($data['country']))) {
         if ($country->getHasStates()) {
             if (null !== ($state = StateQuery::create()->findPk($data['state']))) {
                 if ($state->getCountryId() !== $country->getId()) {
                     $context->addViolation(Translator::getInstance()->trans("This state doesn't belong to this country."));
                 }
             } else {
                 $context->addViolation(Translator::getInstance()->trans("You should select a state for this country."));
             }
         }
     }
 }

作者:marger    项目:theli   
/**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $defaultCountry = CountryQuery::create()->filterByByDefault(1)->findOne();
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubFacade->expects($this->any())->method('getCartTotalPrice')->will($this->returnValue($cartTotalPrice));
     $stubFacade->expects($this->any())->method('getDeliveryCountry')->will($this->returnValue($defaultCountry));
     $stubFacade->expects($this->any())->method('getCheckoutCurrency')->will($this->returnValue($checkoutCurrency));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     return $stubFacade;
 }

作者:vigourouxjulie    项目:theli   
public function testCreate()
 {
     $country = CountryQuery::create()->filterByHasStates(1)->findOne();
     $event = new StateCreateEvent();
     $event->setVisible(1)->setCountry($country->getId())->setIsocode('AA')->setLocale('en_US')->setTitle('State1');
     $action = new State();
     $action->create($event);
     $createdState = $event->getState();
     $this->assertInstanceOf('Thelia\\Model\\State', $createdState);
     $this->assertFalse($createdState->isNew());
     $this->assertEquals($country->getId(), $createdState->getCountryId());
     $this->assertEquals('AA', $createdState->getIsocode());
     $this->assertEquals('en_US', $createdState->getLocale());
     $this->assertEquals('State1', $createdState->getTitle());
     return $createdState;
 }

作者:alex6353    项目:theli   
/**
  * Build Coupon form
  *
  * @return void
  */
 protected function buildForm()
 {
     // Create countries and shipping modules list
     $countries = [0 => '   '];
     $list = CountryQuery::create()->find();
     /** @var Country $item */
     foreach ($list as $item) {
         $countries[$item->getId()] = $item->getTitle();
     }
     asort($countries);
     $countries[0] = Translator::getInstance()->trans("All countries");
     $modules = [0 => '   '];
     $list = ModuleQuery::create()->filterByActivate(BaseModule::IS_ACTIVATED)->filterByType(BaseModule::DELIVERY_MODULE_TYPE)->find();
     /** @var Module $item */
     foreach ($list as $item) {
         $modules[$item->getId()] = $item->getTitle();
     }
     asort($modules);
     $modules[0] = Translator::getInstance()->trans("All shipping methods");
     $this->formBuilder->add('code', 'text', array('constraints' => array(new NotBlank())))->add('title', 'text', array('constraints' => array(new NotBlank())))->add('shortDescription', 'text')->add('description', 'textarea')->add('type', 'text', array('constraints' => array(new NotBlank(), new NotEqualTo(array('value' => -1)))))->add('isEnabled', 'text', array())->add('expirationDate', 'text', array('constraints' => array(new NotBlank(), new Callback(array("methods" => array(array($this, "checkLocalizedDate")))))))->add('isCumulative', 'text', array())->add('isRemovingPostage', 'text', array())->add('freeShippingForCountries', 'choice', array('multiple' => true, 'choices' => $countries))->add('freeShippingForModules', 'choice', array('multiple' => true, 'choices' => $modules))->add('isAvailableOnSpecialOffers', 'text', array())->add('maxUsage', 'text', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(['value' => -1]))))->add('perCustomerUsageCount', 'choice', array('multiple' => false, 'required' => true, 'choices' => [1 => Translator::getInstance()->trans('Per customer'), 0 => Translator::getInstance()->trans('Overall')]))->add('locale', 'hidden', array('constraints' => array(new NotBlank())))->add('coupon_specific', 'collection', array('allow_add' => true, 'allow_delete' => true));
 }


问题


面经


文章

微信
公众号

扫码关注公众号