<commit_before><?php

class WmmsPayment {
	
	var $UserId;
	var $TransactionId;
	var $Date;
	var $PaymentItemId;
	var $TaggedFor;
	
	//__construct($userId, $transactionId, $date, $paymentType, $taggedFor);
	function __construct() {
		$args = func_get_args();
		$this->UserId = $args[0];
		$this->TransactionId = $args[1];
		$this->Date = $args[2];
		$this->PaymentItemId = $args[3];
		$this->TaggedFor = $args[4];
	}
	
	function saveToDb() {
		require_once('../db/payment_items.php');
		require_once('payment_items.php');
		require_once('payment_types.php');
		$paymentItem = db_GetPaymentItemById($this->PaymentItemId);
		UpdatePaidThroughDateForUser($this->UserId, $paymentItem['itemType']);
		
		require_once('../db/transaction.php');
		db_AddTransaction($this->UserId, $this->TransactionId, $this->Date, $this->PaymentItemId, $this->TaggedFor);
	}
	
	private function UpdatePaidThroughDateForUser($userId, $itemType) {
		if($itemId != PaymentTypes::MembershipMonthly && $itemId != PaymentTypes::MembershipYearly) {
			return;
		}
		$memberData = new WmmsMember($userId);
		$date = date("Y-m-d");
		
		if($date > $memberData->PaidThroughDate) { //If membership had lapsed or not started, begin from today.
			$memberData->PaidThroughDate = $date;
		}
		if($itemType == PaymentTypes::MembershipMonthly) {
			$date = date_add($memberData->PaidThroughDate, date_interval_create_from_date_string("1 month"));
		}
		if($itemType == PaymentTypes::MembershipYearly) {
			$date = date_add($memberData->PaidThroughDate, date_interval_create_from_date_string("1 year"));
		}
		$memberData->PaidThroughDate = $date;
		$memberData->saveToDb();
	}
}


class WmmsPriceOverride {
	var $ItemId;
	var $ItemPrice;
	var $GoodThrough;
	var $ItemName;
	var $UserId;
	
	//__construct($ItemId, $ItemPrice, $GoodThrough, $UserId);
	function __construct() {
		$args = func_get_arg();
		$this->ItemId = $args[0];
		$this->ItemPrice = $args[1];
		$this->GoodThrough = $args[2];
		$this->UserId = $args[3];
	}<commit_msg>Fixed lapsed membership grace period<commit_after><?php

class WmmsPayment {
	
	var $UserId;
	var $TransactionId;
	var $Date;
	var $PaymentItemId;
	var $TaggedFor;
	
	//__construct($userId, $transactionId, $date, $paymentType, $taggedFor);
	function __construct() {
		$args = func_get_args();
		$this->UserId = $args[0];
		$this->TransactionId = $args[1];
		$this->Date = $args[2];
		$this->PaymentItemId = $args[3];
		$this->TaggedFor = $args[4];
	}
	
	function saveToDb() {
		require_once('../db/payment_items.php');
		require_once('payment_items.php');
		require_once('payment_types.php');
		$paymentItem = db_GetPaymentItemById($this->PaymentItemId);
		UpdatePaidThroughDateForUser($this->UserId, $paymentItem['itemType']);
		
		require_once('../db/transaction.php');
		db_AddTransaction($this->UserId, $this->TransactionId, $this->Date, $this->PaymentItemId, $this->TaggedFor);
	}
	
	private function UpdatePaidThroughDateForUser($userId, $itemType) {
		if($itemId != PaymentTypes::MembershipMonthly && $itemId != PaymentTypes::MembershipYearly) {
			return;
		}
		$memberData = new WmmsMember($userId);
		$date = date("Y-m-d");
		
		if(date_add($date, date_interval_create_from_date_string("7 days")) > $memberData->PaidThroughDate) { 
			//If membership has lapsed or not started, begin from today.
			$memberData->PaidThroughDate = $date;
		}
		if($itemType == PaymentTypes::MembershipMonthly) {
			$date = date_add($memberData->PaidThroughDate, date_interval_create_from_date_string("1 month"));
		}
		if($itemType == PaymentTypes::MembershipYearly) {
			$date = date_add($memberData->PaidThroughDate, date_interval_create_from_date_string("1 year"));
		}
		$memberData->PaidThroughDate = $date;
		$memberData->saveToDb();
	}
}


class WmmsPriceOverride {
	var $ItemId;
	var $ItemPrice;
	var $GoodThrough;
	var $ItemName;
	var $UserId;
	
	//__construct($ItemId, $ItemPrice, $GoodThrough, $UserId);
	function __construct() {
		$args = func_get_arg();
		$this->ItemId = $args[0];
		$this->ItemPrice = $args[1];
		$this->GoodThrough = $args[2];
		$this->UserId = $args[3];
	}
{'fraction_non_alphanumeric': 0.16658488714425906, 'fraction_numerical': 0.005642787046123651, 'mean_word_length': 5.380281690140845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3189261', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1437, 'n_words': 242}