Piwik\DataTable::deleteRowsOffset PHP Method

deleteRowsOffset() public method

Deletes rows from $offset to $offset + $limit.
public deleteRowsOffset ( integer $offset, integer | null $limit = null ) : integer
$offset integer The offset to start deleting rows from.
$limit integer | null The number of rows to delete. If `null` all rows after the offset will be removed.
return integer The number of rows deleted.
    public function deleteRowsOffset($offset, $limit = null)
    {
        if ($limit === 0) {
            return 0;
        }
        $count = $this->getRowsCount();
        if ($offset >= $count) {
            return 0;
        }
        // if we delete until the end, we delete the summary row as well
        if (is_null($limit) || $limit >= $count) {
            $this->summaryRow = null;
        }
        if (is_null($limit)) {
            array_splice($this->rows, $offset);
        } else {
            array_splice($this->rows, $offset, $limit);
        }
        return $count - $this->getRowsCount();
    }

Usage Example

Beispiel #1
0
 /**
  * See {@link Limit}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     $table->setMetadata(DataTable::TOTAL_ROWS_BEFORE_LIMIT_METADATA_NAME, $table->getRowsCount());
     if ($this->keepSummaryRow) {
         $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
     }
     // we delete from 0 to offset
     if ($this->offset > 0) {
         $table->deleteRowsOffset(0, $this->offset);
     }
     // at this point the array has offset less elements. We delete from limit to the end
     if ($this->limit >= 0) {
         $table->deleteRowsOffset($this->limit);
     }
     if ($this->keepSummaryRow && !empty($summaryRow)) {
         $table->addSummaryRow($summaryRow);
     }
 }