wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.SimpleBatchController.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.SimpleBatchController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/application/controller/class.BatchController.php");
20 
21 /**
22  * @class SimpleBatchController
23  * @ingroup Controller
24  * @brief SimpleBatchController is a controller demonstrating the use
25  * of BatchController for cutting a long task into a fixed number
26  * of smaller tasks.
27  *
28  * <b>Input actions:</b>
29  * - see BatchController
30  *
31  * <b>Output actions:</b>
32  * - see BatchController
33  *
34  * @author ingo herwig <ingo@wemove.com>
35  */
37 {
38  /**
39  * @see BatchController::getWorkPackage()
40  */
41  function getWorkPackage($number)
42  {
43  // create 2 static work packages where each consists of 5 * $number+1 oids,
44  // these will be processed in portions of 3
45  if ($number < 2)
46  {
47  // create different oid lists
48  $oids = array();
49  for ($i=0; $i<5*($number+1); $i++)
50  array_push($oids, $number."-".$i);
51 
52  // for demonstration purposes we call different methods for different oid lists
53  if ($number == 0)
54  $callback = 'createFileA';
55  if ($number == 1)
56  $callback = 'createFileB';
57 
58  return array('name' => 'File '.$number, 'size' => 3, 'oids' => $oids, 'callback' => $callback);
59  }
60  else
61  return null;
62  }
63  /**
64  * Create one file of type A for each oid in oids
65  * @param oids The oids to process
66  * @note This is a callback method called on a matching work package @see BatchController::addWorkPackage()
67  */
68  function createFileA($oids)
69  {
70  // do some processing depending on state here
71  foreach ($oids as $oid)
72  {
73  $curNum = sprintf("%04s",$oid);
74  $fh = fopen("result".$curNum."_A.txt", "a");
75  fputs($fh, date("F j, Y, g:i a").": SimpleBatchController created file A #".$curNum."\n");
76  fclose($fh);
77  }
78  }
79  /**
80  * Create one file of type B for each oid in oids
81  * @param oids The oids to process
82  * @note This is a callback method called on a matching work package @see BatchController::addWorkPackage()
83  */
84  function createFileB($oids)
85  {
86  // do some processing depending on state here
87  foreach ($oids as $oid)
88  {
89  $curNum = sprintf("%04s",$oid);
90  $fh = fopen("result".$curNum."_B.txt", "a");
91  fputs($fh, date("F j, Y, g:i a").": SimpleBatchController created file B #".$curNum."\n");
92  fclose($fh);
93  }
94  }
95 }
96 ?>
SimpleBatchController is a controller demonstrating the use of BatchController for cutting a long tas...
BatchController allows to define work packages that will be processed in a sequence. It simplifies the usage of LongTaskController functionality for splitting different bigger tasks into many smaller (similar) tasks where the whole number of tasks isn't known at designtime.