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


PHP ActiveRecordModel::getInstanceById方法代码示例

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


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

示例1: deleteByID

 public static function deleteByID($className, $id, $foreignKeyName)
 {
     $inst = ActiveRecordModel::getInstanceById($className, $id, ActiveRecordModel::LOAD_DATA);
     $inst->getOwner()->load();
     $inst->deleteImageFiles();
     // check if main image is being deleted
     $owner = $inst->getOwner();
     $owner->load(array(get_class($inst)));
     if ($owner->defaultImage->get()->getID() == $id) {
         // set next image (by position) as the main image
         $f = new ARSelectFilter();
         $cond = new EqualsCond(new ARFieldHandle(get_class($inst), $foreignKeyName), $owner->getID());
         $cond->addAND(new NotEqualsCond(new ARFieldHandle(get_class($inst), 'ID'), $inst->getID()));
         $f->setCondition($cond);
         $f->setOrder(new ARFieldHandle(get_class($inst), 'position'));
         $f->setLimit(1);
         $newDefaultImage = ActiveRecordModel::getRecordSet(get_class($inst), $f);
         if ($newDefaultImage->size() > 0) {
             $owner->defaultImage->set($newDefaultImage->get(0));
             $owner->save();
         }
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
     ActiveRecordModel::executeUpdate('UPDATE ' . $className . ' SET ' . $foreignKeyName . '=NULL , protectedFields="|' . $foreignKeyName . '|" WHERE ID=' . $id);
     //return parent::deleteByID($className, $id);
 }
开发者ID:saiber,项目名称:www,代码行数:26,代码来源:ObjectImage.php

示例2: edit

 public function edit()
 {
     $newsletter = ActiveRecordModel::getInstanceById('NewsletterMessage', $this->request->get('id'), ActiveRecordModel::LOAD_DATA);
     $form = $this->getForm();
     $form->setData($newsletter->toArray());
     $form->set('users', 1);
     $form->set('subscribers', 1);
     $response = new ActionResponse('form', $form);
     $groupsArray = array_merge(ActiveRecord::getRecordSetArray('UserGroup', select()), array(array('ID' => null, 'name' => $this->translate('Customers'))));
     usort($groupsArray, array($this, 'sortGroups'));
     $response->set('groupsArray', $groupsArray);
     $newsletterArray = $newsletter->toArray();
     $text = strlen($newsletterArray['text']);
     $html = strlen($newsletterArray['html']);
     if ($text && $html) {
         $newsletterArray['format'] = self::FORMAT_HTML_TEXT;
     } else {
         if ($text) {
             $newsletterArray['format'] = self::FORMAT_TEXT;
         } else {
             if ($html) {
                 $newsletterArray['format'] = self::FORMAT_HTML;
             }
         }
     }
     $response->set('newsletter', $newsletterArray);
     $response->set('sentCount', $newsletter->getSentCount());
     $response->set('recipientCount', $this->getRecipientCount($form->getData()));
     return $response;
 }
开发者ID:saiber,项目名称:livecart,代码行数:30,代码来源:NewsletterController.php

示例3: edit

 public function edit()
 {
     $condition = ActiveRecordModel::getInstanceById('DiscountCondition', $this->request->get('id'), DiscountCondition::LOAD_DATA, DiscountCondition::LOAD_REFERENCES);
     $condition->loadAll();
     $response = new ActionResponse('condition', $condition->toArray());
     $records = array();
     $zones = ActiveRecordModel::getRecordSetArray('DeliveryZone', new ARSelectFilter());
     //$zones = array_merge(array(DeliveryZone::getDefaultZoneInstance()->toArray()), $zones);
     //$this->loadLanguageFile('backend/DeliveryZone');
     //$zones[0]['name'] = $this->translate('_default_zone');
     $records['DeliveryZone'] = $zones;
     $records['UserGroup'] = ActiveRecordModel::getRecordSetArray('UserGroup', new ARSelectFilter());
     $response->set('records', $records);
     $response->set('serializedValues', array('RuleConditionPaymentMethodIs' => $this->getPaymentMethods(), 'RuleConditionCurrencyIs' => $this->getCurrencies(), 'RuleConditionShippingMethodIs' => $this->getShippingMethods()));
     $form = $this->buildForm();
     $form->setData($condition->toArray());
     $response->set('form', $form);
     // actions
     $f = new ARSelectFilter();
     $f->setOrder(new ARFieldHandle('DiscountAction', 'position'));
     $actions = $condition->getRelatedRecordSet('DiscountAction', $f, array('DiscountCondition', 'DiscountCondition_ActionCondition'));
     foreach ($actions as $action) {
         if ($action->actionCondition->get()) {
             $action->actionCondition->get()->load();
             $action->actionCondition->get()->loadAll();
         }
     }
     $response->set('actions', $actions->toArray());
     $this->setEditResponse($response);
     return $response;
 }
开发者ID:saiber,项目名称:www,代码行数:31,代码来源:DiscountController.php

示例4: delete

 public function delete()
 {
     $product = Product::getInstanceByID($this->request->get('id'), ActiveRecord::LOAD_DATA, array('Category'));
     $category = Category::getInstanceByID($this->request->get('categoryId'), ActiveRecord::LOAD_DATA);
     $relation = ActiveRecordModel::getInstanceById('ProductCategory', array('productID' => $product->getID(), 'categoryID' => $category->getID()));
     $relation->delete();
     return new JSONResponse(array('data' => $relation->toFlatArray()));
 }
开发者ID:saiber,项目名称:livecart,代码行数:8,代码来源:ProductCategoryController.php

示例5: save

 /**
  * @role update
  */
 public function save()
 {
     $validator = $this->buildValidator();
     if (!$validator->isValid()) {
         return new JSONResponse(array('err' => $validator->getErrorList()));
     }
     $post = $this->request->get('id') ? ActiveRecordModel::getInstanceById('ProductRatingType', $this->request->get('id'), ActiveRecordModel::LOAD_DATA) : ProductRatingType::getNewInstance(Category::getInstanceByID($this->request->get('categoryId'), Category::LOAD_DATA));
     $post->loadRequestData($this->request);
     $post->save();
     return new JSONResponse($post->toArray());
 }
开发者ID:saiber,项目名称:livecart,代码行数:14,代码来源:RatingTypeController.php

示例6: save

 public function save()
 {
     $clonedStore = ActiveRecordModel::getInstanceById('ClonedStore', $this->request->get('id'), true);
     $validator = $this->buildValidator();
     if ($validator->isValid()) {
         $clonedStore->loadRequestData($this->request);
         $clonedStore->save();
         return new JSONResponse(array('clonedStore' => $clonedStore->toArray()), 'success', $this->translate('Store configuration was successfully saved'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure');
     }
 }
开发者ID:saiber,项目名称:www,代码行数:12,代码来源:ClonedStoreController.php

示例7: getValidInstanceById

 /**
  *  Return Currency instance by ID and provide additional validation. If the currency doesn't exist
  *  or is not valid, instance of the default currency is returned.
  *
  *  @return Currency
  */
 public static function getValidInstanceById($id, $loadData = true)
 {
     try {
         $instance = ActiveRecordModel::getInstanceById(__CLASS__, $id, $loadData);
     } catch (ARNotFoundException $e) {
         $instance = null;
     }
     if (!$instance || !$instance->isEnabled->get()) {
         $instance = self::getApplication()->getDefaultCurrency();
     }
     return $instance;
 }
开发者ID:saiber,项目名称:livecart,代码行数:18,代码来源:Currency.php

示例8: sort

 /**
  * @role update
  */
 public function sort()
 {
     $target = $this->request->get('target');
     preg_match('/_(\\d+)$/', $target, $match);
     // Get group.
     foreach ($this->request->get($this->request->get('target'), array()) as $position => $id) {
         $item = ActiveRecordModel::getInstanceByID('ProductListItem', $id);
         $item->position->set($position);
         if (isset($match[1])) {
             $item->productList->set(ActiveRecordModel::getInstanceById('ProductList', $match[1]));
         }
         $item->save();
     }
     return new JSONResponse(false, 'success');
 }
开发者ID:saiber,项目名称:livecart,代码行数:18,代码来源:ProductListItemController.php

示例9: save

 /**
  * @role update
  */
 public function save()
 {
     $validator = $this->buildValidator();
     if (!$validator->isValid()) {
         return new JSONResponse(array('err' => $validator->getErrorList()));
     }
     $post = $this->request->get('id') ? ActiveRecordModel::getInstanceById('EyeExamSchedule', $this->request->get('id'), ActiveRecordModel::LOAD_DATA) : ActiveRecordModel::getNewInstance('EyeExamSchedule');
     $post->loadRequestData($this->request);
     $post->save();
     $postArr = $post->toArray();
     if (!isset($locale)) {
         $locale = self::getApplication()->getLocale();
     }
     $date = strtotime($postArr['date']);
     $postArr['formatted_date'] = $locale->getFormattedTime($date);
     return new JSONResponse($postArr);
 }
开发者ID:saiber,项目名称:www,代码行数:20,代码来源:EyeExamScheduleController.php

示例10: update

 public function update()
 {
     $review = ActiveRecordModel::getInstanceById('ProductReview', $this->request->get('id'), ProductReview::LOAD_DATA, array('Product'));
     $validator = $this->buildValidator($review);
     if ($validator->isValid()) {
         $review->loadRequestData($this->request);
         $review->save();
         // set ratings
         foreach ($review->getRelatedRecordSet('ProductRating', new ARSelectFilter()) as $rating) {
             $typeId = $rating->ratingType->get() ? $rating->ratingType->get()->getID() : '';
             $rating->rating->set($this->request->get('rating_' . $typeId));
             $rating->save();
         }
         return new JSONResponse(array('review' => $review->toFlatArray()), 'success', $this->translate('_review_was_successfully_saved'));
     } else {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure');
     }
 }
开发者ID:saiber,项目名称:livecart,代码行数:18,代码来源:ReviewController.php

示例11: update

 public function update()
 {
     return $this->save(ActiveRecordModel::getInstanceById('Manufacturer', $this->request->get('id'), Manufacturer::LOAD_DATA, Manufacturer::LOAD_REFERENCES));
 }
开发者ID:saiber,项目名称:livecart,代码行数:4,代码来源:ManufacturerController.php

示例12: getInstanceById

 public static function getInstanceById($id, $loadData = self::LOAD_DATA, $loadReferencedRecords = false)
 {
     return parent::getInstanceById('UserAddress', $id, $loadData, $loadReferencedRecords);
 }
开发者ID:saiber,项目名称:www,代码行数:4,代码来源:UserAddress.php

示例13: item

 /**
  *	@role login
  */
 public function item()
 {
     $item = ActiveRecordModel::getInstanceById('OrderedItem', $this->request->get('id'), ActiveRecordModel::LOAD_DATA, OrderedItem::LOAD_REFERENCES);
     $item->customerOrder->get()->loadAll();
     $item->loadOptions();
     $subItems = $item->getSubitems();
     $item = $item->toArray();
     $this->addAccountBreadcrumb();
     $this->addFilesBreadcrumb();
     $this->addBreadCrumb(isset($item['Product']['name_lang']) ? $item['Product']['name_lang'] : $item['Product']['Parent']['name_lang'], '');
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('OrderedItem', 'ID'), $item['ID']));
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $this->user->getID()));
     $fileArray = $this->loadDownloadableItems($f);
     if (!$fileArray && !$subItems) {
         return new ActionRedirectResponse('user', 'index');
     }
     $response = new ActionResponse();
     $response->set('user', $this->user->toArray());
     $response->set('files', $fileArray);
     $response->set('item', $item);
     if ($subItems) {
         $response->set('subItems', $subItems->toArray());
     }
     return $response;
 }
开发者ID:GregerA,项目名称:livecart,代码行数:28,代码来源:UserController.php

示例14: variationForm

 public function variationForm()
 {
     $this->loadLanguageFile('Frontend');
     $this->loadLanguageFile('Product');
     $this->loadLanguageFile('backend/Shipment');
     $item = ActiveRecordModel::getInstanceById('OrderedItem', $this->request->get('id'), true, true);
     $item->customerOrder->get()->loadAll();
     $c = new OrderController($this->application);
     $response = $c->variationForm($item->customerOrder->get(), '');
     $response->set('currency', $item->customerOrder->get()->currency->get()->getID());
     $response->set('variations', $item->getProduct()->getVariationData($this->application));
     return $response;
 }
开发者ID:GregerA,项目名称:livecart,代码行数:13,代码来源:OrderedItemController.php

示例15: getInstanceById

 public static function getInstanceById($id)
 {
     return parent::getInstanceById(__CLASS__, $id, self::LOAD_DATA, self::LOAD_REFERENCES);
 }
开发者ID:saiber,项目名称:www,代码行数:4,代码来源:Transaction.php


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