Done !
| Server IP : 46.105.57.169 / Your IP : 216.73.217.35 Web Server : Apache System : Linux webm002.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : verseaumee ( 152031) PHP Version : 8.5.7 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/verseaumee/ptitsanes/plugins/extension/solidres/ |
Upload File : |
<?php
/**
------------------------------------------------------------------------
SOLIDRES - Accommodation booking extension for Joomla
------------------------------------------------------------------------
* @author Solidres Team <contact@solidres.com>
* @website https://www.solidres.com
* @copyright Copyright (C) 2013 - 2019 Solidres. All Rights Reserved.
* @license GNU General Public License version 3, or later
------------------------------------------------------------------------
*/
defined('_JEXEC') or die;
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_solidres/models', 'SolidresModel');
/**
* Solidres Extension Plugin
*
* @package Solidres
* @subpackage Extension.Plugin
* @since 1.5
*/
class plgExtensionSolidres extends JPlugin
{
protected $autoloadLanguage = true;
/**
* The confirmation reservation status
*
* @var int
*/
private $confirmationState;
/**
* Constructor
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'group', 'params', 'language'
* (this list is not meant to be comprehensive).
*
* @since 1.5
*/
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config);
$this->solidresParams = JComponentHelper::getParams('com_solidres');
$this->confirmationState = $this->solidresParams->get('confirm_state', 5);
}
/**
* Allow to processing of Reservation data after it is saved.
*
* @param object $data
* @param object $table
* @param boolean $isNew
* @param object $model
*
* @since 1.6
*/
function onReservationAfterSave($data, $table, $isNew, $model)
{
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_solidres/tables');
$dbo = JFactory::getDbo();
$srReservation = SRFactory::get('solidres.reservation.reservation');
$srRoomType = SRFactory::get('solidres.roomtype.roomtype');
$query = $dbo->getQuery(true);
$reservationId = $table->id;
$roomTypePricesMapping = $model->getState($model->getName() . '.room_type_prices_mapping', null);
$tariffTable = JTable::getInstance('Tariff', 'SolidresTable');
$roomTable = JTable::getInstance('Room', 'SolidresTable');
$reservationMeta = [];
// First if this is a reservation edit, we have to clear the old records first
if (!$isNew)
{
$query->clear();
$query->select('rrx.*, r.room_type_id')
->from($dbo->quoteName('#__sr_reservation_room_xref', 'rrx'))
->leftJoin($dbo->quoteName('#__sr_rooms', 'r') . ' ON r.id = rrx.room_id')
->where('reservation_id = ' . $reservationId);
$reservationRooms = $dbo->setQuery($query)->loadAssocList();
$data['previous_data']['rooms'] = $reservationRooms;
$query->clear();
$query->delete()
->from($dbo->quoteName('#__sr_reservation_room_details'));
// Delete all details of all rooms in this reservations
$query->where('reservation_room_id IN (SELECT id
FROM ' . $dbo->quoteName('#__sr_reservation_room_xref') . '
WHERE reservation_id = ' . $reservationId . ' )');
$dbo->setQuery($query)->execute();
$query->clear();
$query->delete()
->from($dbo->quoteName('#__sr_reservation_room_xref'))
->where('reservation_id = ' . $reservationId);
$dbo->setQuery($query);
$dbo->execute();
$query->clear();
$query->delete()
->from($dbo->quoteName('#__sr_reservation_room_extra_xref'))
->where('reservation_id = ' . $reservationId);
$dbo->setQuery($query);
$dbo->execute();
}
// Insert new records
$isReservationFailed = false;
if (isset($data['room_types']) && is_array($data['room_types']))
{
foreach ($data['room_types'] as $roomTypeId => $bookedTariffs)
{
// If this index not exists, it means this reservation is created by guest
if (!isset($data['reservation_room_select']))
{
// Find a list of available rooms
$availableRoomList = $srRoomType->getListAvailableRoom($roomTypeId, $data['checkin'], $data['checkout'], $table->booking_type, 0, $this->confirmationState);
if (empty($availableRoomList))
{
$isReservationFailed = true;
break;
}
}
foreach ($bookedTariffs as $tariffId => $rooms)
{
foreach ($rooms as $roomIndex => $room)
{
// If this index not exists, it means this reservation is created by guest
if (!isset($data['reservation_room_select']))
{
// Pick the first and assign it
$pickedRoom = array_shift($availableRoomList);
}
else
{
// In this case, the room index is the room ID
$roomTable->load($roomIndex);
$pickedRoom = $roomTable;
}
// Get the tariff info
$tariffTable->load($tariffId);
// Prepare meta data
$reservationMeta['reserved_rooms'][] = $pickedRoom->label;
$room['room_id'] = $pickedRoom->id;
$room['room_label'] = $pickedRoom->label;
if (isset($roomTypePricesMapping)) // For normal booking (both front end and back end)
{
if ($roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_discount'] > 0)
{
$room['room_price'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_incl_discounted'];
$room['room_price_tax_incl'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_incl_discounted'];
$room['room_price_tax_excl'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_excl_discounted'];
}
else
{
$room['room_price'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_incl'];
$room['room_price_tax_incl'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_incl'];
$room['room_price_tax_excl'] = $roomTypePricesMapping[$roomTypeId][$tariffId][$roomIndex]['total_price_tax_excl'];
}
}
$room['tariff_id'] = $tariffId > 0 ? $tariffId : null;
$room['tariff_title'] = !empty($tariffTable->title) ? $tariffTable->title : '';
$room['tariff_description'] = !empty($tariffTable->description) ? $tariffTable->description : '';
$srReservation->storeRoom($reservationId, $room);
// Insert new records for extras per room
if (isset($room['extras']))
{
foreach ($room['extras'] as $extraId => $extraDetails)
{
if (isset($extraDetails['quantity']))
{
$srReservation->storeExtra($reservationId, $room['room_id'], $room['room_label'], $extraId, $extraDetails['name'], $extraDetails['quantity'], $extraDetails['total_extra_cost_tax_incl']);
}
else
{
$srReservation->storeExtra($reservationId, $room['room_id'], $room['room_label'], $extraId, $extraDetails['name'], null, $extraDetails['total_extra_cost_tax_incl']);
}
}
}
}
}
}
}
if ($isReservationFailed)
{
$noRoomReservationStatus = $this->solidresParams->get('default_reservation_no_room_state', 4);
$table->state = $noRoomReservationStatus;
$table->check();
$table->store();
$model->setState($model->getName() . '.save_failed_reasons', array('RoomNotAvailable'));
}
// Store extra items (Per booking)
if (!$isNew)
{
$query->clear();
$query->delete()->from($dbo->quoteName('#__sr_reservation_extra_xref'))->where('reservation_id = ' . $reservationId);
$dbo->setQuery($query);
$dbo->execute();
}
if (isset($data['extras']))
{
foreach ($data['extras'] as $extraId => $extraDetails)
{
$reservationExtraData = array(
'reservation_id' => $reservationId,
'extra_id' => $extraId,
'extra_name' => $extraDetails['name'],
'extra_quantity' => (isset($extraDetails['quantity']) ? $extraDetails['quantity'] : null),
'extra_price' => $extraDetails['total_extra_cost_tax_incl']
);
$tableReservationExtra = JTable::getInstance('ReservationExtra', 'SolidresTable');
$tableReservationExtra->bind($reservationExtraData);
$tableReservationExtra->check();
$tableReservationExtra->store();
$tableReservationExtra->reset();
}
}
// Update the quantity of coupon
if ($isNew)
{
if (isset($data['coupon_id']) && $data['coupon_id'] > 0)
{
$tableCoupon = JTable::getInstance('Coupon', 'SolidresTable');
$tableCoupon->load($data['coupon_id']);
if (!is_null($tableCoupon->quantity) && $tableCoupon->quantity > 0)
{
$tableCoupon->quantity -= 1;
$tableCoupon->check();
$tableCoupon->store();
$tableCoupon->reset();
}
}
}
// Store meta data
if (!empty($reservationMeta))
{
$table->reservation_meta = json_encode($reservationMeta);
$table->check();
$table->store();
}
// Run event
JPluginHelper::importPlugin('solidres');
JFactory::getApplication()->triggerEvent('onReservationAfterSaveComplete', array($data, $table, $isNew, $model));
}
/*function onReservationAssetBeforeSave($data, $table, $isNew) {}*/
/**
* Allow to processing of ReservationAsset data after it is saved.
*
* @param object $data The data representing the ReservationAsset.
* @param object $table
* @param boolean $result
* @param boolean $isNew True is this is new data, false if it is existing data.
*
* @throws Exception
* @return boolean
* @since 1.6
*/
public function onReservationAssetAfterSave($data, $table, $result, $isNew)
{
$dbo = JFactory::getDbo();
$query = $dbo->getQuery(true);
// Process extra fields
if ($table->id && $result && isset($data['reservationasset_extra_fields']) && (count($data['reservationasset_extra_fields'])))
{
try
{
$query->clear();
$query->delete()->from($dbo->quoteName('#__sr_reservation_asset_fields'));
$query->where('reservation_asset_id = ' . $table->id);
$query->where("field_key LIKE 'reservationasset_extra_fields.%'");
$dbo->setQuery($query);
if (!$dbo->execute())
{
throw new Exception($dbo->getErrorMsg());
}
$tuples = array();
$order = 1;
foreach ($data['reservationasset_extra_fields'] as $k => $v)
{
$tuples[] = '(' . $table->id . ', ' . $dbo->quote('reservationasset_extra_fields.' . $k) . ', ' . $dbo->quote($v) . ', ' . $order++ . ')';
}
$dbo->setQuery('INSERT INTO ' . $dbo->quoteName('#__sr_reservation_asset_fields') . ' VALUES ' . implode(', ', $tuples));
if (!$dbo->execute())
{
throw new Exception($dbo->getErrorMsg());
}
}
catch (JException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
// end of extra field processing
// Process Paylater's payment fields
$solidresConfig = new SRConfig(array('scope_id' => $table->id, 'data_namespace' => 'payments/paylater'));
$solidresConfig->set(array(
'paylater_enabled' => $data['payments']['paylater_enabled'],
'paylater_is_default' => $data['payments']['paylater_is_default'],
'paylater_frontend_message' => $data['payments']['paylater_frontend_message'],
'paylater_base_rate' => $data['payments']['paylater_base_rate'],
'paylater_base_rate_value' => $data['payments']['paylater_base_rate_value'],
));
// Process BankWire's payment fields
$solidresConfig = new SRConfig(array('scope_id' => $table->id, 'data_namespace' => 'payments/bankwire'));
$solidresConfig->set(array(
'bankwire_enabled' => $data['payments']['bankwire_enabled'],
'bankwire_is_default' => $data['payments']['bankwire_is_default'],
'bankwire_frontend_message' => $data['payments']['bankwire_frontend_message'],
'bankwire_accountname' => $data['payments']['bankwire_accountname'],
'bankwire_accountdetails' => $data['payments']['bankwire_accountdetails'],
'bankwire_base_rate' => $data['payments']['bankwire_base_rate'],
'bankwire_base_rate_value' => $data['payments']['bankwire_base_rate_value'],
));
// End of processing payment fields
}
/**
* Allow to processing of unit data after it is saved.
*
* @param object $data The data representing the unit.
* @param object $table
* @param boolean $isNew True is this is new data, false if it is existing data.
*
* @throws Exception
* @return void
* @since 1.6
*/
public function onRoomTypeAfterSave($data, $table, $isNew)
{
$dbo = JFactory::getDbo();
$query = $dbo->getQuery(true);
$srRoomType = SRFactory::get('solidres.roomtype.roomtype');
$nullDate = substr($dbo->getNullDate(), 0, 10);
$context = 'com_solidres.edit.roomtype';
// == Processing tariff/prices == //
// Check the current currency_id of this roomtype's reservation asset.
$query->clear();
$query->select('currency_id');
$query->from($dbo->quoteName('#__sr_reservation_assets'));
$query->where('id = ' . (int) $data['reservation_asset_id']);
$currencyId = $dbo->setQuery($query)->loadResult();
// Store the default tariff
if (isset($data['default_tariff']) && is_array($data['default_tariff']))
{
$tariffId = key($data['default_tariff']);
$tariffData = array(
'id' => $tariffId > 0 ? $tariffId : null,
'currency_id' => $currencyId,
'customer_group_id' => null,
'valid_from' => $nullDate,
'valid_to' => $nullDate,
'room_type_id' => $table->id,
'title' => $data['standard_tariff_title'],
'description' => $data['standard_tariff_description'],
'd_min' => null,
'd_max' => null,
'p_min' => null,
'p_max' => null,
'type' => 0, // Default is per room per night
'limit_checkin' => '',
'state' => 1
);
foreach ($data['default_tariff'][$tariffId] as $detailId => $detailInfo)
{
foreach ($detailInfo as $day => $price)
{
$tariffData['details']['per_room'][$day]['id'] = $detailId > 0 ? $detailId : null;
$tariffData['details']['per_room'][$day]['price'] = $price;
$tariffData['details']['per_room'][$day]['w_day'] = $day;
$tariffData['details']['per_room'][$day]['guest_type'] = null;
$tariffData['details']['per_room'][$day]['from_age'] = null;
$tariffData['details']['per_room'][$day]['to_age'] = null;
}
}
$tariffModel = JModelLegacy::getInstance('Tariff', 'SolidresModel', array('ignore_request' => true));
$tariffModel->save($tariffData);
}
// == Processing tariff/prices == //
$query->clear();
$query->delete($dbo->quoteName('#__sr_room_type_coupon_xref'))->where('room_type_id = ' . $dbo->quote($table->id));
$dbo->setQuery($query);
$result = $dbo->execute();
if (!$result)
{
JFactory::getApplication()->enqueueMessage('plgExtensionSolidres::onRoomTypeAfterSave: Delete from ' . $dbo->quoteName('#__sr_room_type_coupon_xref') . ' failure', 'warning');
}
if (isset($data['coupon_id']) && count($data['coupon_id']))
{
foreach ($data['coupon_id'] as $value)
{
$srRoomType->storeCoupon($table->id, $value);
}
}
$query->clear();
$query->delete($dbo->quoteName('#__sr_room_type_extra_xref'))->where('room_type_id = ' . $dbo->quote($table->id));
$dbo->setQuery($query);
$result = $dbo->execute();
if (!$result)
{
JFactory::getApplication()->enqueueMessage('plgExtensionSolidres::onRoomTypeAfterSave: Delete from ' . $dbo->quoteName('#__sr_room_type_extra_xref') . ' failure', 'warning');
}
if (isset($data['extra_id']) && count($data['extra_id']))
{
foreach ($data['extra_id'] as $value)
{
$srRoomType->storeExtra($table->id, $value);
}
}
if (isset($data['rooms']) && count($data['rooms']))
{
foreach ($data['rooms'] as $value)
{
if ($value['id'] == 'new' && !empty($value['label']))
{
$srRoomType->storeRoom($table->id, $value['label']);
}
else if ($value['id'] > 0 && !empty($value['label']))
{
$srRoomType->storeRoom($table->id, $value['label'], $value['id']);
}
}
}
// Process extra fields
if ($table->id && $result && isset($data['roomtype_custom_fields']) && (count($data['roomtype_custom_fields'])))
{
try
{
$query->clear();
$query->delete()->from($dbo->quoteName('#__sr_room_type_fields'));
$query->where('room_type_id = ' . $table->id);
$query->where("field_key LIKE 'roomtype_custom_fields.%'");
$dbo->setQuery($query);
if (!$dbo->execute())
{
throw new Exception($dbo->getErrorMsg());
}
$tuples = array();
$order = 1;
foreach ($data['roomtype_custom_fields'] as $k => $v)
{
$tuples[] = '(' . $table->id . ', ' . $dbo->quote('roomtype_custom_fields.' . $k) . ', ' . $dbo->quote($v) . ', ' . $order++ . ')';
}
$dbo->setQuery('INSERT INTO ' . $dbo->quoteName('#__sr_room_type_fields') . ' VALUES ' . implode(', ', $tuples));
if (!$dbo->execute())
{
throw new Exception($dbo->getErrorMsg());
}
}
catch (JException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
// If this room type is a result of copying, copy complex tariffs
$isCopying = JFactory::getApplication()->getUserState($context . '.is_copying_room_type', false);
if ($isCopying)
{
$isCopyingFrom = JFactory::getApplication()->getUserState($context . '.is_copying_room_type_from', false);
$query->clear();
$query->select('id')->from($dbo->quoteName('#__sr_tariffs'))->where('room_type_id = ' . (int) $isCopyingFrom)
->where('valid_from != ' . $dbo->quote('0000-00-00'))
->where('valid_to != ' . $dbo->quote('0000-00-00'));
$copiedTariffs = $dbo->setQuery($query)->loadObjectList();
foreach ($copiedTariffs as $copiedTariff)
{
$tariffModel = JModelLegacy::getInstance('Tariff', 'SolidresModel', array('ignore_request' => true));
$copiedTariffData = get_object_vars($tariffModel->getItem($copiedTariff->id));
$copiedTariffData['room_type_id'] = $table->id;
$copiedTariffData['id'] = null;
if ($copiedTariffData['mode'] == 1)
{
$copiedTariffData['details'] = json_decode(json_encode($copiedTariffData['details']), true);
if (isset($copiedTariffData['details']) && is_array($copiedTariffData['details']))
{
foreach ($copiedTariffData['details'] as $type => $months)
{
$flatten = array();
foreach ($months as $month => $dates)
{
$flatten = array_merge($flatten, $dates);
}
$copiedTariffData['details'][$type] = $flatten;
}
}
}
foreach ($copiedTariffData['details'] as $tariffType => &$details)
{
foreach ($details as &$detail)
{
$detail = (array) $detail;
$detail['id'] = null;
}
}
$tariffModel->save($copiedTariffData);
}
JFactory::getApplication()->setUserState($context . '.is_copying_room_type', false);
JFactory::getApplication()->setUserState($context . '.is_copying_room_type_from', false);
}
}
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
* @since 1.6
*/
public function onReservationAssetPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_solidres.reservationasset')))
{
return true;
}
// Add the registration fields to the form.
JForm::addFormPath(__DIR__ . '/fields');
$form->loadFile('reservationasset', false);
// Toggle whether the checkin time field is required.
if ($this->params->get('param_reservation_asset_checkin_time', 1) > 0)
{
$form->setFieldAttribute('checkin_time', 'required', $this->params->get('param_reservation_asset_checkin_time') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('checkin_time', 'reservationasset_extra_fields');
}
// Toggle whether the checkout time field is required.
if ($this->params->get('param_reservation_asset_checkout_time', 1) > 0)
{
$form->setFieldAttribute('checkout_time', 'required', $this->params->get('param_reservation_asset_checkout_time') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('checkout_time', 'reservationasset_extra_fields');
}
// Toggle whether the cancellation prepayment field is required.
if ($this->params->get('param_reservation_asset_cancellation_prepayment', 1) > 0)
{
$form->setFieldAttribute('cancellation_prepayment', 'required', $this->params->get('param_reservation_asset_cancellation_prepayment') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('cancellation_prepayment', 'reservationasset_extra_fields');
}
// Toggle whether the children and extra beds field is required.
if ($this->params->get('param_reservation_asset_children_and_extra_beds', 1) > 0)
{
$form->setFieldAttribute('children_and_extra_beds', 'required', $this->params->get('param_reservation_asset_children_and_extra_beds') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('children_and_extra_beds', 'reservationasset_extra_fields');
}
// Toggle whether the children and extra beds field is required.
if ($this->params->get('param_reservation_asset_pets', 1) > 0)
{
$form->setFieldAttribute('pets', 'required', $this->params->get('param_reservation_asset_pets') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('pets', 'reservationasset_extra_fields');
}
// Toggle whether the facebook field is required.
if ($this->params->get('param_reservation_asset_facebook', 1) > 0)
{
$form->setFieldAttribute('facebook', 'required', $this->params->get('param_reservation_asset_facebook') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('facebook', 'reservationasset_extra_fields');
}
// Toggle whether the twitter field is required.
if ($this->params->get('param_reservation_asset_twitter', 1) > 0)
{
$form->setFieldAttribute('twitter', 'required', $this->params->get('param_reservation_asset_twitter') == 2, 'reservationasset_extra_fields');
}
else
{
$form->removeField('twitter', 'reservationasset_extra_fields');
}
return true;
}
/**
* @param string $context The context for the data
* @param int $data The user id
*
* @return boolean
* @since 1.6
*/
public function onReservationAssetPrepareData($context, $data)
{
// Check we are manipulating a valid form.
if (!in_array($context, array('com_solidres.reservationasset')))
{
return true;
}
if (is_object($data))
{
$reservationAssetId = isset($data->id) ? $data->id : 0;
// Load the custom fields data from the database.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('field_key, field_value')->from($db->quoteName('#__sr_reservation_asset_fields'));
$query->where('reservation_asset_id = ' . (int) $reservationAssetId);
$query->where("field_key LIKE 'reservationasset_extra_fields.%'");
$db->setQuery($query);
try
{
$results = $db->loadRowList();
}
catch (RuntimeException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
// Merge the custom fields data into current form data
$data->reservationasset_extra_fields = array();
foreach ($results as $v)
{
$k = str_replace('reservationasset_extra_fields.', '', $v[0]);
$data->reservationasset_extra_fields[$k] = $v[1];
}
// Load the payments config data
$solidresConfig = new SRConfig(array('scope_id' => (int) $reservationAssetId));
if (!isset($data->payments))
{
$data->payments = null;
}
$data->payments = array_merge((array) $data->payments, array(
'paylater_enabled' => $solidresConfig->get('payments/paylater/paylater_enabled'),
'paylater_is_default' => $solidresConfig->get('payments/paylater/paylater_is_default'),
'paylater_frontend_message' => $solidresConfig->get('payments/paylater/paylater_frontend_message'),
'paylater_base_rate' => $solidresConfig->get('payments/paylater/paylater_base_rate'),
'paylater_base_rate_value' => $solidresConfig->get('payments/paylater/paylater_base_rate_value'),
'bankwire_enabled' => $solidresConfig->get('payments/bankwire/bankwire_enabled'),
'bankwire_is_default' => $solidresConfig->get('payments/bankwire/bankwire_is_default'),
'bankwire_frontend_message' => $solidresConfig->get('payments/bankwire/bankwire_frontend_message'),
'bankwire_accountname' => $solidresConfig->get('payments/bankwire/bankwire_accountname'),
'bankwire_accountdetails' => $solidresConfig->get('payments/bankwire/bankwire_accountdetails'),
'bankwire_base_rate' => $solidresConfig->get('payments/bankwire/bankwire_base_rate'),
'bankwire_base_rate_value' => $solidresConfig->get('payments/bankwire/bankwire_base_rate_value'),
));
}
return true;
}
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
* @since 1.6
*/
public function onRoomTypePrepareForm($form, $data)
{
// Load solidres plugin language
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
if (!in_array($form->getName(), array('com_solidres.roomtype')))
{
return true;
}
// Add the registration fields to the form.
JForm::addFormPath(__DIR__ . '/fields');
$form->loadFile('roomtype', false);
// Toggle whether the checkin time field is required.
if ($this->params->get('param_roomtype_room_facilities', 1) > 0)
{
$form->setFieldAttribute('room_facilities', 'required', $this->params->get('param_roomtype_room_facilities') == 2, 'roomtype_custom_fields');
}
else
{
$form->removeField('room_facilities', 'roomtype_custom_fields');
}
// Toggle whether the checkout time field is required.
if ($this->params->get('param_roomtype_room_size', 1) > 0)
{
$form->setFieldAttribute('room_size', 'required', $this->params->get('param_roomtype_room_size') == 2, 'roomtype_custom_fields');
}
else
{
$form->removeField('room_size', 'roomtype_custom_fields');
}
// Toggle whether the cancellation prepayment field is required.
if ($this->params->get('param_roomtype_bed_size', 1) > 0)
{
$form->setFieldAttribute('bed_size', 'required', $this->params->get('param_roomtype_bed_size') == 2, 'roomtype_custom_fields');
}
else
{
$form->removeField('bed_size', 'roomtype_custom_fields');
}
return true;
}
/**
* @param string $context The context for the data
* @param int $data The user id
*
* @return boolean
* @since 1.6
*/
public function onRoomTypePrepareData($context, $data)
{
// Check we are manipulating a valid form.
if (!in_array($context, array('com_solidres.roomtype')))
{
return true;
}
if (is_object($data))
{
$roomTypeId = isset($data->id) ? $data->id : 0;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('field_key, field_value')->from($db->quoteName('#__sr_room_type_fields'));
$query->where('room_type_id = ' . (int) $roomTypeId);
$query->where("field_key LIKE 'roomtype_custom_fields.%'");
$db->setQuery($query);
try
{
$results = $db->loadRowList();
}
catch (RuntimeException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
// Merge the profile data.
$data->roomtype_custom_fields = array();
foreach ($results as $v)
{
$k = str_replace('roomtype_custom_fields.', '', $v[0]);
$data->roomtype_custom_fields[$k] = $v[1];
}
}
return true;
}
/**
* Example after save content method
* Article is passed by reference, but after the save, so no changes will be saved.
* Method is called right after the content is saved
*
* @param string The context of the content passed to the plugin (added in 1.6)
* @param object A JTableContent object
* @param bool If the content is just about to be created
* @param array Full data of tariff with tariff details included
*
* @return boolean
* @since 1.6
*/
public function onTariffAfterSave($context, $table, $isNew, $tariff)
{
if (!isset($tariff['details']))
{
return true;
}
foreach ($tariff['details'] as $tariffType => $details)
{
foreach ($details as $detail)
{
$tariffDetailsTable = JTable::getInstance('TariffDetails', 'SolidresTable');
if (isset($detail['id']))
{
$tariffDetailsTable->load($detail['id']);
}
$detail['tariff_id'] = $table->id;
if (($tariff['type'] == 1 || $tariff['type'] == 3) && substr($detail['guest_type'], 0, 5) == 'child')
{
$detail['from_age'] = $tariff[$detail['guest_type']]['from_age'];
$detail['to_age'] = $tariff[$detail['guest_type']]['to_age'];
}
$tariffDetailsTable->bind($detail);
if ($tariffDetailsTable->price == '')
{
$tariffDetailsTable->price = null;
}
$tariffDetailsTable->check();
$tariffDetailsTable->store(true); // update null value
$tariffDetailsTable->reset();
}
}
}
/**
* Hook into reservation state changing event and send outgoing emails
*
* @param $context
* @param $pks
* @param $value
* @param $oldValue
*
* @return mixed
*
* @since 1.8.0
*/
public function onReservationChangeState($context, $pks, $value, $oldValue = null)
{
$solidresConfig = JComponentHelper::getParams('com_solidres');
if ($context != 'com_solidres.changestate' || $solidresConfig->get('send_email_on_reservation_state_change', 1) == 0)
{
return true;
}
$acceptedStatuses = $solidresConfig->get('status_trigger_reservation_state_change_email', array(4, 5));
if (!in_array($value, $acceptedStatuses))
{
return true;
}
$solidresReservation = SRFactory::get('solidres.reservation.reservation');
$cancellationState = $solidresConfig->get('cancel_state', 4);
// If the reservation's status is changed from any statuses to "Cancelled", send a normal HTML reservation email
if ($value == $cancellationState)
{
return $solidresReservation->sendEmail($pks[0], $value);
}
else // For other status changes, send a text email to notify user
{
return $solidresReservation->sendGenericReservationStatusChangeEmail($pks[0]);
}
}
public function onExtraAfterSave($context, $data, $table, $isNew)
{
$dbo = JFactory::getDbo();
$query = $dbo->getQuery(true);
$query->delete($dbo->quoteName('#__sr_extra_coupon_xref'))->where('extra_id = ' . $dbo->quote($table->id));
$dbo->setQuery($query);
$result = $dbo->execute();
if (!$result)
{
JFactory::getApplication()->enqueueMessage('plgExtensionSolidres::onRoomTypeAfterSave: Delete from ' . $dbo->quoteName('#__sr_extra_coupon_xref') . ' failure', 'warning');
}
if (isset($data['coupon_id']) && count($data['coupon_id']))
{
foreach ($data['coupon_id'] as $value)
{
$query->clear();
$query->insert($dbo->quoteName('#__sr_extra_coupon_xref'))
->columns(array($dbo->quoteName('extra_id'), $dbo->quoteName('coupon_id')))
->values((int) $table->id . ',' . (int) $value);
$dbo->setQuery($query)->execute();
}
}
}
public function onAjaxSolidres()
{
JLoader::register('SRWishList', JPATH_ADMINISTRATOR . '/components/com_solidres/helpers/wishlist.php');
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_solidres/tables');
$app = JFactory::getApplication();
$itemId = (int) $app->input->getUint('itemId');
$scope = $app->input->getString('scope');
$wishList = SRWishList::getInstance($scope);
if ($scope == 'experience' && !SRPlugin::isEnabled('experience'))
{
throw new RuntimeException('The Solidres experience is not enabled.');
}
if (strtolower($app->input->getString('type')) == 'add')
{
if ($scope == 'experience')
{
JTable::addIncludePath(SRPlugin::getAdminPath('experience') . '/tables');
$itemTable = JTable::getInstance('Experience', 'SolidresTable');
}
else
{
$itemTable = JTable::getInstance('ReservationAsset', 'SolidresTable');
}
if ($itemTable->load($itemId))
{
$history = $itemTable->getProperties();
$item = $wishList->add($itemId, $history)->load($itemId);
$item['history'] = $history;
$item['wishListUrl'] = JRoute::_('index.php?option=com_solidres&view=wishlist&scope=' . $scope, false);
return json_encode($item);
}
else
{
throw new RuntimeException('Item ID ' . $itemId . ' not found');
}
}
$wishList->clear($itemId);
$list = $wishList->load($itemId);
return empty($list) ? 0 : count($list);
}
}