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

« back to all changes in this revision

Viewing changes to modules/core/classes/interfaces/ClassCode.xsl

  • 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:
1
 
<?xml version="1.0" encoding="utf-8"?>
2
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
 
                version="1.0">
4
 
 
5
 
  <xsl:output method="text"/>
6
 
  
7
 
  <xsl:template match="class">&lt;?php
8
 
/*
9
 
 * $RCSfile: ClassCode.xsl,v $
10
 
 *
11
 
 * Gallery - a web based photo album viewer and editor
12
 
 * Copyright (C) 2000-2005 Bharat Mediratta
13
 
 * 
14
 
 * This program is free software; you can redistribute it and/or modify
15
 
 * it under the terms of the GNU General Public License as published by
16
 
 * the Free Software Foundation; either version 2 of the License, or (at
17
 
 * your option) any later version.
18
 
 * 
19
 
 * This program is distributed in the hope that it will be useful, but
20
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22
 
 * General Public License for more details.
23
 
 * 
24
 
 * You should have received a copy of the GNU General Public License
25
 
 * along with this program; if not, write to the Free Software
26
 
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
27
 
 */
28
 
/**
29
 
 * @package @@package@@
30
 
 * @subpackage ClassInterfaces
31
 
 * @version $Revision: 1.30 $ $Date: 2005/08/23 03:49:04 $
32
 
 * @author Bharat Mediratta &lt;bharat@menalto.com&gt;
33
 
 */
34
 
 
35
 
/**
36
 
 * Interface class for the <xsl:value-of select="class-name"/> class.
37
 
 * (Class schema version: <xsl:value-of select="schema/schema-major"/>.<xsl:value-of select="schema/schema-minor"/>)
38
 
 *
39
 
 * This file is automatically generated from XML embedded in the
40
 
 * class, combined with the ClassCode.xsl file.  You should not modify
41
 
 * it by hand, as your changes will be lost next time this file is
42
 
 * rebuilt.  If you want to add more getters/setters, you should add
43
 
 * them in the core class.  If you want to change the format of this
44
 
 * file, then you should edit the XSL template.
45
 
 *
46
 
 * @package @@package@@
47
 
 * @subpackage Classes
48
 
 */
49
 
class <xsl:value-of select="class-name"/> extends <xsl:value-of select="class-name"/>_core {
50
 
  <xsl:if test="/class/member">
51
 
    /**
52
 
     * Return meta information about the members of this class
53
 
     *
54
 
     * @return array member => array(type, class)
55
 
     */
56
 
    function getPersistentMemberInfo() {
57
 
        $meta = parent::getPersistentMemberInfo();<xsl:for-each select="member">
58
 
        $meta['members']['<xsl:value-of select="member-name"/>'] = array('class' => '<xsl:value-of select="/class/class-name"/>', 'type' => STORAGE_TYPE_<xsl:value-of select="member-type"/><xsl:if test="id"> | STORAGE_TYPE_ID</xsl:if>);
59
 
    </xsl:for-each>
60
 
        return $meta;
61
 
    }
62
 
 
63
 
    /**
64
 
     * Get the data from this persistent object as an associative array
65
 
     *
66
 
     * @return array memberName => memberValue
67
 
     */
68
 
    function getMemberData() {
69
 
        $data = parent::getMemberData();<xsl:for-each select="member">
70
 
        <xsl:if test="linked">if (isset($this->_linkedEntity)) {
71
 
            $data['<xsl:value-of select="member-name"/>'] = isset($this->_linkedEntity->_<xsl:value-of select="member-name"/>) ? $this->_linkedEntity->_<xsl:value-of select="member-name"/> : null;
72
 
        } else {
73
 
            $data['<xsl:value-of select="member-name"/>'] = isset($this->_<xsl:value-of select="member-name"/>) ? $this->_<xsl:value-of select="member-name"/> : null;
74
 
        }
75
 
        </xsl:if><xsl:if test="not(linked)">
76
 
        $data['<xsl:value-of select="member-name"/>'] = isset($this->_<xsl:value-of select="member-name"/>) ? $this->_<xsl:value-of select="member-name"/> : null;</xsl:if>
77
 
    </xsl:for-each>
78
 
        return $data;
79
 
    }
80
 
  </xsl:if>
81
 
    /**
82
 
     * Return the name of this class with the proper mix of uppercase and
83
 
     * lowercase (get_class() always returns lowercase)
84
 
     *
85
 
     * @return string class name
86
 
     */
87
 
    function getClassName() {
88
 
        return '<xsl:value-of select="class-name"/>';
89
 
    }
90
 
 
91
 
    /** 
92
 
     * Return the path to the PHP file for this class, relative to the gallery2 dir
93
 
     * 
94
 
     * @return string path
95
 
     */ 
96
 
    function getClassFile() { 
97
 
        return 'modules/' .  
98
 
            basename(dirname(dirname(dirname(__FILE__)))) .  
99
 
            '/classes/<xsl:value-of select="class-name"/>.class'; 
100
 
    }
101
 
    <xsl:apply-templates select="map" />
102
 
    <xsl:apply-templates select="member" />
103
 
}
104
 
?&gt;
105
 
</xsl:template>
106
 
 
107
 
  <xsl:template match="map">
108
 
    /**
109
 
     * Get meta information about this class' map 
110
 
     *
111
 
     * @return array map member => type
112
 
     */
113
 
    function getMapInfo() {
114
 
        $info = array();<xsl:for-each select="member">
115
 
        $info['members']['<xsl:value-of select="member-name"/>'] = STORAGE_TYPE_<xsl:value-of select="member-type"/>;</xsl:for-each>
116
 
        return $info; 
117
 
    }
118
 
 
119
 
    /**
120
 
     * Add an entry to this map
121
 
     *
122
 
     * @param array an associative array of the entry data
123
 
     * @return object GalleryStatus a status code
124
 
     * @static
125
 
     */
126
 
    function addMapEntry($data) {
127
 
        global $gallery;
128
 
        foreach (array(<xsl:for-each select="member/member-name">'<xsl:value-of select="."/>', </xsl:for-each>) as $key) {
129
 
            if (!array_key_exists($key, $data)) {
130
 
                return GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__,
131
 
                                            'Missing parameter: ' . $key);
132
 
            }
133
 
        }
134
 
 
135
 
        $storage =&amp; $gallery->getStorage();
136
 
        $ret = $storage->addMapEntry('<xsl:value-of select="/class/class-name"/>', $data);
137
 
        if ($ret->isError()) {
138
 
            return $ret->wrap(__FILE__, __LINE__);
139
 
        }
140
 
        return GalleryStatus::success();
141
 
    }
142
 
 
143
 
    /**
144
 
     * Remove an entry from this map
145
 
     *
146
 
     * @param array an associative array of the entry data to match and remove
147
 
     * @return object GalleryStatus a status code
148
 
     * @static
149
 
     */
150
 
    function removeMapEntry($data) {
151
 
        global $gallery;
152
 
 
153
 
        if (sizeof($data) == 0) {
154
 
            return GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__);
155
 
        }
156
 
 
157
 
        $storage =&amp; $gallery->getStorage();
158
 
        $ret = $storage->removeMapEntry('<xsl:value-of select="/class/class-name"/>', $data);
159
 
        if ($ret->isError()) {
160
 
            return $ret->wrap(__FILE__, __LINE__);
161
 
        }
162
 
        return GalleryStatus::success();
163
 
    }
164
 
 
165
 
    /**
166
 
     * Remove ALL entries from this map.. use with caution!
167
 
     *
168
 
     * @return object GalleryStatus a status code
169
 
     * @static
170
 
     */
171
 
    function removeAllMapEntries() {
172
 
        global $gallery;
173
 
 
174
 
        $storage =&amp; $gallery->getStorage();
175
 
        $ret = $storage->removeAllMapEntries('<xsl:value-of select="/class/class-name"/>');
176
 
        if ($ret->isError()) {
177
 
            return $ret->wrap(__FILE__, __LINE__);
178
 
        }
179
 
        return GalleryStatus::success();
180
 
    }
181
 
 
182
 
    /**
183
 
     * Update an entry in this map
184
 
     *
185
 
     * @param array the entry to match
186
 
     * @param array the values to change
187
 
     * @return object GalleryStatus a status code
188
 
     * @static
189
 
     */
190
 
    function updateMapEntry($match, $change) {
191
 
        global $gallery;
192
 
 
193
 
        if (sizeof($match) == 0 || sizeof($change) == 0) {
194
 
            return GalleryStatus::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__);
195
 
        }
196
 
 
197
 
        $storage =&amp; $gallery->getStorage();
198
 
        $ret = $storage->updateMapEntry('<xsl:value-of select="/class/class-name"/>', $match, $change);
199
 
        if ($ret->isError()) {
200
 
            return $ret->wrap(__FILE__, __LINE__);
201
 
        }
202
 
        return GalleryStatus::success();
203
 
    }
204
 
  </xsl:template>
205
 
 
206
 
  <xsl:template match="member">
207
 
    /**
208
 
     * Get the value of <xsl:value-of select="member-name"/>
209
 
     *
210
 
     * @return <xsl:value-of select="member-type"/> the value
211
 
     */
212
 
    function get<xsl:value-of select="member-name"/>() {<xsl:if test="linked">
213
 
        $linkedEntity = $this->getLinkedEntity();
214
 
        if (isset($linkedEntity)) {
215
 
            return $linkedEntity->get<xsl:value-of select="member-name"/>();
216
 
        }
217
 
        </xsl:if>
218
 
        if (!isset($this->_<xsl:value-of select="member-name"/>)) {
219
 
            return null;
220
 
        }
221
 
        return $this->_<xsl:value-of select="member-name"/>;
222
 
    }
223
 
 
224
 
    /**
225
 
     * Set the value of <xsl:value-of select="member-name"/>
226
 
     *
227
 
     * @param <xsl:value-of select="member-type"/> the value
228
 
     */
229
 
    function set<xsl:value-of select="member-name"/>($value) {<xsl:choose>
230
 
        <xsl:when test="member-type='BOOLEAN'">
231
 
        /* Set the incoming value to be a 1 or 0 */
232
 
        $value = empty($value) ? 0 : 1;
233
 
        </xsl:when>
234
 
        <xsl:when test="member-type='INTEGER'">
235
 
        /* Type cast the incoming value to be an integer */
236
 
        if ($value != null) {
237
 
            $value = (int)$value;
238
 
        }
239
 
        </xsl:when>
240
 
      </xsl:choose>
241
 
        /* Convert unset values to null, to avoid generating warnings. */
242
 
        $value = isset($value) ? $value : null;
243
 
      <xsl:if test="member-type='STRING'">  $value = $this->_truncateString($value, <xsl:choose>
244
 
        <xsl:when test="member-size='SMALL'">32</xsl:when>
245
 
        <xsl:when test="member-size='MEDIUM' or not(member-size)">128</xsl:when>
246
 
        <xsl:when test="member-size='LARGE'">255</xsl:when>
247
 
      </xsl:choose>);</xsl:if>
248
 
        $orig = isset($this->_<xsl:value-of select="member-name"/>) ? $this->_<xsl:value-of select="member-name"/> : null;
249
 
 
250
 
        /* Only take action if the value actually changes */
251
 
        <xsl:choose>
252
 
          <xsl:when test="member-type='INTEGER'">if ($value !== $orig) {</xsl:when>
253
 
          <xsl:when test="member-type='BOOLEAN'">if ($value !== $orig) {</xsl:when>
254
 
          <xsl:otherwise>if ($value != $orig) {</xsl:otherwise>
255
 
        </xsl:choose>
256
 
            $this->setModifiedFlag('<xsl:value-of select="member-name"/>', $value);
257
 
            $this->_<xsl:value-of select="member-name"/> = $value;
258
 
        }
259
 
    }
260
 
  </xsl:template>
261
 
      
262
 
</xsl:stylesheet>