class FeedsBatch in Feeds 6
Same name and namespace in other branches
- 7 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
- class \FeedsBatch
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsBatch:: |
protected | property | ||
FeedsBatch:: |
protected | property | ||
FeedsBatch:: |
public | function | Report progress. | |
FeedsBatch:: |
public | function | Get the total for a stage. | |
FeedsBatch:: |
public | function | Set progress for a stage. | |
FeedsBatch:: |
public | function | Set the total for a stage. | |
FeedsBatch:: |
public | function | 2 |