| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
define('_LOB_SAMPLE_FILE_PATH', dirname(__FILE__) . '/../../etc/lob'); |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
class BookstoreDataPopulator { |
|---|
| 48 |
|
|---|
| 49 |
public static function populate() { |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
// --------------------- |
|---|
| 53 |
|
|---|
| 54 |
//print "\nAdding some new publishers to the list\n"; |
|---|
| 55 |
//print "--------------------------------------\n\n"; |
|---|
| 56 |
|
|---|
| 57 |
$scholastic = new Publisher(); |
|---|
| 58 |
$scholastic->setName("Scholastic"); |
|---|
| 59 |
|
|---|
| 60 |
//print "Added publisher \"Scholastic\" [not saved yet].\n"; |
|---|
| 61 |
|
|---|
| 62 |
$morrow = new Publisher(); |
|---|
| 63 |
$morrow->setName("William Morrow"); |
|---|
| 64 |
$morrow->save(); |
|---|
| 65 |
$morrow_id = $morrow->getId(); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
$penguin = new Publisher(); |
|---|
| 69 |
$penguin->setName("Penguin"); |
|---|
| 70 |
$penguin->save(); |
|---|
| 71 |
$penguin_id = $penguin->getId(); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
$vintage = new Publisher(); |
|---|
| 75 |
$vintage->setName("Vintage"); |
|---|
| 76 |
$vintage->save(); |
|---|
| 77 |
$vintage_id = $vintage->getId(); |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
// Add author records |
|---|
| 82 |
// ------------------ |
|---|
| 83 |
|
|---|
| 84 |
//print "\nAdding some new authors to the list\n"; |
|---|
| 85 |
//print "--------------------------------------\n\n"; |
|---|
| 86 |
|
|---|
| 87 |
$rowling = new Author(); |
|---|
| 88 |
$rowling->setFirstName("J.K."); |
|---|
| 89 |
$rowling->setLastName("Rowling"); |
|---|
| 90 |
|
|---|
| 91 |
// no save() |
|---|
| 92 |
//print "Added author \"J.K. Rowling\" [not saved yet].\n"; |
|---|
| 93 |
|
|---|
| 94 |
$stephenson = new Author(); |
|---|
| 95 |
$stephenson->setFirstName("Neal"); |
|---|
| 96 |
$stephenson->setLastName("Stephenson"); |
|---|
| 97 |
$stephenson->save(); |
|---|
| 98 |
$stephenson_id = $stephenson->getId(); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
$byron = new Author(); |
|---|
| 102 |
$byron->setFirstName("George"); |
|---|
| 103 |
$byron->setLastName("Byron"); |
|---|
| 104 |
$byron->save(); |
|---|
| 105 |
$byron_id = $byron->getId(); |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
$grass = new Author(); |
|---|
| 110 |
$grass->setFirstName("Gunter"); |
|---|
| 111 |
$grass->setLastName("Grass"); |
|---|
| 112 |
$grass->save(); |
|---|
| 113 |
$grass_id = $grass->getId(); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
// Add book records |
|---|
| 118 |
// ---------------- |
|---|
| 119 |
|
|---|
| 120 |
//print "\nAdding some new books to the list\n"; |
|---|
| 121 |
//print "-------------------------------------\n\n"; |
|---|
| 122 |
|
|---|
| 123 |
$phoenix = new Book(); |
|---|
| 124 |
$phoenix->setTitle("Harry Potter and the Order of the Phoenix"); |
|---|
| 125 |
$phoenix->setISBN("043935806X"); |
|---|
| 126 |
$phoenix->setAuthor($rowling); |
|---|
| 127 |
$phoenix->setPublisher($scholastic); |
|---|
| 128 |
$phoenix->setPrice(10.99); |
|---|
| 129 |
$phoenix->save(); |
|---|
| 130 |
$phoenix_id = $phoenix->getId(); |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
// print "Added book \"Harry Potter and the Order of the Phoenix\" [id = $phoenix_id].\n"; |
|---|
| 134 |
|
|---|
| 135 |
$qs = new Book(); |
|---|
| 136 |
$qs->setISBN("0380977427"); |
|---|
| 137 |
$qs->setTitle("Quicksilver"); |
|---|
| 138 |
$qs->setPrice(11.99); |
|---|
| 139 |
$qs->setAuthor($stephenson); |
|---|
| 140 |
$qs->setPublisher($morrow); |
|---|
| 141 |
$qs->save(); |
|---|
| 142 |
$qs_id = $qs->getId(); |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
$dj = new Book(); |
|---|
| 146 |
$dj->setISBN("0140422161"); |
|---|
| 147 |
$dj->setTitle("Don Juan"); |
|---|
| 148 |
$dj->setPrice(12.99); |
|---|
| 149 |
$dj->setAuthor($byron); |
|---|
| 150 |
$dj->setPublisher($penguin); |
|---|
| 151 |
$dj->save(); |
|---|
| 152 |
$dj_id = $dj->getId(); |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
$td = new Book(); |
|---|
| 156 |
$td->setISBN("067972575X"); |
|---|
| 157 |
$td->setTitle("The Tin Drum"); |
|---|
| 158 |
$td->setPrice(13.99); |
|---|
| 159 |
$td->setAuthor($grass); |
|---|
| 160 |
$td->setPublisher($vintage); |
|---|
| 161 |
$td->save(); |
|---|
| 162 |
$td_id = $td->getId(); |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
// Add review records |
|---|
| 166 |
// ------------------ |
|---|
| 167 |
|
|---|
| 168 |
//print "\nAdding some book reviews to the list\n"; |
|---|
| 169 |
//print "------------------------------------\n\n"; |
|---|
| 170 |
|
|---|
| 171 |
$r1 = new Review(); |
|---|
| 172 |
$r1->setBook($phoenix); |
|---|
| 173 |
$r1->setReviewedBy("Washington Post"); |
|---|
| 174 |
$r1->setRecommended(true); |
|---|
| 175 |
$r1->setReviewDate(time()); |
|---|
| 176 |
$r1->save(); |
|---|
| 177 |
$r1_id = $r1->getId(); |
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
$r2 = new Review(); |
|---|
| 181 |
$r2->setBook($phoenix); |
|---|
| 182 |
$r2->setReviewedBy("New York Times"); |
|---|
| 183 |
$r2->setRecommended(false); |
|---|
| 184 |
$r2->setReviewDate(time()); |
|---|
| 185 |
$r2->save(); |
|---|
| 186 |
$r2_id = $r2->getId(); |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
$blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif'; |
|---|
| 190 |
$clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt'; |
|---|
| 191 |
|
|---|
| 192 |
$m1 = new Media(); |
|---|
| 193 |
$m1->setBook($td); |
|---|
| 194 |
$m1->setCoverImage(file_get_contents($blob_path)); |
|---|
| 195 |
$m1->setExcerpt(file_get_contents($clob_path)); |
|---|
| 196 |
$m1->save(); |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
// --------------------- |
|---|
| 200 |
// (this is for many-to-many tests) |
|---|
| 201 |
|
|---|
| 202 |
$blc1 = new BookClubList(); |
|---|
| 203 |
$blc1->setGroupLeader("Crazyleggs"); |
|---|
| 204 |
$blc1->setTheme("Happiness"); |
|---|
| 205 |
|
|---|
| 206 |
$brel1 = new BookListRel(); |
|---|
| 207 |
$brel1->setBook($phoenix); |
|---|
| 208 |
|
|---|
| 209 |
$brel2 = new BookListRel(); |
|---|
| 210 |
$brel2->setBook($dj); |
|---|
| 211 |
|
|---|
| 212 |
$blc1->addBookListRel($brel1); |
|---|
| 213 |
$blc1->addBookListRel($brel2); |
|---|
| 214 |
|
|---|
| 215 |
$bemp1 = new BookstoreEmployee(); |
|---|
| 216 |
$bemp1->setName("John"); |
|---|
| 217 |
$bemp1->setJobTitle("Manager"); |
|---|
| 218 |
|
|---|
| 219 |
$bemp2 = new BookstoreEmployee(); |
|---|
| 220 |
$bemp2->setName("Pieter"); |
|---|
| 221 |
$bemp2->setJobTitle("Clerk"); |
|---|
| 222 |
$bemp2->setSupervisor($bemp1); |
|---|
| 223 |
$bemp2->save(); |
|---|
| 224 |
|
|---|
| 225 |
$role = new AcctAccessRole(); |
|---|
| 226 |
$role->setName("Admin"); |
|---|
| 227 |
|
|---|
| 228 |
$bempacct = new BookstoreEmployeeAccount(); |
|---|
| 229 |
$bempacct->setBookstoreEmployee($bemp1); |
|---|
| 230 |
$bempacct->setAcctAccessRole($role); |
|---|
| 231 |
$bempacct->setLogin("john"); |
|---|
| 232 |
$bempacct->setPassword("johnp4ss"); |
|---|
| 233 |
$bempacct->save(); |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
$store = new Bookstore(); |
|---|
| 238 |
$store->setStoreName("Amazon"); |
|---|
| 239 |
$store->setPopulationServed(5000000000); |
|---|
| 240 |
$store->setTotalBooks(300); |
|---|
| 241 |
$store->save(); |
|---|
| 242 |
|
|---|
| 243 |
$store = new Bookstore(); |
|---|
| 244 |
$store->setStoreName("Local Store"); |
|---|
| 245 |
$store->setPopulationServed(20); |
|---|
| 246 |
$store->setTotalBooks(500000); |
|---|
| 247 |
$store->save(); |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
public static function depopulate() { |
|---|
| 251 |
AuthorPeer::doDeleteAll(); |
|---|
| 252 |
BookPeer::doDeleteAll(); |
|---|
| 253 |
PublisherPeer::doDeleteAll(); |
|---|
| 254 |
ReviewPeer::doDeleteAll(); |
|---|
| 255 |
MediaPeer::doDeleteAll(); |
|---|
| 256 |
BookClubListPeer::doDeleteAll(); |
|---|
| 257 |
BookstoreEmployeePeer::doDeleteAll(); |
|---|
| 258 |
BookstoreEmployeeAccountPeer::doDeleteAll(); |
|---|
| 259 |
CustomerPeer::doDeleteAll(); |
|---|
| 260 |
ContestPeer::doDeleteAll(); |
|---|
| 261 |
BookstoreContestPeer::doDeleteAll(); |
|---|
| 262 |
BookstoreContestEntryPeer::doDeleteAll(); |
|---|
| 263 |
BookstorePeer::doDeleteAll(); |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
} |
|---|
| 267 |
|
|---|