4
* This is the base class for Author.
6
* @see Author, CoughObject
8
abstract class Author_Generated extends CoughObject {
10
protected static $db = null;
11
protected static $dbName = 'test_cough_object';
12
protected static $tableName = 'author';
13
protected static $pkFieldNames = array('author_id');
15
protected $fields = array(
18
'last_modified_datetime' => null,
19
'creation_datetime' => "",
23
protected $fieldDefinitions = array(
25
'db_column_name' => 'author_id',
26
'is_null_allowed' => false,
27
'default_value' => null
30
'db_column_name' => 'name',
31
'is_null_allowed' => false,
34
'last_modified_datetime' => array(
35
'db_column_name' => 'last_modified_datetime',
36
'is_null_allowed' => true,
37
'default_value' => null
39
'creation_datetime' => array(
40
'db_column_name' => 'creation_datetime',
41
'is_null_allowed' => false,
44
'is_retired' => array(
45
'db_column_name' => 'is_retired',
46
'is_null_allowed' => false,
51
protected $objectDefinitions = array();
53
// Static Definition Methods
55
public static function getDb() {
56
if (is_null(Author::$db)) {
57
Author::$db = CoughDatabaseFactory::getDatabase('test_cough_object');
62
public static function getDbName() {
63
return Author::$dbName;
66
public static function getTableName() {
67
return Author::$tableName;
70
public static function getPkFieldNames() {
71
return Author::$pkFieldNames;
74
// Static Construction (factory) Methods
77
* Constructs a new Author object from
78
* a single id (for single key PKs) or a hash of [field_name] => [field_value].
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.
85
* @param mixed $idOrHash - id or hash of [field_name] => [field_value]
86
* @return mixed - Author or null if no record found.
88
public static function constructByKey($idOrHash) {
89
return CoughObject::constructByKey($idOrHash, 'Author');
93
* Constructs a new Author object from custom SQL.
96
* @return mixed - Author or null if exactly one record could not be found.
98
public static function constructBySql($sql) {
99
return CoughObject::constructBySql($sql, 'Author');
103
* Constructs a new Author object after
104
* checking the fields array to make sure the appropriate subclass is
107
* No queries are run against the database.
109
* @param array $hash - hash of [field_name] => [field_value] pairs
112
public static function constructByFields($hash) {
113
return new Author($hash);
116
public function notifyChildrenOfKeyChange(array $key) {
117
foreach ($this->getBook_Collection() as $book) {
118
$book->setAuthorId($key['author_id']);
122
public static function getLoadSql() {
123
$tableName = Author::getTableName();
126
`' . $tableName . '`.*
128
`' . Author::getDbName() . '`.`' . $tableName . '`
132
// Generated attribute accessors (getters and setters)
134
public function getAuthorId() {
135
return $this->getField('author_id');
138
public function setAuthorId($value) {
139
$this->setField('author_id', $value);
142
public function getName() {
143
return $this->getField('name');
146
public function setName($value) {
147
$this->setField('name', $value);
150
public function getLastModifiedDatetime() {
151
return $this->getField('last_modified_datetime');
154
public function setLastModifiedDatetime($value) {
155
$this->setField('last_modified_datetime', $value);
158
public function getCreationDatetime() {
159
return $this->getField('creation_datetime');
162
public function setCreationDatetime($value) {
163
$this->setField('creation_datetime', $value);
166
public function getIsRetired() {
167
return $this->getField('is_retired');
170
public function setIsRetired($value) {
171
$this->setField('is_retired', $value);
174
// Generated one-to-one accessors (loaders, getters, and setters)
176
// Generated one-to-many collection loaders, getters, setters, adders, and removers
178
public function loadBook_Collection() {
180
// Always create the collection
181
$collection = new Book_Collection();
182
$this->setBook_Collection($collection);
184
// But only populate it if we have key ID
185
if ($this->hasKeyId()) {
187
$tableName = Book::getTableName();
190
`' . $tableName . '`.*
192
`' . Book::getDbName() . '`.`' . $tableName . '`
194
`' . $tableName . '`.`author_id` = ' . $db->quote($this->getAuthorId()) . '
197
// Construct and populate the collection
198
$collection->loadBySql($sql);
199
foreach ($collection as $element) {
200
$element->setAuthor_Object($this);
205
public function getBook_Collection() {
206
if (!isset($this->collections['Book_Collection'])) {
207
$this->loadBook_Collection();
209
return $this->collections['Book_Collection'];
212
public function setBook_Collection($bookCollection) {
213
$this->collections['Book_Collection'] = $bookCollection;
216
public function addBook(Book $object) {
217
$object->setAuthorId($this->getAuthorId());
218
$object->setAuthor_Object($this);
219
$this->getBook_Collection()->add($object);
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);
229
return $removedObject;
b'\\ No newline at end of file'