本文整理汇总了PHP中ActiveRecordModel::getInstanceByID方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getInstanceByID方法的具体用法?PHP ActiveRecordModel::getInstanceByID怎么用?PHP ActiveRecordModel::getInstanceByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecordModel
的用法示例。
在下文中一共展示了ActiveRecordModel::getInstanceByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testClone
public function testClone()
{
$text = EavField::getNewInstance('User', EavField::DATATYPE_TEXT, EavField::TYPE_TEXT_SIMPLE);
$text->save();
$singleSel = EavField::getNewInstance('User', EavField::DATATYPE_NUMBERS, EavField::TYPE_NUMBERS_SELECTOR);
$singleSel->handle->set('single.sel');
$singleSel->setValueByLang('name', 'en', 'Select one value');
$singleSel->save();
$value1 = EavValue::getNewInstance($singleSel);
$value1->setValueByLang('value', 'en', $firstValue = '20');
$value1->save();
$value2 = EavValue::getNewInstance($singleSel);
$value2->setValueByLang('value', 'en', $secValue = '30');
$value2->save();
$user = User::getNewInstance('someuser@eavclonetest.com');
$user->save();
$spec = $user->getSpecification();
$spec->setAttributeValueByLang($text, 'en', 'text');
$spec->setAttributeValue($singleSel, $value1);
$user->save();
$cloned = clone $user;
$cloned->email->set('cloneduser@test.com');
$cloned->save();
$this->assertNotSame($cloned->getSpecification(), $user->getSpecification());
$this->assertEquals($cloned->getSpecification()->getAttribute($text)->getValueByLang('value', 'en'), 'text');
ActiveRecordModel::clearPool();
$reloaded = ActiveRecordModel::getInstanceByID('User', $cloned->getID(), true);
$this->assertEquals($reloaded->getSpecification()->getAttribute($text)->getValueByLang('value', 'en'), 'text');
$this->assertEquals($reloaded->getSpecification()->getAttribute($singleSel)->getValue()->get()->getID(), $value1->getID());
}
示例2: save
public function save()
{
$validator = $this->createValidator();
if (!$validator->isValid()) {
return new JSONResponse(array('errors' => $validator->getErrorList(), 'failure'));
}
if ($id = $this->request->get('id')) {
$newsletter = ActiveRecordModel::getInstanceByID('NewsletterMessage', $id);
} else {
$newsletter = ActiveRecordModel::getNewInstance('NewsletterMessage');
}
$format = $this->request->get('newsletter_' . $id . '_format');
if ($format == self::FORMAT_TEXT) {
$this->request->set('html', '');
} else {
if ($format == self::FORMAT_HTML) {
$this->request->set('text', '');
}
}
$newsletter->loadRequestData($this->request);
$newsletter->save();
if ($this->request->get('sendFlag')) {
return $this->send($newsletter);
}
return new JSONResponse($newsletter->toArray());
}
示例3: getInstance
protected function getInstance($record, CsvImportProfile $profile)
{
$fields = $profile->getSortedFields();
if (isset($fields['ProductReview']['ID'])) {
$instance = ActiveRecordModel::getInstanceByID('ProductReview', $record[$fields['ProductReview']['ID']], true);
} else {
if (isset($fields['Product']['ID'])) {
$parent = ActiveRecordModel::getInstanceByID('Product', $record[$fields['Product']['ID']], true);
} else {
if (isset($fields['Product']['sku'])) {
$parent = Product::getInstanceBySku($record[$fields['Product']['sku']]);
} else {
return;
}
}
}
if (empty($instance) && empty($parent)) {
return;
}
if (empty($instance)) {
$instance = ProductReview::getNewInstance($parent, User::getNewInstance(''));
$instance->isEnabled->set(true);
}
return $instance;
}
示例4: edit
/**
* @role update
*/
public function edit()
{
$form = $this->buildForm();
$type = ActiveRecordModel::getInstanceByID('ProductRatingType', $this->request->get('id'), ProductRatingType::LOAD_DATA);
$form->loadData($type->toArray());
return new ActionResponse('form', $form);
}
示例5: destroy
public function destroy($id)
{
try {
$inst = ActiveRecordModel::getInstanceByID('SessionData', $id, true);
$inst->delete();
return true;
} catch (Exception $e) {
return false;
}
}
示例6: sort
/**
* @role update
*/
public function sort()
{
$target = $this->request->get('target');
preg_match('/_(\\d+)$/', $target, $match);
// Get group.
$productID = $match[1];
foreach ($this->request->get($this->request->get('target'), array()) as $position => $id) {
$item = ActiveRecordModel::getInstanceByID('ProductBundle', array('productID' => $productID, 'relatedProductID' => $id), ActiveRecord::LOAD_DATA);
$item->position->set($position);
$item->save();
}
return new JSONResponse(false, 'success');
}
示例7: 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');
}
示例8: getInstance
protected function getInstance($record, CsvImportProfile $profile)
{
$fields = $profile->getSortedFields();
if (isset($fields['NewsPost']['ID'])) {
try {
$instance = ActiveRecordModel::getInstanceByID('NewsPost', $record[$fields['NewsPost']['ID']], true);
} catch (ARNotFoundException $e) {
}
}
if (empty($instance)) {
$instance = ActiveRecordModel::getNewInstance('NewsPost');
}
//$this->setLastImportedRecordName($instance->getID());
return $instance;
}
示例9: getInstance
protected function getInstance($record, CsvImportProfile $profile)
{
pp('User address import get instance');
$fields = $profile->getSortedFields();
if (isset($fields['UserAddress']['ID'])) {
$instance = ActiveRecordModel::getInstanceByID('UserAddress', $record[$fields['UserAddress']['ID']], true);
} else {
if (isset($fields['AddressUser']['ID'])) {
$owner = User::getInstanceByID($record[$fields['AddressUser']['ID']], true);
} else {
if (isset($fields['AddressUser']['email'])) {
$owner = User::getInstanceByEmail($record[$fields['AddressUser']['email']]);
}
}
}
if (isset($owner)) {
if ($profile->isColumnSet('AddressUser.isShipping')) {
$type = $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isShipping')])) ? 'ShippingAddress' : 'BillingAddress';
} else {
$type = 'BillingAddress';
}
$owner->loadAddresses();
}
if (empty($instance)) {
if (empty($owner)) {
return;
}
$isDefault = $profile->isColumnSet('AddressUser.isDefault') && $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isDefault')]));
if ($isDefault) {
$field = 'default' . $type;
$addressType = $owner->{$field}->get();
$instance = $addressType->userAddress->get();
}
if (empty($addressType)) {
$instance = UserAddress::getNewInstance();
$addressType = call_user_func_array(array($type, 'getNewInstance'), array($owner, $instance));
if ($isDefault) {
$owner->{$field}->set($addressType);
}
}
$addressType->userAddress->set($instance);
$instance->addressType = $addressType;
}
return $instance;
}
示例10: getInstance
protected function getInstance($record, CsvImportProfile $profile)
{
$fields = $profile->getSortedFields();
if (isset($fields['NewsletterSubscriber']['ID'])) {
$instance = ActiveRecordModel::getInstanceByID('NewsletterSubscriber', $record[$fields['NewsletterSubscriber']['ID']], true);
} else {
if (isset($fields['NewsletterSubscriber']['email'])) {
$instance = NewsletterSubscriber::getInstanceByEmail($record[$fields['NewsletterSubscriber']['email']]);
} else {
return;
}
}
if (empty($instance)) {
$instance = NewsletterSubscriber::getNewInstanceByEmail($record[$fields['NewsletterSubscriber']['email']]);
}
$this->setLastImportedRecordName($instance->email->get());
return $instance;
}
示例11: testCloning
function testCloning()
{
$user = User::getNewInstance('test@tester.com');
$user->firstName->set('Rinalds');
$user->lastName->set('Uzkalns');
$user->save();
$state = ActiveRecordModel::getInstanceByID('State', 2, ActiveRecordModel::LOAD_DATA);
$address = UserAddress::getNewInstance();
$address->city->set('Vilnius');
$address->state->set($state);
$address->save();
$newAddress = clone $address;
// simple value
$this->assertEqual($address->city->get(), $newAddress->city->get());
// foreign key
$this->assertEqual($address->state->get(), $newAddress->state->get());
$newAddress->save();
// primary key (autoincrement)
$this->assertNotEquals($address->getID(), $newAddress->getID());
}
示例12: getRealTimeRates
public static function getRealTimeRates(ShippingRateCalculator $handler, Shipment $shipment)
{
$rates = new ShippingRateSet();
$handler->setWeight($shipment->getChargeableWeight());
$order = $shipment->order->get();
// TODO: fix issue when address has zip and country data, but are missing city, user and record id!
// (now workround - get address id, if $address has no id, load address by id)
if ($order->isMultiAddress->get()) {
$address = $shipment->shippingAddress->get();
$arr = $shipment->toArray();
} else {
$address = $order->shippingAddress->get();
$arr = $order->toArray();
}
if (!$address->getID() && array_key_exists('shippingAddressID', $arr)) {
$address = ActiveRecordModel::getInstanceByID('UserAddress', $arr['shippingAddressID'], true);
}
if (!$address) {
return $rates;
}
$handler->setDestCountry($address->countryID->get());
$handler->setDestState($address->state->get() ? $address->state->get()->code->get() : $address->stateName->get());
$handler->setDestZip($address->postalCode->get());
$handler->setDestCity($address->city->get());
$config = $shipment->getApplication()->getConfig();
$handler->setSourceCountry($config->get('STORE_COUNTRY'));
$handler->setSourceZip($config->get('STORE_ZIP'));
$handler->setSourceState($config->get('STORE_STATE'));
foreach ($handler->getAllRates() as $k => $rate) {
$newRate = new ShipmentDeliveryRate();
$newRate->setApplication($shipment->getApplication());
$newRate->setCost($rate->getCostAmount(), $rate->getCostCurrency());
$newRate->setServiceName($rate->getServiceName());
$newRate->setClassName($rate->getClassName());
$newRate->setProviderName($rate->getProviderName());
$newRate->setServiceId($rate->getClassName() . '_' . $k);
$rates->add($newRate);
}
return $rates;
}
示例13: testSettingValues
public function testSettingValues()
{
$field = EavField::getNewInstance('User', EavField::DATATYPE_TEXT, EavField::TYPE_TEXT_SIMPLE);
$field->save();
$user = User::getNewInstance('someuser@eavtest.com');
$user->save();
$spec = $user->getSpecification();
$this->assertIsA($spec, 'EavSpecificationManager');
$testValue = 'something';
$spec = $user->getSpecification();
$this->assertSame($spec, $user->getSpecification());
$spec->setAttributeValueByLang($field, 'en', $testValue);
$attr = $spec->getAttribute($field);
$this->assertEqual($testValue, $attr->getValueByLang('value', 'en'));
$spec->save();
$id = $user->getID();
unset($user);
ActiveRecordModel::clearPool();
$user = ActiveRecordModel::getInstanceByID('User', $id, ActiveRecordModel::LOAD_DATA);
$spec = $user->getSpecification();
$attr = $spec->getAttribute($field);
$this->assertEqual($testValue, $attr->getValueByLang('value', 'en'));
}
示例14: delete
/**
* Remove a product from shopping cart
*/
public function delete()
{
$item = ActiveRecordModel::getInstanceByID('OrderedItem', $this->request->get('id'), ActiveRecordModel::LOAD_DATA, array('Product'));
$this->setMessage($this->makeText('_removed_from_cart', array($item->getProduct()->getName($this->getRequestLanguage()))));
$this->order->removeItem($item);
SessionOrder::save($this->order);
return new ActionRedirectResponse('order', 'index', array('query' => 'return=' . $this->request->get('return')));
}
示例15: testLoadAllReferencesIncludingAutoLoad
public function testLoadAllReferencesIncludingAutoLoad()
{
$child = ActiveRecordModel::getNewInstance('LoadReferenceChild');
$child->name->set('child');
$child->setID(4);
$child->save();
$parent = ActiveRecordModel::getNewInstance('LoadReferenceParent');
$parent->setID(4);
$parent->name->set('parent');
$parent->reference->set($child);
$parent->save();
$super = ActiveRecordModel::getNewInstance('LoadReferenceSuper');
$super->setID(1);
$super->name->set('super');
$super->reference->set($parent);
$super->save();
$schema = ActiveRecordModel::getSchemaInstance('LoadReferenceParent');
$schema->registerAutoReference('referenceID');
ActiveRecordModel::clearPool();
$newSuper = ActiveRecordModel::getInstanceByID('LoadReferenceSuper', 1, ActiveRecordModel::LOAD_DATA, true);
$this->assertNotSame($child, $newSuper->reference->get()->reference->get());
$this->assertNotSame($newSuper->reference->get(), $newSuper->reference->get()->reference->get());
$this->assertEqual('child', $newSuper->reference->get()->reference->get()->name->get());
}