Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
 /**
  * Get presenter info for adminstrative endpoints
  *
  */
 public function getPresenterForAdministrative($id)
 {
     $sql = "SELECT " . "p.id AS presenter_id, " . "p.presenter_sequence_id AS presenter_sequence_id, " . "p.default_locale AS presenter_default_locale, " . "p.account_type_display_selection AS account_type_display_selection, " . "p.presenter_account_type_id AS presenter_account_type_id, " . "s.site_url AS url, " . "u.first_name AS first_name, " . "u.last_name AS last_name, " . "u.id AS user_id, " . "u.facebook_id AS facebook, " . "status.name AS status " . "FROM {$this->_table_name} p " . "LEFT JOIN users u ON u.id = p.user_id " . "LEFT JOIN presenter_sites s ON p.id = s.presenter_id " . "LEFT JOIN presenter_statuses status on status.id = p.presenter_status_id " . "WHERE p.presenter_sequence_id = :id";
     $query = $this->_db->prepare($sql);
     $query->bindParam(':id', $id);
     $query->execute();
     $user = $query->fetchObject();
     //get address
     $sql = "SELECT a.address1, a.address2, a.address3, a.city, s.abbrev as state, a.postal_code, c.name as country " . "FROM addresses a " . "JOIN states s ON s.id=a.state_id " . "JOIN countries c ON s.country_id=c.id " . "WHERE a.user_id = :id " . "AND a.address_type_id = 1" . " ORDER BY a.id DESC ";
     $address_query = $this->_db->prepare($sql);
     $address_query->bindParam(':id', $user->user_id);
     $address_query->execute();
     $address = $address_query->fetchObject();
     //get email
     $sql = "SELECT email " . "FROM emails " . "WHERE user_id = :id " . "AND email_type_id = 1";
     $email_query = $this->_db->prepare($sql);
     $email_query->bindParam(':id', $user->user_id);
     $email_query->execute();
     $email = $email_query->fetchObject();
     //get presenter status
     require_once APPLICATION_PATH . MODEL_DIR . '/Presenter_type.php';
     $presenter_type = new Presenter_type();
     @($max_presenter_status_level_id = $presenter_type->getMaxType($user->presenter_id));
     $max_presenter_status_level_name = $presenter_type->getPresenterStatusName($max_presenter_status_level_id);
     //put them together for return
     $user->address1 = isset($address->address1) ? $address->address1 : "";
     $user->address2 = isset($address->address2) ? $address->address2 : "";
     $user->address3 = isset($address->address3) ? $address->address3 : "";
     $user->city = isset($address->city) ? $address->city : "";
     $user->state = isset($address->state) ? $address->state : "";
     $user->postal_code = isset($address->postal_code) ? $address->postal_code : "";
     $user->country = isset($address->country) ? $address->country : "";
     $user->email = isset($email->email) ? $email->email : "";
     $user->status_level_id = $max_presenter_status_level_id;
     $user->status_level_name = $max_presenter_status_level_name;
     return $user;
 }