Commit 322d1338 authored by Michael Iseard's avatar Michael Iseard
Browse files

Huge update, too many changes

parent 648721a8
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JSCodeStyleSettings version="0">
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
</JSCodeStyleSettings>
<PHPCodeStyleSettings>
<option name="ALIGN_KEY_VALUE_PAIRS" value="true" />
<option name="ALIGN_ASSIGNMENTS" value="true" />
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
<option name="PHPDOC_BLANK_LINES_AROUND_PARAMETERS" value="true" />
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
<option name="ELSE_IF_STYLE" value="COMBINE" />
<option name="VARIABLE_NAMING_STYLE" value="SNAKE_CASE" />
<option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="SPACES_AROUND_VAR_WITHIN_BRACKETS" value="true" />
<option name="SPACE_BEFORE_UNARY_NOT" value="true" />
<option name="SPACE_AFTER_UNARY_NOT" value="true" />
</PHPCodeStyleSettings>
<codeStyleSettings language="PHP">
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
<option name="BLANK_LINES_AFTER_PACKAGE" value="1" />
<option name="CLASS_BRACE_STYLE" value="1" />
<option name="METHOD_BRACE_STYLE" value="1" />
<option name="SPECIAL_ELSE_IF_TREATMENT" value="true" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="SPACE_AROUND_UNARY_OPERATOR" value="true" />
<option name="SPACE_WITHIN_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_METHOD_CALL_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_METHOD_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_IF_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_WHILE_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_FOR_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_CATCH_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_SWITCH_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ComposerJsonPluginSettings">
<unboundedVersionInspectionSettings>
<excludedPackages />
</unboundedVersionInspectionSettings>
<customRepositories />
<composerUpdateOptions />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@localhost" uuid="5b552640-805c-491c-8773-0d6facb35bea">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306</jdbc-url>
</data-source>
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="michael">
<words>
<w>atts</w>
<w>axios</w>
<w>dompdf</w>
<w>webhook</w>
<w>wpdb</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JSXNamespaceValidation" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/guzzle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/promises" />
<excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/psr7" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mollie/mollie-api-php" />
<excludeFolder url="file://$MODULE_DIR$/vendor/monolog/monolog" />
<excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/random_compat" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phenx/php-font-lib" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phenx/php-svg-lib" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-message" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sabberworm/php-css-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-idn" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php70" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
<excludeFolder url="file://$MODULE_DIR$/vendor/twig/twig" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="JSX" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/kudos-donations.iml" filepath="$PROJECT_DIR$/.idea/kudos-donations.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" />
<path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" />
<path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" />
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
<path value="$PROJECT_DIR$/vendor/mollie/mollie-api-php" />
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
<path value="$PROJECT_DIR$/vendor/psr/log" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/monolog/monolog" />
<path value="$PROJECT_DIR$/vendor/twig/twig" />
<path value="$PROJECT_DIR$/vendor/phenx/php-font-lib" />
<path value="$PROJECT_DIR$/vendor/phenx/php-svg-lib" />
<path value="$PROJECT_DIR$/vendor/dompdf/dompdf" />
<path value="$PROJECT_DIR$/vendor/sabberworm/php-css-parser" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
<path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/includes/entity/class-kudos-transaction.php" dialect="GenericSQL" />
<file url="PROJECT" dialect="MySQL" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Symfony2PluginSettings">
<option name="dismissEnableNotification" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions" suppressed-tasks="SCSS" />
</project>
\ No newline at end of file
<?php
namespace Kudos;
namespace Kudos\Table;
use Kudos\Entity\Transaction;
use WP_List_Table;
use Kudos\Table_Trait;
use Kudos\Entity\Donor;
class Donors_Table extends WP_List_Table {
class Donors extends WP_List_Table {
use Table_Trait;
/**
* @var array
*/
private $export_columns;
/**
* Class constructor
*
......@@ -15,8 +23,17 @@ class Donors_Table extends WP_List_Table {
*/
public function __construct() {
$this->export_columns = [
'name' => __('Name', 'kudos-donations'),
'email' => __('Email', 'kudos-donations'),
'street' => __('Street', 'kudos-donations'),
'postcode' => __('Postcode', 'kudos-donations'),
'city' => __('City', 'kudos-donations'),
'country' => __('Country', 'kudos-donations'),
];
parent::__construct( [
'table' => Kudos_Donor::getTableName(),
'table' => Donor::getTableName(),
'orderBy' => 'donor_created',
'singular' => __( 'Donor', 'kudos-donations' ),
'plural' => __( 'Donors', 'kudos-donations' ),
......@@ -68,54 +85,7 @@ class Donors_Table extends WP_List_Table {
);
}
$subscription = new Kudos_Donor();
return $subscription->get_table_data($search_custom_vars);
}
/**
* Column name translations used in export
*
* @param array $rows
* @return array
* @since 2.0.0
*/
public function export_column_names($rows) {
// Set header names
$headers = [];
foreach (array_keys($rows[0]) as $header) {
switch ($header) {
case 'donor_created':
$result = __('Date', 'kudos-donations');
break;
case 'name':
$result = __('Name', 'kudos-donations');
break;
case 'email':
$result = __('Email', 'kudos-donations');
break;
case 'value':
$result = __('Amount', 'kudos-donations');
break;
case 'status':
$result = __('Status', 'kudos-donations');
break;
case 'frequency':
$result = __('Frequency', 'kudos-donations');
break;
case 'mode':
$result = __('Mode', 'kudos-donations');
break;
case 'currency':
$result = __('Currency', 'kudos-donations');
break;
default:
$result = ucfirst($header);
}
array_push($headers, $result);
}
return $headers;
return Donor::get_table_data($search_custom_vars);
}
/**
......@@ -242,17 +212,29 @@ class Donors_Table extends WP_List_Table {
*/
function column_donations( $item ) {
$kudos_transaction = new Kudos_Transaction();
$transactions = $kudos_transaction->get_all_by(['customer_id' => $item['customer_id']]);
// $donor = new Donor();
// $donor->get_by(['customer_id' => $item['customer_id']]);
// $transactions = $donor->get_transactions();
$transaction = new Transaction();
$transactions = $transaction->get_all(['customer_id' => $item['customer_id']]);
if($transactions) {
$number = count($transactions);
$total = 0;
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$total = $total + $transaction->value;
if($transaction->fields['status'] === 'paid') {
$refunds = $transaction->get_refunds();
if ( $refunds ) {
$total = $total + $refunds['remaining'];
} else {
$total = $total + $transaction->fields['value'];
}
}
}
return '<a href="'. admin_url('admin.php?page=kudos-transactions&customer_id='. urlencode($item['customer_id']) .'') .'">' . $number . ' ( ' . get_currency_symbol($transactions[0]->currency) . $total . ' )' . '</a>';
return '<a href="'. admin_url('admin.php?page=kudos-transactions&customer_id='. urlencode($item['customer_id']) .'') .'">' . $number . ' ( ' . get_currency_symbol($transactions[0]->fields['currency']) . $total . ' )' . '</a>';
}
return false;
......
......@@ -2,6 +2,9 @@
namespace Kudos;
use Kudos\Table\Donors;
use Kudos\Table\Subscriptions;
use Kudos\Table\Transactions;
use WP_REST_Server;
/**
......@@ -257,17 +260,17 @@ class Kudos_Admin {
public function admin_actions() {
if(isset($_REQUEST['export_transactions'])) {
$table = new Transactions_Table();
$table = new Transactions();
$table->export();
}
if(isset($_REQUEST['export_subscriptions'])) {
$table = new Subscriptions_Table();
$table = new Subscriptions();
$table->export();
}
if(isset($_REQUEST['export_donors'])) {
$table = new Donors_Table();
$table = new Donors();
$table->export();
}
......
<?php
namespace Kudos;
namespace Kudos\Table;
use Kudos\Kudos_Mollie;
use WP_List_Table;
use Kudos\Table_Trait;
use Kudos\Entity\Subscription;
class Subscriptions_Table extends WP_List_Table {
class Subscriptions extends WP_List_Table {
use Table_Trait;
/**
* @var array
*/
private $export_columns;
/**
* Class constructor
*
......@@ -15,8 +23,19 @@ class Subscriptions_Table extends WP_List_Table {
*/
public function __construct() {
$this->export_columns = [
'subscription_created' => __('Date', 'kudos-donations'),
'name' => __('Name', 'kudos-donations'),
'email' => __('Email', 'kudos-donations'),
'value' => __('Amount', 'kudos-donations'),
'status' => __('Status', 'kudos-donations'),
'frequency' => __('Frequency', 'kudos-donations'),
'years' => __('Years', 'kudos-donations'),
'currency' => __('Currency', 'kudos-donations'),
];
parent::__construct( [
'table' => Kudos_Subscription::getTableName(),
'table' => Subscription::getTableName(),
'orderBy' => 'subscription_created',
'singular' => __( 'Subscription', 'kudos-donations' ),
'plural' => __( 'Subscriptions', 'kudos-donations' ),
......@@ -78,54 +97,7 @@ class Subscriptions_Table extends WP_List_Table {
);
}
$subscription = new Kudos_Subscription();
return $subscription->get_table_data($search_custom_vars);
}
/**
* Column name translations used in export
*
* @param array $rows
* @return array
* @since 2.0.0
*/
public function export_column_names($rows) {
// Set header names
$headers = [];
foreach (array_keys($rows[0]) as $header) {
switch ($header) {
case 'subscription_created':
$result = __('Date', 'kudos-donations');
break;
case 'name':
$result = __('Name', 'kudos-donations');
break;
case 'email':
$result = __('Email', 'kudos-donations');
break;
case 'value':
$result = __('Amount', 'kudos-donations');
break;
case 'status':
$result = __('Status', 'kudos-donations');
break;
case 'frequency':
$result = __('Frequency', 'kudos-donations');
break;
case 'mode':
$result = __('Mode', 'kudos-donations');
break;
case 'currency':
$result = __('Currency', 'kudos-donations');
break;
default:
$result = ucfirst($header);
}
array_push($headers, $result);
}
return $headers;
return Subscription::get_table_data($search_custom_vars);
}
/**
......@@ -348,8 +320,10 @@ class Subscriptions_Table extends WP_List_Table {
public static function cancel_subscription( $subscription_id ) {
$kudos_mollie = new Kudos_Mollie();
$kudos_mollie->cancel_subscription($subscription_id);
if($kudos_mollie->cancel_subscription($subscription_id)) {
return true;
}
return false;
}
/**
......
<?php
namespace Kudos;
namespace Kudos\Table;
use WP_List_Table;
use Kudos\Kudos_Invoice;
use Kudos\Table_Trait;
use Kudos\Entity\Transaction;
class Transactions_Table extends WP_List_Table {
class Transactions extends WP_List_Table {
use Table_Trait {
delete_record as trait_delete;
}
/**
* @var Kudos_Invoice
* @var string[]
*/
private $invoice;
private $export_columns;
/**
* Class constructor
......@@ -22,10 +25,23 @@ class Transactions_Table extends WP_List_Table {
*/
public function __construct() {
$this->invoice = new Kudos_Invoice();
add_filter('table_export_row', [$this, 'modify_export_data']);
$this->export_columns = [
'transaction_created' => __('Transaction created', 'kudos-donations'),
'currency' => __('Currency', 'kudos-donations'),
'value' => __('Amount', 'kudos-donations'),
'refunds' => __('Refunded', 'kudos-donations'),
'status' => __('Status', 'kudos-donations'),
'name' => __('Name', 'kudos-donations'),
'email' => __('Email', 'kudos-donations'),
'method' => __('Method', 'kudos-donations'),
'mode' => __('Mode', 'kudos-donations'),
'sequence_type' => __('Type', 'kudos-donations'),
];
parent::__construct( [
'table' => Kudos_Transaction::getTableName(),
'table' => Transaction::getTableName(),
'orderBy' => 'transaction_created',
'singular' => __( 'Transaction', 'kudos-donations' ), //singular name of the listed records
'plural' => __( 'Transactions', 'kudos-donations' ), //plural name of the listed records
......@@ -34,6 +50,22 @@ class Transactions_Table extends WP_List_Table {
}
/**
* Filter used to modify the exported data
*
* @param $row
* @return mixed
* @since 2.0.0
*/
function modify_export_data( $row ) {
if(is_serialized($row['refunds'])) {
$refunds = unserialize($row['refunds']);
$refunded = $refunds['refunded'];
$row['refunds'] = $refunded;
}
return $row;
}
/**
* Add extra markup in the toolbars before or after the list
*
......@@ -100,8 +132,7 @@ class Transactions_Table extends WP_List_Table {
$search_custom_vars = 'WHERE ' . implode(' AND ', $query);
}
$transaction = new Kudos_Transaction();
return $transaction->get_table_data($search_custom_vars);
return Transaction::get_table_data($search_custom_vars);
}
/**
......@@ -116,9 +147,10 @@ class Transactions_Table extends WP_List_Table {
// Set header names
$headers = [];
foreach (array_keys($rows[0]) as $header) {
switch ($header) {
case 'transaction_created':
$result = __('Date Added', 'kudos-donations');
$result = __('Transaction created', 'kudos-donations');
break;
case 'name':
$result = __('Name', 'kudos-donations');
......@@ -144,6 +176,9 @@ class Transactions_Table extends WP_List_Table {
case 'sequenceType':
$result = __('Type', 'kudos-donations');
break;
case 'refunds':
$result = __('Refunded', 'kudos-donations');
break;