本文整理汇总了PHP中Kwf_Model_Select::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Kwf_Model_Select::limit方法的具体用法?PHP Kwf_Model_Select::limit怎么用?PHP Kwf_Model_Select::limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kwf_Model_Select
的用法示例。
在下文中一共展示了Kwf_Model_Select::limit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getSelect
protected function _getSelect(ParamFetcher $paramFetcher, Request $request)
{
$select = new \Kwf_Model_Select();
$select->limit($paramFetcher->get('limit'), $paramFetcher->get('start'));
$queryValue = trim($request->get('query'));
if ($queryValue) {
$exprs = array();
if (!$this->_queryColumns) {
throw new \Kwf_Exception("_queryColumns are required to be set");
}
if ($this->_querySplit) {
$queryValue = explode(' ', $queryValue);
} else {
$queryValue = array($queryValue);
}
foreach ($queryValue as $q) {
$e = array();
foreach ($this->_queryColumns as $c) {
$e[] = new \Kwf_Model_Select_Expr_Like($c, '%' . $q . '%');
}
if (count($e) > 1) {
$exprs[] = new \Kwf_Model_Select_Expr_Or($e);
} else {
$exprs[] = $e[0];
}
}
if (count($exprs) > 1) {
$select->where(new \Kwf_Model_Select_Expr_And($exprs));
} else {
$select->where($exprs[0]);
}
}
return $select;
}
示例2: buildSelect
public function buildSelect(Request $request, array $options = array())
{
$select = new \Kwf_Model_Select();
if ($request->get('limit')) {
$select->limit($request->get('limit'), $request->get('start'));
} else {
$select->limit(25, $request->get('start'));
}
$queryValue = trim($request->get('query'));
if ($queryValue) {
$queryColumns = null;
if (isset($options['queryColumns'])) {
$queryColumns = $options['queryColumns'];
}
$exprs = array();
if (!$queryColumns) {
throw new \Kwf_Exception("queryColumns are required to be set");
}
if (isset($options['querySplit']) && $options['querySplit']) {
$queryValue = explode(' ', $queryValue);
} else {
$queryValue = array($queryValue);
}
foreach ($queryValue as $q) {
$e = array();
foreach ($queryColumns as $c) {
$e[] = new \Kwf_Model_Select_Expr_Like($c, '%' . $q . '%');
}
if (count($e) > 1) {
$exprs[] = new \Kwf_Model_Select_Expr_Or($e);
} else {
$exprs[] = $e[0];
}
}
if (count($exprs) > 1) {
$select->where(new \Kwf_Model_Select_Expr_And($exprs));
} else {
$select->where($exprs[0]);
}
}
$restColumns = $this->model->getSerializationColumns(array('rest_read', 'rest'));
$exprColumns = $this->model->getExprColumns();
foreach (array_intersect(array_keys($restColumns), $exprColumns) as $i) {
$select->expr($i);
}
return $select;
}
示例3: initialSync
public function initialSync($processInCli = true)
{
$stepSize = 100;
$format = self::_optimalImportExportFormat($this->getProxyModel(), $this->getSourceModel());
$count = $this->_sourceModel->countRows();
$progress = null;
if (PHP_SAPI == 'cli' && $processInCli) {
$c = new Zend_ProgressBar_Adapter_Console();
$c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_ETA, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
$progress = new Zend_ProgressBar($c, 0, $count);
}
$startTime = microtime(true);
$this->getProxyModel()->deleteRows(array());
//alles löschen
for ($offset = 0; $offset < $count; $offset += $stepSize) {
$s = new Kwf_Model_Select();
$s->limit($stepSize, $offset);
/*
$data = $this->_sourceModel->export($format, $s);
$this->getProxyModel()->import($format, $data);
*/
//warning: slow code ahead
foreach ($this->_sourceModel->getRows($s) as $row) {
$data = $row->toArray();
$newRow = $this->createRow($data);
foreach ($this->getDependentModels() as $rule => $depModel) {
if ($depModel instanceof Kwf_Model_RowsSubModel_MirrorCacheSimple) {
//dieser code könne vielleicht im Kwf_Model_RowsSubModel_MirrorCacheSimple liegen
$m = $depModel->getSourceModel();
$ref = $m->getReferenceByModelClass(get_class($this), null);
$select = new Kwf_Model_Select();
$select->whereEquals($ref['column'], $row->{$this->getPrimaryKey()});
$childRows = $m->getRows($select);
foreach ($childRows as $childRow) {
$newCRow = $newRow->createChildRow($rule, $childRow->toArray());
}
}
}
$newRow->save();
}
unset($row);
unset($newRow);
unset($newCRow);
unset($childRows);
unset($childRow);
foreach (self::getInstances() as $m) {
$m->clearRows();
}
//echo round(memory_get_usage()/(1024*1024), 3)."MB\n";
if ($progress) {
$text = round(($offset + $stepSize) / (microtime(true) - $startTime)) . ' rows/sec';
$progress->next($stepSize, $text);
}
}
}
示例4: testSelect
public function testSelect()
{
$select = new Kwf_Model_Select();
$select->where('foo = ?', 1);
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE), array(array('foo = ?', 1, null)));
$select->where('bar = ?', 1);
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE), array(array('foo = ?', 1, null), array('bar = ?', 1, null)));
$select->whereEquals('foo', 1);
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_EQUALS), array('foo' => 1));
$select->whereEquals('foo', 'bar');
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_EQUALS), array('foo' => 'bar'));
$select->whereEquals('foo2', 'bar2');
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_EQUALS), array('foo' => 'bar', 'foo2' => 'bar2'));
$select->order('foo');
$this->assertEquals($select->getPart(Kwf_Model_Select::ORDER), array(array('field' => 'foo', 'direction' => 'ASC')));
$select->order('foo2', 'DESC');
$this->assertEquals($select->getPart(Kwf_Model_Select::ORDER), array(array('field' => 'foo', 'direction' => 'ASC'), array('field' => 'foo2', 'direction' => 'DESC')));
$select->limit(10);
$this->assertEquals($select->getPart(Kwf_Model_Select::LIMIT_COUNT), 10);
$this->assertEquals($select->getPart(Kwf_Model_Select::LIMIT_OFFSET), null);
$select->limit(20);
$this->assertEquals($select->getPart(Kwf_Model_Select::LIMIT_COUNT), 20);
$select->limit(25, 10);
$this->assertEquals($select->getPart(Kwf_Model_Select::LIMIT_COUNT), 25);
$this->assertEquals($select->getPart(Kwf_Model_Select::LIMIT_OFFSET), 10);
$this->assertEquals(count($select->getParts()), 5);
$select = new Kwf_Model_Select(array('id' => 1));
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_ID), 1);
$select->whereId(10);
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_ID), 10);
$select->whereId(11);
$this->assertEquals($select->getPart(Kwf_Model_Select::WHERE_ID), 11);
$select = new Kwf_Model_Select();
$select->order(Kwf_Model_Select::ORDER_RAND);
$this->assertEquals($select->getPart(Kwf_Model_Select::ORDER), array(array('field' => Kwf_Model_Select::ORDER_RAND, 'direction' => 'ASC')));
}
示例5: jsonPasteAction
public function jsonPasteAction()
{
$session = new Kwf_Session_Namespace('PagesController:copy');
$id = $session->id;
if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) {
throw new Kwf_Exception_Client(trlKwf('Clipboard is empty'));
}
$source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true));
$target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('id'), array('ignoreVisible' => true));
$user = Zend_Registry::get('userModel')->getAuthedUser();
$acl = Kwf_Registry::get('acl')->getComponentAcl();
if (!$acl->isAllowed($user, $source) || !$acl->isAllowed($user, $target)) {
throw new Kwf_Exception_AccessDenied();
}
$progressBar = new Zend_ProgressBar(new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')), 0, Kwf_Util_Component::getDuplicateProgressSteps($source));
Kwf_Util_MemoryLimit::set(256);
Kwf_Events_ModelObserver::getInstance()->disable();
//This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear.
$newPage = Kwf_Util_Component::duplicate($source, $target, $progressBar);
Kwf_Util_Component::afterDuplicate($source, $newPage);
Kwf_Events_ModelObserver::getInstance()->enable();
$progressBar->finish();
$s = new Kwf_Model_Select();
$s->whereEquals('parent_id', $newPage->row->parent_id);
$s->order('pos', 'DESC');
$s->limit(1);
$lastRow = $newPage->generator->getModel()->getRow($s);
$row = $newPage->generator->getModel()->getRow($newPage->row->id);
$row->pos = $lastRow ? $lastRow->pos + 1 : 1;
$row->visible = false;
$row->save();
}
示例6: testGetIdsOrderLimit
public function testGetIdsOrderLimit()
{
$s = new Kwf_Model_Select();
$s->limit(2);
$s->order('foo');
$ids = $this->_m->getIds($s);
$this->assertEquals(2, count($ids));
$this->assertEquals('1m2', $ids[0]);
$this->assertEquals('2m2', $ids[1]);
$s = new Kwf_Model_Select();
$s->limit(2, 2);
$s->order('foo');
$ids = $this->_m->getIds($s);
$this->assertEquals('1m1', $ids[0]);
$this->assertEquals('1m3', $ids[1]);
$s = new Kwf_Model_Select();
$s->limit(2, 4);
$s->order('foo');
$ids = $this->_m->getIds($s);
$this->assertEquals('2m1', $ids[0]);
$this->assertEquals('2m3', $ids[1]);
}
示例7: select
public function select($where = array(), $order = null, $limit = null, $start = null)
{
if (!is_array($where)) {
$ret = new Kwf_Model_Select();
if ($where) {
$ret->whereEquals($this->getPrimaryKey(), $where);
}
} else {
$ret = new Kwf_Model_Select($where);
}
if ($order) {
$ret->order($order);
}
if ($limit || $start) {
$ret->limit($limit, $start);
}
return $ret;
}