| 1 |
<?php |
| 2 |
namespace LWS\WOOREWARDS; |
| 3 |
|
| 4 |
// don't call the file directly |
| 5 |
if( !defined( 'ABSPATH' ) ) exit(); |
| 6 |
|
| 7 |
/** satic class to manage activation and version updates. */ |
| 8 |
class Wizard extends \LWS\Adminpanel\Wizard |
| 9 |
{ |
| 10 |
protected $subWizard = null; |
| 11 |
protected $color = null; |
| 12 |
|
| 13 |
protected function getColor() |
| 14 |
{ |
| 15 |
if (null === $this->color) { |
| 16 |
$this->color = '#f54f33'; |
| 17 |
} |
| 18 |
return $this->color; |
| 19 |
} |
| 20 |
|
| 21 |
protected function getLogoURL() |
| 22 |
{ |
| 23 |
return LWS_WOOREWARDS_IMG . '/icon-wr.png'; |
| 24 |
} |
| 25 |
|
| 26 |
protected function getTitle() |
| 27 |
{ |
| 28 |
return __("Loyalty System Setup", 'woorewards-lite'); |
| 29 |
} |
| 30 |
|
| 31 |
/** @return object a i_wizard implementation instance or false if user selected none. */ |
| 32 |
protected function getOrCreateWizard() |
| 33 |
{ |
| 34 |
if (null === $this->subWizard) |
| 35 |
{ |
| 36 |
$this->subWizard = false; |
| 37 |
$data = $this->getData(); |
| 38 |
$exists = false; |
| 39 |
$choice = $this->getDataValue($data, 'wchoice', false, $exists); |
| 40 |
if (!$choice) { |
| 41 |
$choice = 'standard'; |
| 42 |
$exists = true; |
| 43 |
} |
| 44 |
if( $exists ) |
| 45 |
{ |
| 46 |
$this->subWizard = $this->instanciateWizard($choice); |
| 47 |
if( !$this->subWizard ) |
| 48 |
{ |
| 49 |
if (defined('WP_DEBUG') && WP_DEBUG) error_log("Unknown wizard: ".$choice); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 50 |
$this->resetData(); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
return $this->subWizard; |
| 55 |
} |
| 56 |
|
| 57 |
/** wizard file must be lower case in wizards subdir. |
| 58 |
* wizard class must implement i_wizard |
| 59 |
* wizard classname must be first letter upper case (and only first letter, not camelCase) */ |
| 60 |
protected function instanciateWizard($choice) |
| 61 |
{ |
| 62 |
$choice = strtolower(\sanitize_key($choice)); // sanitize remove any ../ changedir |
| 63 |
$path = LWS_WOOREWARDS_INCLUDES . "/wizards/{$choice}.php"; |
| 64 |
if( \file_exists($path) ) |
| 65 |
{ |
| 66 |
$classname = '\LWS\WOOREWARDS\Wizards\\'.\ucfirst($choice); |
| 67 |
include_once($path); |
| 68 |
return new $classname($this); |
| 69 |
} |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
protected function getHierarchy() |
| 74 |
{ |
| 75 |
$hierarchy = array( |
| 76 |
//'choice', |
| 77 |
'ini', /// that faky step is required to avoid 'choice' being the last, since last step display submit button instead of next button. |
| 78 |
); |
| 79 |
if( $wiz = $this->getOrCreateWizard() ) |
| 80 |
{ |
| 81 |
// first step must be named 'ini' too |
| 82 |
$hierarchy = $wiz->getHierarchy(); |
| 83 |
//$hierarchy = array_merge(array('choice'), $wiz->getHierarchy()); |
| 84 |
} |
| 85 |
return $hierarchy; |
| 86 |
} |
| 87 |
|
| 88 |
protected function getStepTitle($slug) |
| 89 |
{ |
| 90 |
$title = $slug; |
| 91 |
if( $slug == 'choice' ) |
| 92 |
$title = __("Choose a Wizard", 'woorewards-lite'); |
| 93 |
else if( $wiz = $this->getOrCreateWizard() ) |
| 94 |
$title = $wiz->getStepTitle($slug); |
| 95 |
else if( $slug == 'ini' ) |
| 96 |
$title = __("Settings…", 'woorewards-lite'); |
| 97 |
return $title; |
| 98 |
} |
| 99 |
|
| 100 |
protected function getPage($slug, $mode='') |
| 101 |
{ |
| 102 |
if( $slug != 'choice' && ($wiz = $this->getOrCreateWizard()) ) |
| 103 |
{ |
| 104 |
return $wiz->getPage($slug, $mode); |
| 105 |
} |
| 106 |
else |
| 107 |
{ |
| 108 |
\wp_enqueue_script('wizard-choice', LWS_WOOREWARDS_JS.'/wizard-choice.js', array('jquery'), LWS_WOOREWARDS_VERSION, true); |
| 109 |
return $this->getChoicePage($mode); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
function isValid($step, &$submit) |
| 114 |
{ |
| 115 |
if( $step != 'choice' && ($wiz = $this->getOrCreateWizard()) ) |
| 116 |
return $wiz->isValid($step, $submit); |
| 117 |
return true; |
| 118 |
} |
| 119 |
|
| 120 |
protected function getChoicePage($mode='') |
| 121 |
{ |
| 122 |
return array( |
| 123 |
'groups' => array( |
| 124 |
'wchoice' => array( |
| 125 |
'class' => 'large', |
| 126 |
'fields' => array( |
| 127 |
'wchoice' => array( |
| 128 |
'id' => 'wchoice', |
| 129 |
'title' => '', |
| 130 |
'type' => 'radiogrid', // radiogrid is specific to the wizard |
| 131 |
'extra' => array( |
| 132 |
'type' => 'wizard-choice', |
| 133 |
'source' => array( |
| 134 |
array( |
| 135 |
'value'=>'standard', |
| 136 |
'image' => LWS_WOOREWARDS_IMG . '/standard_system.png', |
| 137 |
'color' => '#526981', |
| 138 |
'label' => __("Standard System", 'woorewards-lite'), |
| 139 |
'descr' => __("The standard system is the most common loyalty system available. Users earn points by performing various actions. When they have enough points, they can unlock rewards such as discount coupons.", 'woorewards-lite'), |
| 140 |
), |
| 141 |
array( |
| 142 |
'value'=>'leveling', |
| 143 |
'image' => LWS_WOOREWARDS_IMG . '/leveling_system.png', |
| 144 |
'color' => '#999999', |
| 145 |
'pro-color' => '#16b9ba', |
| 146 |
'label' => __("Leveling System", 'woorewards-lite'), |
| 147 |
'descr' => __("Leveling systems works differently than standard systems. Users earn points by performing various actions. But they don't spend their points. Instead, they reach different levels and unlock all rewards set at a level when they have enough points.", 'woorewards-lite'), |
| 148 |
'pro-only' => 'yes', |
| 149 |
), |
| 150 |
array( |
| 151 |
'value'=>'event', |
| 152 |
'image' => LWS_WOOREWARDS_IMG . '/events.png', |
| 153 |
'color' => '#999999', |
| 154 |
'pro-color' => '#ff9a4c', |
| 155 |
'label' => __("Special Events", 'woorewards-lite'), |
| 156 |
'descr' => __("Use the special events wizard to create temporary loyalty programs for various occasions. This wizard proposes scenarios for the following events :", 'woorewards-lite')."<br/>". |
| 157 |
"<div class='lws-wizard-desc-grid'>". |
| 158 |
"<ul><li>".__("Black Friday", 'woorewards-lite')."</li>". |
| 159 |
"<li>" . __("Christmas", 'woorewards-lite') . "</li>" . |
| 160 |
"<li>" . __("Easter", 'woorewards-lite') . "</li></ul></div>", |
| 161 |
'pro-only' => 'yes', |
| 162 |
), |
| 163 |
array( |
| 164 |
'value'=>'double', |
| 165 |
'image' => LWS_WOOREWARDS_IMG . '/double_points.png', |
| 166 |
'color' => '#999999', |
| 167 |
'pro-color' => '#6e96b5', |
| 168 |
'label' => __("Double Points", 'woorewards-lite'), |
| 169 |
'descr' => __("Create a special event and allow customers to earn twice the points for a limited period of time. You can also choose to allow users with a special role to earn twice the points. Or both.", 'woorewards-lite'), |
| 170 |
'pro-only' => 'yes', |
| 171 |
), |
| 172 |
array( |
| 173 |
'value'=>'sponsorship', |
| 174 |
'image' => LWS_WOOREWARDS_IMG.'/sponsorship.png', |
| 175 |
'color' => '#999999', |
| 176 |
'pro-color' => '#59515c', |
| 177 |
'label' => __("Referrals", 'woorewards-lite'), |
| 178 |
'descr' => __("Add a points and rewards system that rewards customers for referring new people on your website. Referees also receive a reward to encourage them to subscribe and buy on your website.", 'woorewards-lite'), |
| 179 |
'pro-only' => 'yes', |
| 180 |
), |
| 181 |
array( |
| 182 |
'value'=>'anniversary', |
| 183 |
'image' => LWS_WOOREWARDS_IMG.'/anniversary.png', |
| 184 |
'color' => '#999999', |
| 185 |
'pro-color' => '#a4255b', |
| 186 |
'label' => __("Customer Birthday or Registration Anniversary", 'woorewards-lite'), |
| 187 |
'descr' => __("Celebrate your customers birthday or registration anniversary by sending them a discount coupon on that occasion. Really easy to set up and very appreciated by customers.", 'woorewards-lite'), |
| 188 |
'pro-only' => 'yes', |
| 189 |
), |
| 190 |
), |
| 191 |
) |
| 192 |
) |
| 193 |
) |
| 194 |
) |
| 195 |
) |
| 196 |
); |
| 197 |
} |
| 198 |
|
| 199 |
/** Instanciate pools, events, unlockables, etc. */ |
| 200 |
protected function submit(&$data) |
| 201 |
{ |
| 202 |
if( $wiz = $this->getOrCreateWizard() ) |
| 203 |
return $wiz->submit($data); |
| 204 |
|
| 205 |
if (defined('WP_DEBUG') && WP_DEBUG) error_log("Do some magic!"); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 206 |
return false; |
| 207 |
} |
| 208 |
} |
| 209 |
|