Skip to content

Commit

Permalink
move license logic
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Sep 26, 2024
1 parent fc5e40c commit 63078e0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 62 deletions.
26 changes: 0 additions & 26 deletions classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

class NM_PersonalizedProduct_Admin extends NM_PersonalizedProduct {

public const LICENSE_PLAN_FREE = -1;
public const LICENSE_PLAN_1 = 1; // Essential.
public const LICENSE_PLAN_2 = 2; // Plus.
public const LICENSE_PLAN_3 = 3; // VIP.

var $menu_pages, $plugin_scripts_admin, $plugin_settings;

Expand Down Expand Up @@ -819,28 +815,6 @@ public function load_admin_menu() {
PPOM_Survey::get_instance()->init();
}

/**
* Get the license category (Essential, Plus, VIP).
*
* @param number Plan ID.
*
* @return number The associated category.
*/
public static function get_license_category( $license_plan ) {
$license_categories = array(
self::LICENSE_PLAN_1 => array( 1, 4, 9 ),
self::LICENSE_PLAN_2 => array( 2, 5, 8 ),
self::LICENSE_PLAN_3 => array( 3, 6, 7, 10 ),
);

foreach ( $license_categories as $category => $plans ) {
if ( in_array( $license_plan, $plans ) ) {
return $category;
}
}

return self::LICENSE_PLAN_FREE;
}

/**
* Set legacy user flag.
Expand Down
32 changes: 29 additions & 3 deletions classes/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class NM_PersonalizedProduct {

public const LICENSE_PLAN_FREE = -1;
public const LICENSE_PLAN_1 = 1; // Essential.
public const LICENSE_PLAN_2 = 2; // Plus.
public const LICENSE_PLAN_3 = 3; // VIP.
static $tbl_productmeta = 'nm_personalized';


Expand Down Expand Up @@ -987,6 +991,28 @@ public function show_tooltip( $description, $meta ) {
return $description;
}

/**
* Get the license category (Essential, Plus, VIP).
*
* @param number Plan ID.
*
* @return number The associated category.
*/
public static function get_license_category( $license_plan ) {
$license_categories = array(
self::LICENSE_PLAN_1 => array( 1, 4, 9 ),
self::LICENSE_PLAN_2 => array( 2, 5, 8 ),
self::LICENSE_PLAN_3 => array( 3, 6, 7, 10 ),
);

foreach ( $license_categories as $category => $plans ) {
if ( in_array( $license_plan, $plans ) ) {
return $category;
}
}

return self::LICENSE_PLAN_FREE;
}
/**
* Method to return the type of licence.
*
Expand All @@ -1005,11 +1031,11 @@ public function is_license_of_type( $type ) {
$plan = intval( $plan );
switch ( $type ) {
case 'vip':
return NM_PersonalizedProduct_Admin::get_license_category( $plan ) === 3;
return self::get_license_category( $plan ) === 3;
case 'plus':
return NM_PersonalizedProduct_Admin::get_license_category( $plan ) === 2;
return self::get_license_category( $plan ) === 2;
case 'pro':
return NM_PersonalizedProduct_Admin::get_license_category( $plan ) === 1;
return self::get_license_category( $plan ) === 1;
}

return false;
Expand Down
66 changes: 33 additions & 33 deletions templates/admin/ppom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
$product_id = isset( $_GET['product_id'] ) ? intval( $_GET['product_id'] ) : '';

$license_data = get_option( 'ppom_pro_license_data', array() );
$plan_category = NM_PersonalizedProduct_Admin::LICENSE_PLAN_FREE;
$plan_category = NM_PersonalizedProduct::LICENSE_PLAN_FREE;
$is_pro_installed = ppom_pro_is_installed();
$license_status = $is_pro_installed && ! empty( $license_data->license ) ? $license_data->license : 'invalid';

if ( $is_pro_installed && isset( $license_data->plan ) && is_numeric( $license_data->plan ) ) {
$plan_category = NM_PersonalizedProduct_Admin::get_license_category( intval( $license_data->plan ) );
$plan_category = NM_PersonalizedProduct::get_license_category( intval( $license_data->plan ) );
}

$fields_groups = [
Expand Down Expand Up @@ -105,7 +105,7 @@
'slug' => 'phone',
'title' => __( 'Phone Input', 'woocommerce-product-addon' ),
'description' => __( 'Simple Phone field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-check',
]
]
Expand Down Expand Up @@ -135,21 +135,21 @@
'slug' => 'switcher',
'title' => __( 'Radio Switcher', 'woocommerce-product-addon' ),
'description' => __( 'Radio button switcher', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-dot-circle-o',
],
[
'slug' => 'superlist',
'title' => __( 'Super List', 'woocommerce-product-addon' ),
'description' => __( 'Advanced list input', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-check',
],
[
'slug' => 'chained',
'title' => __( 'Chained Input', 'woocommerce-product-addon' ),
'description' => __( 'Linked dropdown selections where choices in one field depend on previous selections.', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-check',
],
]
Expand All @@ -162,56 +162,56 @@
'slug' => 'file',
'title' => __( 'File Input', 'woocommerce-product-addon' ),
'description' => __( 'File upload field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-file',
],
[
'slug' => 'emojis',
'title' => __( 'Emojis', 'woocommerce-product-addon' ),
'description' => __( 'Emoji picker for input fields', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-user-plus',
],
[
'slug' => 'conditional_meta',
'title' => __( 'Conditional Images', 'woocommerce-product-addon' ),
'description' => __( 'Images that change based on input conditions', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-picture-o',
],
[
'slug' => 'image',
'title' => __( 'Images', 'woocommerce-product-addon' ),
'description' => __( 'Select images.', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-picture-o',
],
[
'slug' => 'imageselect',
'title' => __( 'Image DropDown', 'woocommerce-product-addon' ),
'description' => __( 'Dropdown with image selections', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-file-image-o',
],
[
'slug' => 'audio',
'title' => __( 'Audio / Video', 'woocommerce-product-addon' ),
'description' => __( 'Audio and video input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-file-video-o',
],
[
'slug' => 'cropper',
'title' => __( 'Image Cropper', 'woocommerce-product-addon' ),
'description' => __( 'Image cropping tool', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-crop',
],
[
'slug' => 'texter',
'title' => __( 'Personalization Preview', 'woocommerce-product-addon' ),
'description' => __( 'Preview for personalized products', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-keyboard-o',
]
]
Expand All @@ -229,73 +229,73 @@
'slug' => 'timezone',
'title' => __( 'Timezone Input', 'woocommerce-product-addon' ),
'description' => __( 'Timezone selector for input fields', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-clock-o',
],

[
'slug' => 'daterange',
'title' => __( 'DateRange Input', 'woocommerce-product-addon' ),
'description' => __( 'Date range input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-table',
],
[
'slug' => 'section',
'title' => __( 'HTML', 'woocommerce-product-addon' ),
'description' => __( 'Custom HTML input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-code',
],

[
'slug' => 'color',
'title' => __( 'Color Picker', 'woocommerce-product-addon' ),
'description' => __( 'Color picker input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-modx',
],
[
'slug' => 'palettes',
'title' => __( 'Color Palettes', 'woocommerce-product-addon' ),
'description' => __( 'Color palette selection', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-user-plus',
],
[
'slug' => 'fonts',
'title' => __( 'Fonts Picker', 'woocommerce-product-addon' ),
'description' => __( 'Font selection tool', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-font',
],

[
'slug' => 'domain',
'title' => __( 'Domain', 'woocommerce-product-addon' ),
'description' => __( 'Domain input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_3,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_3,
'icon' => 'fa-server',
],
[
'slug' => 'textcounter',
'title' => __( 'Text Counter', 'woocommerce-product-addon' ),
'description' => __( 'Character count for input fields', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-comments-o',
],
[
'slug' => 'collapse',
'title' => __( 'Collapse', 'woocommerce-product-addon' ),
'description' => __( 'Group and toggle other input fields within a collapsible section, helping to organize long forms more efficiently.', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-money',
],
[
'slug' => 'divider',
'title' => __( 'Divider', 'woocommerce-product-addon' ),
'description' => __( 'Add a visual separator.', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-pencil-square-o',
]
]
Expand All @@ -307,63 +307,63 @@
'slug' => 'fixedprice',
'title' => __( 'Fixed Price', 'woocommerce-product-addon' ),
'description' => __( 'Fixed pricing options', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-money',
],
[
'slug' => 'quantities',
'title' => __( 'Variation Quantity ', 'woocommerce-product-addon' ),
'description' => __( 'Quantity selection with options', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_2,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_2,
'icon' => 'fa-list-ol',
],
[
'slug' => 'pricematrix',
'title' => __( 'Price Matrix', 'woocommerce-product-addon' ),
'description' => __( 'Matrix-based pricing', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-usd',
],
[
'slug' => 'qtypack',
'title' => __( 'Quantities Pack', 'woocommerce-product-addon' ),
'description' => __( 'Pack-based quantity options', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-list-alt',
],
[
'slug' => 'vqmatrix',
'title' => __( 'Variation Matrix', 'woocommerce-product-addon' ),
'description' => __( 'Quantity selector for variations', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_3,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_3,
'icon' => 'fa-list-ol',
],
[
'slug' => 'measure',
'title' => __( 'Measure Input', 'woocommerce-product-addon' ),
'description' => __( 'Measurement input field', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-building-o',
],
[
'slug' => 'quantityoption',
'title' => __( 'Quantity Option', 'woocommerce-product-addon' ),
'description' => __( 'Quantity selection options', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-money',
],
[
'slug' => 'bulkquantity',
'title' => __( 'Bulk Quantity', 'woocommerce-product-addon' ),
'description' => __( 'Bulk quantity selection for products', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-columns',
],
[
'slug' => 'selectqty',
'title' => __( 'Select Option Quantity', 'woocommerce-product-addon' ),
'description' => __( 'Select option\'s quantity', 'woocommerce-product-addon' ),
'plan' => NM_PersonalizedProduct_Admin::LICENSE_PLAN_1,
'plan' => NM_PersonalizedProduct::LICENSE_PLAN_1,
'icon' => 'fa-list-ol',
],
]
Expand Down

0 comments on commit 63078e0

Please sign in to comment.