Nag_Task::getSlice PHP Method

getSlice() public method

Helper method for getting only a slice of the total tasks in this list.
public getSlice ( integer $page, integer $perpage = null ) : Nag_Task
$page integer The starting page.
$perpage integer The count of tasks per page.
return Nag_Task The resulting task list.
    public function getSlice($page = 0, $perpage = null)
    {
        $this->reset();
        // Position at start task
        $start = $page * (empty($perpage) ? 0 : $perpage);
        $count = 0;
        while ($count < $start) {
            if (!$this->each()) {
                return new Nag_Task();
            }
            ++$count;
        }
        $count = 0;
        $results = new Nag_Task();
        $max = empty($perpage) ? $this->count() - $start : $perpage;
        while ($count < $max) {
            if ($next = $this->each()) {
                $results->add($next);
                ++$count;
            } else {
                $count = $max;
            }
        }
        $results->process();
        return $results;
    }

Usage Example

Beispiel #1
0
 /**
  * Fetch the matching resources that should appear on the current page
  *
  * @param integer $page     Start page.
  * @param integer $perpage  Number of tasks per page.
  *
  * @return Nag_Task  A list of tasks.
  */
 public function getSlice($page = 0, $perpage = null)
 {
     // Refresh the search
     $this->runSearch();
     return $this->_tasks->getSlice($page, $perpage);
 }