Drupal: Donate userpoints to node author

×

Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseCondition::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 1652 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property MergeQuery::$condition is deprecated in MergeQuery->__construct() (line 1344 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).

This CodLet will dispay a userpoint form on node pages which allow the current user to donate some userpoints to the author of the node. This CodeLet will award the points to admin user by default.

Drupal: Donate userpoints to node author | Drupal Developer
CodeLet: 

<?php
/**
* @file
*
* Donate userpoints on a node page
*
* @author DrupalD
*
*/

/**
* usertip_get_usertip
*
* @param unknown_type $node
* @author DrupalD
*/
function usertip_get_usertip($sn__uid = NULL) {
global $user;
$form = array();
$sn__points = usertip_user_get_pionts();
$form['usertip_container'] = array(
'#type' => 'fieldset',
'#title' => t('Give Tip'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 2,
);

if ($user->uid != 1 && user_access('give points to another user') && $sn__points != 0) {
$sn__donation_tid = variable_get('userpoints_category_default_tid');
$r__result = db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $sn__donation_tid));
$os__category = $r__result->fetchObject();
$form['usertip_container']['usertip_remaining'] = array(
'#markup' => t('Your point balance is !points for !category category', array('!points' => $sn__points, '!category' => $os__category->name)),
'#weight' => -10
);

$form['usertip_container']['usertip_form'] = array(
'#markup' => drupal_render(drupal_get_form('userpoints_donation_giveform', 1, 0, NULL)),
'#weight' => -9,
);

$form['usertip_container']['usertip_doners'] = array(
'#markup' => _get_usertip_donors(),
'#wieght' => -8,
);
}
else {
$form['usertip_container']['tip_warning'] = array(
'#markup' => t('Either you do not have privilege to tip or your point balance is low.')
);
}

return drupal_render($form);
}

/**
* Implementation of hook_form_alter
*
* @param unknown_type $form
* @param unknown_type $form_state
* @param unknown_type $form_id
* @author DrupalD
*/
function usertip_form_alter(&$form, $form_state, $form_id) {
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'jquery.form');
include_once('includes/ajax.inc');

if ($form_id == 'userpoints_donation_giveform') {
$form_state['build_info']['base_form_id'] = str_replace('-', '_', 'userpoints-donation-giveform');
$form['to']['#type'] = 'hidden';
$form['amount']['#type'] = 'select';
$form['amount']['#size'] = 1;
$form['amount']['#prefix'] = "";
$form['amount']['#suffix'] = "";
$form['amount']['#options'] = array(
0 => t('Select amount'),
5 => 5,
10 => 10,
25 => 25,
50 => 50,
100 => 100,
);

$form['submit']['#attributes'] = array('class' => array('use-ajax-submit'));
$form['submit']['#value'] = t('tip');
$form['submit']['#prefix'] = "";
$form['submit']['#suffix'] = "";
$form['reason']['#type'] = 'hidden';
$form['reason']['#default_value'] = t('Video');
unset($form['tid']);
}
}

/**
* Implementation of hook_block_info
*
* @author DrupalD
*/
function usertip_block_info() {
$block['usertip'] = array(
'info' => t('Give tip'),
'cache' => DRUPAL_NO_CACHE,
);
return $block;
}

/**
* Implementation of hook_block_view
*
* @param unknown_type $delta
* @author DrupalD
*/
function usertip_block_view($delta = '') {
switch ($delta) {
case 'usertip':
$block['subject'] = t('Give tip');
$block['content'] = usertip_get_usertip();
break;
}
return $block;
}

/**
* _get_usertip_donors
*
* Return faces of usertip donors
*
* @author DrupalD
*/
function _get_usertip_donors() {
global $user;
$output = "";
$r__result = db_select('userpoints_txn', 'utn');
$r__result->leftjoin('users', 'u', 'utn.uid = u.uid');
$r__result->fields('utn', array('points'))
->fields('u', array('picture', 'name', 'uid'))
->condition('utn.operation', 'userpoints_donation_given', '=')
->condition('utn.entity_type', 'user', '=')
->condition('utn.entity_id', 1, '=')
->orderby ('utn.time_stamp', 'DESC')
->range(0, 5);
$am__user = $r__result->execute();
while ($am__user_record = $am__user->fetchAssoc()) {
if ($am__user_record['picture']) {
$r__image = db_select('file_managed', 'fm');
$r__image->leftjoin('users', 'u', 'fm.fid = u.picture');
$r__image->fields('fm', array('uri'))
->condition('fm.fid', $am__user_record['picture'], '=');
$as__image = $r__image->execute()->fetchAssoc();
$ss__user = ($am__user_record['name'] == $user->name) ? t('You') : $am__user_record['name'];
$ss__alt_title = t('@name has dondated @points tip', array('@name' => $ss__user, '@points' => abs($am__user_record['points'])));
$am__variable = array(
'path' => $as__image['uri'],
'width' => '16px',
'height' => '16px',
'alt' => $ss__alt_title,
'title' => $ss__alt_title,
);
$ss__image = theme('image', $am__variable);
$output .= "". l($ss__image, "user/". $am__user_record['uid'], array('html' => TRUE)) ."";
}
}
return $output ."";
}

/**
* usertip_user_get_pionts
*
* @author DrupalD
*/
function usertip_user_get_pionts() {
global $user;
$sn__donation_tid = variable_get('userpoints_category_default_tid');
$r__result = db_select('userpoints', 'up');
$r__result->fields('up', array('points'))
->condition('up.uid', $user->uid, '=');
$am__points = $r__result->execute();
$om__balance = $am__points->fetchAll();
if (isset($om__balance[0]->points)) {
return $om__balance[0]->points;
}
else {
return 0;
}
}
?>

Compatibility: 
Is CodeLet useful?: 
Drupal: Donate userpoints to node author | Drupal Developer

Error

The website encountered an unexpected error. Please try again later.