~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/core/classes/GalleryPersistent.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: GalleryPersistent.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
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>
26
26
 */
27
27
 
28
28
/**
29
 
 * This member is unmodified
30
 
 */
31
 
define('MEMBER_UNMODIFIED', 0x00000000);
32
 
 
33
 
/**
34
 
 * This member is modified
35
 
 */
36
 
define('MEMBER_MODIFIED', 0x00000001);
37
 
 
38
 
/**
39
29
 * A class that contains information about the state of its members
40
30
 *
41
31
 * @package GalleryCore
65
55
        /*
66
56
         * Initialize our persistent info tracker
67
57
         */
68
 
        $this->_persistentStatus = new stdClass();
69
 
        $this->_persistentStatus->flags = 0;
70
 
        $this->_persistentStatus->modified = array();
71
 
        $this->_persistentStatus->originalValue = array();
72
 
    }
73
 
 
74
 
    /**
75
 
     * Return type info about this class's persistent members.
76
 
     *
77
 
     * This class as no persistent members, so return an empty array.
78
 
     * Subclasses will add data to the array.
79
 
     */
80
 
    function getPersistentMemberInfo() {
81
 
        return array();
82
 
    }
83
 
 
84
 
    /**
85
 
     * Get the data from this persistent object as an associative array
86
 
     *
87
 
     * @return array memberName => memberValue
88
 
     */
89
 
    function getMemberData() {
90
 
        return array('_className' => get_class($this));
 
58
        $this->_persistentStatus['flags'] = 0;
 
59
        $this->_persistentStatus['originalValue'] = array();
91
60
    }
92
61
 
93
62
    /**
94
63
     * Have we modified any data in this class?
95
64
     *
96
 
     * @return bool true if modified, false if not.
97
 
     */
98
 
    function isModified() {
99
 
        return !empty($this->_persistentStatus->modified);
100
 
    }
101
 
 
102
 
    /**
103
 
     * Set the modified flag for a member
104
 
     *
105
 
     * @param string the name of the member
106
 
     * @param mixed the new field value
107
 
     */
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();
112
 
        }
113
 
 
114
 
        if ($this->_persistentStatus->originalValue[$name] === $newValue) {
115
 
            unset($this->_persistentStatus->modified[$name]);
116
 
        } else {
117
 
            $this->_persistentStatus->modified[$name] = MEMBER_MODIFIED;
118
 
        }
119
 
    }
120
 
 
121
 
    /**
122
 
     * Get the modification flag for a member
123
 
     */
124
 
    function getModifiedFlag($name) {
125
 
        if (empty($this->_persistentStatus->modified[$name])) {
126
 
            return MEMBER_UNMODIFIED;
127
 
        } else {
128
 
            return $this->_persistentStatus->modified[$name];
129
 
        }
130
 
    }
131
 
 
132
 
    /**
133
 
     * Get a list of all the members that have been modified
134
 
     *
135
 
     * @return array string key names
136
 
     */
137
 
    function getModifiedKeys() {
138
 
        return array_keys($this->_persistentStatus->modified);
139
 
    }
140
 
 
141
 
    /**
142
 
     * Reset all modification flags
143
 
     */
144
 
    function clearModifiedFlags() {
145
 
        $this->_persistentStatus->modified = array();
146
 
        $this->_persistentStatus->originalValue = array();
 
65
     * @return array bool true if modified, false if not.
 
66
     */
 
67
    function isModified($member=null) {
 
68
        if ($member) {
 
69
            return $this->_persistentStatus['originalValue'][$member] !== $this->$member;
 
70
        } else {
 
71
            $target = $this->entityType;
 
72
            foreach (array_keys($this->_persistentStatus['originalValue']) as $key) {
 
73
                if ($this->_persistentStatus['originalValue'][$key] != $this->$key) {
 
74
                    return true;
 
75
                }
 
76
            }
 
77
            return false;
 
78
        }
 
79
    }
 
80
 
 
81
    /**
 
82
     * Return the original value of the given member.
 
83
     * @return mixed the value, or null if it was not defined.
 
84
     */
 
85
    function getOriginalValue($member) {
 
86
        if (!isset($this->_persistentStatus['originalValue'][$member])) {
 
87
            return null;
 
88
        }
 
89
        return $this->_persistentStatus['originalValue'][$member];
 
90
    }
 
91
 
 
92
    /**
 
93
     * Reset all original values to the current values in the entity (or
 
94
     * null if so specified).
 
95
     *
 
96
     * @param bool reset all original values to null if true
 
97
     * @return object GalleryStatus a status code
 
98
     */
 
99
    function resetOriginalValues($resetToNull=false) {
 
100
        list ($ret, $data) = GalleryCoreApi::describeEntity($this->entityType);
 
101
        if ($ret) {
 
102
            return null;
 
103
        }
 
104
 
 
105
        $this->_persistentStatus['originalValue'] = array();
 
106
        $target = $this->entityType;
 
107
        while ($target) {
 
108
            foreach (array_keys($data[$target]['members']) as $member) {
 
109
                if ($resetToNull) {
 
110
                    $this->_persistentStatus['originalValue'][$member] = null;
 
111
                } else {
 
112
                    $this->_persistentStatus['originalValue'][$member] =
 
113
                        isset($this->$member) ? $this->$member : null;
 
114
                }
 
115
            }
 
116
            $target = $data[$target]['parent'];
 
117
        }
 
118
 
 
119
        return null;
147
120
    }
148
121
 
149
122
    /**
155
128
     * @param string a bit flag to set
156
129
     */
157
130
    function setPersistentFlag($flag) {
158
 
        $this->_persistentStatus->flags |= $flag;
 
131
        $this->_persistentStatus['flags'] |= $flag;
159
132
    }
160
133
 
161
134
    /**
167
140
     * @param string a bit flag to clear
168
141
     */
169
142
    function clearPersistentFlag($flag) {
170
 
        $this->_persistentStatus->flags &= ~$flag;
 
143
        $this->_persistentStatus['flags'] &= ~$flag;
171
144
    }
172
145
 
173
146
    /**
180
153
     * @return bool true if the bit is on, false otherwise
181
154
     */
182
155
    function testPersistentFlag($flag) {
183
 
        return $this->_persistentStatus->flags & $flag;
 
156
        return $this->_persistentStatus['flags'] & $flag;
184
157
    }
185
158
 
186
159
    /**
187
 
     * Truncate a string to the given size.
 
160
     * Return the relative path to the class for this entity
188
161
     *
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
192
164
     */
193
 
    function _truncateString($input, $size) {
194
 
        if ($input == '') {
195
 
            return $input;
 
165
    function getClassFile() {
 
166
        list ($ret, $data) = GalleryCoreApi::describeEntity($this->entityType);
 
167
        if ($ret) {
 
168
            return array($ret->wrap(__FILE__, __LINE__), null);
196
169
        }
197
 
 
198
 
        return GalleryUtilities::utf8Substring($input, 0, $size);
 
170
        return array(
 
171
            null, "modules/{$data[$this->entityType]['module']}/classes/{$this->entityType}.class");
199
172
    }
200
173
}
201
174
?>