~coughphp/coughphp/2.0

« back to all changes in this revision

Viewing changes to cough_generator/tests/test_configs/test_config1/expected_output/generated/Book_Generated.class.php

  • Committer: Anthony Bush
  • Date: 2008-06-20 17:24:30 UTC
  • mfrom: (257.1.15 coughphp-awbush)
  • Revision ID: anthony@anthonybush.com-20080620172430-te0xk0yna2e7clp0
Merging from coughphp-awbush branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * This is the base class for Book.
 
5
 * 
 
6
 * @see Book, CoughObject
 
7
 **/
 
8
abstract class Book_Generated extends CoughObject {
 
9
        
 
10
        protected static $db = null;
 
11
        protected static $dbName = 'test_cough_object';
 
12
        protected static $tableName = 'book';
 
13
        protected static $pkFieldNames = array('book_id');
 
14
        
 
15
        protected $fields = array(
 
16
                'book_id' => null,
 
17
                'title' => "",
 
18
                'author_id' => 0,
 
19
                'introduction' => "",
 
20
                'last_modified_datetime' => null,
 
21
                'creation_datetime' => "",
 
22
                'is_retired' => 0,
 
23
        );
 
24
        
 
25
        protected $fieldDefinitions = array(
 
26
                'book_id' => array(
 
27
                        'db_column_name' => 'book_id',
 
28
                        'is_null_allowed' => false,
 
29
                        'default_value' => null
 
30
                ),
 
31
                'title' => array(
 
32
                        'db_column_name' => 'title',
 
33
                        'is_null_allowed' => false,
 
34
                        'default_value' => ""
 
35
                ),
 
36
                'author_id' => array(
 
37
                        'db_column_name' => 'author_id',
 
38
                        'is_null_allowed' => false,
 
39
                        'default_value' => 0
 
40
                ),
 
41
                'introduction' => array(
 
42
                        'db_column_name' => 'introduction',
 
43
                        'is_null_allowed' => false,
 
44
                        'default_value' => ""
 
45
                ),
 
46
                'last_modified_datetime' => array(
 
47
                        'db_column_name' => 'last_modified_datetime',
 
48
                        'is_null_allowed' => true,
 
49
                        'default_value' => null
 
50
                ),
 
51
                'creation_datetime' => array(
 
52
                        'db_column_name' => 'creation_datetime',
 
53
                        'is_null_allowed' => false,
 
54
                        'default_value' => ""
 
55
                ),
 
56
                'is_retired' => array(
 
57
                        'db_column_name' => 'is_retired',
 
58
                        'is_null_allowed' => false,
 
59
                        'default_value' => 0
 
60
                ),
 
61
        );
 
62
        
 
63
        protected $objectDefinitions = array(
 
64
                'Author_Object' => array(
 
65
                        'class_name' => 'Author'
 
66
                ),
 
67
        );
 
68
        
 
69
        // Static Definition Methods
 
70
        
 
71
        public static function getDb() {
 
72
                if (is_null(Book::$db)) {
 
73
                        Book::$db = CoughDatabaseFactory::getDatabase('test_cough_object');
 
74
                }
 
75
                return Book::$db;
 
76
        }
 
77
        
 
78
        public static function getDbName() {
 
79
                return Book::$dbName;
 
80
        }
 
81
        
 
82
        public static function getTableName() {
 
83
                return Book::$tableName;
 
84
        }
 
85
        
 
86
        public static function getPkFieldNames() {
 
87
                return Book::$pkFieldNames;
 
88
        }
 
89
        
 
90
        // Static Construction (factory) Methods
 
91
        
 
92
        /**
 
93
         * Constructs a new Book object from
 
94
         * a single id (for single key PKs) or a hash of [field_name] => [field_value].
 
95
         * 
 
96
         * The key is used to pull data from the database, and, if no data is found,
 
97
         * null is returned. You can use this function with any unique keys or the
 
98
         * primary key as long as a hash is used. If the primary key is a single
 
99
         * field, you may pass its value in directly without using a hash.
 
100
         * 
 
101
         * @param mixed $idOrHash - id or hash of [field_name] => [field_value]
 
102
         * @return mixed - Book or null if no record found.
 
103
         **/
 
104
        public static function constructByKey($idOrHash) {
 
105
                return CoughObject::constructByKey($idOrHash, 'Book');
 
106
        }
 
107
        
 
108
        /**
 
109
         * Constructs a new Book object from custom SQL.
 
110
         * 
 
111
         * @param string $sql
 
112
         * @return mixed - Book or null if exactly one record could not be found.
 
113
         **/
 
114
        public static function constructBySql($sql) {
 
115
                return CoughObject::constructBySql($sql, 'Book');
 
116
        }
 
117
        
 
118
        /**
 
119
         * Constructs a new Book object after
 
120
         * checking the fields array to make sure the appropriate subclass is
 
121
         * used.
 
122
         * 
 
123
         * No queries are run against the database.
 
124
         * 
 
125
         * @param array $hash - hash of [field_name] => [field_value] pairs
 
126
         * @return Book
 
127
         **/
 
128
        public static function constructByFields($hash) {
 
129
                return new Book($hash);
 
130
        }
 
131
        
 
132
        public function notifyChildrenOfKeyChange(array $key) {
 
133
                foreach ($this->getBook2library_Collection() as $book2library) {
 
134
                        $book2library->setBookId($key['book_id']);
 
135
                }
 
136
        }
 
137
        
 
138
        public static function getLoadSql() {
 
139
                $tableName = Book::getTableName();
 
140
                return '
 
141
                        SELECT
 
142
                                `' . $tableName . '`.*
 
143
                        FROM
 
144
                                `' . Book::getDbName() . '`.`' . $tableName . '`
 
145
                ';
 
146
        }
 
147
        
 
148
        // Generated attribute accessors (getters and setters)
 
149
        
 
150
        public function getBookId() {
 
151
                return $this->getField('book_id');
 
152
        }
 
153
        
 
154
        public function setBookId($value) {
 
155
                $this->setField('book_id', $value);
 
156
        }
 
157
        
 
158
        public function getTitle() {
 
159
                return $this->getField('title');
 
160
        }
 
161
        
 
162
        public function setTitle($value) {
 
163
                $this->setField('title', $value);
 
164
        }
 
165
        
 
166
        public function getAuthorId() {
 
167
                return $this->getField('author_id');
 
168
        }
 
169
        
 
170
        public function setAuthorId($value) {
 
171
                $this->setField('author_id', $value);
 
172
        }
 
173
        
 
174
        public function getIntroduction() {
 
175
                return $this->getField('introduction');
 
176
        }
 
177
        
 
178
        public function setIntroduction($value) {
 
179
                $this->setField('introduction', $value);
 
180
        }
 
181
        
 
182
        public function getLastModifiedDatetime() {
 
183
                return $this->getField('last_modified_datetime');
 
184
        }
 
185
        
 
186
        public function setLastModifiedDatetime($value) {
 
187
                $this->setField('last_modified_datetime', $value);
 
188
        }
 
189
        
 
190
        public function getCreationDatetime() {
 
191
                return $this->getField('creation_datetime');
 
192
        }
 
193
        
 
194
        public function setCreationDatetime($value) {
 
195
                $this->setField('creation_datetime', $value);
 
196
        }
 
197
        
 
198
        public function getIsRetired() {
 
199
                return $this->getField('is_retired');
 
200
        }
 
201
        
 
202
        public function setIsRetired($value) {
 
203
                $this->setField('is_retired', $value);
 
204
        }
 
205
        
 
206
        // Generated one-to-one accessors (loaders, getters, and setters)
 
207
        
 
208
        public function loadAuthor_Object() {
 
209
                $this->setAuthor_Object(Author::constructByKey($this->getAuthorId()));
 
210
        }
 
211
        
 
212
        public function getAuthor_Object() {
 
213
                if (!isset($this->objects['Author_Object'])) {
 
214
                        $this->loadAuthor_Object();
 
215
                }
 
216
                return $this->objects['Author_Object'];
 
217
        }
 
218
        
 
219
        public function setAuthor_Object($author) {
 
220
                $this->objects['Author_Object'] = $author;
 
221
        }
 
222
        
 
223
        // Generated one-to-many collection loaders, getters, setters, adders, and removers
 
224
        
 
225
        public function loadBook2library_Collection() {
 
226
                
 
227
                // Always create the collection
 
228
                $collection = new Book2library_Collection();
 
229
                $this->setBook2library_Collection($collection);
 
230
                
 
231
                // But only populate it if we have key ID
 
232
                if ($this->hasKeyId()) {
 
233
                        $db = Book2library::getDb();
 
234
                        $tableName = Book2library::getTableName();
 
235
                        $sql = '
 
236
                                SELECT
 
237
                                        `' . $tableName . '`.*
 
238
                                FROM
 
239
                                        `' . Book2library::getDbName() . '`.`' . $tableName . '`
 
240
                                WHERE
 
241
                                        `' . $tableName . '`.`book_id` = ' . $db->quote($this->getBookId()) . '
 
242
                        ';
 
243
 
 
244
                        // Construct and populate the collection
 
245
                        $collection->loadBySql($sql);
 
246
                        foreach ($collection as $element) {
 
247
                                $element->setBook_Object($this);
 
248
                        }
 
249
                }
 
250
        }
 
251
        
 
252
        public function getBook2library_Collection() {
 
253
                if (!isset($this->collections['Book2library_Collection'])) {
 
254
                        $this->loadBook2library_Collection();
 
255
                }
 
256
                return $this->collections['Book2library_Collection'];
 
257
        }
 
258
        
 
259
        public function setBook2library_Collection($book2libraryCollection) {
 
260
                $this->collections['Book2library_Collection'] = $book2libraryCollection;
 
261
        }
 
262
        
 
263
        public function addBook2library(Book2library $object) {
 
264
                $object->setBookId($this->getBookId());
 
265
                $object->setBook_Object($this);
 
266
                $this->getBook2library_Collection()->add($object);
 
267
                return $object;
 
268
        }
 
269
        
 
270
        public function removeBook2library($objectOrId) {
 
271
                $removedObject = $this->getBook2library_Collection()->remove($objectOrId);
 
272
                if (is_object($removedObject)) {
 
273
                        $removedObject->setBookId("");
 
274
                        $removedObject->setBook_Object(null);
 
275
                }
 
276
                return $removedObject;
 
277
        }
 
278
        
 
279
}
 
280
 
 
281
?>
 
 
b'\\ No newline at end of file'