~coughphp/coughphp/2.0

« back to all changes in this revision

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