4
* This is the base class for Book.
6
* @see Book, CoughObject
8
abstract class Book_Generated extends CoughObject {
10
protected static $db = null;
11
protected static $dbName = 'test_cough_object';
12
protected static $tableName = 'book';
13
protected static $pkFieldNames = array('book_id');
15
protected $fields = array(
20
'last_modified_datetime' => null,
21
'creation_datetime' => "",
25
protected $fieldDefinitions = array(
27
'db_column_name' => 'book_id',
28
'is_null_allowed' => false,
29
'default_value' => null
32
'db_column_name' => 'title',
33
'is_null_allowed' => false,
37
'db_column_name' => 'author_id',
38
'is_null_allowed' => false,
41
'introduction' => array(
42
'db_column_name' => 'introduction',
43
'is_null_allowed' => false,
46
'last_modified_datetime' => array(
47
'db_column_name' => 'last_modified_datetime',
48
'is_null_allowed' => true,
49
'default_value' => null
51
'creation_datetime' => array(
52
'db_column_name' => 'creation_datetime',
53
'is_null_allowed' => false,
56
'is_retired' => array(
57
'db_column_name' => 'is_retired',
58
'is_null_allowed' => false,
63
protected $objectDefinitions = array(
64
'Author_Object' => array(
65
'class_name' => 'Author'
69
// Static Definition Methods
71
public static function getDb() {
72
if (is_null(Book::$db)) {
73
Book::$db = CoughDatabaseFactory::getDatabase('test_cough_object');
78
public static function getDbName() {
82
public static function getTableName() {
83
return Book::$tableName;
86
public static function getPkFieldNames() {
87
return Book::$pkFieldNames;
90
// Static Construction (factory) Methods
93
* Constructs a new Book object from
94
* a single id (for single key PKs) or a hash of [field_name] => [field_value].
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.
101
* @param mixed $idOrHash - id or hash of [field_name] => [field_value]
102
* @return mixed - Book or null if no record found.
104
public static function constructByKey($idOrHash) {
105
return CoughObject::constructByKey($idOrHash, 'Book');
109
* Constructs a new Book object from custom SQL.
112
* @return mixed - Book or null if exactly one record could not be found.
114
public static function constructBySql($sql) {
115
return CoughObject::constructBySql($sql, 'Book');
119
* Constructs a new Book object after
120
* checking the fields array to make sure the appropriate subclass is
123
* No queries are run against the database.
125
* @param array $hash - hash of [field_name] => [field_value] pairs
128
public static function constructByFields($hash) {
129
return new Book($hash);
132
public function notifyChildrenOfKeyChange(array $key) {
133
foreach ($this->getBook2library_Collection() as $book2library) {
134
$book2library->setBookId($key['book_id']);
138
public static function getLoadSql() {
139
$tableName = Book::getTableName();
142
`' . $tableName . '`.*
144
`' . Book::getDbName() . '`.`' . $tableName . '`
148
// Generated attribute accessors (getters and setters)
150
public function getBookId() {
151
return $this->getField('book_id');
154
public function setBookId($value) {
155
$this->setField('book_id', $value);
158
public function getTitle() {
159
return $this->getField('title');
162
public function setTitle($value) {
163
$this->setField('title', $value);
166
public function getAuthorId() {
167
return $this->getField('author_id');
170
public function setAuthorId($value) {
171
$this->setField('author_id', $value);
174
public function getIntroduction() {
175
return $this->getField('introduction');
178
public function setIntroduction($value) {
179
$this->setField('introduction', $value);
182
public function getLastModifiedDatetime() {
183
return $this->getField('last_modified_datetime');
186
public function setLastModifiedDatetime($value) {
187
$this->setField('last_modified_datetime', $value);
190
public function getCreationDatetime() {
191
return $this->getField('creation_datetime');
194
public function setCreationDatetime($value) {
195
$this->setField('creation_datetime', $value);
198
public function getIsRetired() {
199
return $this->getField('is_retired');
202
public function setIsRetired($value) {
203
$this->setField('is_retired', $value);
206
// Generated one-to-one accessors (loaders, getters, and setters)
208
public function loadAuthor_Object() {
209
$this->setAuthor_Object(Author::constructByKey($this->getAuthorId()));
212
public function getAuthor_Object() {
213
if (!isset($this->objects['Author_Object'])) {
214
$this->loadAuthor_Object();
216
return $this->objects['Author_Object'];
219
public function setAuthor_Object($author) {
220
$this->objects['Author_Object'] = $author;
223
// Generated one-to-many collection loaders, getters, setters, adders, and removers
225
public function loadBook2library_Collection() {
227
// Always create the collection
228
$collection = new Book2library_Collection();
229
$this->setBook2library_Collection($collection);
231
// But only populate it if we have key ID
232
if ($this->hasKeyId()) {
233
$db = Book2library::getDb();
234
$tableName = Book2library::getTableName();
237
`' . $tableName . '`.*
239
`' . Book2library::getDbName() . '`.`' . $tableName . '`
241
`' . $tableName . '`.`book_id` = ' . $db->quote($this->getBookId()) . '
244
// Construct and populate the collection
245
$collection->loadBySql($sql);
246
foreach ($collection as $element) {
247
$element->setBook_Object($this);
252
public function getBook2library_Collection() {
253
if (!isset($this->collections['Book2library_Collection'])) {
254
$this->loadBook2library_Collection();
256
return $this->collections['Book2library_Collection'];
259
public function setBook2library_Collection($book2libraryCollection) {
260
$this->collections['Book2library_Collection'] = $book2libraryCollection;
263
public function addBook2library(Book2library $object) {
264
$object->setBookId($this->getBookId());
265
$object->setBook_Object($this);
266
$this->getBook2library_Collection()->add($object);
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);
276
return $removedObject;
b'\\ No newline at end of file'