You are here

class FeedsBatch in Feeds 7

Same name and namespace in other branches
  1. 6 includes/FeedsBatch.inc \FeedsBatch

A FeedsBatch object holds the state of an import or clear batch.

Used in FeedsSource class. Counter variables are public for easier access.

Hierarchy

Expanded class hierarchy of FeedsBatch

File

includes/FeedsBatch.inc, line 14

View source
class FeedsBatch {

  // Total of each stage of this batch.
  protected $total;

  // Progress of each stage of this batch.
  protected $progress;
  public function __construct() {
    $this->total = array();
    $this->progress = array();
  }

  /**
   * Set the total for a stage.
   */
  public function setTotal($stage, $total) {
    $this->total[$stage] = $total;
  }

  /**
   * Get the total for a stage.
   */
  public function getTotal($stage) {
    return $this->total[$stage];
  }

  /**
   * Set progress for a stage.
   *
   * @param $stage
   *   The stage to set the progress for. One of FEEDS_FETCHING, FEEDS_PARSING,
   *   FEEDS_PROCESING or FEEDS_CLEARING.
   * @param $progress
   *   The number of items worked off for the given stage. This should be the
   *   number of items worked off across all page loads, not just the present
   *   page load.
   */
  public function setProgress($stage, $progress) {
    $this->progress[$stage] = $progress;
  }

  /**
   * Report progress.
   *
   * @param $stage
   *   The stage to set the progress for. One of FEEDS_FETCHING, FEEDS_PARSING,
   *   FEEDS_PROCESING or FEEDS_CLEARING.
   */
  public function getProgress($stage = NULL) {
    if ($stage) {
      $progress = $this->progress[$stage];
      if ($progress == FEEDS_BATCH_COMPLETE) {
        return FEEDS_BATCH_COMPLETE;
      }
      $total = $this->total[$stage];
    }
    else {
      $complete = TRUE;
      $progress = 0;
      foreach ($this->progress as $p) {
        $progress += $p;
        $complete &= $p == FEEDS_BATCH_COMPLETE;
      }
      if ($complete) {
        return FEEDS_BATCH_COMPLETE;
      }
      $total = array_sum($this->total);
    }
    $progress = 1.0 / $total * $progress;
    return $progress == FEEDS_BATCH_COMPLETE ? 0.999 : $progress;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsBatch::$progress protected property
FeedsBatch::$total protected property
FeedsBatch::getProgress public function Report progress.
FeedsBatch::getTotal public function Get the total for a stage.
FeedsBatch::setProgress public function Set progress for a stage.
FeedsBatch::setTotal public function Set the total for a stage.
FeedsBatch::__construct public function 2