Skip to content

Commit

Permalink
Added #75 Promotion Requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven committed Dec 5, 2015
1 parent 723bced commit ff65c78
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
4 changes: 3 additions & 1 deletion inc/languages/english/admin/config_thankyoulike.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@

$l['tyl_uninstall'] = 'Thank You/Like System - Uninstallation';
$l['tyl_uninstall_message'] = 'Do you wish to drop all plugin data entries from the database?';
?>

$l['setting_thankyoulike_promotion'] = 'ThankYou/Like Count';
$l['setting_thankyoulike_promotion_desc'] = 'Enter the number of thankyou/likes required. ThankYou/Like count must be selected as a required value for this to be included. Select the type of comparison for thankyou/likes.';
87 changes: 87 additions & 0 deletions inc/plugins/thankyoulike.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
$plugins->add_hook("admin_config_settings_change","thankyoulike_settings_page");
$plugins->add_hook("admin_page_output_footer","thankyoulike_settings_peeker");

// Start ThankYou/Like Promotions Hooks
if(defined("IN_ADMINCP"))
{
$plugins->add_hook('admin_formcontainer_output_row', 'thankyoulike_promotion_formcontainer_output_row');
$plugins->add_hook('admin_user_group_promotions_edit_commit', 'thankyoulike_promotion_commit');
$plugins->add_hook('admin_user_group_promotions_add_commit', 'thankyoulike_promotion_commit');
}
$plugins->add_hook('task_promotions', 'thankyoulike_promotion_task');
// End ThankYou/Like Promotions Hooks

function thankyoulike_info()
{
global $plugins_cache, $mybb, $db, $lang, $cache;
Expand Down Expand Up @@ -228,6 +238,15 @@ function thankyoulike_install()

$db->insert_query($prefix."stats", $total_data);
}
// Add ThankYou/Like Promotions Tables Fields
if(!$db->field_exists("thankyoulike", "promotions"))
{
$db->add_column("promotions", "thankyoulike", "int NOT NULL default '0'");
}
if(!$db->field_exists("thankyouliketype", "promotions"))
{
$db->add_column("promotions", "thankyouliketype", "char(2) NOT NULL default ''");
}

// Insert Template elements
$templateset = array(
Expand Down Expand Up @@ -650,6 +669,15 @@ function thankyoulike_uninstall()
{
$db->drop_table($prefix.'stats');
}
// Remove ThankYou/Like Promotions Tables Fields
if($db->field_exists("thankyoulike", "promotions"))
{
$db->drop_column("promotions", "thankyoulike");
}
if($db->field_exists("thankyouliketype", "promotions"))
{
$db->drop_column("promotions", "thankyouliketype");
}
}
}

Expand Down Expand Up @@ -1689,3 +1717,62 @@ function load'.$prefix.'Peekers(){
}
</script>';
}

// Start ThankYou/Like Promotions Functions
function thankyoulike_promotion_formcontainer_output_row(&$args)
{
global $run_module, $form_container, $mybb, $db, $lang, $form, $options, $options_type, $promotion;

if(!($run_module == 'user' && !empty($form_container->_title) && $mybb->get_input('module') == 'user-group_promotions' && in_array($mybb->get_input('action'), array('add', 'edit'))))
{
return;
}

$lang->load('config_thankyoulike');

if($args['label_for'] == 'requirements')
{
$options['thankyoulike'] = $lang->setting_thankyoulike_promotion;
$args['content'] = $form->generate_select_box('requirements[]', $options, $mybb->input['requirements'], array('id' => 'requirements', 'multiple' => true, 'size' => 5));
}

if($args['label_for'] == 'timeregistered')
{
if($mybb->get_input('pid', 1) && !isset($mybb->input['thankyoulike']))
{
$thankyoulike = $promotion['thankyoulike'];
$thankyouliketype = $promotion['thankyouliketype'];
}
else
{
$thankyoulike = $mybb->get_input('thankyoulike');
$thankyouliketype = $mybb->get_input('thankyouliketype');
}

$form_container->output_row($lang->setting_thankyoulike_promotion, $lang->setting_thankyoulike_promotion_desc, $form->generate_numeric_field('thankyoulike', (int)$thankyoulike, array('id' => 'thankyoulike'))." ".$form->generate_select_box("thankyouliketype", $options_type, $thankyouliketype, array('id' => 'thankyouliketype')), 'thankyoulike');
}
}

function thankyoulike_promotion_commit()
{
global $db, $mybb, $pid, $update_promotion, $pid;

is_array($update_promotion) or $update_promotion = array();

$update_promotion['thankyoulike'] = $mybb->get_input('thankyoulike', 1);
$update_promotion['thankyouliketype'] = $db->escape_string($mybb->get_input('thankyouliketype'));

if($mybb->get_input('action') == 'add')
{
$db->update_query('promotions', $update_promotion, "pid='{$pid}'");
}
}

function thankyoulike_promotion_task(&$args)
{
if(in_array('thankyoulike', explode(',', $args['promotion']['requirements'])) && (int)$args['promotion']['thankyoulike'] >= 0 && !empty($args['promotion']['thankyouliketype']))
{
$args['sql_where'] .= "{$args['and']}tyl_unumrcvtyls{$args['promotion']['thankyouliketype']}'{$args['promotion']['thankyoulike']}'";
$args['and'] = ' AND ';
}
}

0 comments on commit ff65c78

Please sign in to comment.