| 1 | <?php
|
| 2 | //namespace org/imaginus/pogopogoSe4/php/vodaodb/
|
| 3 |
|
| 4 |
|
| 5 | /////// YOU CAN PUT CUSTOM CODE HERE AT YOUR OWN RISK!
|
| 6 | /////// BUT BE WARY OF OVERWRITING THIS FILE IF YOU DO!
|
| 7 |
|
| 8 |
|
| 9 | /************************************************
|
| 10 | * Generated by VoDaoDb Wed Jul 3 18:14:00 GMT-0400 2013
|
| 11 | * @author Todd Mullen, <AnEmail@gmail.com>)
|
| 12 | * @copyright Do whatever you want except sell my work as yours, or reverse engineer it so you can make changes and then sell that as yours.
|
| 13 | * @license @see copyright
|
| 14 | * @filesource VoDaoDb v0.9 - Imaginus.org
|
| 15 | *
|
| 16 | *****************
|
| 17 | * Project: pogopogoSe4
|
| 18 | * Parent: imaginus.org
|
| 19 | * //No class comments
|
| 20 | ************************************************/
|
| 21 |
|
| 22 |
|
| 23 | if ( 0 > version_compare( PHP_VERSION, '5' ) ) {
|
| 24 | die( 'This file was generated for PHP 5' );
|
| 25 | }
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 | /**
|
| 31 | * DbExchange acts as a warehouse for Value Objects. It tracks raw row data & created instances.
|
| 32 | * It also keeps track of the VOs' states so that all new INSERTs, UPDATEs, &/or DELETEs can be performed at the end of execution rather than throughout.
|
| 33 | * It is a singleton class, so if/when a VO is pulled from the db or instantiated,
|
| 34 | * DbExchange will retain a reference to it and prevent fetching or instantiating the same object twice.
|
| 35 | *
|
| 36 | * @access public
|
| 37 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 38 | */
|
| 39 | class DbExchange {
|
| 40 |
|
| 41 |
|
| 42 | // --- ATTRIBUTES ---
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 | // --- TABLE & VIEW NAME CONSTANTS ---
|
| 47 | const DEV_DATA = "dev_data";
|
| 48 | const E4_ACTIVITY_ACTIONS = "E4_activity_actions";
|
| 49 | const E4_ACTIVITY_ACTIONSETTINGS = "E4_activity_actionsettings";
|
| 50 | const E4_ACTIVITY_ACTIONTYPES = "E4_activity_actiontypes";
|
| 51 | const E4_ACTIVITY_ATTACHMENTS = "E4_activity_attachments";
|
| 52 | const E4_ACTIVITY_COMMENTS = "E4_activity_comments";
|
| 53 | const E4_ACTIVITY_LIKES = "E4_activity_likes";
|
| 54 | const E4_ACTIVITY_NOTIFICATIONS = "E4_activity_notifications";
|
| 55 | const E4_ACTIVITY_NOTIFICATIONSETTINGS = "E4_activity_notificationsettings";
|
| 56 | const E4_ACTIVITY_NOTIFICATIONTYPES = "E4_activity_notificationtypes";
|
| 57 | const E4_ACTIVITY_STREAM = "E4_activity_stream";
|
| 58 | const E4_ALBUM_ALBUMS = "E4_album_albums";
|
| 59 | const E4_ALBUM_CATEGORIES = "E4_album_categories";
|
| 60 | const E4_ALBUM_PHOTOS = "E4_album_photos";
|
| 61 | const E4_ANNOUNCEMENT_ANNOUNCEMENTS = "E4_announcement_announcements";
|
| 62 | const E4_AUTHORIZATION_ALLOW = "E4_authorization_allow";
|
| 63 | const E4_AUTHORIZATION_LEVELS = "E4_authorization_levels";
|
| 64 | const E4_AUTHORIZATION_PERMISSIONS = "E4_authorization_permissions";
|
| 65 | const E4_BLOG_BLOGS = "E4_blog_blogs";
|
| 66 | const E4_BLOG_CATEGORIES = "E4_blog_categories";
|
| 67 | const E4_BLOG_SUBSCRIPTIONS = "E4_blog_subscriptions";
|
| 68 | const E4_CHAT_BANS = "E4_chat_bans";
|
| 69 | const E4_CHAT_EVENTS = "E4_chat_events";
|
| 70 | const E4_CHAT_MESSAGES = "E4_chat_messages";
|
| 71 | const E4_CHAT_ROOMS = "E4_chat_rooms";
|
| 72 | const E4_CHAT_ROOMUSERS = "E4_chat_roomusers";
|
| 73 | const E4_CHAT_USERS = "E4_chat_users";
|
| 74 | const E4_CHAT_WHISPERS = "E4_chat_whispers";
|
| 75 | const E4_CORE_ADCAMPAIGNS = "E4_core_adcampaigns";
|
| 76 | const E4_CORE_ADPHOTOS = "E4_core_adphotos";
|
| 77 | const E4_CORE_ADS = "E4_core_ads";
|
| 78 | const E4_CORE_AUTH = "E4_core_auth";
|
| 79 | const E4_CORE_BANNEDEMAILS = "E4_core_bannedemails";
|
| 80 | const E4_CORE_BANNEDIPS = "E4_core_bannedips";
|
| 81 | const E4_CORE_BANNEDUSERNAMES = "E4_core_bannedusernames";
|
| 82 | const E4_CORE_BANNEDWORDS = "E4_core_bannedwords";
|
| 83 | const E4_CORE_COMMENTS = "E4_core_comments";
|
| 84 | const E4_CORE_CONTENT = "E4_core_content";
|
| 85 | const E4_CORE_GEOTAGS = "E4_core_geotags";
|
| 86 | const E4_CORE_JOBS = "E4_core_jobs";
|
| 87 | const E4_CORE_JOBTYPES = "E4_core_jobtypes";
|
| 88 | const E4_CORE_LANGUAGES = "E4_core_languages";
|
| 89 | const E4_CORE_LIKES = "E4_core_likes";
|
| 90 | const E4_CORE_LINKS = "E4_core_links";
|
| 91 | const E4_CORE_LISTITEMS = "E4_core_listitems";
|
| 92 | const E4_CORE_LISTS = "E4_core_lists";
|
| 93 | const E4_CORE_LOG = "E4_core_log";
|
| 94 | const E4_CORE_MAIL = "E4_core_mail";
|
| 95 | const E4_CORE_MAILRECIPIENTS = "E4_core_mailrecipients";
|
| 96 | const E4_CORE_MAILTEMPLATES = "E4_core_mailtemplates";
|
| 97 | const E4_CORE_MENUITEMS = "E4_core_menuitems";
|
| 98 | const E4_CORE_MENUS = "E4_core_menus";
|
| 99 | const E4_CORE_MIGRATIONS = "E4_core_migrations";
|
| 100 | const E4_CORE_MODULES = "E4_core_modules";
|
| 101 | const E4_CORE_NODES = "E4_core_nodes";
|
| 102 | const E4_CORE_PAGES = "E4_core_pages";
|
| 103 | const E4_CORE_PROCESSES = "E4_core_processes";
|
| 104 | const E4_CORE_REFERRERS = "E4_core_referrers";
|
| 105 | const E4_CORE_REPORTS = "E4_core_reports";
|
| 106 | const E4_CORE_ROUTES = "E4_core_routes";
|
| 107 | const E4_CORE_SEARCH = "E4_core_search";
|
| 108 | const E4_CORE_SERVICEPROVIDERS = "E4_core_serviceproviders";
|
| 109 | const E4_CORE_SERVICES = "E4_core_services";
|
| 110 | const E4_CORE_SERVICETYPES = "E4_core_servicetypes";
|
| 111 | const E4_CORE_SESSION = "E4_core_session";
|
| 112 | const E4_CORE_SETTINGS = "E4_core_settings";
|
| 113 | const E4_CORE_STATISTICS = "E4_core_statistics";
|
| 114 | const E4_CORE_STATUS = "E4_core_status";
|
| 115 | const E4_CORE_STYLES = "E4_core_styles";
|
| 116 | const E4_CORE_TAGMAPS = "E4_core_tagmaps";
|
| 117 | const E4_CORE_TAGS = "E4_core_tags";
|
| 118 | const E4_CORE_TASKS = "E4_core_tasks";
|
| 119 | const E4_CORE_THEMES = "E4_core_themes";
|
| 120 | const E4_INVITES = "E4_invites";
|
| 121 | const E4_MESSAGES_CONVERSATIONS = "E4_messages_conversations";
|
| 122 | const E4_MESSAGES_MESSAGES = "E4_messages_messages";
|
| 123 | const E4_MESSAGES_RECIPIENTS = "E4_messages_recipients";
|
| 124 | const E4_NETWORK_MEMBERSHIP = "E4_network_membership";
|
| 125 | const E4_NETWORK_NETWORKS = "E4_network_networks";
|
| 126 | const E4_PAYMENT_GATEWAYS = "E4_payment_gateways";
|
| 127 | const E4_PAYMENT_ORDERS = "E4_payment_orders";
|
| 128 | const E4_PAYMENT_PACKAGES = "E4_payment_packages";
|
| 129 | const E4_PAYMENT_PRODUCTS = "E4_payment_products";
|
| 130 | const E4_PAYMENT_SUBSCRIPTIONS = "E4_payment_subscriptions";
|
| 131 | const E4_PAYMENT_TRANSACTIONS = "E4_payment_transactions";
|
| 132 | const E4_SEAOCORE_LOCATIONS = "E4_seaocore_locations";
|
| 133 | const E4_SEAOCORE_SEARCHFORMSETTING = "E4_seaocore_searchformsetting";
|
| 134 | const E4_SEAOCORE_TABS = "E4_seaocore_tabs";
|
| 135 | const E4_SEAOCORES = "E4_seaocores";
|
| 136 | const E4_SITELIKE_MIXSETTINGS = "E4_sitelike_mixsettings";
|
| 137 | const E4_SITELIKE_MYSETTINGS = "E4_sitelike_mysettings";
|
| 138 | const E4_SITELIKE_SETTINGS = "E4_sitelike_settings";
|
| 139 | const E4_SITESLIDESHOW_IMAGES = "E4_siteslideshow_images";
|
| 140 | const E4_SITESLIDESHOWS = "E4_siteslideshows";
|
| 141 | const E4_STORAGE_CHUNKS = "E4_storage_chunks";
|
| 142 | const E4_STORAGE_FILES = "E4_storage_files";
|
| 143 | const E4_STORAGE_MIRRORS = "E4_storage_mirrors";
|
| 144 | const E4_STORAGE_SERVICES = "E4_storage_services";
|
| 145 | const E4_STORAGE_SERVICETYPES = "E4_storage_servicetypes";
|
| 146 | const E4_USER_BLOCK = "E4_user_block";
|
| 147 | const E4_USER_FACEBOOK = "E4_user_facebook";
|
| 148 | const E4_USER_FIELDS_MAPS = "E4_user_fields_maps";
|
| 149 | const E4_USER_FIELDS_META = "E4_user_fields_meta";
|
| 150 | const E4_USER_FIELDS_OPTIONS = "E4_user_fields_options";
|
| 151 | const E4_USER_FIELDS_SEARCH = "E4_user_fields_search";
|
| 152 | const E4_USER_FIELDS_VALUES = "E4_user_fields_values";
|
| 153 | const E4_USER_FORGOT = "E4_user_forgot";
|
| 154 | const E4_USER_JANRAIN = "E4_user_janrain";
|
| 155 | const E4_USER_LISTITEMS = "E4_user_listitems";
|
| 156 | const E4_USER_LISTS = "E4_user_lists";
|
| 157 | const E4_USER_LOGINS = "E4_user_logins";
|
| 158 | const E4_USER_MEMBERSHIP = "E4_user_membership";
|
| 159 | const E4_USER_ONLINE = "E4_user_online";
|
| 160 | const E4_USER_SETTINGS = "E4_user_settings";
|
| 161 | const E4_USER_SIGNUP = "E4_user_signup";
|
| 162 | const E4_USER_TWITTER = "E4_user_twitter";
|
| 163 | const E4_USER_VERIFY = "E4_user_verify";
|
| 164 | const E4_USERS = "E4_users";
|
| 165 | const E4_VIDEO_CATEGORIES = "E4_video_categories";
|
| 166 | const E4_VIDEO_RATINGS = "E4_video_ratings";
|
| 167 | const E4_VIDEO_VIDEOS = "E4_video_videos";
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 | /**
|
| 172 | * Static variable that holds the single instance of ValueObjects::Store().
|
| 173 | * Private so that it cannot be accessed directly.
|
| 174 | * Access via the static instance() method which creates the actual instance
|
| 175 | * it hasn't already ben created.
|
| 176 | *
|
| 177 | * @access private
|
| 178 | * @var DbExchange
|
| 179 | */
|
| 180 | private static $_instance = null;
|
| 181 |
|
| 182 |
|
| 183 | /**
|
| 184 | * Holds a copy of all value objects that have been instantiated.
|
| 185 | * //TODO: Refactor this as a multidimensional array with aryNew, aryClean,
|
| 186 | * and aryDeleted as its four children. Rather than shuffling objects
|
| 187 | * arrays, change the "status" entry for each DO.
|
| 188 | *
|
| 189 | * @access private
|
| 190 | * @var array
|
| 191 | */
|
| 192 | private $_aryAll = array();
|
| 193 |
|
| 194 |
|
| 195 | /**
|
| 196 | * Holds a copy of all domain objects that are marked for Db `INSERT`
|
| 197 | *
|
| 198 | * @access private
|
| 199 | * @var array
|
| 200 | */
|
| 201 | private $_aryNew = array();
|
| 202 |
|
| 203 |
|
| 204 | /**
|
| 205 | * Holds a copy of all domain objects that do not need require any Db activity
|
| 206 | *
|
| 207 | * @access private
|
| 208 | * @var array
|
| 209 | */
|
| 210 | private $_aryClean = array();
|
| 211 |
|
| 212 |
|
| 213 | /**
|
| 214 | * Holds a copy of all domain objects that are marked for Db `UPDATE`
|
| 215 | *
|
| 216 | * @access private
|
| 217 | * @var array
|
| 218 | */
|
| 219 | private $_aryDirty = array();
|
| 220 |
|
| 221 |
|
| 222 | /**
|
| 223 | * Holds a copy of all domain objects that are marked for Db `DELETE`
|
| 224 | *
|
| 225 | * @access private
|
| 226 | * @var array
|
| 227 | */
|
| 228 | private $_aryDeleted = array();
|
| 229 |
|
| 230 |
|
| 231 | // --- OPERATIONS --- //
|
| 232 |
|
| 233 |
|
| 234 | /**
|
| 235 | * Static accessor method for acquiring the DbExchange singleton
|
| 236 | *
|
| 237 | * @access public
|
| 238 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 239 | * @return DbExchange
|
| 240 | */
|
| 241 | static public function Store() {
|
| 242 | if( empty( self::$_instance ) ) {
|
| 243 | self::$_instance = new self();
|
| 244 | }
|
| 245 | return self::$_instance;
|
| 246 | }//End Store()
|
| 247 |
|
| 248 |
|
| 249 | /**
|
| 250 | * The constructor is private to prevent creating a second / different copy of DbExchange
|
| 251 | * @access private
|
| 252 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 253 | * @return void
|
| 254 | */
|
| 255 | private function __construct() {
|
| 256 | //Nothing to do here
|
| 257 | }//End __construct()
|
| 258 |
|
| 259 |
|
| 260 | /**
|
| 261 | * Pushes a new $vo into $aryAll and $aryNew ( if not already set )
|
| 262 | *
|
| 263 | * @access public
|
| 264 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 265 | * @param AbstractValueObject $vo
|
| 266 | * @return void
|
| 267 | */
|
| 268 | public function addNew( AbstractValueObject $vo ) {
|
| 269 | if( $vo->isView ){return;}
|
| 270 | echo "<b>" . __METHOD__ . "()</b><br/>";
|
| 271 | //if( !in_array( $vo, $this->_aryAll, true ) ) {
|
| 272 | //$this->_aryAll[] = $vo;
|
| 273 | //echo "Added to aryAll: $vo<br />";
|
| 274 | //}
|
| 275 | //if( !in_array( $vo, $this->_aryNew, true ) ) {
|
| 276 | $this->_aryNew[] = $vo;
|
| 277 | echo "Marked As New: $vo<br />";
|
| 278 | //}
|
| 279 | echo "<br/>";
|
| 280 | }//End addNew()
|
| 281 |
|
| 282 |
|
| 283 | /**
|
| 284 | * Pushes $vo into $aryAll if not already set
|
| 285 | * Relocates $vo to $aryClean if it is in $aryNew (to be INSERTed), $aryDirty (to be UPDATEd), or $aryDeleted (to be DELETEd)
|
| 286 | *
|
| 287 | * @access public
|
| 288 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 289 | * @param AbstractValueObject $vo
|
| 290 | * @return void
|
| 291 | */
|
| 292 | public function addClean( AbstractValueObject $vo ) {
|
| 293 | echo "<b>" . __METHOD__ . "()</b><br/>";
|
| 294 | $key = $vo->globalKeyStr();//$this->globalKey( $vo );
|
| 295 | if( !in_array( $vo, $this->_aryAll, true ) ) {
|
| 296 | $this->_aryAll[$key] = $vo;
|
| 297 | echo "Added to aryAll: $vo.<br />";
|
| 298 | }
|
| 299 | if( !in_array( $vo, $this->_aryClean, true ) ) {
|
| 300 | $this->_aryClean[$key] = $vo;
|
| 301 | echo "Added to aryClean: $vo.<br />";
|
| 302 | }
|
| 303 | //Filter the new objects
|
| 304 | //echo "Trim aryNew. ";
|
| 305 | //$this->_aryNew =
|
| 306 | //$this->trimDoFromAry( $this->_aryNew, $vo );
|
| 307 | //Filter the dirty objects
|
| 308 | echo "Trim aryDirty. ";
|
| 309 | //$this->_aryDirty =
|
| 310 | //$this->trimDoFromAry( $this->_aryDirty, $vo );
|
| 311 | //Filter the deleted objects
|
| 312 | echo "Trim aryDeleted. ";
|
| 313 | //$this->_aryDeleted =
|
| 314 | //$this->trimDoFromAry( $this->_aryDeleted, $vo );
|
| 315 | echo "Trimming aryDeleted and aryDirty<br/>";
|
| 316 | unset( $this->_aryDirty[$key], $this->_aryDeleted[$key] );
|
| 317 | echo "Marked As Clean: $vo<br/>";
|
| 318 | }//End addClean()
|
| 319 |
|
| 320 |
|
| 321 | /**
|
| 322 | * Pushes $vo into $aryAll if not already set
|
| 323 | * Relocates $vo to $aryDirty if it is in $aryNew, $aryClean, or $aryDeleted
|
| 324 | *
|
| 325 | * @access public
|
| 326 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 327 | * @param AbstractValueObject $vo
|
| 328 | * @return void
|
| 329 | */
|
| 330 | public function addDirty( AbstractValueObject $vo ) {
|
| 331 | if( $vo->isView ){return;}
|
| 332 | echo "<b>" . __METHOD__ . "()</b><br/>";
|
| 333 | $key = $vo->globalKeyStr();//$this->globalKey( $vo );
|
| 334 | if( !in_array( $vo, $this->_aryAll, true ) ) {
|
| 335 | $this->_aryAll[$key] = $vo;
|
| 336 | echo "Added to aryAll: $vo.<br />";
|
| 337 | }
|
| 338 | if( !in_array( $vo, $this->_aryDirty, true ) ) {
|
| 339 | $this->_aryDirty[$key] = $vo;
|
| 340 | echo "Added to aryDirty: $vo.<br />";
|
| 341 | }
|
| 342 | //$key = $this->globalKey( $vo );
|
| 343 | echo "Trimming aryNew, aryClean, and aryDeleted<br/>";
|
| 344 | unset( $this->_aryNew[$key], $this->_aryClean[$key], $this->_aryDeleted[$key] );
|
| 345 | //Filter the new objects
|
| 346 | //echo "Trim aryNew. ";
|
| 347 | //$this->_aryNew =
|
| 348 | //$this->trimDoFromAry( $this->_aryNew, $vo );
|
| 349 | //Filter the clean objects
|
| 350 | //echo "Trim aryClean. ";
|
| 351 | //$this->_aryClean =
|
| 352 | //$this->trimDoFromAry( $this->_aryClean, $vo );
|
| 353 | //Filter the deleted objects
|
| 354 | //echo "Trim aryDeleted. ";
|
| 355 | //$this->_aryDeleted =
|
| 356 | //$this->trimDoFromAry( $this->_aryDeleted, $vo );
|
| 357 | echo "Marked As Dirty: $vo<br/>";
|
| 358 | }//End addDirty()
|
| 359 |
|
| 360 |
|
| 361 | /**
|
| 362 | * Pushes $vo into $aryAll if not already set
|
| 363 | * Relocates $vo if it is in $aryNew, $aryDirty, or $aryClean
|
| 364 | *
|
| 365 | * @access public
|
| 366 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 367 | * @param AbstractValueObject $vo
|
| 368 | * @return null
|
| 369 | */
|
| 370 | public function addDeleted( AbstractValueObject $vo ) {
|
| 371 | if( $vo->isView ){return;}
|
| 372 | echo "<b>" . __METHOD__ . "()</b><br/>";
|
| 373 | $key = $vo->globalKeyStr();//$this->globalKey( $vo );
|
| 374 | if( !in_array( $vo, $this->_aryAll, true ) ) {
|
| 375 | $this->_aryAll[$key] = $vo;
|
| 376 | echo "Added to aryAll: $vo.<br />";
|
| 377 | }
|
| 378 | if( !in_array( $vo, $this->_aryDeleted, true ) ) {
|
| 379 | $this->_aryDeleted[$key] = $vo;
|
| 380 | echo "Added to aryDeleted: $vo.<br />";
|
| 381 | }
|
| 382 | // $key = $this->globalKey( $vo );
|
| 383 | echo "Trimming aryNew, aryClean, and aryDirty<br/>";
|
| 384 | unset( $this->_aryNew[$key], $this->_aryClean[$key], $this->_aryDirty[$key] );
|
| 385 | //Filter the new objects
|
| 386 | //echo "Trim aryNew.";
|
| 387 | //$this->_aryNew =
|
| 388 | //$this->trimDoFromAry( $this->_aryNew, $vo );
|
| 389 | //Filter the clean objects
|
| 390 | //echo "Trim aryClean.";
|
| 391 | //$this->_aryClean =
|
| 392 | //$this->trimDoFromAry( $this->_aryClean, $vo );
|
| 393 | //Filter the deleted objects
|
| 394 | //echo "Trim aryDirty.";
|
| 395 | //$this->_aryDirty =
|
| 396 | //$this->trimDoFromAry( $this->_aryDirty, $vo );
|
| 397 | echo "Marked As Deleted: $vo<br/>";
|
| 398 | }//End addDeleted()
|
| 399 |
|
| 400 |
|
| 401 | /**
|
| 402 | * Executes all INSERT, UPDATE, & DELETE operations by calling
|
| 403 | * commitInserts(), commitUpdates(), & commitDeletes() sequentially.
|
| 404 | *
|
| 405 | * @access public
|
| 406 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 407 | * @return bool Returns true if all operations perform successfully, false otherwise.
|
| 408 | */
|
| 409 | public function commitAll() {
|
| 410 | echo "<b>" . __METHOD__ . "()</b>...<br/>";
|
| 411 | if( !$this->commitInserts() ) {
|
| 412 | echo "Inserts failed<br />";
|
| 413 | return false;
|
| 414 | }
|
| 415 | if( !$this->commitUpdates() ) {
|
| 416 | echo "Updates failed<br />";
|
| 417 | return false;
|
| 418 | }
|
| 419 | if( !$this->commitDeletes() ) {
|
| 420 | echo "Deletes failed<br />";
|
| 421 | return false;
|
| 422 | }
|
| 423 | echo "Commited all database synchronizations.<br />";
|
| 424 | return true;
|
| 425 | }//End commitAll()
|
| 426 |
|
| 427 |
|
| 428 | /**
|
| 429 | * Executes all INSERT operations.
|
| 430 | *
|
| 431 | * @access public
|
| 432 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 433 | * @return bool
|
| 434 | */
|
| 435 | public function commitInserts() {
|
| 436 | $errAry = array();
|
| 437 | $ttl = count( $this->_aryNew );
|
| 438 | echo "Inserting ( " . $ttl . " ) VO objects...<br/>";
|
| 439 | for ( $i = 1; $i < $ttl + 1; $i++ ){ // as $vo ) {
|
| 440 | /* @var $vo AbstractValueObject */
|
| 441 | $vo = array_shift( $this->_aryNew );
|
| 442 | echo "<hr/>Removed New #$i : $vo<br/>";
|
| 443 | //unset( $this->_aryNew[$i] );
|
| 444 | //This is to prevent the indexes from getting out of whack when the objects are removed.
|
| 445 | //if( count( $this->_aryNew ) == 0 ){$this->_aryNew = array();}
|
| 446 | if( $vo->map()->insert( $vo ) ) {
|
| 447 | $this->addClean( $vo );
|
| 448 | } else {
|
| 449 | $this->_aryNew[$i . "xErr"] = $vo;
|
| 450 | $errAry[] = "Failed Insert: " . $vo->getKeyStr();
|
| 451 | }
|
| 452 | }
|
| 453 | if( count( $errAry ) != 0 ) {
|
| 454 | echo "Insert Errors: <hr />" . print_r( $errAry, true ) . "<hr />";
|
| 455 | return false;
|
| 456 | }
|
| 457 | return true;
|
| 458 | }//End commitInserts()
|
| 459 |
|
| 460 |
|
| 461 | /**
|
| 462 | * Executes all UPDATE operations.
|
| 463 | *
|
| 464 | * @access public
|
| 465 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 466 | * @return bool
|
| 467 | */
|
| 468 | public function commitUpdates() {
|
| 469 | $errAry = array();
|
| 470 | echo "Updating ( ". count( $this->_aryDirty ) ." ) VO objects...<br/>";
|
| 471 | foreach ( $this->_aryDirty as $vo ) {
|
| 472 | /* @var $vo AbstractValueObject */
|
| 473 | if( $vo->map()->update( $vo ) ) {
|
| 474 | $this->addClean( $vo );
|
| 475 | } else {
|
| 476 | $errAry[] = "Failed Insert: " . $vo->getKeyStr();
|
| 477 | }
|
| 478 | }
|
| 479 | if( count( $errAry ) != 0 ) {
|
| 480 | echo "Update Errors: <hr />" . print_r( $errAry, true ) . "<hr />";
|
| 481 | return false;
|
| 482 | }
|
| 483 | return true;
|
| 484 | }//End commitUpdates()
|
| 485 |
|
| 486 |
|
| 487 | /**
|
| 488 | * Executes all DELETE operations.
|
| 489 | *
|
| 490 | * @access public
|
| 491 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 492 | * @return bool
|
| 493 | */
|
| 494 | public function commitDeletes() {
|
| 495 | $errAry = array();
|
| 496 | echo "Deleting ( ". count( $this->_aryDeleted ) ." ) VO objects...<br/>";
|
| 497 | foreach ( $this->_aryDeleted as $vo ) {
|
| 498 | /* @var $vo AbstractValueObject */
|
| 499 | if( $vo->map()->delete( $vo ) ) {
|
| 500 | //Remove the $vo from the watcher arrays
|
| 501 | echo "Trim aryAll & aryDeleted<br/>";
|
| 502 | //$this->_aryAll =
|
| 503 | $key = $this->globalKey( $vo );
|
| 504 | unset( $this->_aryAll[$key], $this->_aryDeleted[$key] );
|
| 505 | //$this->trimDoFromAry( $this->_aryAll, $vo );
|
| 506 | //echo "Trim from aryDeleted: ";
|
| 507 | //$this->_aryDeleted =
|
| 508 | //$this->trimDoFromAry( $this->_aryDeleted, $vo );
|
| 509 | unset( $key, $vo );
|
| 510 | } else {
|
| 511 | $errAry[] = "Failed Delete: " . $vo->getKeyStr();
|
| 512 | }
|
| 513 | }
|
| 514 | if( count( $errAry ) != 0 ) {
|
| 515 | echo "Delete Errors: <hr />" . print_r( $errAry, true ) . "<hr />";
|
| 516 | return false;
|
| 517 | }
|
| 518 | return true;
|
| 519 | }//End commitDeletes()
|
| 520 |
|
| 521 |
|
| 522 | /**
|
| 523 | * Empties all objects from all arrays.
|
| 524 | */
|
| 525 | public function removeAll() {
|
| 526 | echo __METHOD__ . " Removing all object references.<br/>";
|
| 527 | $this->_aryAll = $this->_aryClean = $this->_aryDeleted = $this->_aryDirty = $this->_aryNew = array();
|
| 528 | }//End removeAll()
|
| 529 |
|
| 530 |
|
| 531 | /**
|
| 532 | * DbExchange::has() accepts a class name and a key string and uses them to determine if it has the data that corresponds to that instance/row.
|
| 533 | *
|
| 534 | *
|
| 535 | * @access public
|
| 536 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 537 | * @param string classname
|
| 538 | * @param mixed id - An int or string
|
| 539 | * @return mixed AbstractValueObject || null
|
| 540 | */
|
| 541 | public function has( $classname, $voKeyStr ) {
|
| 542 | $key = $classname . $voKeyStr;
|
| 543 | echo "<b>" . __METHOD__ . "()</b> Looking for '$key'<br/>";
|
| 544 | if( isset ( $this->_aryAll[$key] ) ) {
|
| 545 | return $this->_aryAll[$key];
|
| 546 | }
|
| 547 | return null;
|
| 548 | }//End has()
|
| 549 |
|
| 550 |
|
| 551 | /**
|
| 552 | * Returns a unique identifier for each concrete domain object by concatenating
|
| 553 | * the object's classname with it's table primary key string.
|
| 554 | *
|
| 555 | * @access private
|
| 556 | * @author Todd Mullen - ???, <AnEmail@gmail.com>
|
| 557 | * @param AbstractValueObject $vo
|
| 558 | * @return string
|
| 559 | */
|
| 560 | private function globalKey( AbstractValueObject $vo ) {
|
| 561 | $key = get_class( $vo ) . "." . $vo->getKeyStr();
|
| 562 | return $key;
|
| 563 | }//End globalKey()
|
| 564 |
|
| 565 |
|
| 566 | // --- Utility Methods ---
|
| 567 |
|
| 568 |
|
| 569 | public function Summary() {
|
| 570 | return "<code><div><h3>".__METHOD__."</h3>"
|
| 571 | . $this->dumpClean() . $this->dumpNew() . $this->dumpDirty() . $this->dumpDeleted(). $this->dumpAllAry()
|
| 572 | . "</div></code>";
|
| 573 | }//End Summary()
|
| 574 |
|
| 575 |
|
| 576 | public function dumpAllAry() {
|
| 577 | return "<div> ( " . count( $this->_aryAll ) . " ) <b>All VOs</b>:" . $this->dumpAry( $this->_aryAll ) . "</div>";
|
| 578 | }//End dumpAllAry()
|
| 579 |
|
| 580 |
|
| 581 | public function dumpNew() {
|
| 582 | return "<div> ( " . count( $this->_aryNew ) . " ) <b>New VOs</b>:" . $this->dumpAry( $this->_aryNew ) . "</div>";
|
| 583 | }//End dumpNew()
|
| 584 |
|
| 585 |
|
| 586 | public function dumpClean() {
|
| 587 | return "<div> ( " . count( $this->_aryClean ) . " ) <b>Clean VOs</b>:" . $this->dumpAry( $this->_aryClean ) . "</div>";
|
| 588 | }//End dumpClean()
|
| 589 |
|
| 590 |
|
| 591 | public function dumpDirty() {
|
| 592 | return "<div> ( " . count( $this->_aryDirty ) . " ) <b>Dirty VOs</b>:" . $this->dumpAry( $this->_aryDirty ) . "</div>";
|
| 593 | }//End dumpDirty()
|
| 594 |
|
| 595 |
|
| 596 | public function dumpDeleted() {
|
| 597 | return "<div> ( " . count( $this->_aryDeleted ) . " ) <b>Deleted VOs</b>:" . $this->dumpAry( $this->_aryDeleted ) . "</div>";
|
| 598 | }//End dumpDeleted()
|
| 599 |
|
| 600 |
|
| 601 | protected function dumpAry( $ary ) {
|
| 602 | if( count( $ary ) == 0 ){ return " <i>*Empty*</i>";}
|
| 603 | $str = "<br />";
|
| 604 | foreach ( $ary as $key => $value ) {
|
| 605 | $str .= "Key '$key': $value<br />";
|
| 606 | }
|
| 607 | //. implode( "<br />", $ary );
|
| 608 | return $str;
|
| 609 | }//End dumpAry()
|
| 610 |
|
| 611 |
|
| 612 | public function __toString() {
|
| 613 | return self::Store()->Summary();
|
| 614 | }//End __toString()
|
| 615 |
|
| 616 |
|
| 617 | public function __clone() {
|
| 618 | throw new Exception( __CLASS__ . ' cannot be cloned or duplicated.' );
|
| 619 | }//End __clone()
|
| 620 |
|
| 621 |
|
| 622 | }//End DbExchange Class
|
| 623 | ?> |