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; }
public function removeUnnecessaryCategoriesFromSnapshot(ClonedStore $store) { $conds = array(); foreach ($store->getRelatedRecordSet('ClonedStoreCategory', select(), 'Category') as $storeCat) { $cat = $storeCat->category->get(); if (1 == $cat->getID()) { continue; } $cat->load(); $cond = lte(f('Category.lft'), $cat->lft->get()); $cond->addAND(gte(f('Category.rgt'), $cat->rgt->get())); $conds[] = $cond; } $this->flush(__LINE__); if (!$conds) { return; } $this->flush(__LINE__); $cond = new OrChainCondition($conds); $ids = array(); foreach (ActiveRecordModel::getFieldValues('Category', select($cond), array('ID')) as $id) { $ids[] = array_shift($id); } $idstr = 'IN (' . implode(', ', $ids) . ')'; // delete unused extra category references // ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.ProductCategory WHERE categoryID NOT ' . $idstr); $this->flush(__LINE__); //var_dump('before: ' . array_shift(array_shift(ActiveRecord::getDataBySQL('SELECT COUNT(*) FROM ' . $this->importDatabase . '.Product')))); ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID NOT ' . $idstr . ') AND ((SELECT COUNT(*) FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND (ProductCategory.categoryID ' . $idstr . ')) = 0)'); //echo 'DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID NOT ' . $idstr . ') AND ((SELECT COUNT(*) FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND (ProductCategory.categoryID ' . $idstr . ')) = 0)'; //var_dump('AFTER: ' . array_shift(array_shift(ActiveRecord::getDataBySQL('SELECT COUNT(*) FROM ' . $this->importDatabase . '.Product')))); //die('test'); $this->flush(__LINE__); // fix main category ActiveRecord::executeUpdate('UPDATE ' . $this->importDatabase . '.Product SET categoryID=(SELECT categoryID FROM ' . $this->importDatabase . '.ProductCategory WHERE productID=Product.ID AND ProductCategory.categoryID IN (' . implode(',', $ids) . ') LIMIT 1) WHERE (parentID IS NULL) AND (categoryID NOT ' . $idstr . ')'); $this->flush(__LINE__); // remove redundant extra categories ActiveRecord::executeUpdate('DELETE ' . $this->importDatabase . '.ProductCategory FROM ' . $this->importDatabase . '.ProductCategory LEFT JOIN ' . $this->importDatabase . '.Product ON ProductCategory.productID=Product.ID WHERE ProductCategory.categoryID=Product.categoryID'); $this->flush(__LINE__); // delete unused products ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Product WHERE (categoryID IS NULL) AND (parentID IS NULL)'); $this->flush(__LINE__); // get all remaining categories $sql = 'SELECT lft, rgt FROM ' . $this->importDatabase . '.Category WHERE ID IN (SELECT categoryID FROM ' . $this->importDatabase . '.ProductCategory)'; $conds = array(); foreach (ActiveRecordModel::getDataBySQL($sql) as $row) { $cond = lte(f('Category.lft'), $row['lft']); $cond->addAND(gte(f('Category.rgt'), $row['rgt'])); $conds[] = $cond; } $this->flush(__LINE__); $cond = new OrChainCondition($conds); $ids = array(); foreach (ActiveRecordModel::getFieldValues('Category', select($cond), array('ID')) as $id) { $ids[] = array_shift($id); } $this->flush(__LINE__); $allidstr = 'IN (' . implode(', ', $ids) . ')'; // delete unused categories ActiveRecord::executeUpdate('DELETE FROM ' . $this->importDatabase . '.Category WHERE (ID<>1) AND (ID NOT ' . $idstr . ') AND (ID NOT ' . $allidstr . ')'); $this->flush(__LINE__); // disable/enable existing products according to category selection $store->addQueuedQuery('UPDATE Category SET isEnabled=0 WHERE (ID NOT ' . $idstr . ') AND (ID NOT ' . $allidstr . ')'); $store->addQueuedQuery('UPDATE Category SET isEnabled=1 WHERE ((ID ' . $idstr . ') OR (ID ' . $allidstr . ')) AND (COALESCE(LOCATE("|isEnabled|", protectedFields), 0) = 0)'); $this->flush(__LINE__); $store->addQueuedQuery('UPDATE Product SET isEnabled=0 WHERE (parentID IS NULL) AND (categoryID NOT ' . $idstr . ') AND (categoryID NOT ' . $allidstr . ')'); //$store->addQueuedQuery('UPDATE Product SET isEnabled=1 WHERE (parentID IS NULL) AND ((categoryID ' . $idstr . ') OR (categoryID ' . $allidstr . ')) AND (COALESCE(LOCATE("|isEnabled|", protectedFields), 0) = 0)'); $this->flush(__LINE__); }
public function previous($diff = -1) { $product = Product::getInstanceByID($this->request->get('id'), true, array('Category')); $this->category = !$this->request->get('category') ? $product->category->get() : Category::getInstanceByID($this->request->get('category'), true); $this->getAppliedFilters(); $this->getSelectFilter(); if ($this->request->get('quickShopSequence')) { $ids = json_decode($this->request->get('quickShopSequence')); } else { $ids = array(); foreach (ActiveRecordModel::getFieldValues('Product', $this->productFilter->getSelectFilter(), array('ID'), array('Category')) as $row) { $ids[] = $row['ID']; } } $index = array_search($product->getID(), $ids); $prevIndex = $index + $diff; if ($prevIndex < 0) { $prevIndex = count($ids) - 1; } else { if ($prevIndex == count($ids)) { $prevIndex = 0; } } include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.productUrl.php'; if ('quickShop' == $this->request->get('originalAction')) { return new ActionRedirectResponse('product', 'quickShop', array('id' => $ids[$prevIndex], 'query' => $this->getContext())); } else { return new RedirectResponse(createProductUrl(array('product' => Product::getInstanceByID($ids[$prevIndex], true)->toArray(), 'query' => $this->getContext()), $this->application)); } }
private function getActiveTimeList($date) { $f = new ARSelectFilter(); $f->setCondition(new AndChainCondition(array(eq(f('EyeExamSchedule.date'), 'DATE(\'' . $date . '\')'), isnull(f('EyeExamSchedule.eyeExamRequestID'))))); $f->setOrder(new ARFieldHandle('EyeExamSchedule', 'doctorName'), 'ASC'); $f->setOrder(new ARFieldHandle('EyeExamSchedule', 'time'), 'ASC'); $workingHours = ActiveRecordModel::getFieldValues('EyeExamSchedule', $f, array('ID', 'doctorName', 'time', 'isVisible')); return $workingHours; }