Nette\Database\Table\GroupedSelection::execute PHP Method

execute() protected method

******************* internal ****************d*g*
protected execute ( )
    protected function execute()
    {
        if ($this->rows !== NULL) {
            $this->observeCache = $this;
            return;
        }
        $accessedColumns = $this->accessedColumns;
        $this->loadRefCache();
        if (!isset($this->refCacheCurrent['data'])) {
            // we have not fetched any data yet => init accessedColumns by cached accessedColumns
            $this->accessedColumns = $accessedColumns;
            $limit = $this->sqlBuilder->getLimit();
            $rows = count($this->refTable->rows);
            if ($limit && $rows > 1) {
                $this->sqlBuilder->setLimit(NULL, NULL);
            }
            parent::execute();
            $this->sqlBuilder->setLimit($limit, NULL);
            $data = [];
            $offset = [];
            $this->accessColumn($this->column);
            foreach ((array) $this->rows as $key => $row) {
                $ref =& $data[$row[$this->column]];
                $skip =& $offset[$row[$this->column]];
                if ($limit === NULL || $rows <= 1 || count($ref) < $limit && $skip >= $this->sqlBuilder->getOffset()) {
                    $ref[$key] = $row;
                } else {
                    unset($this->rows[$key]);
                }
                $skip++;
                unset($ref, $skip);
            }
            $this->refCacheCurrent['data'] = $data;
            $this->data =& $this->refCacheCurrent['data'][$this->active];
        }
        $this->observeCache = $this;
        if ($this->data === NULL) {
            $this->data = [];
        } else {
            foreach ($this->data as $row) {
                $row->setTable($this);
                // injects correct parent GroupedSelection
            }
            reset($this->data);
        }
    }

Usage Example

示例#1
0
 protected function execute()
 {
     if ($this->rows !== NULL) {
         return;
     }
     parent::execute();
     if ($this->accessedColumns) {
         $this->accessedColumns[$this->column] = TRUE;
     }
     $this->onExecute();
 }