本文整理汇总了PHP中ActiveRecordModel::getRecordSet方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecordModel::getRecordSet方法的具体用法?PHP ActiveRecordModel::getRecordSet怎么用?PHP ActiveRecordModel::getRecordSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecordModel
的用法示例。
在下文中一共展示了ActiveRecordModel::getRecordSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
}
示例2: getOrderFiles
public static function getOrderFiles(ARSelectFilter $f)
{
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), 0));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isPaid'), true));
//$f->mergeCondition(new EqualsCond(new ARFieldHandle('Product', 'type'), Product::TYPE_DOWNLOADABLE));
$f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
$downloadable = ActiveRecordModel::getRecordSet('OrderedItem', $f, array('Product', 'CustomerOrder'));
$fileArray = array();
foreach ($downloadable as &$item) {
$files = $item->getProduct()->getFiles();
$itemFiles = array();
foreach ($files as $file) {
if ($item->isDownloadable($file)) {
$itemFiles[] = $file->toArray();
}
}
if (!$itemFiles) {
continue;
}
$array = $item->toArray();
$array['Product']['Files'] = ProductFileGroup::mergeGroupsWithFields($item->getProduct()->getFileGroups()->toArray(), $itemFiles);
foreach ($array['Product']['Files'] as $key => $file) {
if (!isset($file['ID'])) {
unset($array['Product']['Files'][$key]);
}
}
$fileArray[] = $array;
}
return $fileArray;
}
示例3: syncAll
public function syncAll($select = null)
{
$this->errors = array();
$this->flush(__LINE__);
// find deleted records
$file = $this->getIDFile();
$previousIDs = file_exists($file) ? include $file : array();
$deleted = $this->getDeletedRecordIDs($previousIDs);
$this->flush(__LINE__);
// get previous timestamp
$file = $this->getTimestampFile();
$timestamp = null;
//$timestamp = file_exists($file) ? include $file : null;
$this->flush(__LINE__);
// get files
$files = $this->getFileList();
$this->flush(__LINE__);
// update each store
$select = !empty($select) ? $select : select();
foreach (ActiveRecordModel::getRecordSet('ClonedStore', $select) as $store) {
$this->flush(__LINE__);
$this->updateStore($store, $deleted, $files);
}
file_put_contents($this->getIDFile(), '<?php return ' . var_export($this->getRecordIDs(), true) . ';', LOCK_EX);
file_put_contents($this->getTimestampFile(), '<?php return ' . var_export($this->getTimestamp(), true) . ';', LOCK_EX);
}
示例4: testAutoReference
public function testAutoReference()
{
$child = ActiveRecordModel::getNewInstance('AutoReferenceChild');
$child->name->set('child');
$child->save();
$parent = ActiveRecordModel::getNewInstance('AutoReferenceParent');
$parent->setID(4);
$parent->name->set('parent');
$parent->reference->set($child);
$parent->save();
ActiveRecordModel::clearPool();
// test loading data array
$f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('AutoReferenceParent', 'ID'), 4));
$array = array_shift(ActiveRecordModel::getRecordSetArray('AutoReferenceParent', $f));
$this->assertEqual($array['ID'], 4);
$this->assertEqual($array['Reference']['name'], 'child');
ActiveRecordModel::clearPool();
// test loading instance by ID
$newParent = ActiveRecordModel::getInstanceByID('AutoReferenceParent', 4, ActiveRecordModel::LOAD_DATA);
$this->assertEqual($newParent->reference->get()->name->get(), 'child');
$this->assertNotSame($parent, $newParent);
$this->assertNotSame($child, $newParent->reference->get());
// test loading record set
$newParent = ActiveRecordModel::getRecordSet('AutoReferenceParent', $f)->get(0);
$this->assertEqual($newParent->reference->get()->name->get(), 'child');
$this->assertNotSame($parent, $newParent);
$this->assertNotSame($child, $newParent->reference->get());
}
示例5: process
public function process($loadReferencedRecords = array())
{
set_time_limit(0);
ignore_user_abort(true);
$this->deleteCancelFile();
$filter = $this->grid->getFilter();
$filter->setLimit(0);
$ids = array();
foreach (ActiveRecordModel::getFieldValues($this->grid->getModelClass(), $filter, array('ID'), ActiveRecordModel::LOAD_REFERENCES) as $row) {
$ids[] = $row['ID'];
}
$totalCount = count($ids);
$progress = 0;
$response = new JSONResponse(array('act' => $this->request->get('act')), 'success', $this->completionMessage);
ActiveRecord::beginTransaction();
$chunkSize = count($ids) / self::MASS_ACTION_CHUNK_SIZE > 5 ? self::MASS_ACTION_CHUNK_SIZE : ceil(count($ids) / 5);
foreach (array_chunk($ids, $chunkSize) as $chunk) {
$response->flush('|' . base64_encode(json_encode(array('total' => $totalCount, 'progress' => $progress, 'pid' => $this->pid))));
$this->processSet(ActiveRecordModel::getRecordSet($this->grid->getModelClass(), new ARSelectFilter(new INCond(new ARFieldHandle($this->grid->getModelClass(), 'ID'), $chunk)), $loadReferencedRecords));
$progress += count($chunk);
}
ActiveRecord::commit();
$response->flush('|');
return $response;
}
示例6: 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);
}
示例7: getSpecificationFieldSet
public function getSpecificationFieldSet($loadReferencedRecords = false)
{
$f = new ARSelectFilter(new EqualsCond(new ARFieldHandle($this->getFieldClass(), 'classID'), EavField::getClassID($this->owner)));
if ($this->owner->getStringIdentifier()) {
$f->mergeCondition(new EqualsCond(new ARFieldHandle('EavField', 'stringIdentifier'), $this->owner->getStringIdentifier()));
}
$f->setOrder(new ARFieldHandle($this->getFieldClass(), 'position'));
return ActiveRecordModel::getRecordSet($this->getFieldClass(), $f, $loadReferencedRecords);
}
示例8: getUserAddress
public static function getUserAddress($className, $addressID, User $user)
{
$f = new ARSelectFilter();
$f->setCondition(new EqualsCond(new ARFieldHandle($className, 'ID'), $addressID));
$f->mergeCondition(new EqualsCond(new ARFieldHandle($className, 'userID'), $user->getID()));
$s = ActiveRecordModel::getRecordSet($className, $f, array('UserAddress'));
if (!$s->size()) {
throw new ARNotFoundException($className, $addressID);
}
return $s->get(0);
}
示例9: getThemeByProduct
public static function getThemeByProduct(Product $product)
{
$c = eq(__CLASS__ . '.productID', $product->getID());
$c->addOr(self::getCategoryCondition($product->getCategory()));
$f = select($c);
$f->setOrder(new ARExpressionHandle('CategoryPresentation.productID=' . $product->getID()), 'DESC');
self::setCategoryOrder($product->getCategory(), $f);
// check if a theme is defined for this product particularly
$set = ActiveRecordModel::getRecordSet(__CLASS__, $f, array('Category'));
return self::getInheritedConfig($set);
}
示例10: loadOptionsForItemSet
public static function loadOptionsForItemSet(ARSet $orderedItems)
{
// load applied product option choices
$ids = array();
foreach ($orderedItems as $key => $item) {
$ids[] = $item->getID();
}
$f = new ARSelectFilter(new INCond(new ARFieldHandle('OrderedItemOption', 'orderedItemID'), $ids));
foreach (ActiveRecordModel::getRecordSet('OrderedItemOption', $f, array('DefaultChoice' => 'ProductOptionChoice', 'Option' => 'ProductOption', 'Choice' => 'ProductOptionChoice')) as $itemOption) {
$itemOption->orderedItem->get()->loadOption($itemOption);
}
}
示例11: getInstanceByName
public static function getInstanceByName($name)
{
$filter = new ARSelectFilter();
$filter->setCondition(new EqualsCond(new ARFieldHandle('Manufacturer', 'name'), $name));
$filter->setLimit(1);
$set = ActiveRecordModel::getRecordSet('Manufacturer', $filter);
if ($set->size() > 0) {
return $set->get(0);
} else {
return self::getNewInstance($name);
}
}
示例12: getOrder
/**
* Get CustomerOrder instance from session
*
* @return CustomerOrder
*/
public static function getOrder()
{
if (self::$instance) {
return self::$instance;
}
$session = new Session();
$id = $session->get('CustomerOrder');
if ($id) {
try {
$instance = CustomerOrder::getInstanceById($id, true);
if (!$instance->getOrderedItems()) {
$instance->loadItems();
}
$instance->isSyncedToSession = true;
} catch (ARNotFoundException $e) {
unset($instance);
}
}
if (!isset($instance)) {
$userId = SessionUser::getUser()->getID();
// get the last unfinalized order by this user
if ($userId > 0) {
$f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('CustomerOrder', 'userID'), $userId));
$f->mergeCondition(new NotEqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
$f->setOrder(new ARFieldHandle('CustomerOrder', 'ID'), 'DESC');
$f->setLimit(1);
$orders = ActiveRecordModel::getRecordSet('CustomerOrder', $f);
if ($orders->size()) {
$instance = $orders->get(0);
}
}
}
if (!isset($instance)) {
$instance = CustomerOrder::getNewInstance(User::getNewInstance(0));
$instance->user->set(NULL);
}
if (!$instance->user->get() && SessionUser::getUser()->getID() > 0) {
$instance->setUser(SessionUser::getUser());
$instance->save();
}
if ($instance->isFinalized->get()) {
$session->unsetValue('CustomerOrder');
return self::getOrder();
}
// fixes issue when trying to add OrderedItem to unsaved(without ID) CustomerOrder.
// ~ but i don't know if returning unsaved CustomerOrder is expected behaviour.
if ($instance->isExistingRecord() == false) {
$instance->save(true);
}
self::setOrder($instance);
return $instance;
}
示例13: view
public function view()
{
$f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('NewsPost', 'ID'), $this->request->get('id')));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('NewsPost', 'isEnabled'), true));
$s = ActiveRecordModel::getRecordSet('NewsPost', $f);
if (!$s->size()) {
throw new ARNotFoundException('NewsPost', $this->request->get('id'));
}
$newsPost = $s->get(0)->toArray();
$this->addIndexBreadCrumb();
$this->addBreadCrumb($newsPost['title_lang'], '');
return new ActionResponse('news', $newsPost);
}
示例14: getRecordSetArrayByIDs
public static function getRecordSetArrayByIDs($recordIDs, $loadRecordData = false)
{
if (!is_array($recordIDs)) {
$recordIDs = array($recordIDs);
}
$filter = new ARSelectFilter();
$filter->setCondition(new InCond(new ARFieldHandle(__CLASS__, 'ID'), $recordIDs));
// ActiveRecordModel::getRecordSetArray() will not get required setup and period prices!
$rs = ActiveRecordModel::getRecordSet(__CLASS__, $filter);
$result = array();
foreach ($rs->toArray() as $item) {
$result[$item['ID']] = $item;
}
return $result;
}
示例15: getLastOrders
protected function getLastOrders()
{
$f = select();
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isFinalized'), true));
$f->mergeCondition(new EqualsCond(new ARFieldHandle('CustomerOrder', 'isCancelled'), false));
$f->setOrder(new ARFieldHandle('CustomerOrder', 'dateCompleted'), 'desc');
$f->setLimit(10);
$customerOrders = ActiveRecordModel::getRecordSet('CustomerOrder', $f, ActiveRecordModel::LOAD_REFERENCES);
$ordersArray = array();
if ($customerOrders->size() > 0) {
$i = 0;
foreach ($customerOrders as $order) {
$ordersArray[$i] = $order->toArray();
$ordersArray[$i]['status_name'] = CustomerOrder::getStatusName($ordersArray[$i]['status'] ? $ordersArray[$i]['status'] : CustomerOrder::STATUS_NEW);
$i++;
}
return $ordersArray;
}
return array();
}