/** * Check if the event qualifies for points and award them to the user * * @param string $event * @param string $type * @param mixed $object * @return boolean */ function apply_event_rules($event, $type, $object) { // Subject $user = elgg_get_logged_in_user_entity(); if (!$user) { return true; } if ($user->isAdmin()) { return true; } // Object if (is_object($object)) { $entity = $object; } else { if (is_array($object)) { $entity = elgg_extract('entity', $object, null); if (!$entity) { $entity = elgg_extract('user', $object, null); } if (!$entity) { $entity = elgg_extract('group', $object, null); } } } if (!is_object($entity)) { // Terminate early, nothing to act upon return true; } // Get rules associated with events $rules = get_scoring_rules('events'); // Apply rules foreach ($rules as $rule_name => $rule_options) { $rule_options['name'] = $rule_name; $gmRule = gmRule::applyRule($entity, $rule_options, "{$event}::{$type}"); $errors = $gmRule->getErrors(); if ($errors) { foreach ($errors as $error) { register_error($error); } } $messages = $gmRule->getMessages(); if ($messages) { foreach ($messages as $message) { system_message($message); } } //error_log(print_r($gmRule->getLog(), true)); if ($gmRule->terminateEvent()) { return false; } } return true; }
$throttles = array('daily_max', 'daily_action_max', 'alltime_action_max', 'daily_recur_max', 'alltime_recur_max', 'object_recur_max', 'daily_object_max', 'alltime_object_max', 'action_object_max'); echo '<div class="clearfix">'; foreach ($throttles as $throttle) { echo '<div class="elgg-col elgg-col-1of2">'; echo '<div class="pam">'; echo '<label>' . elgg_echo("mechanics:settings:{$throttle}") . '</label>'; echo elgg_view('input/text', array('value' => $vars['entity']->{$throttle}, 'name' => "params[{$throttle}]")); echo '</div>'; echo '</div>'; } echo '<div class="elgg-col elgg-col-1of2">'; echo '<div class="pam">'; echo '<label>' . elgg_echo("mechanics:settings:allow_negative_total") . '</label>'; echo '<span class="elgg-text-help">' . elgg_echo('mechanics:settings:allow_negative_total:help') . '</span>'; echo elgg_view('input/dropdown', array('value' => $vars['entity']->allow_negative_total, 'name' => "params[allow_negative_total]", 'options_values' => array(true => elgg_echo('option:yes'), false => elgg_echo('option:no')))); echo '</div>'; echo '</div>'; echo '</div>'; echo '<h3>' . elgg_echo('mechanics:settings:scoring_rules') . '</h3>'; echo '<div class="elgg-text-help">' . elgg_echo('mechanics:settings:scoring_rules:help') . '</div>'; $rules = get_scoring_rules('events'); echo '<div class="clearfix">'; foreach ($rules as $rule => $options) { echo '<div class="elgg-col elgg-col-1of2">'; echo '<div class="pam">'; echo '<label>' . $options['title'] . '</label><br />'; echo elgg_view('input/text', array('value' => $vars['entity']->{$rule}, 'name' => "params[{$rule}]", 'maxlength' => '3')); echo '</div>'; echo '</div>'; } echo '</div>';
<?php namespace hypeJunction\GameMechanics; $badge_rules = elgg_extract('value', $vars, false); $options_values = array('' => elgg_echo('mechanics:select')); $system_rules = get_scoring_rules('events'); foreach ($system_rules as $rule_name => $rule_options) { if (elgg_get_plugin_setting($rule_name, PLUGIN_ID)) { $options_values[$rule_name] = $rule_options['title']; } } for ($i = 0; $i <= 9; $i++) { if ($badge_rules) { if (isset($badge_rules['name'])) { $rule = array('name' => $badge_rules['name'][$i], 'recurse' => $badge_rules['recurse'][$i], 'guid' => $badge_rules['guid'][$i]); } else { $rule = elgg_extract($i, $badge_rules, false); if (is_numeric($rule)) { $rule_entity = get_entity($rule); } else { if (elgg_instanceof($rule)) { $rule_entity = $rule; } } } } echo '<div class="clearfix">'; echo '<div class="elgg-col elgg-col-2of3">'; echo '<label>' . elgg_echo('mechanics:badges:rule') . '</label>'; echo elgg_view('input/dropdown', array('name' => 'rules[name][]', 'options_values' => $options_values, 'value' => $rule_entity ? $rule_entity->annotation_value : elgg_extract('name', $rule, '')));