php XLite-Core-Database类(方法)实例源码

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

作者:hp    项目:heartland-x-cart5-plugi   
public function getPaymentMethod()
 {
     if (!$this->paymentMethod) {
         $this->paymentMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findOneBy(array('class' => self::MODEL_PATH));
     }
     return $this->paymentMethod;
 }

作者:kewaunite    项目:xcar   
/**
  * Update list
  *
  * @return void
  */
 protected function doActionVolumeDiscountsUpdate()
 {
     $list = new \XLite\Module\CDev\VolumeDiscounts\View\ItemsList\VolumeDiscounts();
     $list->processQuick();
     // Additional correction to re-define end of subtotal range for each discount
     \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\VolumeDiscounts\\Model\\VolumeDiscount')->correctSubtotalRangeEnd();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Get item
  *
  * @return \XLite\Model\OrderItem
  */
 public function getItem()
 {
     if (!isset($this->item)) {
         // Initialize order item from request param item_id
         if (is_numeric(\XLite\Core\Request::getInstance()->item_id)) {
             $item = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->find(\XLite\Core\Request::getInstance()->item_id);
             if ($item && $item->getProduct() && $item->hasAttributeValues()) {
                 $this->item = $item;
             }
         }
     }
     if (!isset($this->item) && \XLite\Core\Request::getInstance()->productId) {
         // Initialize order item from productId param
         $product = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find(\XLite\Core\Request::getInstance()->productId);
         if ($product) {
             $this->item = new \XLite\Model\OrderItem();
             $this->item->setProduct($product);
             $this->item->setAttributeValues($product->prepareAttributeValues());
         }
     }
     if (!isset($this->item)) {
         // Order item was not initialized: set to false to prevent re-initialization
         $this->item = false;
     }
     return $this->item;
 }

作者:hp    项目:heartland-x-cart5-plugi   
protected function getPaymentMethod()
 {
     if ($this->paymentMethod == null) {
         $this->paymentMethod = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findOneBy(array('class' => \XLite\Module\Heartland\Securesubmit\Core\Securesubmit::MODEL_PATH));
     }
     return $this->paymentMethod;
 }

作者:kewaunite    项目:xcar   
/**
  * This object will be used if another one is not passed
  *
  * @return \XLite\Module\XC\AuctionInc\Model\ProductAuctionInc
  */
 protected function getDefaultModelObject()
 {
     $model = $this->getModelId() ? \XLite\Core\Database::getRepo('XLite\\Module\\XC\\AuctionInc\\Model\\ProductAuctionInc')->findOneBy(array('product' => $this->getModelId())) : null;
     $model = $model ?: new \XLite\Module\XC\AuctionInc\Model\ProductAuctionInc();
     $model->setProduct($this->getProduct());
     return $model;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Preprocessor for no-action run
  *
  * @return void
  */
 protected function doNoAction()
 {
     if (\XLite\Core\Request::getInstance()->completed) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Category')->removeProductFilterCache();
     }
     parent::doNoAction();
 }

作者:kewaunite    项目:xcar   
/**
  * Return the category name for the title
  *
  * @return string
  */
 public function getCategory()
 {
     if (is_null($this->category)) {
         $this->category = \XLite\Core\Database::getRepo('XLite\\Model\\Category')->find($this->getCategoryId());
     }
     return $this->category;
 }

作者:kings    项目:cor   
/**
  * Read config options
  *
  * @param mixed $force ____param_comment____ OPTIONAL
  *
  * @return void
  */
 public function readConfig($force = false)
 {
     if (!isset($this->config) || $force) {
         $this->config = \XLite\Core\Database::getRepo('XLite\\Model\\Config')->getAllOptions($force);
     }
     return $this->config;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Switch state
  *
  * @return void
  */
 protected function doActionSwitch()
 {
     $value = !\XLite\Core\Config::getInstance()->XC->ThemeTweaker->edit_mode;
     \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'XC\\ThemeTweaker', 'name' => 'edit_mode', 'value' => $value));
     \XLite\Core\TopMessage::addInfo($value ? 'Webmaster mode is enabled' : 'Webmaster mode is disabled');
     $this->setReturnURL($this->buildURL('theme_tweaker_templates'));
 }

作者:kirkbauer    项目:kirkx   
/**
  * Execute certain hook handle
  *
  * @return void
  */
 public function executeHookHandler()
 {
     if (\XLite\Upgrade\Cell::getInstance()->isUpgraded()) {
         $entries = \XLite\Upgrade\Cell::getInstance()->getEntries();
         if ($entries) {
             \Includes\Utils\Operator::showMessage('', true, false);
             /** @var \XLite\Upgrade\Entry\AEntry $entry */
             foreach ($entries as $entry) {
                 if (!$entry->isPostUpgradeActionsCalled()) {
                     $message = '...Invoke actions for ' . $entry->getActualName();
                     \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
                     \Includes\Decorator\Utils\CacheManager::logMessage($message);
                     $isInvoked = \XLite\Upgrade\Cell::getInstance()->runHelper($entry, 'post_rebuild');
                     if ($isInvoked && \XLite\Upgrade\Cell::getInstance()->getHookRedirect()) {
                         break;
                     }
                     if (!\XLite\Upgrade\Cell::getInstance()->hasUnfinishedUpgradeHooks('post_rebuild', $entry)) {
                         // All post-rebuild hooks completed, run the rest actions...
                         \XLite\Upgrade\Cell::getInstance()->runCommonHelper($entry, 'add_labels');
                         \XLite\Upgrade\Cell::getInstance()->callInstallEvent($entry);
                         $entry->setPostUpgradeActionsCalled();
                     }
                     if (\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)) {
                         break;
                     }
                 }
             }
         }
     }
     \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL);
     \XLite\Core\Database::getEM()->flush();
     \XLite\Core\Database::getEM()->clear();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Return params list to use for search
  *
  * @return \XLite\Core\CommonCell
  */
 protected function getSearchCondition()
 {
     $result = parent::getSearchCondition();
     $productId = $this->getProductId();
     $result->{\XLite\Module\XC\Reviews\Model\Repo\Review::SEARCH_PRODUCT} = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($productId);
     return $result;
 }

作者:kings    项目:cor   
/**
  * Action of license key registration
  *
  * @return void
  */
 protected function doActionRegisterKey()
 {
     $key = \XLite\Core\Request::getInstance()->key;
     $addonsInfo = \XLite\Core\Marketplace::getInstance()->checkAddonKey($key);
     if ($addonsInfo && $addonsInfo[$key]) {
         $addonsInfo = $addonsInfo[$key];
         $repo = \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey');
         foreach ($addonsInfo as $info) {
             $module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findOneBy(array('author' => $info['author'], 'name' => $info['name']));
             if ($module) {
                 $entity = $repo->findKey($info['author'], $info['name']);
                 if ($entity) {
                     $entity->setKeyValue($key);
                     $repo->update($entity);
                 } else {
                     $entity = $repo->insert($info + array('keyValue' => $key));
                 }
                 \XLite\Core\Database::getEM()->flush();
                 // Clear cache for proper installation
                 \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST);
                 $this->showInfo(__FUNCTION__, 'License key has been successfully verified for "{{name}}" module by "{{author}}" author', array('name' => $module->getModuleName(), 'author' => $module->getAuthorName()));
             } else {
                 $this->showError(__FUNCTION__, 'Key is validated, but the module [' . implode(',', $info) . '] was not found');
             }
         }
     } else {
         $error = \XLite\Core\Marketplace::getInstance()->getError();
         if ($error) {
             $this->showError(__FUNCTION__, 'Response from marketplace: ' . $error);
         } else {
             $this->showError(__FUNCTION__, 'Response from marketplace is not received');
         }
     }
     $this->setReturnURL($this->buildURL('addons_list_marketplace'));
 }

作者:kings    项目:cor   
/**
  * Execute certain hook handle
  *
  * @return void
  */
 public function executeHookHandler()
 {
     foreach (\Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::getFixtures() as $fixture) {
         \XLite\Core\Database::getInstance()->loadFixturesFromYaml($fixture);
     }
     \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::removeFixtures();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Get product class
  *
  * @return \XLite\Model\ProductClass
  */
 public function getProductClass()
 {
     if (is_null($this->productClass) && \XLite\Core\Request::getInstance()->product_class_id) {
         $this->productClass = \XLite\Core\Database::getRepo('XLite\\Model\\ProductClass')->find(intval(\XLite\Core\Request::getInstance()->product_class_id));
     }
     return $this->productClass;
 }

作者:kings    项目:cor   
/**
  * Define widget params
  *
  * @return void
  */
 protected function getOrder()
 {
     if ($this->getParam(self::PARAM_ORDER_ID) && is_null($this->order)) {
         $this->order = \XLite\Core\Database::getRepo('\\XLite\\Model\\Order')->find($this->getParam(self::PARAM_ORDER_ID));
     }
     return $this->order;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Returns shipping method
  *
  * @return \XLite\Model\Shipping\Method
  */
 protected function getMethod()
 {
     if (null === $this->method) {
         $this->method = \XLite\Core\Database::getRepo('XLite\\Model\\Shipping\\Method')->find(\XLite\Core\Request::getInstance()->methodId);
     }
     return $this->method;
 }

作者:kings    项目:cor   
/**
  * Get order
  *
  * @return \XLite\Model\Order
  */
 public function getOrder()
 {
     if (!isset($this->order)) {
         $this->order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find(\XLite\Core\Request::getInstance()->order_id);
     }
     return $this->order;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Check field validity
  *
  * @return boolean
  */
 protected function checkFieldValidity()
 {
     $result = parent::checkFieldValidity();
     if ($result && $this->getValue()) {
         $length = strlen($this->getValue());
         // Check size
         if (static::MIN_SIZE > $length) {
             // Too small
             $result = false;
             $this->errorMessage = static::t('The length of X field must be greater than Y', array('name' => $this->getLabel(), 'min' => static::MIN_SIZE));
         } elseif (static::MAX_SIZE < $length) {
             // Too big
             $result = false;
             $this->errorMessage = static::t('The length of X field must be less than Y', array('name' => $this->getLabel(), 'max' => static::MAX_SIZE));
         } else {
             // Check duplicate
             $modelId = \XLite\Core\Request::getInstance()->id;
             $model = $modelId ? \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Coupons\\Model\\Coupon')->find($modelId) : null;
             $duplicates = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Coupons\\Model\\Coupon')->findDuplicates($this->getValue(), $model);
             if ($duplicates) {
                 $result = false;
                 $this->errorMessage = static::t('X code is already used for other coupon, please specify a different code', array('code' => $this->getValue()));
             }
         }
     }
     return $result;
 }

作者:kings    项目:cor   
/**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $c = new \XLite\Model\Country();
     foreach ($this->entityData as $field => $testValue) {
         $setterMethod = 'set' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $c->{$setterMethod}($testValue);
         $value = $c->{$getterMethod}();
         $this->assertEquals($testValue, $value, 'Creation checking (' . $field . ')');
     }
     $s = new \XLite\Model\State();
     $s->setState('test state');
     $s->setCode('ttt');
     $c->addStates($s);
     $em = \XLite\Core\Database::getEM();
     $em->persist($c);
     $em->flush();
     $em->clear();
     $c = \XLite\Core\Database::getEM()->merge($c);
     foreach ($this->entityData as $field => $testValue) {
         $getterMethod = 'get' . \XLite\Core\Converter::getInstance()->convertToCamelCase($field);
         $this->assertEquals($testValue, $c->{$getterMethod}(), 'Creation checking (' . $field . ') #2');
     }
     $this->assertEquals($s->getStateId(), $c->getStates()->get(0)->getStateId(), 'check state');
     $em->remove($c);
     $em->flush();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Update payment method
  *
  * @return void
  */
 protected function doActionUpdate()
 {
     $settings = \XLite\Core\Request::getInstance()->settings;
     $method = $this->getPaymentMethod();
     if (!$method) {
         \XLite\Core\TopMessage::addError('An attempt to update settings of unknown payment method');
     } else {
         if (is_array($settings)) {
             foreach ($settings as $name => $value) {
                 $method->setSetting($name, trim($value));
             }
         }
         $properties = \XLite\Core\Request::getInstance()->properties;
         if (is_array($properties) && !empty($properties)) {
             $method->map($properties);
         }
         \XLite\Core\Database::getRepo('\\XLite\\Model\\Payment\\Method')->update($method);
         // If "just added" method is configured and can be enabled then we enable it
         if (\XLite\Core\Request::getInstance()->just_added && $method->isConfigured() && $method->canEnable()) {
             $method->setEnabled(true);
             \XLite\Core\Database::getEM()->flush();
         }
         if ($method->isConfigured()) {
             \XLite\Core\TopMessage::addInfo('The settings of payment method successfully updated');
             $this->setReturnURL($this->buildURL('payment_settings'));
         } else {
             \XLite\Core\TopMessage::addWarning('Payment method has not been configured properly');
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号