WordPress.org

Ready to get started?Download WordPress

Forums

CubePoints
for events manager (18 posts)

  1. mp3_dinle
    Member
    Posted 1 year ago #

    is it possible to modify cubepoints for evets manager plugin

    if user booking any event get point?

    http://wordpress.org/extend/plugins/cubepoints/

  2. Gabriel
    Member
    Posted 1 year ago #

    Of course. The best thing about CubePoints is that you can add your own modules to it allowing you to hook into most plugins. Have a look at the existing modules in CubePoints and see if you can create a new one that hooks into your desired plugin.

  3. mp3_dinle
    Member
    Posted 1 year ago #

    yes i looked them but i could not found about events manager plugin

    For example
    if member join any event get points
    if member maybe join event get half points
    not join get minus points :)

    And also user can rate events and locations

  4. Gabriel
    Member
    Posted 1 year ago #

    None of the modules that comes with CubePoints can accomplish this by default. You would need to make a custom module that hooks into your plugin. If you can post the link to the plugin you are using I could have a look and see if we can make you a custom module.

  5. mp3_dinle
    Member
    Posted 1 year ago #

  6. Gabriel
    Member
    Posted 1 year ago #

    Ok so I made you a very simple module that will award points when a booking is "Approved" and remove these points if an already "Approved" booking is changed to cancelled or rejected (or any other status).

    If you feel comfortable with PHP it shouldn't be hard to add further features like when a user is "Maybe" joining etc.

    Please note that I have not used this plugin before today so I do not know how you can have a "maybe joining" feature.

    Installation:
    1. Create a file and name it event_manager.php
    2. Copy the code bellow into this file and save.
    3. Upload to wp-content/plugins/cubepoints/modules/ folder
    4. Activate the "Event Points" module just as you do with any other module
    5. Under "Config" set how many points a user gets for a booking and save.
    Done.

    <?php
    /** Event Manager Module */
    cp_module_register( __( 'Event Points' ) , 'eventpoints' , '1.0', 'dbm', 'http://www.merovingi.com', 'http://www.merovingi.com' , __( 'This module lets you award points for interacting with the Event Manager Plugin' ), 1 );
    /**
     * Add Setting when installing
     */
    add_action( 'cp_module_eventpoints_activate', 'cp_module_eventpoints_install' );
    function cp_module_eventpoints_install(){
    	add_option( 'cp_module_eventpoints_join', 10 );
    }
    
    if ( cp_module_activated( 'eventpoints' ) ) {
    	/**
    	 * Module Config
    	 */
    	add_action( 'cp_config_form', 'cp_module_eventpoints_config' );
    	function cp_module_eventpoints_config()
    	{ ?>
    		<br />
    		<h3><?php _e( 'Event Manager' ); ?></h3>
    		<table class="form-table">
    
    			<tr valign="top">
    				<th scope="row"><label for="cp_module_eventpoints_join"><?php _e( 'Points for Attending Event' ); ?>:</label></th>
    				<td valign="middle"><input type="text" id="cp_module_eventpoints_join" name="cp_module_eventpoints_join" value="<?php echo get_option( 'cp_module_eventpoints_join' ); ?>" size="30" /></td>
    			</tr>
    
    		</table>
    	<?php
    	}
    
    	/**
    	 * Save Points Settings
    	 */
    	add_action( 'cp_config_process', 'cp_module_eventpoints_config_process' );
    	function cp_module_eventpoints_config_process()
    	{
    		$cp_module_eventpoints_join = (int) $_POST['cp_module_eventpoints_join'];
    
    		update_option( 'cp_module_eventpoints_join', $cp_module_eventpoints_join );
    	}
    
    	/**
    	 * Adjust CubePoints Log Descriptions
    	 */
    	add_action( 'cp_logs_description', 'cp_admin_logs_desc_eventpoints', 10, 4 );
    	function cp_admin_logs_desc_eventpoints( $type, $uid, $points, $data )
    	{
    		if ( $type != 'eventpoints' ) { return; }
    
    		$data = unserialize( $data );
    		$post = get_post( $data['event_id'] );
    		$user = get_user_by('id', $uid );
    		if ( $data['action'] == 'join' )
    			echo  'Awarded points for attending <a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>.';
    		elseif ( $data['action'] == 'remove' )
    			echo 'Removed points due to booking changed from "Approved".';
    	}
    
    	/**
    	 * Add Booking
    	 * If bookings gets automatically approved we add points using this filter.
    	 */
    	add_filter( 'em_bookings_add', 'cp_module_eventpoints_hook_add', 10, 2 );
    	function cp_module_eventpoints_hook_add( $result, $booking )
    	{
    		// If bookings get automatically approved and booking was successfully added, add points
    		if ( get_option( 'dbem_bookings_approval' ) == 0 && $result === true ) {
    
    			$points_for_joining = get_option( 'cp_module_eventpoints_join' );
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'join' );
    			cp_points( 'eventpoints', $booking->person_id, $points_for_joining, serialize($data) );
    
    		}
    
    		return $result;
    	}
    	/**
    	 * Approve Booking
    	 * If bookings gets approved by admin we add points using this filter.
    	 */
    	add_filter( 'em_booking_set_status', 'cp_module_eventpoints_hook_set_status', 10, 2 );
    	function cp_module_eventpoints_hook_set_status( $result, $booking )
    	{
    		$points_for_joining = get_option( 'cp_module_eventpoints_join' );
    
    		// If the new status is 'approved', add points
    		if ( $booking->booking_status == 1 && $booking->previous_status != 1 ) {
    
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'join' );
    			cp_points( 'eventpoints', $booking->person_id, $points_for_joining, serialize($data) );
    
    		}
    		// Else if status got changed from previously 'approved', remove points given
    		elseif ( $booking->booking_status != 1 && $booking->previous_status == 1 ) {
    
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'remove' );
    			cp_points( 'eventpoints', $booking->person_id, 0-$points_for_joining, serialize($data) );
    
    		}
    
    		return $result;
    	}
    }
    ?>
  7. hkairsoftpo
    Member
    Posted 1 year ago #

    Hi Gabriel,

    I'm also looking for integration with events manager, while this should work for booking an event, I was wondering if you could help make something that works for also creating an event. Currently I have events set up as posts, but creating an event does not assign points for some reason - maybe it needs to be a custom post? I saw your reply to another person regarding custom posts but I'm not much of a coder so don't know how to make sense of it: http://www.wpquestions.com/question/show/id/2756

    Would highly appreciate your help!

    Thanks

  8. Gabriel
    Member
    Posted 1 year ago #

    For CubePoints to give points for Published posts the following has to be met:

    - The Post has not received points before. (if you publish a post, get points and later make it a draft and then re-publish, the second time you will not get points).
    - More then zero points must be granted when publishing points.

    If you are publishing a private post you will not get points it seems. You will find the hook that awards points in cp_hooks.php on line 75.

  9. vulneratum
    Member
    Posted 1 year ago #

    Is there a way to award points to users submitting events (in the default manner)?

  10. Blindacme
    Member
    Posted 1 year ago #

    Hi Gabriel, you are a saint for going out of your way to provide the snippet above.

    I would like to modify your snippet above so that if someone says they are attending the event then they would be deducted the amount of points for attending an event (could vary)..

    Im stuck because it seems your website has been down and I have been continuously trying it for the past week, although I know what happened to it, I hope you get back online soon but with all of that being said I cant find anything anywhere on how to actually "spend" your points because it all takes me to your forum which is currently down.

    How can I set up the above to deduct points if a user decides to attend an event and where could I define the amount of points it costs for each event?

    I am fairly comfortable with PHP so any direction would be nice since I cant seem to get on your site to find out how the spending mechanism works.

    Thanks in advance

  11. Gabriel
    Member
    Posted 1 year ago #

    Hey Blindacme.

    Not sure what you mean with the website being down. For the record CubePoints is not my plugin, it's just a plugin I have a lot of experience with.

    I have included bellow the code modified to deduct points.
    Furthermore I changed it so it will first see if the post (event) has a custom post meta called "cubepoints_cost". If it does, that amount is deducted / refunded. If not, the default settings under "Config" is used instead.

    If you set a positive number under "Config", it will automatically change this into a negative value but you should be able to save a negative value under Config.

    <?php
    /** Event Manager Module */
    cp_module_register( __( 'Event Points' ) , 'eventpoints' , '1.0', 'dbm', 'http://www.merovingi.com', 'http://www.merovingi.com' , __( 'This module lets you award points for interacting with the Event Manager Plugin' ), 1 );
    /**
     * Add Setting when installing
     */
    add_action( 'cp_module_eventpoints_activate', 'cp_module_eventpoints_install' );
    function cp_module_eventpoints_install(){
    	add_option( 'cp_module_eventpoints_join', 10 );
    }
    
    if ( cp_module_activated( 'eventpoints' ) ) {
    	/**
    	 * Module Config
    	 */
    	add_action( 'cp_config_form', 'cp_module_eventpoints_config' );
    	function cp_module_eventpoints_config()
    	{ ?>
    		<br />
    		<h3><?php _e( 'Event Manager' ); ?></h3>
    		<table class="form-table">
    
    			<tr valign="top">
    				<th scope="row"><label for="cp_module_eventpoints_join"><?php _e( 'Points for Attending Event' ); ?>:</label></th>
    				<td valign="middle"><input type="text" id="cp_module_eventpoints_join" name="cp_module_eventpoints_join" value="<?php echo get_option( 'cp_module_eventpoints_join' ); ?>" size="30" /></td>
    			</tr>
    
    		</table>
    	<?php
    	}
    
    	/**
    	 * Save Points Settings
    	 */
    	add_action( 'cp_config_process', 'cp_module_eventpoints_config_process' );
    	function cp_module_eventpoints_config_process()
    	{
    		$cp_module_eventpoints_join = (int) $_POST['cp_module_eventpoints_join'];
    
    		update_option( 'cp_module_eventpoints_join', $cp_module_eventpoints_join );
    	}
    
    	/**
    	 * Adjust CubePoints Log Descriptions
    	 */
    	add_action( 'cp_logs_description', 'cp_admin_logs_desc_eventpoints', 10, 4 );
    	function cp_admin_logs_desc_eventpoints( $type, $uid, $points, $data )
    	{
    		if ( $type != 'eventpoints' ) { return; }
    
    		$data = unserialize( $data );
    		$post = get_post( $data['event_id'] );
    		$user = get_user_by('id', $uid );
    		if ( $data['action'] == 'join' )
    			echo  'Awarded points for attending <a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>.';
    		elseif ( $data['action'] == 'remove' )
    			echo 'Removed points due to booking changed from "Approved".';
    	}
    
    	/**
    	 * Add Booking
    	 * If bookings gets automatically approved we add points using this filter.
    	 */
    	add_filter( 'em_bookings_add', 'cp_module_eventpoints_hook_add', 10, 2 );
    	function cp_module_eventpoints_hook_add( $result, $booking )
    	{
    		// If bookings get automatically approved and booking was successfully added, add points
    		if ( get_option( 'dbem_bookings_approval' ) == 0 && $result === true ) {
    
    			// If a custom post meta is set use that cost.
    			$custom_cost = get_post_meta( $booking->event->post_id, 'cubepoints_cost', true );
    			if ( empty( $custom_cost ) )
    				$custom_cost = get_option( 'cp_module_eventpoints_join' );
    
    			// Make sure it is a negative number since we want to deduct
    			if ( $custom_cost > 0 )
    				$custom_cost = '-' . $custom_cost;
    
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'join' );
    			cp_points( 'eventpoints', $booking->person_id, $custom_cost, serialize( $data ) );
    
    		}
    
    		return $result;
    	}
    	/**
    	 * Approve Booking
    	 * If bookings gets approved by admin we add points using this filter.
    	 */
    	add_filter( 'em_booking_set_status', 'cp_module_eventpoints_hook_set_status', 10, 2 );
    	function cp_module_eventpoints_hook_set_status( $result, $booking )
    	{
    		// If a custom post meta is set use that cost.
    		$cost = get_post_meta( $booking->event->post_id, 'cubepoints_cost', true );
    		if ( empty( $cost ) )
    			$cost = get_option( 'cp_module_eventpoints_join' );
    
    		// If the new status is 'approved', add points
    		if ( $booking->booking_status == 1 && $booking->previous_status != 1 ) {
    
    			// Make sure it is a negative number since we want to deduct
    			if ( $cost > 0 ) $cost = '-' . $cost;
    
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'join' );
    			cp_points( 'eventpoints', $booking->person_id, $cost, serialize( $data ) );
    
    		}
    		// Else if status got changed from previously 'approved', remove points given
    		elseif ( $booking->booking_status != 1 && $booking->previous_status == 1 ) {
    
    			// Make sure the value is positive to refund
    			$cost = abs( $cost );
    
    			$data = array( 'event_id' => $booking->event->post_id, 'action' => 'remove' );
    			cp_points( 'eventpoints', $booking->person_id, $cost, serialize( $data ) );
    
    		}
    
    		return $result;
    	}
    }
    ?>
  12. Blindacme
    Member
    Posted 1 year ago #

    Thanks, I just noticed you were not the original developer, which makes you even more awesome for helping so many people out with this, but yes - their site has been down for awhile and I just got cubepoints and was not able to find anything on deducting points.

    Thanks for your help I will work with it and see if I get it working for my needs..

    BTW kudos on your site man, Looks great! love the design

  13. Blindacme
    Member
    Posted 1 year ago #

    Gabriel, may I pick your brain for just one more thing? I was told I should use the em_booking_get_price filter similar to the one below.. I just dont know how I could easily incorporate this into the module so that I dont have to use custom fields but things are kind of automatic.

    I figured with your experience with cubepoints this could be an easy question for you to answer and I really, really appreciate all the help your giving as I start to understand things.

    Here is a sample filter -

    function my_em_booking_get_price($content){
                    $content .= "Hello!";
            return $content;
    }
    add_filter('em_booking_get_price','my_em_booking_get_price');

    Here is another example of the filter I found online just in case it helps -

    function my_em_booking_price($format = false, $EM_Booking){
     $discount = 1; //no discount
     if( $EM_Booking->booking_spaces > 2 ){
            $discount = 0.75; //25% discount
     }
     $price = $EM_Ticket->price * $discount;
     if($format){
            return em_get_currency_symbol().number_format($price,2);
     }
     return $price;
    }
    add_action('em_booking_get_price', 'my_em_booking_price', 10, 2);
  14. Gabriel
    Member
    Posted 1 year ago #

    So what exactly are you looking for? Do you want to deduct the amount an event costs?

  15. evalesco
    Member
    Posted 11 months ago #

    This is so awesome. It is EXACTLY what I am looking for (using cubepoints to pay for events). You are a saint!

    Thanks Gabriel!

  16. evalesco
    Member
    Posted 11 months ago #

    Although, all of the sudden it stopped working. I think it happened after the last Buddypress update. When I purchase something using Cubepoints points are no longer deducted. Can you make any sense of this? Thanks!

  17. iheartwine
    Member
    Posted 9 months ago #

    Gabriel, what is the best solution to set how many points user should get for attending a particular event? I mean sort of a custom field (input) during event adding, where admin can set different values for different events. Similiar to above solution, user should get points for attandance, or give them back if booking is cancelled?

    Actually I'm trying to change a bit "events" to "tasks" that are associated with date, and each task that user will take apart should be rewarded - those points I want to display in user page.

    many thanks in advance!

  18. Gabriel
    Member
    Posted 9 months ago #

    @iheartwine Save your value as a custom post meta for each event. Then hook in to Event Manager and award points when they attend and deduct points if they cancel.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.