Own DKP Calculation

From EQdkp Plus
Jump to: navigation, search


Custom Columns

Sometimes you want other columns be shown at pages like the point table than the default one.

Add own presets

The following content contains functions or information that are available in a future Version of EQdkp Plus.
We do not provide support for this functions or information yet. You are using this functions/information on your own risk.

One possibility is to create own presets. That means that you create a preset that uses a PDH-Readmodule method and you are adjusting the parameters of this method. For Example: You want to display the attendance of an member of 40 days (default there is 30, 60, 90 days or lifetime).

  • Go to the "Table- & Points-Management"
  • Open Tab "Custom Columns"
  • Go to section "Add custom column"
  • Select Module "member_attendance"
  • Select Tag "attendance"
  • Fill out the fields "Call params" and "Description params".

Custom preset.png

You should use placeholders for as many fields as possible. Only fields that should be static, in this case the "time_period", you should enter values. Take a look at the Variables Section for some Variables.

  • After saving your preset, you have to edit your Point-Layout and add your new preset to the desired Table using the Dropdowns.

Placeholders

Name Variables Placeholder
Member-ID $member_id  %member_id%
MultiDKP-ID $dkp_id  %dkp_id%
With Twink $with_twink, $with_twinks  %with_twink%
Event-ID $event_id  %event_id%
Adjustment-ID $adj_id, $adjustment_id  %adjustment_id%
Item-ID $item_id  %item_id%
Raid-ID $raid_id  %raid_id%

Write own Readmodule

If you want to do something that a default method cannot provide, e.g. use only 90% of EP for EPGP Calculation, you can write your own PDH-Readmodule.

In this example, we create a special attendance module.

Files and Folders

  • First, we need an name for our new module, let's take "mycustomattendance".
  • Now, create a folder named "mycustomattendance" in Folder "core/data_handler/includes/modules/read".
  • Create in your created folder a new file called "pdh_r_mycustomattendance.class.php"

Basic Read Module Structure

<?php
if ( !defined('EQDKP_INC') ){
	die('Do not access this file directly.');
}

if ( !class_exists( "pdh_r_mycustomattendance" ) ) {
	class pdh_r_mycustomattendance extends pdh_r_generic {
		public static function __shortcuts() {
			//Here you have to assign shortcuts, if you want to use $this->pdh or $this->pdc instead of register('pdh') or register('pdc')
			$shortcuts = array('pdc', 'pdh'	);
			return array_merge(parent::$shortcuts, $shortcuts);
		}
		
		
		public $default_lang = 'english';

		public $hooks = array(
		);

		public $presets = array(
		);

		public function reset(){
		}

		public function init(){
		}

	}//end class
}//end if
?>

This is the basic structure for an Readmodule. As you can see, there are no presets or calculation methods yet.

Adding a Preset

The structure for Presets looks like this:

public $presets = array(
	'mycustomattendance_30' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 30, '%with_twink%'), array(30)),
	'mycustomattendance_60' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 60, '%with_twink%'), array(60)),
	'mycustomattendance_90' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 90, '%with_twink%'), array(90)),
	'mycustomattendance_lt' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 'LT', '%with_twink%'), array('LT')),
	//Structure:
	//'UNIQUE_PRESET_ID' => array('METHOD_THAT_CREATES_THE_CONTENT', array(PARAMS_FOR_THE_METHOD), array(PARAMS_FOR_THE_CAPTION_METHOD)),
);

You should use the #Placeholders, they will be replaced through the real value.

Adding the Methods

We have the preset, but we need the method that handles the column content. The Method "mycustomattendance" has to be prefixed with "get_". Something like that:

public function get_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks=true){
	/* The Calculation is in here */
}

The Caption Method has to prefixed with "get_caption_", like that:

public function get_caption_mycustomattendance($period){
	if($period == 'LT'){
		return $this->pdh->get_lang('mycustomattendance', 'lifetime');
	}else{
		return sprintf($this->pdh->get_lang('mycustomattendance', 'attendance'), $period);
	}
}

Doing some Calculation

The Content of the calculation method depends on what you want. In this example, we need the current DKP Value and the Raidcount for the given Period.

$floatPoints = $this->pdh->get('points', 'current', array($member_id, $multidkp_id, 0, 0, $with_twinks));

The get-Method of PDH needs the following params:

  • points = The Module Name, in this case "pdh_r_points", located in "points" folder
  • current = The Method Name in this module. Without the get_ Prefix. Therefore you can only access methods prefixed with get_
  • params-Array = The Params for the Method. In this case, the get_current-Method looks like this: get_current($member_id, $multidkp_id, $event_id=0, $itempool_id=0, $with_twink=true)

Next, we get the Member Attendance and return $floatPoints / $intRaidAttendance.

public function get_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks=true){
	/* The Calculation is in here */
	
	//This calls method get_current in pdh module points
	$floatPoints = $this->pdh->get('points', 'current', array($member_id, $multidkp_id, 0, 0, $with_twinks));
	
	//This calls method get_attendace in pdh module member_attendance
	$arrAttendance = $this->pdh->get('member_attendance', 'attendance', array($member_id, $multidkp_id, $time_period, $with_twinks, true));
	
	//$arrAttendance contains total_raidcount, member_raidcount and member_attendance
	$intRaidAttendance = $arrAttendance['member_raidcount'];
	
	//This will return the column value as a float
	return ($floatPoints / $intRaidAttendance);
}

Output Formatting

To make the output look nicer, you can create a method prefixed with get_html_.

//This will format the value a bit nicer for the column
public function get_html_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks=true){
	return round($this->get_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks));
}

The html Method rounds the Value.

Module Language

We use a language Variable in the caption method. Therefore we must create a language file. Add a new subfolder called "language" to the module folder (core/data_handler/includes/modules/read/mycustomattendance/language/). In this folder, create a new php file in your language, e.g. french.php or german.php. Please add also an english.php, because English is the default fallback language.

english.php:

<?php
if ( !defined('EQDKP_INC') ){
    header('HTTP/1.0 404 Not Found');exit;
}

$module_lang = array(
	'attendance'	=> 'MyAttendance (%d days)',
	'lifetime'		=> 'MyAttendance (lifetime)',
);

$preset_lang = array(
	'mycustomattendance_30'	=> 'MyAttendance (30 days)',
	'mycustomattendance_60'	=> 'MyAttendance (60 days)',
	'mycustomattendance_90'	=> 'MyAttendance (90 days)',
	'mycustomattendance_lt'	=> 'MyAttendance (lifetime)',
);
?>

Module Lang will contain the heading for the column. Preset Lang is to identify the column at the Tablemanagement.

Whole file

The whole new readmodule looks like this:

<?php
if ( !defined('EQDKP_INC') ){
	die('Do not access this file directly.');
}

if ( !class_exists( "pdh_r_mycustomattendance" ) ) {
	class pdh_r_mycustomattendance extends pdh_r_generic {
		
		//This method is only for EQdkp Plus 1.0
		public static function __shortcuts() {
			//Here you have to assign shortcuts, if you want to use $this->pdh or $this->pdc instead of register('pdh') or register('pdc')
			$shortcuts = array('pdc', 'pdh'	);
			return array_merge(parent::$shortcuts, $shortcuts);
		}

		public $default_lang = 'english';

		public $hooks = array(
		);

		public $presets = array(
			'mycustomattendance_30' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 30, '%with_twink%'), array(30)),
			'mycustomattendance_60' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 60, '%with_twink%'), array(60)),
			'mycustomattendance_90' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 90, '%with_twink%'), array(90)),
			'mycustomattendance_lt' => array('mycustomattendance', array('%member_id%', '%dkp_id%', 'LT', '%with_twink%'), array('LT')),
			//Structure:
			//'UNIQUE_PRESET_ID' => array('METHOD_THAT_CREATES_THE_CONTENT', array(PARAMS_FOR_THE_METHOD), array(PARAMS_FOR_THE_CAPTION_METHOD)),
		);

		public function reset(){
		}

		public function init(){
		}
		
		public function get_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks=true){
			/* The Calculation is in here */
			
			//This calls method get_current in pdh module points
			$floatPoints = $this->pdh->get('points', 'current', array($member_id, $multidkp_id, 0, 0, $with_twinks));
			
			//This calls method get_attendace in pdh module member_attendance
			$arrAttendance = $this->pdh->get('member_attendance', 'attendance', array($member_id, $multidkp_id, $time_period, $with_twinks, true));
			
			//$arrAttendance contains total_raidcount, member_raidcount and member_attendance
			$intRaidAttendance = $arrAttendance['member_raidcount'];
			
			//This will return the column value as a float
			return ($floatPoints / $intRaidAttendance);
		}
		
		//This will format the value a bit nicer for the column
		public function get_html_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks=true){
			return round($this->get_mycustomattendance($member_id, $multidkp_id, $time_period, $with_twinks));
		}
	
		public function get_caption_mycustomattendance($period){
			if($period == 'LT'){
				return $this->pdh->get_lang('mycustomattendance', 'lifetime');
			}else{
				return sprintf($this->pdh->get_lang('mycustomattendance', 'attendance'), $period);
			}
		}

	}//end class
}//end if
?>