src/wcmf/application/controller/BatchController.php
protected function addWorkPackage($name, $size, array $oids, $callback, $args=null) {
    $request = $this->getRequest();
    $response = $this->getResponse();
    if (strlen($callback) == 0) {
      throw new ApplicationException($request, $response,
              ApplicationError::getGeneral("Wrong work package description '".$name."': No callback given."));
    }

    $workPackages = $this->getLocalSessionValue(self::PACKAGES_VAR);
    $counter = 1;
    $total = sizeof($oids);
    while(sizeof($oids) > 0) {
      $items = [];
      for($i=0; $i<$size && sizeof($oids)>0; $i++) {
        $nextItem = array_shift($oids);
        $items[] = sprintf('%s', $nextItem);
      }

      // define status text
      $start = $counter;
      $end = ($counter+sizeof($items)-1);
      $stepsText = $counter;
      if ($start != $end) {
        $stepsText .= '-'.($counter+sizeof($items)-1);
      }
      $statusText = "";
      if ($total > 1) {
        $statusText = $stepsText.'/'.$total;
      }

      $curWorkPackage = [
        'name' => $name.' '.$statusText,
        'oids' => $items,
        'callback' => $callback,
        'args' => $args
      ];
      $workPackages[] = $curWorkPackage;
      $counter += $size;
    }
    $this->workPackages = $workPackages;

    // update session
    $this->setLocalSessionValue(self::PACKAGES_VAR, $workPackages);
    $this->setLocalSessionValue(self::NUM_STEPS_VAR, sizeof($workPackages));
  }
protected function addWorkPackage($name, $size, array $oids, $callback, $args=null) {
    $request = $this->getRequest();
    $response = $this->getResponse();
    if (strlen($callback) == 0) {
      throw new ApplicationException($request, $response,
              ApplicationError::getGeneral("Wrong work package description '".$name."': No callback given."));
    }

    $workPackages = $this->getLocalSessionValue(self::PACKAGES_VAR);
    $counter = 1;
    $total = sizeof($oids);
    while(sizeof($oids) > 0) {
      $items = [];
      for($i=0; $i<$size && sizeof($oids)>0; $i++) {
        $nextItem = array_shift($oids);
        $items[] = sprintf('%s', $nextItem);
      }

      // define status text
      $start = $counter;
      $end = ($counter+sizeof($items)-1);
      $stepsText = $counter;
      if ($start != $end) {
        $stepsText .= '-'.($counter+sizeof($items)-1);
      }
      $statusText = "";
      if ($total > 1) {
        $statusText = $stepsText.'/'.$total;
      }

      $curWorkPackage = [
        'name' => $name.' '.$statusText,
        'oids' => $items,
        'callback' => $callback,
        'args' => $args
      ];
      $workPackages[] = $curWorkPackage;
      $counter += $size;
    }
    $this->workPackages = $workPackages;

    // update session
    $this->setLocalSessionValue(self::PACKAGES_VAR, $workPackages);
    $this->setLocalSessionValue(self::NUM_STEPS_VAR, sizeof($workPackages));
  }
protected function addWorkPackage ( $ name , $ size , array $ oids , $ callback , $ args = null ) { $ request = $ this -> getRequest ( ) ; $ response = $ this -> getResponse ( ) ; if ( strlen ( $ callback ) == 0 ) { throw new ApplicationException ( $ request , $ response , ApplicationError :: getGeneral ( "Wrong work package description '" . $ name . "': No callback given." ) ) ; } $ workPackages = $ this -> getLocalSessionValue ( self :: PACKAGES_VAR ) ; $ counter = 1 ; $ total = sizeof ( $ oids ) ; while ( sizeof ( $ oids ) > 0 ) { $ items = [ ] ; for ( $ i = 0 ; $ i < $ size && sizeof ( $ oids ) > 0 ; $ i ++ ) { $ nextItem = array_shift ( $ oids ) ; $ items [ ] = sprintf ( '%s' , $ nextItem ) ; } // define status text $ start = $ counter ; $ end = ( $ counter + sizeof ( $ items ) - 1 ) ; $ stepsText = $ counter ; if ( $ start != $ end ) { $ stepsText .= '-' . ( $ counter + sizeof ( $ items ) - 1 ) ; } $ statusText = "" ; if ( $ total > 1 ) { $ statusText = $ stepsText . '/' . $ total ; } $ curWorkPackage = [ 'name' => $ name . ' ' . $ statusText , 'oids' => $ items , 'callback' => $ callback , 'args' => $ args ] ; $ workPackages [ ] = $ curWorkPackage ; $ counter += $ size ; } $ this -> workPackages = $ workPackages ; // update session $ this -> setLocalSessionValue ( self :: PACKAGES_VAR , $ workPackages ) ; $ this -> setLocalSessionValue ( self :: NUM_STEPS_VAR , sizeof ( $ workPackages ) ) ; }
Add a work package to session. This package will be divided into sub packages of given size.
@param $name Display name of the package (will be supplemented by startNumber-endNumber, e.g. '1-7', '8-14', ...)
@param $size Size of one sub package. This defines how many of the oids will be passed to the callback in one call (e.g. '7' means pass 7 oids per call)
@param $oids An array of object ids (or other application specific package identifiers) that will be distributed into sub packages of given size
@param $callback The name of method to call for this package type.
The callback method must accept the following parameters:
1. array parameter (the object ids to process in the current call)
2. optionally array parameter (the additional arguments)
@param $args Associative array of additional callback arguments (application specific) (default: _null_)
Add a work package to session . This package will be divided into sub packages of given size .