| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Wizard pre-checkin help instruction. |
| 16 |
* |
| 17 |
* @since 1.18.2 (J) - 1.8.2 (WP) |
| 18 |
*/ |
| 19 |
class VBOHelpWizardDriverGeneralCronPrecheckin extends VBOHelpWizardInstructionaware |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @inheritDoc |
| 23 |
*/ |
| 24 |
public function getID() |
| 25 |
{ |
| 26 |
return 'general.cron_precheckin'; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @inheritDoc |
| 31 |
*/ |
| 32 |
public function getIcon() |
| 33 |
{ |
| 34 |
return VikBookingIcons::i('user-check'); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* @inheritDoc |
| 39 |
*/ |
| 40 |
public function getPriority() |
| 41 |
{ |
| 42 |
return 9999; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @inheritDoc |
| 47 |
*/ |
| 48 |
public function isConfigured() |
| 49 |
{ |
| 50 |
if (!VBOFactory::getConfig()->getBool('precheckinenabled')) { |
| 51 |
// pre-checkin disabled |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
// check whether a published cron job exists to collect pre-checkins |
| 56 |
return (bool) (new VBOModelCronjob)->getItem([ |
| 57 |
'class_file' => 'precheckin_reminder', |
| 58 |
'published' => 1, |
| 59 |
]); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* @inheritDoc |
| 64 |
*/ |
| 65 |
public function isProcessable(?string &$btnText = null) |
| 66 |
{ |
| 67 |
$btnText = JText::translate('VBO_SCHEDULE_CRONJOB'); |
| 68 |
|
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* @inheritDoc |
| 74 |
*/ |
| 75 |
public function process(array $args = []) |
| 76 |
{ |
| 77 |
$config = VBOFactory::getConfig(); |
| 78 |
$config->set('precheckinenabled', 1); |
| 79 |
$config->set('precheckinminoffset', 0); |
| 80 |
|
| 81 |
switch ($config->get('maincountry')) { |
| 82 |
case 'IT': |
| 83 |
$config->set('checkindata', 'italy'); |
| 84 |
break; |
| 85 |
|
| 86 |
case 'PT': |
| 87 |
$config->set('checkindata', 'portugal'); |
| 88 |
break; |
| 89 |
|
| 90 |
case 'ES': |
| 91 |
// in case of states under "Catalunya" (Barcelona, Girona, Lleida, Tarragona) use "spain" driver, otherwise fallback to ses hospedajes |
| 92 |
$config->set('checkindata', in_array($config->get('mainstate'), ['08', '17', '25', '43']) ? 'spain' : 'spainseshospedajes'); |
| 93 |
break; |
| 94 |
} |
| 95 |
|
| 96 |
$cron = (new VBOModelCronjob)->getItem([ |
| 97 |
'class_file' => 'precheckin_reminder', |
| 98 |
]); |
| 99 |
|
| 100 |
if (!$cron) { |
| 101 |
// create the cron job |
| 102 |
$cron = new stdClass; |
| 103 |
$cron->cron_name = 'Pre-Checkin Reminder'; |
| 104 |
$cron->class_file = 'precheckin_reminder'; |
| 105 |
$cron->params = [ |
| 106 |
'remindbefored' => 7, |
| 107 |
'less_days_advance' => 1, |
| 108 |
'subject' => 'Pre-Checkin Reminder', |
| 109 |
'tpl_text' => '', |
| 110 |
]; |
| 111 |
|
| 112 |
// attempt to create a new job instance |
| 113 |
$job = VBOFactory::getCronFactory()->createInstance($cron->class_file, $cron); |
| 114 |
|
| 115 |
// use the default e-mail template generated by the cron |
| 116 |
$cron->params['tpl_text'] = $job->getDefaultTemplate(); |
| 117 |
|
| 118 |
$cron->params = json_encode($cron->params); |
| 119 |
} |
| 120 |
|
| 121 |
// make sure the cron job is published |
| 122 |
$cron->published = 1; |
| 123 |
|
| 124 |
// insert or update the cron |
| 125 |
if (!(new VBOModelCronjob)->save($cron)) { |
| 126 |
throw new RuntimeException('Unable to save the pre-checkin cron!', 500); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|