本文整理汇总了PHP中ActiveRecordModel类的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel类的具体用法?PHP ActiveRecordModel怎么用?PHP ActiveRecordModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActiveRecordModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restoreInstance
public static function restoreInstance($className, ActiveRecordModel $owner, EavFieldCommon $field, $value)
{
$specItem = parent::getInstanceByID($className, array(call_user_func(array($className, 'getOwnerIDColumnName')) => $owner->getID(), call_user_func(array($className, 'getFieldIDColumnName')) => $field->getID()));
$specItem->value->set($value);
$specItem->resetModifiedStatus();
return $specItem;
}
示例2: save
protected function save(ActiveRecordModel $listGroup)
{
$validator = $this->buildValidator();
if ($validator->isValid()) {
$listGroup->loadRequestData($this->request);
$listGroup->save();
return new JSONResponse(array('ID' => $listGroup->getID(), 'data' => $listGroup->toArray()), 'success');
} else {
return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure');
}
}
示例3: filter
public function filter($emptyListIsException = false)
{
$request = $this->application->getRequest();
$parser = $this->getParser();
$apiFieldNames = $parser->getApiFieldNames();
$parser->loadDataInRequest($request);
$f = new ARSelectFilter();
$id = $request->get('ID');
if (!empty($id)) {
$f->mergeCondition(new EqualsCond(new ARFieldHandle('ProductVariation', 'ID'), $id));
} else {
throw new Exception('Product variation ID is required');
}
$product_variations = ActiveRecordModel::getRecordSetArray('ProductVariation', $f);
$response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
if ($emptyListIsException && count($product_variations) == 0) {
throw new Exception('Product variation not found');
}
while ($variation = array_shift($product_variations)) {
$xml = $response->addChild('product_variation');
foreach ($variation as $k => $v) {
if (in_array($k, $apiFieldNames)) {
$xml->addChild($k, $v);
}
}
}
return new SimpleXMLResponse($response);
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->controller = new EavFieldController(self::getApplication());
ActiveRecordModel::executeUpdate('DELETE FROM EavField');
ActiveRecordModel::executeUpdate('DELETE FROM EavFieldGroup');
}
示例5: getUrl
public function getUrl()
{
$params = array();
// user name
$params['merchant'] = $this->getConfigValue('merchant');
if ($this->getConfigValue('test')) {
$params['test'] = 'yes';
}
// A seller reference number for a transaction
$params['orderid'] = $this->details->invoiceID->get();
$params['uniqueoid'] = $this->details->invoiceID->get();
// The payment amount
$params['amount'] = $this->details->amount->get() * 100;
// The currency code of the payment amount.
$params['currency'] = $this->getCurrency($this->details->currency->get());
//$this->notifyUrl = preg_replace('/currency\=[A-Z]{3}/', '', $this->notifyUrl);
$params['callbackurl'] = $this->notifyUrl;
$params['accepturl'] = $this->returnUrl;
$params['cancelurl'] = $this->siteUrl;
$params['lang'] = ActiveRecordModel::getApplication()->getLocaleCode();
$params['skiplastpage'] = 1;
$params['md5key'] = $this->getMd5Key($params);
$pairs = array();
foreach ($params as $key => $value) {
$pairs[] = $key . '=' . urlencode($value);
}
return 'https://payment.architrade.com/paymentweb/start.action?' . implode('&', $pairs);
}
示例6: index
public function index()
{
$this->addIndexBreadCrumb();
$f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
$f->setOrder(new ARFieldHandle('NewsPost', 'position'), 'DESC');
return new ActionResponse('news', ActiveRecordModel::getRecordSetArray('NewsPost', $f));
}
示例7: 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;
}
示例8: filter
public function filter($emptyListIsException = false)
{
$request = $this->application->getRequest();
$parser = $this->getParser();
$apiFieldNames = $parser->getApiFieldNames();
$parser->loadDataInRequest($request);
$f = new ARSelectFilter();
$ID = $request->get('ID');
if (!empty($countryID)) {
$f->mergeCondition(new EqualsCond(new ARFieldHandle('DeliveryZoneCountry', 'ID'), $ID));
}
$countryZones = ActiveRecordModel::getRecordSetArray('DeliveryZoneCountry', $f);
$response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
if ($emptyListIsException && count($countryZones) == 0) {
throw new Exception('DeliveryZoneCountry not found');
}
while ($country_zone = array_shift($countryZones)) {
$xmlCountryZone = $response->addChild('delivery_zone_country');
foreach ($country_zone as $k => $v) {
if (in_array($k, $apiFieldNames)) {
$xmlCountryZone->addChild($k, $v);
}
}
}
return new SimpleXMLResponse($response);
}
示例9: index
public function index()
{
// get filter to select manufacturers of active products only
$rootCat = Category::getRootNode();
$f = new ARSelectFilter();
$productFilter = new ProductFilter($rootCat, $f);
$ids = $counts = array();
foreach (ActiveRecordModel::getDataBySQL('SELECT DISTINCT(manufacturerID), COUNT(*) AS cnt FROM Product ' . $f->createString() . ' GROUP BY manufacturerID') as $row) {
$ids[] = $row['manufacturerID'];
$counts[$row['manufacturerID']] = $row['cnt'];
}
$f = new ARSelectFilter(new InCond(new ARFieldHandle('Manufacturer', 'ID'), $ids));
$f->mergeCondition(new NotEqualsCond(new ARFieldHandle('Manufacturer', 'name'), ''));
$f->setOrder(new ARFieldHandle('Manufacturer', 'name'));
$manufacturers = ActiveRecordModel::getRecordSetArray('Manufacturer', $f);
foreach ($manufacturers as &$manufacturer) {
$manufacturer['url'] = $this->getManufacturerFilterUrl($manufacturer);
}
$this->addBreadCrumb($this->translate('_manufacturers'), '');
$response = new ActionResponse();
$response->setReference('manufacturers', $manufacturers);
$response->set('counts', $counts);
$response->set('rootCat', $rootCat->toArray());
return $response;
}
示例10: reorder
/**
* Reorder pages
*
* @role sort
*/
public function reorder()
{
$inst = StaticPage::getInstanceById($this->request->get('id'), StaticPage::LOAD_DATA);
$f = new ARSelectFilter();
$handle = new ARFieldHandle('StaticPage', 'position');
if ('down' == $this->request->get('order')) {
$f->setCondition(new MoreThanCond($handle, $inst->position->get()));
$f->setOrder($handle, 'ASC');
} else {
$f->setCondition(new LessThanCond($handle, $inst->position->get()));
$f->setOrder($handle, 'DESC');
}
$f->setLimit(1);
$s = ActiveRecordModel::getRecordSet('StaticPage', $f);
if ($s->size()) {
$pos = $inst->position->get();
$replace = $s->get(0);
$inst->position->set($replace->position->get());
$replace->position->set($pos);
$inst->save();
$replace->save();
return new JSONResponse(array('id' => $inst->getID(), 'order' => $this->request->get('order')), 'success');
} else {
return new JSONResponse(false, 'failure', $this->translate('_could_not_reorder_pages'));
}
}
示例11: setUp
public function setUp()
{
parent::setUp();
ActiveRecordModel::executeUpdate('DELETE FROM ClonedStore');
$this->usd = ActiveRecordModel::getNewInstance('Currency');
$this->usd->setID('ZZZ');
$this->usd->save(ActiveRecord::PERFORM_INSERT);
@unlink(ClonedStoreUpdater::getTimestampFile());
@unlink(ClonedStoreUpdater::getIDFile());
// create stores
for ($k = 0; $k <= 0; $k++) {
$this->stores[$k] = ClonedStore::getNewInstance();
$this->stores[$k]->domain->set($k);
$this->stores[$k]->save();
echo $this->stores[$k]->lastImport->get();
}
// create categories
$root = Category::getRootNode();
for ($k = 0; $k <= 5; $k++) {
$this->categories[] = $this->createCategory($root, $k);
}
$this->categories['1.1'] = $this->createCategory($this->categories[1], '1.1');
$this->categories['1.2'] = $this->createCategory($this->categories[1], '1.2');
$this->categories['1.2.1'] = $this->createCategory($this->categories['1.2'], '1.2.1');
$this->categories['1.2.2'] = $this->createCategory($this->categories['1.2'], '1.2.2');
usleep(1500000);
}
示例12: 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());
}
示例13: getNumber
public function getNumber()
{
$config = ActiveRecordModel::getApplication()->getConfig();
$startAt = $config->get('SequentialInvoiceNumber_START_AT');
$prefix = $config->get('SequentialInvoiceNumber_PREFIX');
$suffix = $config->get('SequentialInvoiceNumber_SUFFIX');
// get last finalized order
$last = array_pop(ActiveRecord::getRecordSetArray('CustomerOrder', $this->getSelectFilter()));
$lastNumber = $last ? $last['invoiceNumber'] : $startAt;
if (substr($lastNumber, 0, strlen($prefix)) == $prefix) {
$lastNumber = substr($lastNumber, strlen($prefix));
}
if (substr($lastNumber, -1 * strlen($suffix)) == $suffix) {
$lastNumber = substr($lastNumber, 0, -1 * strlen($suffix));
}
preg_match('/[0-9]+/', $lastNumber, $matches);
$lastNumber = array_shift($matches);
if ($lastNumber < $startAt) {
$lastNumber = $startAt;
}
// avoid selecting the same order if the invoice number is already taken
$this->getSelectFilter()->mergeCondition(neq('CustomerOrder.ID', $last['ID']));
$lastNumber += max($config->get('SequentialInvoiceNumber_STEP'), 1);
$lastNumber = str_pad($lastNumber, $config->get('SequentialInvoiceNumber_MIN_LENGTH'), '0', STR_PAD_LEFT);
$lastNumber = $prefix . $lastNumber . $suffix;
return $lastNumber;
}
示例14: getTopCustomers
public function getTopCustomers()
{
$this->setDateHandle(new ARFieldHandle('CustomerOrder', 'dateCompleted'));
$this->setChartType(self::TABLE);
$q = $this->getQuery('ROUND(SUM(CustomerOrder.totalAmount * ' . $this->getCurrencyMultiplier() . '), 2)');
$f = $q->getFilter();
$f->resetOrder();
$f->resetGrouping();
$f->setOrder(new ARExpressionHandle('cnt'), 'DESC');
$q->addField('userID');
$f->setGrouping(new ARExpressionHandle('userID'));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), 1));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), 0));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), 1));
$f->setLimit(self::TABLE_LIMIT);
$q->joinTable('CustomerOrder', 'User', 'userID', 'ID');
$this->getReportData($q);
$ids = array();
foreach ($this->values as $product) {
$ids[$product['userID']] = $product['cnt'];
}
// fetch user details
$fields = array_flip(array('fullName', 'cnt'));
foreach (ActiveRecordModel::getRecordSetArray('User', new ARSelectFilter(new INCond(new ARFieldHandle('User', 'ID'), array_keys($ids)))) as $user) {
$user['cnt'] = $ids[$user['ID']];
$ids[$user['ID']] = array_merge($fields, array_intersect_key($user, $fields));
}
$this->values = $ids;
}
示例15: process
public function process()
{
if (!$this->response instanceof ActionResponse) {
return;
}
$products = $this->response->get('products');
$ids = array();
foreach ($products as $key => $product) {
$ids[$product['ID']] = !empty($product['parentID']) ? $product['parentID'] : $product['ID'];
}
if (!$ids) {
return;
}
$f = select(in(f('ProductImage.productID'), array_values($ids)), new LikeCond(f('ProductImage.title'), '%Virtual Mirror%'));
$hasMirror = array();
foreach (ActiveRecordModel::getRecordSetArray('ProductImage', $f) as $mirror) {
$hasMirror[$mirror['productID']] = true;
}
foreach ($ids as $realID => $parentID) {
if (!empty($hasMirror[$parentID])) {
$hasMirror[$realID] = true;
}
}
foreach ($products as $key => $product) {
if ($hasMirror[$product['ID']]) {
$products[$key]['hasMirror'] = true;
}
}
$this->response->set('hasMirror', $hasMirror);
$this->response->set('products', $products);
}