Hi all!
for my first post, i'll be a little bit talkative
i spent the last two weeks busy setting up the new site for our guild.
i am especially looking how to implement eqdkp and solving a few issues we had with the standard features, one of which is decay for multidkp.
so i went through understanding the data model, the framework (php, scripting, mysql, plugins, etc.). btw i was not helped by the example provided (hello world plugin) because it
was not working
next steps is implementing our second feature: bonus dkp for members for those who put their attendance on raidplanner
to come back to multidkp this thread was most useful so i decided to share what i did.
here is the main piece of my code for multidkp decay; it is not yet cleaned up but it is working (x% off if attendance less than 50% on the last month raids). The main idea for multidkp is to use the eqdkp class "dkpplus".
hope it will help some of you guys !
Code:
<?php
/*
* Decay aadkp
* Mortal@Voljin
*/
// EQdkp required files/vars
define('EQDKP_INC', true);
define('IN_ADMIN', true);
define('PLUGIN', 'aadkp');
$eqdkp_root_path = './../../../';
include_once ('../includes/common.php');
// Check if plugin is installed
if (!$pm->check(PLUGIN_INSTALLED, 'aadkp')) { message_die('The aadkp plugin is not installed.'); }
// Check user permission
$user->check_auth('a_aadkp');
// Get the plugin
$aadkp = $pm->get_plugin('aadkp');
//---------
global $table_prefix;
global $db, $eqdkp, $user, $tpl, $pm;
global $SID;
function gen_group_key($part1, $part2, $part3)
{
// Normalize data
$part1 = htmlspecialchars(stripslashes($part1));
$part2 = htmlspecialchars(stripslashes($part2));
$part3 = htmlspecialchars(stripslashes($part3));
// Get the first 10-11 digits of each md5 hash
$part1 = substr(md5($part1), 0, 10);
$part2 = substr(md5($part2), 0, 11);
$part3 = substr(md5($part3), 0, 11);
// Group the hashes together and create a new hash based on uniqid()
$group_key = $part1 . $part2 . $part3;
$group_key = md5(uniqid($group_key));
return $group_key;
}
// Process submit
if ($_POST['percent'] and $_POST['account']){
$percent = $_POST['percent'];
$account = $_POST['account'];
$account_id= substr($account,0,stripos($account,":"));
$account_name= substr($account,stripos($account,":")+1);
$info = "processing id=".$account."/".$account_id."(".$account_name.") with ".$percent."% decay\n";
// Calcul du nombre de raids sur le dernier mois
$start_date=mktime(0, 0, 0, date('m'), date('d')-30, date('Y'));
$end_date= time();
$raids_count = $db->query_first( "SELECT count(DISTINCT FROM_UNIXTIME(raid_date,'%y%m%d')) as raid_c FROM eqdkp_raids, eqdkp_multidkp2event WHERE (raid_date BETWEEN " . $start_date . " AND " . $end_date . ") AND multidkp2event_eventname = raid_name AND multidkp2event_multi_id=".$account_id );
$info = $info. "nb de raids:".$raids_count."\n";
// tableau des membres
$sql = "SELECT * FROM eqdkp_members m";
if ( !($result = mysql_query($sql)) ) {
message_die('Could not obtain member DKP information', '', __FILE__, __LINE__, $sql);
}
while ($row = $db->fetch_record($result)) # member row
{
// participation
$raid_count = $db->query_first( "SELECT count(DISTINCT FROM_UNIXTIME(r.raid_date,'%y%m%d')) as raid_c FROM eqdkp_raids r, eqdkp_multidkp2event, eqdkp_raid_attendees ra WHERE (r.raid_date BETWEEN " . $start_date . " AND " . $end_date . ") AND multidkp2event_eventname = r.raid_name AND multidkp2event_multi_id=".$account_id." AND ra.raid_id=r.raid_id AND ra.member_name='".$row['member_name']."'"); // or message_die(mysql_error());
$percent_of_raids = ( $raids_count > 0 ) ? round(($raid_count / $raids_count) * 100) : 100;
// $info=$info. $row['member_name'] . ":" . $percent_of_raids ."%" ;
// get multidkp
$member_multidkp = $dkpplus-> multiDkpMemberArray($row['member_name']) ; // create the multiDKP Table
if(!empty($member_multidkp[$row['member_name']]))
{
foreach ($member_multidkp[$row['member_name']] as $key) # Compte dkp
{
if ( $key['name'] == $account_name) {
$current=$key['current'];
$adjust=$key['adjust'];
// $info = $info."DKP:".$current."/adjust:".$adjust."\n";
}
}
}
// decay
if ($current > 0){
$decay = -($current * $percent / 100);
}else{
$decay = 0;
}
if ($percent_of_raids<50 and $decay<0) {
// ajustement
$adjustment_reason = "Depreciation de " . $percent . "% (participation de " .$percent_of_raids."%)";
$info = $info . $row['member_name'] . ":" . $adjustment_reason .":DKP avant=".$current."; decay=".$decay.":".$user->data['username']."\n";
$group_key = gen_group_key($time, stripslashes($adjustment_reason), $decay, $event);
$sql = "INSERT INTO eqdkp_adjustments (adjustment_value, adjustment_date, member_name, adjustment_reason, adjustment_added_by, adjustment_updated_by, adjustment_group_key, raid_name) VALUES (".$decay.", $end_date, '".$row['member_name']."', '$adjustment_reason', '".$user->data['username']."', NULL, '$group_key' , '$account_name')";
// $info = $info . $sql ."\n";
mysql_query ($sql);
$newadjust = $adjust + $decay;
$sql = "UPDATE eqdkp_members set member_adjustment = '$newadjust' WHERE member_name = '".$row['member_name']."'";
// $info = $info . $sql ."\n";
mysql_query ($sql);
}
} // end fetch
} //end submit
// comptes dkp
$sql = "SELECT * FROM " . $table_prefix . "multidkp";
if (!($settings_result = $db->query($sql))) { message_die('Pas de comptes dkp', '', __FILE__, __LINE__, $sql); }
while($roww = $db->fetch_record($settings_result)) {
$opt1 = $roww['multidkp_id'];
$opt2 = $roww['multidkp_name'];
$opt = $opt."<option value='".$opt1.":".$opt2."'>".$opt2."</option>";
}
//------------------------
//
// Populate the fields
//
$tpl->assign_vars(array(
// Form vars
'F_CONFIG' => 'admindecay.php' . $SID,
// Form values
'MESSAGE' => (isset($info) && $info!=1) ? stripmultslashes($info) : "",
'OPTIONS' => isset($opt) ? $opt : "",
// Language
'L_SUBMIT' => $user->lang['submit'],
'L_GENERAL' => "Dépreciation mensuelle",
)
);
$eqdkp->set_vars(array(
'page_title' => sprintf($user->lang['admin_title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': Dépréciation mensuelle',
'template_path' => $pm->get_data('aadkp', 'template_path'),
'template_file' => 'admin/decay.html',
'display' => true)
);
?>