20
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
23
* @version $Revision: 1.16 $ $Date: 2005/08/23 03:49:03 $
23
* @version $Revision: 1.17 $ $Date: 2006/01/10 04:39:21 $
24
24
* @package GalleryCore
25
25
* @author Bharat Mediratta <bharat@menalto.com>
29
* This member is unmodified
31
define('MEMBER_UNMODIFIED', 0x00000000);
34
* This member is modified
36
define('MEMBER_MODIFIED', 0x00000001);
39
29
* A class that contains information about the state of its members
41
31
* @package GalleryCore
66
56
* Initialize our persistent info tracker
68
$this->_persistentStatus = new stdClass();
69
$this->_persistentStatus->flags = 0;
70
$this->_persistentStatus->modified = array();
71
$this->_persistentStatus->originalValue = array();
75
* Return type info about this class's persistent members.
77
* This class as no persistent members, so return an empty array.
78
* Subclasses will add data to the array.
80
function getPersistentMemberInfo() {
85
* Get the data from this persistent object as an associative array
87
* @return array memberName => memberValue
89
function getMemberData() {
90
return array('_className' => get_class($this));
58
$this->_persistentStatus['flags'] = 0;
59
$this->_persistentStatus['originalValue'] = array();
94
63
* Have we modified any data in this class?
96
* @return bool true if modified, false if not.
98
function isModified() {
99
return !empty($this->_persistentStatus->modified);
103
* Set the modified flag for a member
105
* @param string the name of the member
106
* @param mixed the new field value
108
function setModifiedFlag($name, $newValue) {
109
if (!array_key_exists($name, $this->_persistentStatus->originalValue)) {
110
$method = 'get' . $name;
111
$this->_persistentStatus->originalValue[$name] = $this->$method();
114
if ($this->_persistentStatus->originalValue[$name] === $newValue) {
115
unset($this->_persistentStatus->modified[$name]);
117
$this->_persistentStatus->modified[$name] = MEMBER_MODIFIED;
122
* Get the modification flag for a member
124
function getModifiedFlag($name) {
125
if (empty($this->_persistentStatus->modified[$name])) {
126
return MEMBER_UNMODIFIED;
128
return $this->_persistentStatus->modified[$name];
133
* Get a list of all the members that have been modified
135
* @return array string key names
137
function getModifiedKeys() {
138
return array_keys($this->_persistentStatus->modified);
142
* Reset all modification flags
144
function clearModifiedFlags() {
145
$this->_persistentStatus->modified = array();
146
$this->_persistentStatus->originalValue = array();
65
* @return array bool true if modified, false if not.
67
function isModified($member=null) {
69
return $this->_persistentStatus['originalValue'][$member] !== $this->$member;
71
$target = $this->entityType;
72
foreach (array_keys($this->_persistentStatus['originalValue']) as $key) {
73
if ($this->_persistentStatus['originalValue'][$key] != $this->$key) {
82
* Return the original value of the given member.
83
* @return mixed the value, or null if it was not defined.
85
function getOriginalValue($member) {
86
if (!isset($this->_persistentStatus['originalValue'][$member])) {
89
return $this->_persistentStatus['originalValue'][$member];
93
* Reset all original values to the current values in the entity (or
94
* null if so specified).
96
* @param bool reset all original values to null if true
97
* @return object GalleryStatus a status code
99
function resetOriginalValues($resetToNull=false) {
100
list ($ret, $data) = GalleryCoreApi::describeEntity($this->entityType);
105
$this->_persistentStatus['originalValue'] = array();
106
$target = $this->entityType;
108
foreach (array_keys($data[$target]['members']) as $member) {
110
$this->_persistentStatus['originalValue'][$member] = null;
112
$this->_persistentStatus['originalValue'][$member] =
113
isset($this->$member) ? $this->$member : null;
116
$target = $data[$target]['parent'];
180
153
* @return bool true if the bit is on, false otherwise
182
155
function testPersistentFlag($flag) {
183
return $this->_persistentStatus->flags & $flag;
156
return $this->_persistentStatus['flags'] & $flag;
187
* Truncate a string to the given size.
160
* Return the relative path to the class for this entity
189
* @param string the input string
190
* @param in the target max string size
191
* @return the truncated string
162
* @return array object GalleryStatus a status code
163
* string a path like modules/core/classes/GalleryUser.class
193
function _truncateString($input, $size) {
165
function getClassFile() {
166
list ($ret, $data) = GalleryCoreApi::describeEntity($this->entityType);
168
return array($ret->wrap(__FILE__, __LINE__), null);
198
return GalleryUtilities::utf8Substring($input, 0, $size);
171
null, "modules/{$data[$this->entityType]['module']}/classes/{$this->entityType}.class");