当前位置: 首页>>代码示例>>PHP>>正文


PHP UserGroup::getInstanceByID方法代码示例

本文整理汇总了PHP中UserGroup::getInstanceByID方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::getInstanceByID方法的具体用法?PHP UserGroup::getInstanceByID怎么用?PHP UserGroup::getInstanceByID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserGroup的用法示例。


在下文中一共展示了UserGroup::getInstanceByID方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updatePrice

 private function updatePrice($replaceQuantityPrices)
 {
     $request = $this->getApplication()->getRequest();
     $sku = $request->get('sku');
     $product = Product::getInstanceBySku($sku, array('ProductPrice'));
     if ($product == null) {
         throw new Exception('Product not found');
     }
     $currency = $request->get('currency');
     if ($currency == '') {
         $currency = $this->getApplication()->getDefaultCurrency()->getID();
     }
     $price = $request->get('definedPrice');
     if (is_numeric($price)) {
         $product->setPrice($currency, $price, false);
     }
     $price = $request->get('definedListPrice');
     if (is_numeric($price)) {
         $product->setPrice($currency, $price, true);
     }
     $quantityPrices = $request->get('quantityPrices');
     $groupedQuantityPrices = array();
     foreach ($quantityPrices as $item) {
         if ($item['currency'] == '') {
             $item['currency'] = $currency;
         }
         if ($item['group'] == '') {
             $item['group'] = 0;
         }
         $groupedQuantityPrices[$item['currency']][$item['quantity']][$item['group']] = $item['price'];
     }
     foreach ($product->getRelatedRecordSet('ProductPrice', new ARSelectFilter()) as $productPrice) {
         if ($replaceQuantityPrices == true) {
             $productPrice->serializedRules->set(serialize(array()));
         }
         $currencyID = $productPrice->currency->get()->getID();
         if (array_key_exists($currencyID, $groupedQuantityPrices)) {
             foreach ($groupedQuantityPrices[$currencyID] as $quanty => $qItem) {
                 foreach ($qItem as $group => $price) {
                     $group = !$group ? null : UserGroup::getInstanceByID($group);
                     $productPrice->setPriceRule($quanty, $group, $price);
                 }
             }
             $productPrice->save();
             unset($groupedQuantityPrices[$currencyID]);
             // for this currency saved
         }
     }
     if (count($groupedQuantityPrices) > 0) {
         // there is missing ProductPrice for some currencies,
         // will try to save as  new ProductPrice items
         foreach ($groupedQuantityPrices as $currency => $rules) {
             $productPrice = ProductPrice::getNewInstance($product, Currency::getInstanceById($currency));
             $productPrice->serializedRules->set(serialize($rules));
             $productPrice->save();
         }
     }
     $product->save();
     return $this->statusResponse($sku, 'updated');
 }
开发者ID:saiber,项目名称:livecart,代码行数:60,代码来源:ProductPriceApi.php

示例2: getUser

 /**
  * Get current user (from session)
  * @return User
  */
 public static function getUser()
 {
     if (!empty(self::$currentUser)) {
         return self::$currentUser;
     }
     $session = new Session();
     $id = $session->get('User');
     $app = ActiveRecordModel::getApplication();
     if (!$id) {
         $user = self::getAnonymousUser();
     } else {
         $user = User::getInstanceById($id);
         // set user's prefered locale code
         $reqLang = $app->getRequest()->get('requestLanguage');
         $localeCode = $reqLang ? $reqLang : $app->getLocaleCode();
         try {
             if ($session->get('userLocale') != $localeCode) {
                 $user->load();
                 $user->locale->set($localeCode);
                 $user->save();
                 $session->set('userLocale', $localeCode);
             }
             if (!$session->isValueSet('UserGroup') || is_null($session->get('UserGroup'))) {
                 $user->load();
                 $group = $user->userGroup->get() ? $user->userGroup->get()->getID() : 0;
                 $session->set('UserGroup', $group);
             }
             $user->userGroup->set(UserGroup::getInstanceByID($session->get('UserGroup')));
         } catch (ARNotFoundException $e) {
             $user = self::getAnonymousUser();
         }
     }
     if ($app->getSessionHandler()) {
         $app->getSessionHandler()->setUser($user);
     }
     return $user;
 }
开发者ID:saiber,项目名称:www,代码行数:41,代码来源:SessionUser.php

示例3: remove

 /**
  * @role remove
  */
 public function remove()
 {
     $userGroup = UserGroup::getInstanceByID((int) $this->request->get("id"), true);
     $userGroupArray = $userGroup->toArray();
     $userGroup->delete();
     return new JSONResponse(array('userGroup' => $userGroupArray), 'success', $this->translate('_user_group_was_successfully_removed'));
 }
开发者ID:saiber,项目名称:livecart,代码行数:10,代码来源:UserGroupController.php

示例4: error_reporting

<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
include '../application/Initialize.php';
ClassLoader::import('application.LiveCart');
new LiveCart();
ClassLoader::import('application.model.user.UserGroup');
$group = UserGroup::getInstanceByID(1, true);
$group->setAllRoles();
$group->save();
开发者ID:saiber,项目名称:livecart,代码行数:11,代码来源:ResetRoles.php

示例5: save

 private function save(User $user = null)
 {
     $validator = self::createUserFormValidator($this, $user);
     if ($validator->isValid()) {
         $email = $this->request->get('email');
         $password = $this->request->get('password');
         if ($user && $email != $user->email->get() && User::getInstanceByEmail($email) || !$user && User::getInstanceByEmail($email)) {
             return new JSONResponse(false, 'failure', $this->translate('_err_this_email_is_already_being_used_by_other_user'));
         }
         if ($groupID = (int) $this->request->get('UserGroup')) {
             $group = UserGroup::getInstanceByID((int) $groupID);
         } else {
             $group = null;
         }
         if (!$user) {
             $user = User::getNewInstance($email, $password, $group);
         }
         $user->loadRequestData($this->request);
         $user->userGroup->set($group);
         if (!empty($password)) {
             $user->setPassword($password);
         }
         $user->save();
         $this->saveAddresses($user);
         BackendToolbarItem::registerLastViewedUser($user);
         return new JSONResponse(array('user' => $user->toFlatArray()), 'success', $this->translate('_user_details_were_successfully_saved'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_user_details'));
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:30,代码来源:UserController.php

示例6: importInstance

 public function importInstance($record, CsvImportProfile $profile)
 {
     $this->className = 'Product';
     $impReq = new Request();
     $defLang = $this->application->getDefaultLanguageCode();
     $references = array('DefaultImage' => 'ProductImage', 'Manufacturer', 'ShippingClass', 'TaxClass');
     $cat = $this->getCategory($profile, $record);
     $extraCategories = null;
     $fields = $profile->getSortedFields();
     if (isset($fields['Categories']['ExtraCategories'])) {
         $extraCategories = explode('; ', $record[$fields['Categories']['ExtraCategories']]);
     }
     if (isset($fields['Product']) && $cat) {
         $product = null;
         if (isset($fields['Product']['ID']) && !empty($record[$fields['Product']['ID']])) {
             $id = $record[$fields['Product']['ID']];
             if (ActiveRecord::objectExists('Product', $id)) {
                 $product = Product::getInstanceByID($id, Product::LOAD_DATA, $references);
             }
         } else {
             if (isset($fields['Product']['sku']) && !empty($record[$fields['Product']['sku']])) {
                 $product = Product::getInstanceBySku($record[$fields['Product']['sku']], $references);
             }
         }
         if ($product && $product->getID()) {
             $this->registerImportedID($product->getID());
         }
         if (!$product && 'update' == $this->options['action'] || $product && 'add' == $this->options['action']) {
             return false;
         }
         if ($product) {
             $product->loadSpecification();
             $product->loadPricing();
         } else {
             if ($cat instanceof Category) {
                 $product = Product::getNewInstance($cat);
             } else {
                 $product = $cat->createChildProduct();
             }
             $product->isEnabled->set(true);
         }
         // product information
         $impReq->clearData();
         foreach ($profile->getFields() as $csvIndex => $field) {
             $column = $field['name'];
             $params = $field['params'];
             if (!isset($record[$csvIndex]) || empty($column)) {
                 continue;
             }
             $value = $record[$csvIndex];
             list($className, $field) = explode('.', $column, 2);
             if (isset($params['language'])) {
                 $lang = $params['language'];
                 if ($lang != $defLang) {
                     $field .= '_' . $lang;
                 }
             }
             if ($value) {
                 if ('Product.parentID' == $column) {
                     $product->parent->set();
                     continue;
                 }
                 if ('Product.parentSKU' == $column) {
                     $product->parent->set(Product::getInstanceBySKU($value));
                     continue;
                 }
             }
             if ('Product.taxClass' == $column) {
                 $product->taxClass->set(TaxClass::findByName($value));
             }
             if ('Product.shippingClass' == $column) {
                 $product->shippingClass->set(ShippingClass::findByName($value));
             }
             if ('Product' == $className) {
                 if ('shippingWeight' == $field) {
                     if ($this->application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH') {
                         $value = $value / 0.45359237;
                     }
                 }
                 if ('shippingWeight' == $field && $product->parent->get()) {
                     $value = $this->setChildSetting($product, 'weight', $value);
                 }
                 $impReq->set($field, $value);
             } else {
                 if ('Manufacturer' == $className) {
                     $impReq->set('manufacturer', $value);
                 } else {
                     if ('ProductPrice.price' == $column) {
                         if ($product->parent->get()) {
                             $value = $this->setChildSetting($product, 'price', $value);
                         }
                         $value = preg_replace('/,([0-9]{3})/', '\\1', $value);
                         $value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value));
                         $currency = isset($params['currency']) ? $params['currency'] : $this->application->getDefaultCurrencyCode();
                         $quantityLevel = isset($params['quantityLevel']) ? $params['quantityLevel'] : '';
                         $group = isset($params['group']) ? $params['group'] : '';
                         $price = $product->getPricingHandler()->getPriceByCurrencyCode($currency);
                         $product->getPricingHandler()->setPrice($price);
                         if ($group || $quantityLevel) {
                             if ($value > 0) {
//.........这里部分代码省略.........
开发者ID:GregerA,项目名称:livecart,代码行数:101,代码来源:ProductImport.php

示例7: saveQuickEdit

 public function saveQuickEdit()
 {
     $user = User::getInstanceByID((int) $this->request->get('id'), true);
     $validator = UserController::createUserFormValidator($this, $user, true);
     if ($validator->isValid()) {
         $email = $this->request->get('email');
         $password = $this->request->get('password');
         if ($user && $email != $user->email->get() && User::getInstanceByEmail($email) || !$user && User::getInstanceByEmail($email)) {
             return new JSONResponse(false, 'failure', $this->translate('_err_this_email_is_already_being_used_by_other_user'));
         }
         if ($groupID = (int) $this->request->get('UserGroup')) {
             $group = UserGroup::getInstanceByID((int) $groupID);
         } else {
             $group = null;
         }
         if (!$user) {
             $user = User::getNewInstance($email, $password, $group);
         }
         $user->loadRequestData($this->request);
         $user->userGroup->set($group);
         if (!empty($password)) {
             $user->setPassword($password);
         }
         $user->save();
         return $this->quickEditSaveResponse($user);
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_not_save_user_details'));
     }
 }
开发者ID:saiber,项目名称:www,代码行数:29,代码来源:UserGroupController.php

示例8: update

 /**
  * Saves changes to current group roles
  *
  * @role permissions
  */
 public function update()
 {
     $userGroupID = (int) $this->request->get('id');
     $userGroup = UserGroup::getInstanceByID($userGroupID, UserGroup::LOAD_DATA);
     // disabled roles
     $disable = ClassLoader::getRealPath('storage.configuration.DisabledRoles') . '.php';
     if (file_exists($disable)) {
         $disabledRoles = (include $disable);
         foreach ($disabledRoles as $disabled) {
             $c = new EqualsCond(new ARFieldHandle('Role', 'name'), $disabled);
             if (!isset($cond)) {
                 $cond = $c;
             } else {
                 $cond->addOr($c);
             }
         }
         if (isset($cond)) {
             $disabled = array();
             foreach (ActiveRecordModel::getRecordSetArray('Role', new ARSelectFilter($cond)) as $role) {
                 $disabled[$role['ID']] = true;
             }
         }
     }
     if (!isset($disabled)) {
         $disabled = array();
     }
     $validator = $this->createRolesFormValidator($userGroup);
     if ($validator->isValid()) {
         foreach (explode(',', $this->request->get('checked')) as $roleID) {
             if (preg_match('/smart/', $roleID) || isset($disabled[$roleID])) {
                 continue;
             }
             $userGroup->applyRole(Role::getInstanceByID((int) $roleID));
         }
         foreach (explode(',', $this->request->get('unchecked')) as $roleID) {
             if (preg_match('/smart/', $roleID) || isset($disabled[$roleID])) {
                 continue;
             }
             $userGroup->cancelRole(Role::getInstanceByID((int) $roleID));
         }
         $userGroup->save();
         return new JSONResponse(false, 'success', $this->translate('_group_permissions_were_successfully_updated'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', '_could_not_update_group_permissions');
     }
 }
开发者ID:saiber,项目名称:www,代码行数:51,代码来源:RolesController.php


注:本文中的UserGroup::getInstanceByID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。