/* * Borrar puntos * Option 2: listado de usuarios con puntos (expertos) */ if (elgg_is_active_plugin('elggx_userpoints')) { $options_count = array('type' => 'user', 'limit' => false, 'count' => true, 'order_by_metadata' => array('name' => 'userpoints_points', 'direction' => DESC, 'as' => integer)); $options_count['metadata_name_value_pairs'] = array(array('name' => 'userpoints_points', 'value' => -10, 'operand' => '>')); $count = elgg_get_entities_from_metadata($options_count); $options = array('type' => 'user', 'limit' => $limit, 'offset' => $offset); //, 'order_by_metadata' => array('name' => 'userpoints_points', 'direction' => DESC, 'as' => integer)); //$options['metadata_name_value_pairs'] = array(array('name' => 'userpoints_points', 'value' => -10, 'operand' => '>'));no solo los que tienen puntos... todos $experts = elgg_get_entities_from_metadata($options); foreach ($experts as $entity) { $points = -$entity->userpoints_points; $description = elgg_echo('evaluationcontent:reset_all:description') . $entity->username; $userpoint = userpoints_add($entity->guid, $points, $description); $user = get_user($entity->guid); $user->nValorations = 0; $user->expertise = 0; //system_message($user->nValorations . " reset " . $user->username); $user->karma = elgg_echo('hflts:karma:none'); /* hard core erasing is plausible too $prefix = elgg_get_config('dbprefix'); delete_data("DELETE from {$prefix}metadata where name_id=" . add_metastring('userpoints_points')); */ } } /* * Borrar evaluaciones */ $list = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => 'evaluation_content', 'order_by_metadata' => ['name' => 'state', 'direction' => 'ASC', 'as' => 'text']]);
function delete_assessment($entity_guid) { $evaluation = get_entity($entity_guid); $user = get_entity($evaluation->user_guid); if ($evaluation->state == "archived") { //system_message($user->username . " was assessed by " . $evaluation->owner_guid . " (nValorations " . $user->nValorations .")"); //drop owner points if the evaluation granted one if (elgg_is_active_plugin('elggx_userpoints')) { $points = -1; $description = $points . elgg_echo('evaluationcontent:point'); userpoints_add($evaluation->owner_guid, $points, $description, 'admin'); } //update user nValorations if ($user->nValorations > 0) { $user->nValorations = $user->nValorations - 1; } //karma should be also updated } //drop grade if (!elgg_trigger_plugin_hook('evaluationcontent:delete', 'system', array('evaluation' => $evaluation), true)) { register_error(elgg_echo("evaluationcontent:notdeleted")); } if (!$evaluation->delete()) { register_error(elgg_echo("evaluationcontent:notdeleted")); } }
/** * Hooks on the invitefriends/invite action and either awards * points for the invite or sets up a pending userpoint record * where points can be awarded when the invited user registers. */ function elggx_userpoints_invite() { if (!($points = elgg_get_plugin_setting('invite', 'elggx_userpoints'))) { return; } $emails = get_input('emails'); $emails = explode("\n", $emails); if (sizeof($emails)) { foreach ($emails as $email) { $email = trim($email); if (get_user_by_email($email)) { continue; } if (elgg_get_plugin_setting('verify_email', 'elggx_userpoints') && !elggx_userpoints_validEmail($email)) { continue; } if ((int) elgg_get_plugin_setting('require_registration', 'elggx_userpoints')) { if (!elggx_userpoints_invite_status(elgg_get_logged_in_user_guid(), $email)) { $userpoint = userpoints_add_pending(elgg_get_logged_in_user_guid(), $points, $email, 'invite'); if (elgg_is_active_plugin('expirationdate') && ($expire = (int) elgg_get_plugin_setting('expire_invite', 'elggx_userpoints'))) { $ts = time() + $expire; expirationdate_set($userpoint->guid, date('Y-m-d H:i:s', $ts), false); } } } else { if (!elggx_userpoints_invite_status(elgg_get_logged_in_user_guid(), $email)) { userpoints_add(elgg_get_logged_in_user_guid(), $points, $email, 'invite'); $userpoint = userpoints_add_pending(elgg_get_logged_in_user_guid(), 0, $email, 'invite'); if (elgg_is_active_plugin('expirationdate') && ($expire = (int) elgg_get_plugin_setting('expire_invite', 'elggx_userpoints'))) { $ts = time() + $expire; expirationdate_set($userpoint->guid, date('Y-m-d H:i:s', $ts), false); } } } } } }
$fail(); } $autoArchive = elgg_get_plugin_setting('auto_moderation', 'hflts'); //esto lo quiero implementar con una llamada al action archive, pero por lo pronto asi (un action se lanza desde botón) if ($autoArchive) { /* * se premiará con 1 punto al usuario que realiza la valoracion usando el plugin userpoints (+badgets) * TO DO el numero de puntos puede ser configurable */ if (elgg_is_active_plugin('elggx_userpoints')) { $points = 1; $notify = "Se otorga un punto a " . $evaluation->owner . " por la evaluación realizada a " . $evaluation->name . " relativa al viaje " . $evaluation->trip; //system_message($notify); $description = elgg_echo('evaluationcontent:pointtaken') . $points . elgg_echo('evaluationcontent:point'); /* $user = get_user_by_username('strem'); userpoints_add($user->guid, $points, $description, 'admin');*/ userpoints_add($evaluation->owner_guid, $points, $description, 'admin'); } //Registro del numero de valoraciones $user = get_entity($evaluation->user_guid); if (!$user->nValorations) { $user->karma = 0; $user->nValorations = 0; } $user->nValorations = $user->nValorations + 1; // change the state $evaluation->state = "archived"; system_message(elgg_echo("evaluationcontent:archived")); // allow another plugin to override if (!elgg_trigger_plugin_hook('evaluationcontent:archive', 'system', ['evaluation' => $evaluation], true)) { register_error(elgg_echo("evaluationcontent:notarchived")); forward(REFERER);
<?php /** * Gain userpoints for hours worked - a skeletal plugin that might need to get customized according to your needs. * * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author iionly * @copyright iionly */ // get the form input $params = get_input('params'); $hours_worked = $params['hours_worked']; $description = $params['description']; //get GUID and name of user who has entered the hours of revisions $user_guid = elgg_get_logged_in_user_guid(); $username = elgg_get_logged_in_user_entity()->name; if (function_exists('userpoints_add')) { // Add userpoints $userpoints_balance = $hours_worked * USERPOINTS_PER_HOUR; if ($description == '') { $description = elgg_echo('userpoints_balance:no_description', array($username)); } $success = userpoints_add($user_guid, $userpoints_balance, 'Userpoint Balance: ' . $description); if ($success) { system_message(elgg_echo('userpoints_balance:pointsuccess', array($userpoints_balance, $hours_worked))); } else { register_error(elgg_echo('userpoints_balance:pointfail')); } } forward(REFERER);
<?php $params = get_input('params'); $user = get_user_by_username($params['username']); userpoints_add($user->guid, $params['points'], $params['description'], 'admin'); system_message(elgg_echo("elggx_userpoints:add:success", array($params['points'], elgg_echo('elggx_userpoints:lowerplural'), $params['username']))); forward(REFERER);