Exemplo n.º 1
0
 function CountMembers($activeOnly = false)
 {
     global $wpdb, $WishListMemberInstance;
     $table = $WishListMemberInstance->TablePrefix . 'userlevels';
     $table_options = $WishListMemberInstance->TablePrefix . 'userlevel_options';
     $member_count = wlm_cache_get('wishlist_member_all_levels_members_count', 'wishlist-member');
     if ($member_count === false) {
         $results = $wpdb->get_results("SELECT `level_id`,COUNT(*) AS `cnt` FROM `{$table}` GROUP BY `level_id`");
         foreach ($results as $result) {
             $member_count[$result->level_id] = $result->cnt;
         }
         wlm_cache_set('wishlist_member_all_levels_members_count', $member_count, 'wishlist-member');
     }
     if ($activeOnly) {
         $date = $this->noexpire == 1 ? '1000-00-00 00:00:00' : date('Y-m-d H:i:s', strtotime("-{$this->expire} {$this->calendar}"));
         $query = sprintf("SELECT COUNT(DISTINCT `%1\$s`.`user_id`) FROM `%1\$s` LEFT JOIN `%2\$s`\n\t\t\t\t\tON `%1\$s`.`ID`=`%2\$s`.`userlevel_id`\n\t\t\t\t\tAND (`%2\$s`.`option_name` IN ('cancelled','forapproval','unconfirmed','registration_date')\n\t\t\t\t\tAND `%2\$s`.`option_value`<>''\n\t\t\t\t\tAND `%2\$s`.`option_value`<>0\n\t\t\t\t\tand `%2\$s`.`option_value`<='%3\$s')\n\t\t\t\t\t\tWHERE `%1\$s`.`level_id`=%4\$d\n\t\t\t\t\t\tAND `%2\$s`.`userlevel_id` IS NULL", $table, $table_options, $date, $this->ID);
         return $wpdb->get_var($query);
     } else {
         return $member_count[$this->ID];
     }
 }
Exemplo n.º 2
0
 /**
  * Return Member's Membership Levels
  * @global object $wpdb
  * @param int $id User ID
  * @param boolean $names (optional) Default False. TRUE to return Level names instead of IDs
  * @param boolean $activeOnly (optional) Default False. TRUE to return active levels only
  * @param boolean $no_cache (optional) Default False. TRUE to skip cache data
  * @param boolean $no_userlevels (optional) Default False. TRUE to exclude User Level (U-xxx)
  * @param boolean $include_scheduled (optional) Default TRUE. FALSE to exclude scheduled levels
  * @return array Levels
  */
 function GetMembershipLevels($id, $names = null, $activeOnly = null, $no_cache = null, $no_userlevels = null, $include_scheduled = null)
 {
     global $wpdb;
     $names = is_null($names) ? false : $names;
     $activeOnly = is_null($activeOnly) ? false : $activeOnly;
     $no_cache = is_null($no_cache) ? false : $no_cache;
     $no_userlevels = is_null($no_userlevels) ? false : $no_userlevels;
     if (is_null($include_scheduled)) {
         $include_scheduled = true;
     }
     $levels = $no_cache === true ? false : wlm_cache_get($id, $this->Tables->userlevels);
     #empty user == no membership levels
     if (empty($id)) {
         return array();
     }
     if ($levels === false) {
         if ($include_scheduled) {
             $query = $wpdb->prepare("SELECT `level_id` FROM `{$this->Tables->userlevels}` WHERE `user_id`=%d", $id);
         } else {
             $query = $wpdb->prepare("SELECT `level_id`,MAX(`option_name`='scheduled_move' OR `option_name`='scheduled_add' OR `option_name`='scheduled_remove') `scheduled` FROM `{$this->Tables->userlevels}` `l` LEFT JOIN `{$this->Tables->userlevel_options}` `lo` ON `l`.`ID`=`lo`.`userlevel_id` WHERE `user_id`=%d GROUP BY `level_id` HAVING `scheduled`=0", $id);
         }
         $levels = $wpdb->get_col($query);
         wlm_cache_set($id, $levels, $this->Tables->userlevels);
     }
     if ($names) {
         $wpm_levels = $this->GetOption('wpm_levels');
         $names = array();
         foreach ((array) $levels as $level) {
             $name = $wpm_levels[$level]['name'];
             if ($this->LevelCancelled($level, $id) or $this->LevelForApproval($level, $id) or $this->LevelUnConfirmed($level, $id) or $this->LevelExpired($level, $id)) {
                 $name = '<strike>' . $name . '</strike>';
             }
             $names[] = $name;
         }
         return implode(', ', $names);
     } else {
         if ($activeOnly) {
             foreach ((array) $levels as $key => $level) {
                 if ($this->IsLevelScheduled($level, $id) or $this->LevelCancelled($level, $id) or $this->LevelForApproval($level, $id) or $this->LevelUnConfirmed($level, $id) or $this->LevelExpired($level, $id)) {
                     unset($levels[$key]);
                 }
             }
             $levels = array_merge($levels, array());
         }
         if (!$no_userlevels) {
             // force individual user level
             $levels[] = 'U-' . $id;
         }
         return $levels;
     }
 }
Exemplo n.º 3
0
 /**
  * Get UserLevel meta information
  * @global object $wpdb
  * @param int $user_id
  * @param int $level_id
  * @param string $meta
  * @return mixed
  */
 function Get_UserLevelMeta($user_id, $level_id, $meta)
 {
     global $wpdb;
     if (empty($user_id)) {
         return false;
     }
     $cache_key = $user_id . '_' . $level_id . '_' . $meta;
     $cache_group = $this->Tables->userlevel_options;
     $value = wlm_cache_get($cache_key, $cache_group);
     if ($value !== false) {
         return $value;
     }
     $userlevel_id = $this->Get_UserLevelIndex($user_id, $level_id);
     if ($userlevel_id === false) {
         $value = null;
     } else {
         $query = $wpdb->prepare("SELECT `option_value` FROM `{$this->Tables->userlevel_options}` WHERE `userlevel_id`=%d AND `option_name`='%s'", $userlevel_id, $meta);
         $row = $wpdb->get_row($query);
         //rewritten so that we don't actually return "false" instead
         //cache the null value so that we don't have
         //to hit the db next time.
         if (!is_object($row)) {
             $value = null;
         } else {
             $value = $row->option_value;
         }
     }
     $value = maybe_unserialize($value);
     wlm_cache_set($cache_key, $value, $cache_group);
     return $value;
 }
Exemplo n.º 4
0
 /**
  * Retrieves an option's value
  * @param string $option The name of the option
  * @param boolean $dec (optional) True to decrypt the return value
  * @param boolean $no_cache (optional) True to skip cache data
  * @return string The option value
  */
 function GetOption($option, $dec = null, $no_cache = null)
 {
     global $wpdb;
     $cache_key = $option;
     $cache_group = $this->OptionsTable;
     if (is_null($dec)) {
         $dec = false;
     }
     if (is_null($no_cache)) {
         $no_cache = false;
     }
     $value = $no_cache === true ? false : wlm_cache_get($cache_key, $cache_group);
     if ($value === false) {
         $row = $wpdb->get_row($wpdb->prepare("SELECT `option_value` FROM `{$this->OptionsTable}` WHERE `option_name`='%s'", $option));
         if (!is_object($row)) {
             return false;
         }
         $value = $row->option_value;
         $value = maybe_unserialize($value);
         wlm_cache_set($cache_key, $value, $cache_group);
     }
     if ($dec) {
         $value = $this->WLMDecrypt($value);
     }
     return $value;
 }