wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.CommitVisitor.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.CommitVisitor.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/visitor/class.Visitor.php");
20 /**
21  * @class CommitVisitor
22  * @ingroup Visitor
23  * @brief The CommitVisitor is used to commit the object's changes to the object storage.
24  * The objects must implement the PersistentObject interface.
25  *
26  * @author ingo herwig <ingo@wemove.com>
27  */
28 class CommitVisitor extends Visitor
29 {
30  var $_result = array();
31 
32  /**
33  * Visit the current object in iteration and commit changes.
34  * @param obj A reference to the current object.
35  */
36  function visit(&$obj)
37  {
38  $oldState = $obj->getState();
39  switch($oldState)
40  {
41  case STATE_DIRTY:
42  case STATE_NEW:
43  // save changes / insert
44  $obj->save();
45  break;
46 
47  case STATE_DELETED:
48  // delete object
49  $obj->delete();
50  break;
51  }
52 
53  // store commit in result array
54  if (!isset($this->_result[$oldState]))
55  $this->_result[$oldState] = array();
56  $this->_result[$oldState][sizeof($this->_result[$oldState])] = $obj->getOID();
57  }
58 
59  /**
60  * Get the last commit result.
61  * @return An associative array with the persistent states as keys and
62  * arrays of oids (after commit) as values
63  */
64  function getResult()
65  {
66  return $this->_result;
67  }
68 
69  /**
70  * Clear the commit result.
71  */
72  function clearResult()
73  {
74  $this->_result = array();
75  }
76 }
77 ?>
const STATE_DIRTY
The CommitVisitor is used to commit the object's changes to the object storage. The objects must impl...
const STATE_DELETED
Visitor is used to extend an object's functionality by not extending its interface. Classes to use with the Visitor must implement the acceptVisitor() method. Visitor implements the 'Visitor Pattern'. It implements the 'Template Method Pattern' to allow subclasses to do any Pre- and Post Visit operations (doPreVisit() and doPostVisit() methods). The abstract base class Visitor defines the interface for all specialized Visitor classes.
const STATE_NEW