silverstripe-reports/code/Newsletter/BatchProcess.php

107 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* @package cms
* @subpackage newsletter
*/
/**
* Create a process in session which is incremented to calls from the client
* @package cms
* @subpackage newsletter
*/
class BatchProcess extends Object {
protected $objects;
protected $current;
protected $id;
protected $scriptOutput = true;
function __construct( $collection ) {
$this->current = 0;
if( $collection ) {
if( is_array( $collection ) )
$this->objects = $collection;
elseif( is_a( $collection, 'DataObjectSet' ) ) {
$this->objects = $collection->toArray();
} else
$this->objects = array( $collection );
}
}
function runToCompletion() {
$this->scriptOutput = false;
$this->current = 0;
$ignore = $this->next( count( $this->objects ) );
$this->complete();
}
function getID() {
return $this->id;
}
function next() {
self::addProcess( $this );
return $this->id.':'.$this->current.'/'.count( $this->objects );
}
function start() {
$this->current = 0;
$this->id = self::generateID();
if( !$this->objects || count( $this->objects ) === 0 )
switch externals to trunk. Inform-merge: from the changeset: r32477: Merge 2.0-inform from trunk previously r32478: Merge 2.0-inform from trunk previously r32481: merge 2.0infom with lastes chunk r32483: merge 2.0infom with lastes chunk r33526: Final styling of all forms and combined communication form add/alter javascript for height adjustment of First / Second block r33580: styling for combined form communication in myinfom pages r33706: styling of combined form (communication) in Email r33881: made compatible to $extraClass r33885: added defaultVal r33887: fixed typo r34728: modified SmallFieldHolder?() r34729: added "validationError"-class r34914: WIP3866: Factfinder: Hide "self emplyed" block r34964: Change current plan upto TraumaInsurance? r35038: disabled friggin field focus r35230: #1032 Fixed hash-link insertion r35887: conditionally setting parameters in sourceID() - to avoid empty overrides r35892: Saving value in SQL-compatible format (YYYY-MM-DD instead of DD/MM/YYYY), with fallback for non-sql values (just passed through without conversion) r35928: Removed "create a" from PageType?-dropdown, sorting alphabetically, falling back to $singular_name r35990: branched off for membertablefield r35994: fix for membertablefield r36024: added array-condition needed for DMYDateField r36083: fix bug for compositeField -> dropDatalessField r36394: removed debug code r36826: change wrong indent format r36828: WIP 4262: Logging out of My Inform goes to blank page r36858: Fixed error caused in r12472 while merging to Session-class r37132: Merged partial changesets from branches/2.0-nzct, only adding childID to detailform when not in add-mode r40815: add an unsubscribe record when a member subscribe a newslettertype r41113: fix the bug described in http://support.silverstripe.com/info/ticket/31: CRM not showing search results r43226: fixed search (partial merge from trunk) r43268: merged createNewPassword() from trunk, was referencing a non-existinent global function randomString() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@45473 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-11-23 02:10:19 +01:00
return $this->complete();
return $this->next();
}
function complete() {
self::removeProcess( $this );
}
static function generateID() {
return count(Session::get('BatchProcesses')) + 1;
}
static function addProcess( $process ) {
Session::set('BatchProcesses.' . ($process->getID() - 1), serialize($process));
}
static function removeProcess( $process ) {
Session::clear('BatchProcesses.' . ($process->getID() - 1));
}
}
/**
* Controller for calling the batch processes via Ajax.
* @package cms
* @subpackage newsletter
*/
class BatchProcess_Controller extends Controller {
function next() {
$processID = $this->urlParams['ID'];
if( !$processID ) {
return _t('BatchProcess_Controller.ERROR', 'ERROR: Could not continue process');
}
$process = unserialize(Session::get('BatchProcesses.' . ($this->urlParams['ID'] - 1)));
if( !$process ) {
return _t('BatchProcess_Controller.ERROR', 'ERROR:Could not continue process');
}
if( $this->urlParams['Batch'] )
return $process->next( $this->urlParams['Batch'] );
else
return $process->next();
}
}
?>