コード例 #1
0
ファイル: Data.php プロジェクト: kameshwariv/testexample
 /**
  * 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);
 }