A free points management plugin for WordPress.
myCRED Logo
myCRED Logo
  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download
    Navigation
    • Loading navigation ...
    All Classes
    myCRED classes
    1. myCRED_Hook
    2. myCRED_Lottery
    3. myCRED_Module
    4. myCRED_Payment_Gateway
    5. myCRED_Query_Log
    6. myCRED_Remote
    7. myCRED_Settings
    Categories
    Filter by category
    1. Actions
    2. Classes
    3. Filters
    4. Functions
    5. Hooks
    6. Objects
    7. Shortcodes
    8. Template Tags
    Chapters
    Documentation
    1. Chapter I - Introduction
    2. Chapter II - Getting Started
    3. Chapter III - Add-ons
    4. Chapter IV - Premium Add-ons
    5. Chapter V - For Developers
    6. Chapter VI - Reference Guides
myCRED_Lottery

Codex / mycred/game / Classes / myCRED_Lottery

Navigation:

  1. Description
  2. Usage
  3. Properties
  4. Methods
  5. Lottery Parameters
  6. Usage Examples

Description

The myCRED_Lottery class handles all lottery related information. This class does not save any information to your database, it only retrieves and processes lottery details in order for you to be able to present or retrieve.

This class requires a lottery post ID to work and only handles one lottery at a time.

 

 

Usage

$lottery = new myCRED_Lottery( $lottery_id );

 

Properties

  • $id (int)
    Lottery post ID.
  • $post (object)
    The lottery post object.
  • $prefs (array)
    This lotteries preferences.
  • $state (string)
    The lotteries current state.
  • $mycred (array)
    The myCRED_Settings Object.

 

Methods

  1. myCRED_Lottery()Constructs the lottery class and populates the lottery’s ID, preferences and loads the myCRED_Settings object.

  2. lottery_exists()Checks if a lottery exists and if the lottery is found, the lottery post object is populated. If this method is not called, the post object is not populated!

  3. default_prefs()This method holds the default settings for lotteries. It is mainly used internally though this class to populate preferences. It’s main job is to make sure there are no missing settings.

  4. get_prefs()Returns the current lotteries preferences.

  5. get_type()Returns the lottery type which is stored as a post meta under ‘mycred_lottery_type’.

  6. get_schedule_prefs()Returns the lottery schedule settings.

  7. get_game_prefs()Returns the lottery game settings.

  8. get_participation_prefs()Returns the lottery participation settings.

  9. get_winnings_prefs()Returns the lottery winnings settings.

  10. get_jackpot_prefs()Returns the lottery jackpot settings.

  11. get_exclude_prefs()Returns the lottery exclude settings.

  12. get_requirements_prefs()Returns the lottery requirements settings.

  13. get_templates_prefs()Returns the lottery templates.

  14. get_state()Returns the lotteries state which is stored as a post meta under ‘mycred_lottery_status’.

  15. get_title()Returns the lottery post title.

  16. get_content()Returns the lottery post content.

  17. can_play( $user_id, $entries, $repeat )Checks if a user can play this lottery. Returns a string value.

    • $user_id (int) required
      The user id to check.
    • $entries (int) required
      The number of entries this user would like to enter. Defaults to 1.
    • $repeat (int) required
      The number of repeats that the user would like play (if allowed). Defaults to 1.

    Returned string values:

    • play – User can play
    • visitor – User is not logged in
    • closed – Lottery is closed
    • excluded – User is excluded
    • req – User does not meet minimum requirements
    • max – User has reached heir maximum number of entries in this lottery
    • insolvent – User can not afford to play
  18. is_excluded( $user_id )Checks if a user is excluded from playing according to the “Exclude” preferences. Returns true or false.

    • $user_id (int)
      The user ID to check.
  19. fail_requirements( $user_id )Checks if a user fails to reach the minimum requirements for this lottery. Returns to true or false.

    • $user_id (int)
      The user ID to check.
  20. max_entry( $user_id )Checks if a user has reached the maximum entries allowed for this lottery according to the “Participation” settings.

    • $user_id (int)
      The user ID to check.
  21. is_insolvent( $user_id, $entries, $repeat )Checks if a user has enough points to play the number of entries and repeats that is requested. Returns true or false.

    • $user_id (int) required
      The user id to check.
    • $entries (int) required
      The number of entries this user would like to enter. Defaults to 1.
    • $repeat (int) required
      The number of repeats that the user would like play (if allowed). Defaults to 1.
  22. get_entries( $users )Returns either all lottery entries or all users with entries in this lottery. Returns an associative array.

    • $users (bool)
      If set to true, an array of user ids are returned else if it is set to false, an associative array of user ids and entries are returned.
  23. get_total_users_playing()Returns the number of users that are playing this lottery.

  24. get_total_entries()Returns the total number of entries in this lottery.

  25. get_users_entries( $user_id )Returns a given users entries.

    • $user_id (int)
      The user ID.
  26. count_users_entries( $user_id )Returns the number of entries a user has in this lottery.

    • $user_id (int)
      The user ID to check.
  27. get_ticket( $entry )Converts an entry string into an assosiative array containing the entries values.

    • $entry (string)
      The entry string.
  28. get_current_ticket_id()Returns the latest lottery ticket ID.

  29. get_ticket_play( $ticket_id, $play )Returns the users play in this lottery. If the lottery is a draw winner type of lottery, the lottery ID is shown while in pick number lotteries, the users played number are returned.

    • $ticket_id (int)
      The ticket ID.
    • $play (string)
      The users play.
  30. get_ticket_run( $repeat )Returns the number of days / weeks a play will run based on the lottery schedule.

    • $repeat (int)
      The number a lottery entry is repeated.
  31. get_current_jackpot()Returns the current jackpot (if used).

  32. increment_current_jackpot()Returns the jackpot amount based on the current jackpot incremented according to the “Jackpot” settings.

 

Lottery Parameters

  • id (int)
    Required Lottery Post ID.

 

Usage Examples

Example 1: Get the lottery post object and echo the publishing date.

$lottery_id = 1;
$lottery = new myCRED_Lottery( $lottery_id );
if ( $lottery->lottery_exists() ) {
	echo 'This lottery was published on: ' . $lottery->post->post_date;
}
else {
	echo 'Lottery not found.';
}

Example 2: Check if the current user can play the lottery and if they can not, show the appropriate template for why not.

$user_id = get_current_user_id();
$lottery_id = 1;
$lottery = new myCRED_Lottery( $lottery_id );
$can_play = $lottery->can_play( $user_id );
// can_play() will return the string 'play' if user can play
if ( $can_play == 'play' ) {
	// user can play
}
else {
	// user can not play so we get all templates
	$templates = $lottery->get_templates_prefs();
	echo $templates[ $can_play ];
}

About myCRED

myCRED is a free, open-source and developer friendly points management tool for WordPress powered websites.

Download Rate Plugin

Documentation

  • Add-ons
  • Core Shortcodes
  • F.A.Q.
  • Tutorials
  • Third Party Plugins
  • Code Snippets

Support

  • Product Licenses
  • Customization
  • Support Forums
  • Plugin Changelog
  • Contact

Copyright 2013 - 2019 byWPExperts; All rights reserved. myCRED is licensed under GPL 2.0

Terms & Conditions • Use of Cookies • Store Policy • Community Rules

Suggest Codex Example

You can submit suggestions for codex examples that you have available as a public gist. If you are a member on the mycred.me website, you can earn Tokens for each submission. To claim these Tokens, make sure you provide your mycred.me username.

Please make sure the example you submit is relevant and if you include documentation, it's provided in English.

  • Chapters
    • Chapter I – Introduction
    • Chapter II – Getting Started
    • Chapter III – Add-ons
    • Chapter IV – Premium Add-ons
    • Chapter V – For Developers
    • Chapter VI – Reference Guides
  • Categories
    • Actions
    • Classes
    • Constants
    • Filters
    • Functions
    • Objects
    • Shortcodes
    • Hooks
    • Template Tags
  • Packages
    • mycred/api
    • mycred/badge
    • mycred/balance
    • mycred/banking
    • mycred/content
    • mycred/core
    • mycred/coupon
    • mycred/email
    • mycred/game
    • mycred/log
    • mycred/notice
    • mycred/payment
    • mycred/purchase
    • mycred/rank
    • mycred/transfer
  • Store
  • Download