/** * Get the full data set for a selected (single) user * * Gets the user, presenter, email, phone, address, and product credit records for this user. * Also returns the meta data - that is the available types for certain data types * for instance, the phones table has a type_id. * The meta data would contain the names of these types keyed to their id for referencing int he code. * Example: user.meta.phone[<insert the user's phone type id here>].name would dynamically give you the phone type name * * Returns stdClass * user * id * first_name * middle_name * last_name * entity * date_of_birth * consent_to_agreements * presenter * id * presenter_sequence_id * user_id * sponosr_id * market_id * market_sequence_id * government_id * consent_to_agreements * default_locale * terminated_date * presenter_status_id * _autiddate * status_level_name * status_level_id * presenter_site * id * presenter_id * site_url * is_primary * head_shot * bio * analytics_code * presenter_info * fast_start_end_date * email * {id} * id * email_type_id * user_id * email * phone * {id} * id * phone_type_id * user_id * nickname * phone * address * {id} * id * address_type_id * user_id * nickname * address1 * address2 * address3 * city * county * state_id * postal_code * country_id * product_credits * transactions * [] * product_credit_id * presenter_id * entry_user * amount * credit_type * entry_type * status * reference_id * timestamp * currency * balances * younique_cash * parties * [] * id * party_name * start_time * end_time * party_total * finalized_sate * display_result * presenter_sequence_id * presenter_facebook * hostess_facebook * presenter_name * hostess_name * display - initial display setting - closed parties are false, open are true * orders * [] * id * date_completed * presenter * customer * grand_total * status_name * status_id * display - initial display setting - closed parties are false, open are true * coupons * records * [] * id * coupon_presenter_id * user_id * date_added * user_visible * reference_id * date_redeemed * redemption_reference_id * redemption_amount * expiration_date * available * meta - see _getMeta for structure * * @param int $user_id * @param bool $include_meta_data * @return \stdClass */ public function getAllUserData($user_id, $include_meta_data = TRUE) { require_once APPLICATION_PATH . MODEL_DIR . '/User.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Presenter.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Email.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Phone.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Address.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Address_geocode.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Market.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Product_credits.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Order.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Party.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Coupon_presenter_user.php'; require_once APPLICATION_PATH . MODEL_DIR . '/User_oauth2.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Accomplishments.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_documents.php'; require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_us_tax_data.php'; $results = new stdClass(); //user table $user = new User(); $results->user = $user->getDataById($user_id); //presenter $presenter = new Presenter(); $results->presenter = $presenter->getDataByUserId($user_id, TRUE); if (!empty($results->presenter)) { //compliance info $results->presenter->compliance = $presenter->getComplianceDataByUserId($user_id, $results->presenter->market_id); //presenter_site require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_site.php'; $presenter_site = new Presenter_site(); $results->presenter_site = $presenter_site->getDataByPresenterId($results->presenter->id); //presenter_us_tax_data require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_us_tax_data.php'; $results->presenter_us_tax_data = $presenter->getBusinessDataByPresenterId($results->presenter->id); //get presenter status require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_type.php'; $presenter_type = new Presenter_type(); $results->presenter->status_level_id = $presenter_type->getMaxType($results->presenter->id); $results->presenter->status_level_name = $presenter_type->getPresenterStatusName($results->presenter->status_level_id); //get sponsor data $sponsor = new Presenter(); $results->presenter->sponsor = $sponsor->getSponsorData($results->presenter->sponsor_id); //presenter info $results->presenter_info = new stdClass(); $sign_up_date = new DateTime($results->presenter->consent_to_agreements); //to get the right end date for fast start, we ned to check if they are in a new market that had a 1 month //delay between sign up and sales $fast_start_end_date = YouniqueAPI::call("presenter/getFastStartDeadline/" . $results->presenter->presenter_sequence_id); $results->presenter_info->fast_start_end_date = date("M d, Y", strtotime($fast_start_end_date)); $presenter_documents = new Presenter_documents(); $results->presenter_documents = $presenter_documents->getPresenterDocuments($results->presenter->presenter_sequence_id); } //these have multiple records potentially, so we load them on their own //emails $email = new Email(); $results->email = $email->getDataByUserId($user_id); //phones $phone = new Phone(); $results->phone = $phone->getDataByUserId($user_id); //oauth $oauth = new User_oauth2(); $results->oauth = $oauth->getDataByUserId($user_id); //addresses $address = new Address(); $geo = new Address_geocode(); $results->address = $address->getDataByUserId($user_id); //accomplishments $accomplishments = new Accomplishments(); $results->accomplishments = $this->_sortAccomplishments($accomplishments->getDataByUserId($user_id)); foreach ($results->address as $a_key => &$a_value) { $a_geo = $geo->getByAddressId($a_value['id']); if (!$a_geo) { continue; } $a_value['geo_id'] = $a_geo->id; $a_value['lat'] = $a_geo->lat; $a_value['lng'] = $a_geo->lng; } //todo: apply geocodes //get product credit info $product_credits = new Product_credits(); $results->product_credits = new stdClass(); $results->product_credits->transactions = $product_credits->getTransactionsByUserId($user_id); $results->product_credits->balances = $product_credits->getBalancesByUserId($user_id); //markets $market = new Market(); $results->country_codes = new stdClass(); $results->country_codes->transactions = $market->getCountryCodesByMarkets(); $result = new stdClass(); foreach ($results as $key => $value) { if ($key == 'accomplishments') { $result->{$key} = $value; continue; } $result->{$key} = $this->_rekeyArray($value); } //orders $order = new Order(); $result->orders = $order->getOrdersByUserId($user_id); //check replacement percentage $order_ids = []; foreach ($result->orders as $value) { $order_ids[] = $value['id']; } if (!empty($results->presenter)) { $result->presenter->replacement_percentage = $order->getUserReplacementOrderPercentage($order_ids); //parties $party = new Party(); $result->parties = $party->getPresenterParties($results->presenter->id); } //coupons $coupon = new Coupon_presenter_user(); $result->coupons = new stdClass(); $result->coupons->records = $coupon->getDataByUserId($user_id); $result->coupons->promocoupons = $coupon->getPromoCoupons(); $result->coupons->promorecords = $coupon->getPromoDataByUserId($user_id); $result->coupons->available = 0; $result->coupons->promoavailable = 0; if (!empty($result->coupons->promorecords)) { foreach ($result->coupons->promorecords as $key => $value) { if ($value['date_redeemed'] == NULL) { $result->coupons->promoavailable++; } } } foreach ($result->coupons->records as $key => $value) { if ($value['date_redeemed'] == NULL) { $result->coupons->available++; } } //meta if ($include_meta_data) { $result->meta = $this->_getMetaData(); } return $this->_filterResults($result); }
<?php $inIndex = true; require_once "../lib/setup/databaseInfo.php"; require_once "../lib/database.php"; require_once "../lib/observers.php"; require_once "../lib/cometobservations.php"; require_once "../lib/accomplishments.php"; require_once "../lib/messages.php"; date_default_timezone_set('UTC'); $objDatabase = new Database(); $objObserver = new Observers(); $objCometObservation = new CometObservations(); $objAccomplishments = new Accomplishments(); $objMessages = new Messages(); print "Database update add a hasDrawing field to cometobservations.<br />\n"; $sql = "ALTER TABLE cometobservations ADD COLUMN hasDrawing INT(1) NOT NULL DEFAULT 0"; $run = $objDatabase->execSQL($sql); $upload_dir = '../comets/cometdrawings'; $dir = opendir($upload_dir); while (FALSE !== ($file = readdir($dir))) { if (!("." == $file or ".." == $file or ".svn" == $file) && strpos($file, 'resized') == 0) { $objCometObservation->setHasDrawing(substr($file, 0, strpos($file, '.jpg'))); } } print "Database update add an accomplishments table and fill it for all users.<br />\n"; $sql = "DROP TABLE IF EXISTS accomplishments"; $run = $objDatabase->execSQL($sql); $sql = "CREATE TABLE accomplishments (\n observer VARCHAR(255) NOT NULL DEFAULT '',\n messierBronze INT(1) NOT NULL DEFAULT 0,\n messierSilver INT(1) NOT NULL DEFAULT 0,\n messierGold INT(1) NOT NULL DEFAULT 0,\n messierDrawingsBronze INT(1) NOT NULL DEFAULT 0,\n messierDrawingsSilver INT(1) NOT NULL DEFAULT 0,\n messierDrawingsGold INT(1) NOT NULL DEFAULT 0,\n caldwellBronze INT(1) NOT NULL DEFAULT 0,\n caldwellSilver INT(1) NOT NULL DEFAULT 0,\n caldwellGold INT(1) NOT NULL DEFAULT 0,\n caldwellDrawingsBronze INT(1) NOT NULL DEFAULT 0,\n caldwellDrawingsSilver INT(1) NOT NULL DEFAULT 0,\n caldwelldrawingsGold INT(1) NOT NULL DEFAULT 0,\n herschelBronze INT(1) NOT NULL DEFAULT 0,\n herschelSilver INT(1) NOT NULL DEFAULT 0,\n herschelGold INT(1) NOT NULL DEFAULT 0,\n herschelDiamond INT(1) NOT NULL DEFAULT 0,\n herschelPlatina INT(1) NOT NULL DEFAULT 0,\n herschelDrawingsBronze INT(1) NOT NULL DEFAULT 0,\n herschelDrawingsSilver INT(1) NOT NULL DEFAULT 0,\n herschelDrawingsGold INT(1) NOT NULL DEFAULT 0,\n herschelDrawingsDiamond INT(1) NOT NULL DEFAULT 0,\n herschelDrawingsPlatina INT(1) NOT NULL DEFAULT 0,\n herschelIIBronze INT(1) NOT NULL DEFAULT 0,\n herschelIISilver INT(1) NOT NULL DEFAULT 0,\n herschelIIGold INT(1) NOT NULL DEFAULT 0,\n herschelIIDiamond INT(1) NOT NULL DEFAULT 0,\n herschelIIPlatina INT(1) NOT NULL DEFAULT 0,\n herschelIIDrawingsBronze INT(1) NOT NULL DEFAULT 0,\n herschelIIDrawingsSilver INT(1) NOT NULL DEFAULT 0,\n herschelIIDrawingsGold INT(1) NOT NULL DEFAULT 0,\n herschelIIDrawingsDiamond INT(1) NOT NULL DEFAULT 0,\n herschelIIDrawingsPlatina INT(1) NOT NULL DEFAULT 0,\n drawingsNewbie INT(1) NOT NULL DEFAULT 0,\n drawingsRookie INT(1) NOT NULL DEFAULT 0,\n drawingsBeginner INT(1) NOT NULL DEFAULT 0,\n drawingsTalented INT(1) NOT NULL DEFAULT 0,\n drawingsSkilled INT(1) NOT NULL DEFAULT 0,\n drawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n drawingsExperienced INT(1) NOT NULL DEFAULT 0,\n drawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n drawingsSenior INT(1) NOT NULL DEFAULT 0,\n drawingsExpert INT(1) NOT NULL DEFAULT 0,\n cometObservationsNewbie INT(1) NOT NULL DEFAULT 0,\n cometObservationsRookie INT(1) NOT NULL DEFAULT 0,\n cometObservationsBeginner INT(1) NOT NULL DEFAULT 0,\n cometObservationsTalented INT(1) NOT NULL DEFAULT 0,\n cometObservationsSkilled INT(1) NOT NULL DEFAULT 0,\n cometObservationsIntermediate INT(1) NOT NULL DEFAULT 0,\n cometObservationsExperienced INT(1) NOT NULL DEFAULT 0,\n cometObservationsAdvanced INT(1) NOT NULL DEFAULT 0,\n cometObservationsSenior INT(1) NOT NULL DEFAULT 0,\n cometObservationsExpert INT(1) NOT NULL DEFAULT 0,\n cometsObservedNewbie INT(1) NOT NULL DEFAULT 0,\n cometsObservedRookie INT(1) NOT NULL DEFAULT 0,\n cometsObservedBeginner INT(1) NOT NULL DEFAULT 0,\n cometsObservedTalented INT(1) NOT NULL DEFAULT 0,\n cometsObservedSkilled INT(1) NOT NULL DEFAULT 0,\n cometsObservedIntermediate INT(1) NOT NULL DEFAULT 0,\n cometsObservedExperienced INT(1) NOT NULL DEFAULT 0,\n cometsObservedAdvanced INT(1) NOT NULL DEFAULT 0,\n cometsObservedSenior INT(1) NOT NULL DEFAULT 0,\n cometsObservedExpert INT(1) NOT NULL DEFAULT 0,\n cometDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n cometDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n cometDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n cometDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n cometDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n cometDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n cometDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n cometDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n cometDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n cometDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n openClusterNewbie INT(1) NOT NULL DEFAULT 0,\n openClusterRookie INT(1) NOT NULL DEFAULT 0,\n openClusterBeginner INT(1) NOT NULL DEFAULT 0,\n openClusterTalented INT(1) NOT NULL DEFAULT 0,\n openClusterSkilled INT(1) NOT NULL DEFAULT 0,\n openClusterIntermediate INT(1) NOT NULL DEFAULT 0,\n openClusterExperienced INT(1) NOT NULL DEFAULT 0,\n openClusterAdvanced INT(1) NOT NULL DEFAULT 0,\n openClusterSenior INT(1) NOT NULL DEFAULT 0,\n openClusterExpert INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n openClusterDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n globularClusterNewbie INT(1) NOT NULL DEFAULT 0,\n globularClusterRookie INT(1) NOT NULL DEFAULT 0,\n globularClusterBeginner INT(1) NOT NULL DEFAULT 0,\n globularClusterTalented INT(1) NOT NULL DEFAULT 0,\n globularClusterSkilled INT(1) NOT NULL DEFAULT 0,\n globularClusterIntermediate INT(1) NOT NULL DEFAULT 0,\n globularClusterExperienced INT(1) NOT NULL DEFAULT 0,\n globularClusterAdvanced INT(1) NOT NULL DEFAULT 0,\n globularClusterSenior INT(1) NOT NULL DEFAULT 0,\n globularClusterExpert INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n globularClusterDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaNewbie INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaRookie INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaBeginner INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaTalented INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaSkilled INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaIntermediate INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaExperienced INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaAdvanced INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaSenior INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaExpert INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n planetaryNebulaDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n galaxyNewbie INT(1) NOT NULL DEFAULT 0,\n galaxyRookie INT(1) NOT NULL DEFAULT 0,\n galaxyBeginner INT(1) NOT NULL DEFAULT 0,\n galaxyTalented INT(1) NOT NULL DEFAULT 0,\n galaxySkilled INT(1) NOT NULL DEFAULT 0,\n galaxyIntermediate INT(1) NOT NULL DEFAULT 0,\n galaxyExperienced INT(1) NOT NULL DEFAULT 0,\n galaxyAdvanced INT(1) NOT NULL DEFAULT 0,\n galaxySenior INT(1) NOT NULL DEFAULT 0,\n galaxyExpert INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n galaxyDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n nebulaNewbie INT(1) NOT NULL DEFAULT 0,\n nebulaRookie INT(1) NOT NULL DEFAULT 0,\n nebulaBeginner INT(1) NOT NULL DEFAULT 0,\n nebulaTalented INT(1) NOT NULL DEFAULT 0,\n nebulaSkilled INT(1) NOT NULL DEFAULT 0,\n nebulaIntermediate INT(1) NOT NULL DEFAULT 0,\n nebulaExperienced INT(1) NOT NULL DEFAULT 0,\n nebulaAdvanced INT(1) NOT NULL DEFAULT 0,\n nebulaSenior INT(1) NOT NULL DEFAULT 0,\n nebulaExpert INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n nebulaDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n objectsNewbie INT(1) NOT NULL DEFAULT 0,\n objectsRookie INT(1) NOT NULL DEFAULT 0,\n objectsBeginner INT(1) NOT NULL DEFAULT 0,\n objectsTalented INT(1) NOT NULL DEFAULT 0,\n objectsSkilled INT(1) NOT NULL DEFAULT 0,\n objectsIntermediate INT(1) NOT NULL DEFAULT 0,\n objectsExperienced INT(1) NOT NULL DEFAULT 0,\n objectsAdvanced INT(1) NOT NULL DEFAULT 0,\n objectsSenior INT(1) NOT NULL DEFAULT 0,\n objectsExpert INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsNewbie INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsRookie INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsBeginner INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsTalented INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsSkilled INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsIntermediate INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsExperienced INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsAdvanced INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsSenior INT(1) NOT NULL DEFAULT 0,\n objectsDrawingsExpert INT(1) NOT NULL DEFAULT 0,\n PRIMARY KEY (observer) \n )"; $run = $objDatabase->execSQL($sql); // We loop over all observers